Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.ModuleTypeInfo


                /** Get the target collector and dump it's definition to the console */
                public void actionPerformed(ActionEvent evt) {
                    CollectorGem targetCollector = tableTop.getTargetCollector();
                    Target targetGem = tableTop.getDisplayedGem(targetCollector).getTarget();                   
                    MetaModule currentMetaModule = getWorkspace().getMetaModule(getWorkingModuleName());
                    ModuleTypeInfo currentModuleTypeInfo = currentMetaModule.getTypeInfo();
                   
                    System.out.println("Gem Definition:");
                    System.out.println(targetGem.getTargetDef(null, currentModuleTypeInfo)+"\n");
                   
                }
View Full Code Here


     * @return the representation of the library class.
     * @throws UnableToResolveForeignEntityException
     */
    private static JavaClassRep makeLibraryClass(final JavaScope libClassScope, final JavaTypeName libClassName, final ModuleName moduleName, final ProgramModelManager programModelManager, final Monitor monitor) throws UnableToResolveForeignEntityException {
       
        final ModuleTypeInfo moduleTypeInfo = programModelManager.getModuleTypeInfo(moduleName);
        final LECCModule module = (LECCModule)programModelManager.getModule(moduleName);
        final ScopedEntityNamingPolicy.UnqualifiedInCurrentModuleOrInPreludeIfUnambiguous scopedEntityNamingPolicy =
            new ScopedEntityNamingPolicy.UnqualifiedInCurrentModuleOrInPreludeIfUnambiguous(moduleTypeInfo);
       
        final JavaClassRep classRep = new JavaClassRep(libClassName, JavaTypeName.OBJECT, libClassScope.getModifier()|Modifier.FINAL, new JavaTypeName[0]);
       
        // Code fragment:
        //
        // private {LibClassConstructorName} {}
        //
       
        classRep.addConstructor(makePrivateConstructor(libClassName));

        // We sort the functional agents, because the order returned by the ModuleTypeInfo is neither source order nor alphabetical order
        // Case-sensitive ordering would order data constructors ahead of functions
        final FunctionalAgent[] functionalAgents = moduleTypeInfo.getFunctionalAgents();
        Arrays.sort(functionalAgents, new Comparator<FunctionalAgent>() {
            public int compare(final FunctionalAgent a, final FunctionalAgent b) {
                return a.getName().compareTo(b.getName());
            }});
       
        final Map<String, String> methodNameMapping = sanitizeMethodNamesForJava(functionalAgents);
        final JavadocCrossReferenceGenerator crossRefGen = new JavadocLinkGenerator(methodNameMapping, scopedEntityNamingPolicy);
       
        // Add each functional agent as a method if it has a visible scope and it is not an overloaded function
        for (final FunctionalAgent functionalAgent : functionalAgents) {
            if (isScopeVisibleAsJavaLibraryAPI(functionalAgent.getScope())) {
                // Check that the functional agent has a type that can be handled.
                final TypeExpr functionalAgentType = functionalAgent.getTypeExpr();
               
                if (!hasTypeClassConstraints(functionalAgentType)) {
                   
                    final Pair<List<ClassTypeInfo>, ClassTypeInfo> argTypesAndReturnType = getArgTypesAndReturnTypeForLibraryMethod(functionalAgentType);
                    final List<ClassTypeInfo> argTypes = argTypesAndReturnType.fst();
                    final ClassTypeInfo returnType = argTypesAndReturnType.snd();
                   
                    final JavaMethod unboxedArgsVariant =
                        makeLibraryMethod(module, functionalAgent, functionalAgentType, argTypes, returnType, scopedEntityNamingPolicy, crossRefGen, methodNameMapping);
                   
                    classRep.addMethod(unboxedArgsVariant);
                   
                    if (hasNonCalValueArgument(argTypes)) {
                        // The first method has at least one unboxed/foreign argument, so we create a second version
                        // that takes all arguments as CalValues
                       
                        final int nArgs = argTypes.size();
                        final List<ClassTypeInfo> calValueArgTypes = new ArrayList<ClassTypeInfo>();
                        for (int i = 0; i < nArgs; i++) {
                            calValueArgTypes.add(ClassTypeInfo.makeNonForeign());
                        }
                       
                        final JavaMethod calValueArgsVariant =
                            makeLibraryMethod(module, functionalAgent, functionalAgentType, calValueArgTypes, returnType, scopedEntityNamingPolicy, crossRefGen, methodNameMapping);
                       
                        classRep.addMethod(calValueArgsVariant);
                    }
                } else {
                    // Report that the functional agent was skipped because its type contains type class constraints
                    if (functionalAgent instanceof ClassMethod) {
                        monitor.skippingClassMethod(functionalAgent.getName());
                    } else {
                        // an overloaded functional agent is really either a class method or a function, and never a data cons
                        monitor.skippingFunctionWithTypeClassConstraints(functionalAgent.getName());
                    }
                }
            }
        }
       
        // Add the Javadoc
        classRep.setJavaDoc(
            new JavaDocComment(CALDocToJavaDocUtilities.getJavadocFromCALDocComment(
                moduleTypeInfo.getCALDocComment(), true, null, null, null,
                scopedEntityNamingPolicy, crossRefGen, true, true, false, true)));

        ////
        /// Add the static check
        //
View Full Code Here

       
        if (namespaceName.isProperPrefixOf(workingModule.getName())) {
            return true;
        }
       
        final ModuleTypeInfo moduleTypeInfo = workingModule.getTypeInfo();
        final int n = moduleTypeInfo.getNImportedModules();
        for (int i = 0; i < n; i++) {
            if (namespaceName.isProperPrefixOf(moduleTypeInfo.getNthImportedModule(i).getModuleName())) {
                return true;
            }
        }
       
        return false;
View Full Code Here

     * @param provider The CategoryNodeProvider to provide custom nodes to represent the categories.
     * @param reuseNodes whether to try to reuse child nodes when re-categorizing a given node.
     */
    private void categorizeByX(final BrowserTreeNode selectedNode, GemCategorizer<?> categorizer, CategoryNodeProvider provider, boolean reuseNodes) {

        ModuleTypeInfo workingModuleTypeInfo = perspective.getWorkingModuleTypeInfo();
       
        // Before categorizing sort gems alphabetically so they appear
        // in alphabetical order inside their categories.
        GemComparatorSorter sorter = new GemUnqualifiedNameCaseInsensitiveSorter();
        List<GemEntity> childList = sorter.getSortedList(getAllEntities(selectedNode));
View Full Code Here

    @Override
    void doRevert() {
       
        // We want to use the unqualified names if possible
        NavFrameOwner owner = getEditorPanel().getNavigatorOwner();
        ModuleTypeInfo moduleInfo = owner.getPerspective().getWorkingModuleTypeInfo();
        ScopedEntityNamingPolicy namingPolicy = new UnqualifiedUnlessAmbiguous(moduleInfo);

        // Determine the information needed to display argument information
        ArgumentMetadata[] arguments = getArgumentsFromMetadata();
        ArgumentMetadata[] adjusted = getArgumentsFromMetadata();
View Full Code Here

        } else if (gem instanceof RecordCreationGem) {
            return ((RecordCreationGem)gem).getDisplayName();

        } else if (gem instanceof FunctionalAgentGem) {
            ModuleTypeInfo moduleTypeInfo = displayContext.getContextModuleTypeInfo();
            ScopedEntityNamingPolicy namingPolicy = moduleTypeInfo == null ?
                                                    namingPolicy = ScopedEntityNamingPolicy.FULLY_QUALIFIED :
                                                    new ScopedEntityNamingPolicy.UnqualifiedUnlessAmbiguous(moduleTypeInfo);
            return ((FunctionalAgentGem)gem).getGemEntity().getAdaptedName(namingPolicy);     
       
View Full Code Here

     * @param workspaceModuleNameResolver the module name resolver to use to generate an appropriate module name
     * @param treeViewDisplayMode the display mode for the tree.
     * @return a node for the module.
     */
    private NavModuleNode makeModuleNode(final MetaModule metaModule, final ModuleNameResolver workspaceModuleNameResolver, TreeViewDisplayMode treeViewDisplayMode) {
        ModuleTypeInfo moduleInfo = metaModule.getTypeInfo();

        NavModuleNode moduleNode = new NavModuleNode(metaModule, workspaceModuleNameResolver, treeViewDisplayMode);
        urlToNodeMap.put(moduleNode.getAddress(), moduleNode);

        // Load all functions.
        FunctionalAgent[] entities = moduleInfo.getFunctionalAgents();
        if (entities.length > 0) {

            NavVaultNode functionsNode = new NavFunctionVaultNode();
            List<NavFunctionNode> functionNodes = new ArrayList<NavFunctionNode>();
                       
            for (final FunctionalAgent entity : entities) {
                if (entity instanceof Function) {
                    functionNodes.add(new NavFunctionNode((Function) entity));
                }
            }

            if (functionNodes.size() > 0) {
                moduleNode.add(functionsNode);
                urlToNodeMap.put(functionsNode.getAddress(), functionsNode);
                addAllNodes(functionsNode, functionNodes, false);
            }
        }
       
        // Load all the type constructors.
        int constructorCount = moduleInfo.getNTypeConstructors();
        if (constructorCount > 0) {

            List<NavTreeNode> typeConstructorNodes = new ArrayList<NavTreeNode>(constructorCount);
            for (int i = 0; i < constructorCount; i++) {
               
                TypeConstructor typeConstructor = moduleInfo.getNthTypeConstructor(i);
                NavTreeNode typeConstructorNode = new NavTypeConstructorNode(typeConstructor);
                typeConstructorNodes.add(typeConstructorNode);
               
                // Load the data constructors.
                int dataConstructorCount = typeConstructor.getNDataConstructors();
                for (int n = 0; n < dataConstructorCount; n++) {
                    NavTreeNode dataConstructorNode = new NavDataConstructorNode(typeConstructor.getNthDataConstructor(n));
                    typeConstructorNode.add(dataConstructorNode);
                    urlToNodeMap.put(dataConstructorNode.getAddress(), dataConstructorNode);
                }
            }
           
            NavVaultNode typeConstructorsNode = new NavTypeConstructorVaultNode();
            moduleNode.add(typeConstructorsNode);
            urlToNodeMap.put(typeConstructorsNode.getAddress(), typeConstructorsNode);
            addAllNodes(typeConstructorsNode, typeConstructorNodes, false);
        }

        // Load all the type classes.
        int classCount = moduleInfo.getNTypeClasses();
        if (classCount > 0) {

            List<NavTreeNode> classNodes = new ArrayList<NavTreeNode>(classCount);
           
            for (int i = 0; i < classCount; i++) {
   
                TypeClass typeClass = moduleInfo.getNthTypeClass(i);
   
                NavTreeNode typeClassNode = new NavTypeClassNode(typeClass);
                classNodes.add(typeClassNode);
   
                // Load the class methods.
                int methodCount = typeClass.getNClassMethods();
                if (methodCount > 0) {
   
                    List<NavClassMethodNode> classMethodNodes = new ArrayList<NavClassMethodNode>(methodCount);               
                    for (int n = 0; n < methodCount; n++) {
                        classMethodNodes.add(new NavClassMethodNode(typeClass.getNthClassMethod(n)));
                    }

                    addAllNodes(typeClassNode, classMethodNodes, false);
                }
            }

            NavVaultNode classesNode = new NavTypeClassVaultNode();
            moduleNode.add(classesNode);
            urlToNodeMap.put(classesNode.getAddress(), classesNode);
            addAllNodes(classesNode, classNodes, false);
        }

        // Load all the class instances
        int instanceCount = moduleInfo.getNClassInstances();
        if (instanceCount > 0) {

            List<NavTreeNode> classInstanceNodes = new ArrayList<NavTreeNode>(instanceCount);
            for (int n = 0; n < instanceCount; n++) {
               
                ClassInstance instance = moduleInfo.getNthClassInstance(n);
               
                NavTreeNode classInstanceNode = new NavClassInstanceNode(moduleInfo.getNthClassInstance(n), moduleInfo);
                classInstanceNodes.add(classInstanceNode);
               
                // Load the instance methods.
                int methodCount = instance.getNInstanceMethods();
                if (methodCount > 0) {
   
                    List<NavInstanceMethodNode> instanceMethodNodes = new ArrayList<NavInstanceMethodNode>(methodCount);               
                    for (int k = 0; k < methodCount; k++) {
                        String methodName = instance.getTypeClass().getNthClassMethod(k).getName().getUnqualifiedName();
                        instanceMethodNodes.add(new NavInstanceMethodNode(moduleInfo.getNthClassInstance(n), methodName, moduleInfo));
                    }

                    addAllNodes(classInstanceNode, instanceMethodNodes, false);
                }
            }
View Full Code Here

            // in the following if-else checks, if the metadata is null, it will fail all the instanceof checks
            // and simply fall off the end with no additional HTML generated, which is what is intended in such cases.
           
            if (metadata instanceof FunctionalAgentMetadata) {
                QualifiedName qualifiedName = featureName.toQualifiedName();
                ModuleTypeInfo moduleTypeInfoForFeature = owner.getPerspective().getMetaModule(qualifiedName.getModuleName()).getTypeInfo();
                FunctionalAgent envEntity = moduleTypeInfoForFeature.getFunctionalAgent(qualifiedName.getUnqualifiedName());
               
                boolean isRequiredClassMethod = false;
                if (envEntity instanceof ClassMethod) {
                    ClassMethod method = (ClassMethod)envEntity;
                    isRequiredClassMethod = (method.getDefaultClassMethodName() == null); // no default -> required
                }
               
                CALDocComment caldoc = envEntity.getCALDocComment();
                buffer.append(getBasicMetadataHtml(owner, metadata, caldoc));
                buffer.append(getFunctionalAgentMetadataHtml(owner, (FunctionalAgentMetadata) metadata, url, caldoc, isRequiredClassMethod));
                buffer.append(getAdditionalMetadataHtml(owner, metadata, caldoc));
               
            } else if (metadata instanceof ModuleMetadata) {
                ModuleName moduleName = featureName.toModuleName();
                ModuleTypeInfo moduleTypeInfoForFeature = owner.getPerspective().getMetaModule(moduleName).getTypeInfo();
               
                CALDocComment caldoc = moduleTypeInfoForFeature.getCALDocComment();
                buffer.append(getBasicMetadataHtml(owner, metadata, caldoc));
                buffer.append(getModuleMetadataHtml(owner, (ModuleMetadata) metadata));
                buffer.append(getAdditionalMetadataHtml(owner, metadata, caldoc));
               
            } else if (metadata instanceof TypeClassMetadata) {
                QualifiedName qualifiedName = featureName.toQualifiedName();
                ModuleTypeInfo moduleTypeInfoForFeature = owner.getPerspective().getMetaModule(qualifiedName.getModuleName()).getTypeInfo();
                TypeClass typeClass = moduleTypeInfoForFeature.getTypeClass(qualifiedName.getUnqualifiedName());
               
                CALDocComment caldoc = typeClass.getCALDocComment();
                buffer.append(getBasicMetadataHtml(owner, metadata, caldoc));
                buffer.append(getTypeClassMetadataHtml(owner, (TypeClassMetadata) metadata));
                buffer.append(getAdditionalMetadataHtml(owner, metadata, caldoc));
               
            } else if (metadata instanceof TypeConstructorMetadata) {
                QualifiedName qualifiedName = featureName.toQualifiedName();
                ModuleTypeInfo moduleTypeInfoForFeature = owner.getPerspective().getMetaModule(qualifiedName.getModuleName()).getTypeInfo();
                TypeConstructor typeCons = moduleTypeInfoForFeature.getTypeConstructor(qualifiedName.getUnqualifiedName());
               
                CALDocComment caldoc = typeCons.getCALDocComment();
                buffer.append(getBasicMetadataHtml(owner, metadata, caldoc));
                buffer.append(getTypeConstructorMetadataHtml(owner, (TypeConstructorMetadata) metadata));
                buffer.append(getAdditionalMetadataHtml(owner, metadata, caldoc));
               
            } else if (metadata instanceof ClassInstanceMetadata) {
                ClassInstanceIdentifier classInstanceID = featureName.toInstanceIdentifier();
                ModuleTypeInfo moduleTypeInfoForFeature = owner.getPerspective().getMetaModule(featureName.toModuleName()).getTypeInfo();
                ClassInstance instance = moduleTypeInfoForFeature.getClassInstance(classInstanceID);
               
                CALDocComment caldoc = instance.getCALDocComment();
                buffer.append(getBasicMetadataHtml(owner, metadata, caldoc));
                buffer.append(getClassInstanceMetadataHtml(owner, (ClassInstanceMetadata) metadata));
                buffer.append(getAdditionalMetadataHtml(owner, metadata, caldoc));
               
            } else if (metadata instanceof InstanceMethodMetadata) {
                ClassInstanceIdentifier classInstanceID = featureName.toInstanceIdentifier();
                ModuleTypeInfo moduleTypeInfoForFeature = owner.getPerspective().getMetaModule(featureName.toModuleName()).getTypeInfo();
                ClassInstance instance = moduleTypeInfoForFeature.getClassInstance(classInstanceID);
               
                CALDocComment caldoc = instance.getMethodCALDocComment(featureName.toInstanceMethodName());
                buffer.append(getBasicMetadataHtml(owner, metadata, caldoc));
                buffer.append(getInstanceMethodMetadataHtml(owner, (InstanceMethodMetadata) metadata, url, caldoc));
                buffer.append(getAdditionalMetadataHtml(owner, metadata, caldoc));
View Full Code Here

        buffer.append("<h2>" + getAnchorHtml(IMPORTS_ANCHOR, NavigatorMessages.getString("NAV_ImportedModules_Header")) + "</h2>");

        SortedSet<ModuleTypeInfo> importedModules = new TreeSet<ModuleTypeInfo>(new ModuleTypeInfoComparator());
       
        ModuleName moduleName = metadata.getFeatureName().toModuleName();
        ModuleTypeInfo moduleTypeInfo = owner.getPerspective().getMetaModule(moduleName).getTypeInfo();
        int nImportedModules = moduleTypeInfo.getNImportedModules();
       
        if (nImportedModules == 0) {
            buffer.append(NavigatorMessages.getString("NAV_NoValue"));

        } else {
            for (int n = 0; n < nImportedModules; n++) {
                importedModules.add(moduleTypeInfo.getNthImportedModule(n));
            }
           
            buffer.append("<tt>");
           
            for (final ModuleTypeInfo importedModuleInfo : importedModules) {
                NavAddress moduleAddress = NavAddress.getAddress(importedModuleInfo);
                buffer.append(getLinkHtml(moduleAddress, NavAddressHelper.getDisplayText(owner, moduleAddress)));
                buffer.append(", ");
            }
           
            // remove trailing comma
            buffer.delete(buffer.length() - 2, buffer.length());
            buffer.append("</tt>");
        }
      
        // create a list of friend modules  
        buffer.append("<h2>" + getAnchorHtml(FRIENDS_ANCHOR, NavigatorMessages.getString("NAV_FriendModules_Header")) + "</h2>");

        SortedSet<ModuleName> friendModules = new TreeSet<ModuleName>();
       
        int nFriendModules = moduleTypeInfo.getNFriendModules();
       
        if (nFriendModules == 0) {
            buffer.append(NavigatorMessages.getString("NAV_NoValue"));

        } else {
            for (int n = 0; n < nFriendModules; n++) {
                friendModules.add(moduleTypeInfo.getNthFriendModule(n));
            }
           
            buffer.append("<tt>");
           
            for (final ModuleName friendModule : friendModules) {
View Full Code Here

        List<ClassInstance> instances = new ArrayList<ClassInstance>();
       
        for (int n = 0, numMods = workspace.getNMetaModules(); n < numMods; n++) {
           
            MetaModule metaModule = workspace.getNthMetaModule(n);
            ModuleTypeInfo moduleTypeInfo = metaModule.getTypeInfo();
           
            for (int i = 0, num = moduleTypeInfo.getNClassInstances(); i < num; i++) {
               
                ClassInstance instance = moduleTypeInfo.getNthClassInstance(i);
               
                if (instance.isTypeConstructorInstance() &&
                    ((ClassInstanceIdentifier.TypeConstructorInstance)instance.getIdentifier()).getTypeConsName().equals(typeCons.getName())) {
                    classes.add(instance.getTypeClass());
                    instances.add(instance);
View Full Code Here

TOP

Related Classes of org.openquark.cal.compiler.ModuleTypeInfo

Copyright © 2018 www.massapicom. 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.