Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.ModuleName


    private void command_resetMachineState(String moduleToResetString) {
        if (moduleToResetString.length() == 0) {
            // Reset cached results in all modules.
            resetMachineState();
        } else {
            ModuleName moduleToReset = resolveModuleNameInProgram(moduleToResetString, true);
            if (moduleToReset != null) {
                resetMachineState(moduleToReset);
            }
        }
    }
View Full Code Here


       
            oldNameString = args[1];
            newNameString = args[2];
            if(category == Category.MODULE_NAME) {
               
                ModuleName oldNameAsModuleName = ModuleName.maybeMake(oldNameString);
                if(oldNameAsModuleName == null) {
                    iceLogger.log(Level.INFO, "Error: " + oldNameString + " is not a valid module name");
                    return;
                }
               
                oldName = QualifiedName.make(oldNameAsModuleName, Refactorer.Rename.UNQUALIFIED_NAME_FOR_MODULE_RENAMING);
           
            } else if(QualifiedName.isValidCompoundName(oldNameString)) {
                oldName = QualifiedName.makeFromCompoundName(oldNameString);
           
            } else {
                iceLogger.log(Level.INFO, "Error: " + oldNameString + " is not a valid qualified name");
                return;
            }
       
        } else {
           
            oldNameString = args[0];
            newNameString = args[1];

            ModuleName oldNameAsModuleName = ModuleName.maybeMake(oldNameString);
            // the null check for oldNameAsModuleName comes a bit later (a few lines down)
           
            QualifiedName oldNameAsQualifiedName;
            if (QualifiedName.isValidCompoundName(oldNameString)) {
                oldNameAsQualifiedName = QualifiedName.makeFromCompoundName(oldNameString);
            } else {
                oldNameAsQualifiedName = null;
            }
           
            List<Category> entityCategories = new ArrayList<Category>();
            if (oldNameAsModuleName != null && getWorkspaceManager().getModuleTypeInfo(oldNameAsModuleName) != null) {
                entityCategories.add(Category.MODULE_NAME);
            }
           
            if (oldNameAsQualifiedName != null) {
                ModuleName moduleName = oldNameAsQualifiedName.getModuleName();
                String unqualifiedName = oldNameAsQualifiedName.getUnqualifiedName();
               
                ModuleTypeInfo moduleTypeInfo = getWorkspaceManager().getModuleTypeInfo(moduleName);
                if(moduleTypeInfo != null) {

                    if(moduleTypeInfo.getFunctionOrClassMethod(unqualifiedName) != null) {
                        entityCategories.add(Category.TOP_LEVEL_FUNCTION_OR_CLASS_METHOD);
                    }

                    if(moduleTypeInfo.getDataConstructor(unqualifiedName) != null) {
                        entityCategories.add(Category.DATA_CONSTRUCTOR);
                    }

                    if(moduleTypeInfo.getTypeConstructor(unqualifiedName) != null) {
                        entityCategories.add(Category.TYPE_CONSTRUCTOR);
                    }

                    if(moduleTypeInfo.getTypeClass(unqualifiedName) != null) {
                        entityCategories.add(Category.TYPE_CLASS);
                    }
                }
            }
           
            if(entityCategories.size() == 0) {
                iceLogger.log(Level.INFO, "Error: " + oldNameString + " does not exist");
                return;
            }

            if(entityCategories.size() > 1) {
                iceLogger.log(Level.INFO, "Error: " + oldNameString + " is ambiguous; please specify a context");
                return;
            }
           
            category = entityCategories.get(0);
           
            if (category == Category.MODULE_NAME) {
                oldName = QualifiedName.make(oldNameAsModuleName, Refactorer.Rename.UNQUALIFIED_NAME_FOR_MODULE_RENAMING);
            } else {
                oldName = oldNameAsQualifiedName;
            }
        }
       
        if (category == Category.MODULE_NAME) {
            ModuleName newNameAsModuleName = ModuleName.make(newNameString);
            newName = QualifiedName.make(newNameAsModuleName, Refactorer.Rename.UNQUALIFIED_NAME_FOR_MODULE_RENAMING);
        } else if(QualifiedName.isValidCompoundName(newNameString)) {
            newName = QualifiedName.makeFromCompoundName(newNameString);
        } else {
            newName = QualifiedName.make(oldName.getModuleName(), newNameString);
            newNameString = newName.getQualifiedName();
        }

        // Error checks
        if(!entityExists(oldName, category)) {
            iceLogger.log(Level.INFO, "Error: " + oldNameString + " does not exist");
            return;
        }
       
        if(entityExists(newName, category)) {
            iceLogger.log(Level.INFO, "Error: " + newNameString + " already exists");
            return;
        }       
       
        if((Character.isUpperCase(oldName.getUnqualifiedName().charAt(0)) && !Character.isUpperCase(newName.getUnqualifiedName().charAt(0))) ||
           (!Character.isUpperCase(oldName.getUnqualifiedName().charAt(0)) && Character.isUpperCase(newName.getUnqualifiedName().charAt(0)))) {
              
            iceLogger.log(Level.INFO, "Error: Old and new names must be of the same type (ie, if one starts with an uppercase letter, so must the other)");
            return;
        }
       
        if(category != Category.MODULE_NAME && !oldName.getModuleName().equals(newName.getModuleName())) {
            iceLogger.log(Level.INFO, "Error: Renamed entities must remain in the same module");
            return;
        }
       
        // Okay, the basics check out.
        System.out.print("Renaming " + oldNameString + " to " + newNameString + "...");
        CompilerMessageLogger messageLogger = new MessageLogger();
        Refactorer refactorer = new Refactorer.Rename(getWorkspaceManager().getWorkspace().asModuleContainer(), getWorkspaceManager().getTypeChecker(), oldName, newName, category);

        refactorer.setStatusListener(new Refactorer.StatusListener() {
            public void willUseResource(ModuleSourceDefinition resource) {
                System.out.print(".");
            }
            public void doneUsingResource(ModuleSourceDefinition resource) {
            }
        });

        refactorer.calculateModifications(messageLogger);

        if(messageLogger.getMaxSeverity().compareTo(CompilerMessage.Severity.ERROR) >= 0) {
            System.out.println("");
            dumpCompilerMessages(messageLogger);
            return;
        }

        refactorer.apply(messageLogger);
        System.out.println("");

        if(messageLogger.getMaxSeverity().compareTo(CompilerMessage.Severity.ERROR) >= 0) {
            dumpCompilerMessages(messageLogger);
            return;
        }

        if(!compileWorkspace(false, true, false)) {
            System.out.print("Compile failed, rolling back changes...");
            refactorer.undo(messageLogger);
            System.out.println("");
            return;
        }

        if(category == Category.MODULE_NAME) {
            ModuleName oldNameAsModuleName = ModuleName.maybeMake(oldNameString);
            if(oldNameAsModuleName == null) {
                iceLogger.log(Level.INFO, "Invalid module name '" + oldNameString + "'");
                return;
            }
           
View Full Code Here

        String[] args = info.split(" ");

        int argi = 0, startLine = -1, endLine = -1;

        // get the module name if specified or use current module
        final ModuleName moduleName;
        if (info.length() > 0 && args.length > 0
                && ModuleName.maybeMake(args[0]) != null) {
            moduleName = resolveModuleNameInWorkspace(args[0], true);
            if (moduleName == null) {
                return;
View Full Code Here

        Refactorer refactorer = null;
        boolean noGrouping = false;
       
        String[] args = info.split(" ");
        if(args[0].equals("import") || args[0].equals("imports")) {
            ModuleName moduleName = targetModule;
            if(args.length >= 3) {
                moduleName = ModuleName.maybeMake(args[1]);
                if(moduleName == null) {
                    iceLogger.log(Level.INFO, "Invalid module name '" + args[1] + "'");
                    return;
                }
               
                if(args[2].equals("nogroup")) {
                    noGrouping = true;
               
                } else {
                    iceLogger.log(Level.INFO, "Unrecognized option '" + args[2]);
                    return;
                }
               
            } else if(args.length >= 2) {
                moduleName = ModuleName.maybeMake(args[1]);
                if (moduleName == null) {
                    if(args[1].equals("nogroup")){
                        moduleName = targetModule;
                        noGrouping = true;
                    } else {
                        iceLogger.log(Level.INFO, "Unrecognized option '" + args[1]);
                        return;
                    }
                }
            }
           
            moduleName = resolveModuleNameInWorkspace(moduleName.toSourceText(), true);
            if (moduleName == null) {
                return;
            }
           
            refactorer = new Refactorer.CleanImports(getWorkspaceManager().getWorkspace().asModuleContainer(), moduleName, noGrouping);
            iceLogger.log(Level.INFO, "Cleaning imports in module " + moduleName + "...");
           
        } else if(args[0].equals("typeDecls")) {
            final ModuleName moduleName;
            if(args.length > 1) {
                moduleName = resolveModuleNameInWorkspace(args[1], true);
                if (moduleName == null) {
                    return;
                }
View Full Code Here

     * Resolves the given qualified name in the context of the current program. If the given name cannot be unambiguously resolved, null is returned.
     * @param qualifiedName the qualified name to resolve.
     * @return the corresponding fully qualified name, or null if the given name cannot be unambiguously resolved.
     */
    private QualifiedName resolveQualifiedNameInProgram(QualifiedName qualifiedName) {
        ModuleName resolvedModuleName = resolveModuleNameInProgram(qualifiedName.getModuleName().toSourceText(), true);
        if (resolvedModuleName == null) {
            return null;
        } else {
            return QualifiedName.make(resolvedModuleName, qualifiedName.getUnqualifiedName());
        }
View Full Code Here

     * @param listModuleCommand the command to suggest to the user to display a list of appropriate modules.
     * @return the corresponding fully qualified module name, or null if the given name cannot be unambiguously resolved.
     */
    private ModuleName resolveModuleName(String moduleNameString, ModuleNameResolver moduleNameResolver, boolean logWarningIfNotResolvable, String listModuleCommand) {

        final ModuleName result;
       
        ModuleName moduleName = ModuleName.maybeMake(moduleNameString);

        if (moduleName == null) {
            iceLogger.log(Level.INFO, moduleNameString + " is not a valid module.  Use " + listModuleCommand + " to display a list of available modules.");
            result = null;
           
View Full Code Here

     */
    protected void command_setModule (String newTargetModuleString) {
        // We use a module name resolver to resolve partially qualified module names.
        // For example, it is okay to use ":sm M2" to change to the Cal.Test.General.M2 module.
       
        ModuleName newTargetModule = resolveModuleNameInProgram(newTargetModuleString, true);
        if (newTargetModule != null) {
            targetModule = newTargetModule;
            preferredWorkingModuleName = targetModule;
        }       
    }
View Full Code Here

     * Show dependents of the named module.
     * @param moduleNameString
     */
    private void command_showModuleDependents (String moduleNameString) {
       
        ModuleName moduleName = resolveModuleNameInProgram(moduleNameString, true);
       
        if (moduleName != null) {
            Set<ModuleName> moduleNameSet = getWorkspaceManager().getDependentModuleNames(moduleName);
            if (!moduleNameSet.isEmpty()) {
                List<ModuleName> moduleNameList = new ArrayList<ModuleName>(moduleNameSet);
View Full Code Here

     */
    private void command_removeModule (String moduleToRemoveString) {
        if (this.workspaceManager != null) {
            synchronized (this.workspaceManager) {
               
                ModuleName moduleToRemove = resolveModuleNameInWorkspace(moduleToRemoveString, true);
               
                if (moduleToRemove != null) {
                    CALWorkspace wkspc = workspaceManager.getWorkspace();
                    if (wkspc.containsModule(moduleToRemove)) {
                        Status s = new Status("Remove Status");
View Full Code Here

        }
       
        if (this.workspaceManager != null) {
            synchronized (this.workspaceManager) {
               
                ModuleName unresolvedModuleName = ModuleName.maybeMake(moduleNameString);
               
                ModuleName[] moduleNamesInWorkspace = getWorkspaceManager().getWorkspace().getModuleNames();
                ModuleNameResolver workspaceModulesResolver = ModuleNameResolver.make(new HashSet<ModuleName>(Arrays.asList(moduleNamesInWorkspace)));
                ModuleNameResolver.ResolutionResult workspaceResolution = workspaceModulesResolver.resolve(unresolvedModuleName);
               
                ModuleNameResolver discoverableModulesResolver = ModuleNameResolver.make(getDiscoverableModules());

                ModuleName moduleName = resolveModuleName(moduleNameString, discoverableModulesResolver, workspaceResolution.isUnknown(), ":sdm");

                if (moduleName == null) {

                    if (workspaceResolution.isKnownUnambiguous()) {
                        iceLogger.log(Level.INFO, "The module " + workspaceResolution.getResolvedModuleName().toSourceText() + " is already in the workspace.");
View Full Code Here

TOP

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

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.