Examples of CodeQualificationMap


Examples of org.openquark.cal.compiler.CodeQualificationMap

            }
           
            String qualifiedNewExpressionString = qualificationResults.getQualifiedCode();
           
            // Update the qualification map
            CodeQualificationMap newQualifiedMap = oldExpression.getQualificationMap();                       
            boolean qualificationMapWasUpdated = updateQualificationMap(newQualifiedMap);
            boolean moduleContextNeedsUpdating =
                (category == Category.MODULE_NAME && oldName.getModuleName().equals(oldExpression.getModuleContext()));
           
            if (!newExpressionString.equals(oldExpression.getExpressionText()) || qualificationMapWasUpdated || moduleContextNeedsUpdating) {
View Full Code Here

Examples of org.openquark.cal.compiler.CodeQualificationMap

        Element textElement = elements.get(1);
        XMLPersistenceHelper.checkTag(textElement, MetadataPersistenceConstants.EXPRESSION_CAL_TEXT_TAG);
        String calText = XMLPersistenceHelper.getElementStringValue(textElement);
       
        String qualifiedCalText = null;
        CodeQualificationMap qualificationMap = new CodeQualificationMap();
        if (elements.size() > 2) {
            // This check is done for backwards compatibility; the following code
            // is executed only for expressions which contain a qualification map.
           
            Element textElement2 = elements.get(2);
            XMLPersistenceHelper.checkTag(textElement2, MetadataPersistenceConstants.EXPRESSION_QUALIFIED_CAL_TEXT_TAG);
            qualifiedCalText = XMLPersistenceHelper.getElementStringValue(textElement2);
           
            qualificationMap.loadFromXML((Element)element);
        }
       
        if (calText == null) {
            calText = "";
        }
View Full Code Here

Examples of org.openquark.cal.compiler.CodeQualificationMap

        // We analyze using the userQualifiedIdentifiers since symbols
        // which we have previously selected a module for may appear in the code.
        // The map in the qualification results will have unnecessary entries removed,
        // and this is what we store in the codegem.

        CodeQualificationMap currentQualificationMap = userQualifiedIdentifiers;       
        CodeAnalyser.AnalysisResults results = codeAnalyser.analyseCode(codeGemBodyText, varNamesWhichAreArgs, currentQualificationMap);

        // Add any new arguments to the set of existing argument names
        varNamesWhichAreArgs.addAll(Arrays.asList(results.getAllArgumentNames()));
View Full Code Here

Examples of org.openquark.cal.compiler.CodeQualificationMap

            varNamesWhichAreArgs.remove(unqualifiedName);
        }

        // Change the module mapping

        CodeQualificationMap qualificationMap = userQualifiedIdentifiers;
        qualificationMap.removeQualification(unqualifiedName, qualificationForm);
        qualificationMap.putQualification(unqualifiedName, newModule, qualificationForm);

        // re-evaluate the gem based on the new variable form
        doSyntaxSmarts();

        if (recordingEditStates) {
View Full Code Here

Examples of org.openquark.cal.compiler.CodeQualificationMap

            String fullyQualifiedText = editor.getQualifiedCodeText(editor.getSelectionStart(), editor.getSelectionEnd(), codeAnalyser);

            // Run through the selected identifiers, and build up a map of the
            // used qualifications and arguments.
            Set<String> argumentNames = new LinkedHashSet<String>();
            CodeQualificationMap qualificationMap = new CodeQualificationMap();
            List<AnalysedIdentifier> selectedIdentifiers = editor.getSelectedIdentifiers(editor.getSelectionStart(), editor.getSelectionEnd());
            for (final CodeAnalyser.AnalysedIdentifier identifier : selectedIdentifiers) {

                if (identifier.getQualificationType() == QualificationType.UnqualifiedResolvedTopLevelSymbol) {
                    qualificationMap.putQualification(identifier.getName(), identifier.getResolvedModuleName(), identifier.getCategory());

                } else if ((varNamesWhichAreArgs != null)
                        && (identifier.getQualificationType() == QualificationType.UnqualifiedArgument)
                        && (varNamesWhichAreArgs.contains(identifier.getName()))) {
                    argumentNames.add(identifier.getName());
View Full Code Here

Examples of org.openquark.cal.compiler.CodeQualificationMap

                (CodeTextTransferable.CodeTextStructure)t.getTransferData(CodeTextTransferable.codeStructureFlavor);

            // Combine the new map entries into our own

            if (userQualifiedIdentifiers != null) {
                CodeQualificationMap codeQualificationMap = codeTextStructure.getQualificationMap();
                appendToEditorMap(codeQualificationMap, SourceIdentifier.Category.DATA_CONSTRUCTOR);
                appendToEditorMap(codeQualificationMap, SourceIdentifier.Category.TOP_LEVEL_FUNCTION_OR_CLASS_METHOD);
                appendToEditorMap(codeQualificationMap, SourceIdentifier.Category.TYPE_CLASS);
                appendToEditorMap(codeQualificationMap, SourceIdentifier.Category.TYPE_CONSTRUCTOR);
            }
View Full Code Here

Examples of org.openquark.cal.compiler.CodeQualificationMap

        String codeString = new String(codeText);
        String updatedCodeString = codeString;
       
        // Load the qualification map
        Element qualificationMapElement = XMLPersistenceHelper.getChildElement(codeElement, CodeQualificationMap.QUALIFICATION_MAP_TAG);
        CodeQualificationMap qualificationMap = new CodeQualificationMap();
        if (qualificationMapElement != null) {
            qualificationMap.loadFromXML(codeElement);
        }
       
        if (category != SourceIdentifier.Category.MODULE_NAME) {
            QualifiedName qualificationMapEntry = qualificationMap.getQualifiedName(oldName.getUnqualifiedName(), category);
            if (oldName.equals(qualificationMapEntry)) {
                // The old name is in the qualification map. This means there might be an unqualified reference to the symbol that when
                // renamed might clash with one of the arguments. Let's check for that now.
               
                // First, load the arguments
                Element argsElement = (childElems.size() < 4) ? null : (Element) childElems.get(3);
                XMLPersistenceHelper.checkIsElement(argsElement);
                XMLPersistenceHelper.checkTag(argsElement, GemPersistenceConstants.CODE_GEM_ARGUMENTS_TAG);
               
                // We'll create both a list (for easy iteration) and a set (for easy membership checks).
                List<Element> argNodes = XMLPersistenceHelper.getChildElements(argsElement, GemPersistenceConstants.CODE_GEM_ARGUMENT_TAG);
                int numArgs = argNodes.size();
                String[] argNames = new String[numArgs];
                for (int i = 0; i < numArgs; i++) {
                    Element argNode = argNodes.get(i);               
                    argNames[i] = argNode.getAttribute(GemPersistenceConstants.CODE_GEM_ARGUMENT_NAME_ATTR);
                }
                List<String> argNamesList = Arrays.asList(argNames);
                Set<String> argNamesSet = new HashSet<String>(argNamesList);
               
                // Next, loop over the arguments and look for the conflict..
                for (int i = 0, n = argNamesList.size(); i < n; i++) {
                    String argName = argNamesList.get(i);
                    if (argName.equals(newName.getUnqualifiedName())) {
                        // Here we are. The new name is going to collide with this argument's name.
                        // We are going to have to rename this argument.
                        QualifiedName oldArgName = QualifiedName.make(moduleName, argName);
                       
                        // Figure out a suitable new name for the argument that does not conflict with anything else.
                        int suffix = 1;
                        QualifiedName newArgName;
                        while (true) {
                            String potentialName = argName + suffix;
                           
                            // Make sure that the new potential name is not the name of another argument and is not in the qualification map
                            if (!argNamesSet.contains(potentialName) &&
                                    (qualificationMap.getQualifiedName(
                                            potentialName, SourceIdentifier.Category.TOP_LEVEL_FUNCTION_OR_CLASS_METHOD) == null)) {
                                newArgName = QualifiedName.make(moduleName, potentialName);
                                break;
                            }
                            suffix++;
                        }
                       
                        // Update the reference to the argument in the code expression
                        updatedCodeString = typeChecker.calculateUpdatedCodeExpression(codeString, moduleName, moduleNameResolver, qualificationMap, oldArgName, newArgName, SourceIdentifier.Category.TOP_LEVEL_FUNCTION_OR_CLASS_METHOD, null);
                       
                        // Create a new argument node and replace the old one with it.
                        Element oldArgNode = argNodes.get(i);
                        Element newArgNode = document.createElement(GemPersistenceConstants.CODE_GEM_ARGUMENT_TAG);
                        newArgNode.setAttribute(GemPersistenceConstants.CODE_GEM_ARGUMENT_NAME_ATTR, newArgName.getUnqualifiedName());
                        argsElement.replaceChild(newArgNode, oldArgNode);
                       
                        changesMade = true;
                        break;
                       
                    }
                }
            }
        }
       
        // Update the code expression
        updatedCodeString = typeChecker.calculateUpdatedCodeExpression(updatedCodeString, moduleName, moduleNameResolver, qualificationMap, oldName, newName, category, null);
        if (!updatedCodeString.equals(codeString)) {
            CDATASection newCodeChild = XMLPersistenceHelper.createCDATASection(document, updatedCodeString);
            codeElement.replaceChild(newCodeChild, codeChild);
            changesMade = true;
        }        
       
       
        // Update the qualification map
        if (qualificationMap != null) {
            if (updateQualificationMap(qualificationMap)) {
                codeElement.removeChild(qualificationMapElement);
                qualificationMap.saveToXML(codeElement);
                changesMade = true;               
            }
        }
        return changesMade;
    }
View Full Code Here

Examples of org.openquark.cal.compiler.CodeQualificationMap

     */
    @Override
    NavExampleEditor makeNewEditor() {
        // Create a default expression and example
        ModuleName moduleName = getEditorPanel().getNavigatorOwner().getPerspective().getWorkingModuleName();
        CALExpression expression = new CALExpression(moduleName, "", new CodeQualificationMap(), "");
        CALExample example = new CALExample(expression, "", true);
       
        return new NavExampleEditor(this, example);
    }
View Full Code Here

Examples of org.openquark.cal.compiler.CodeQualificationMap

        super(0);

        setName(DEFAULT_NAME);
       
        // Create an empty qualification map
        qualificationMap = new CodeQualificationMap();
       
        // Initialize code and arguments to nothing
        qualifiedCode = "";
        visibleCode = "";
View Full Code Here

Examples of org.openquark.cal.compiler.CodeQualificationMap

        }
       
        // Set the code
        setQualifiedCode(CAL_Prelude.Functions.error.getQualifiedName() + " \"Uninitialized code gem.\"");
        visibleCode = qualifiedCode;
        qualificationMap = new CodeQualificationMap();

        // Set the arguments
        setArguments(codeGemArguments);

        // Set the code result type.
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.