Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.ModuleSourceDefinition


            addStatus.add(new Status(Status.Severity.WARNING, "No registered source manager."));
            return true;            // true or false??
        }
       
        // Update the module source provider.
        ModuleSourceDefinition newModuleSourceDefinition = sourceManager.getSource(moduleName, addStatus);
        List<ModuleSourceDefinition> newModuleSources = new ArrayList<ModuleSourceDefinition>(Arrays.asList(sourceDefinitionGroup.getModuleSources()));
       
        ModuleSourceDefinition existingModuleSource = sourceDefinitionGroup.getModuleSource(moduleName);
        if (existingModuleSource != null) {
            newModuleSources.remove(existingModuleSource);
        }
        newModuleSources.add(newModuleSourceDefinition);
View Full Code Here


        for (final ModuleName moduleName : moduleNames) {
            if (moduleName.equals(CAL_Prelude.MODULE_NAME)) {
                removeStatus.add(new Status(Status.Severity.ERROR, "Cannot remove Cal.Core.Prelude module.", null));
                return false;
            }
            ModuleSourceDefinition sourceToRemove = sourceDefinitionGroup.getModuleSource(moduleName);
            if (sourceToRemove == null) {
                return false;
            }
            sourcesToRemove.add (sourceToRemove);
        }
       
        List<ModuleSourceDefinition> newModuleSources = new ArrayList<ModuleSourceDefinition>(Arrays.asList(sourceDefinitionGroup.getModuleSources()));
       
        for (final ModuleSourceDefinition sourceToRemove : sourcesToRemove) {
            newModuleSources.remove(sourceToRemove);
            ModuleName moduleName = sourceToRemove.getModuleName();

            // Remove module resources from the resource manager if not nullary.
            // We can also remove if nullary, if we imported (during this session) from another vault.
            VaultElementInfo vaultInfo = getVaultInfo(moduleName);
            if (!isNullary() || vaultInfo == null || !isStandardVaultDescriptor(vaultInfo.getVaultDescriptor())) {
View Full Code Here

    synchronized public final ModuleName[] getModuleNames() {
        int nModules = sourceDefinitionGroup.getNModules();
        ModuleName[] moduleNames = new ModuleName[nModules];

        for (int i = 0; i < nModules; i++) {
            ModuleSourceDefinition sourceDefinition = sourceDefinitionGroup.getModuleSource(i);
            moduleNames[i] = sourceDefinition.getModuleName();
        }
       
        return moduleNames;
    }
View Full Code Here

        // Flag indicating whether currently searching inside proper section
        boolean insideSection = false;

        Reader sourceReader = null;
        try {
            ModuleSourceDefinition sourceDefinition = getSourceDefinition(moduleName);
            if (sourceDefinition == null) {
                return false;
            }

            sourceReader = sourceDefinition.getSourceReader(new Status("Reader status"));
            if (sourceReader == null) {
                return false;
            }
           
            BufferedReader bufferedReader = new BufferedReader(sourceReader);
View Full Code Here

        String beginString = "// @@@begin ";
        String endString = "// @@@end ";
        String beginNameString = beginString + entityName;
        String endNameString = endString + entityName;
       
        ModuleSourceDefinition sourceDefinition = getSourceDefinition(moduleName);
        if (sourceDefinition == null) {
            return false;
        }
       
        Reader sourceReader = sourceDefinition.getSourceReader(null);
        if (sourceReader == null) {
            String message = "Couldn't read definition for \"" + entityName + "\".";
            saveStatus.add(new Status(Status.Severity.ERROR, message));
            return false;
        }
        BufferedReader bufferedReader = new BufferedReader(sourceReader);
       
        try {
            // The new file text..
            StringBuilder newFileTextBuilder = new StringBuilder();
           
            if (!scExists) {
                // The gem does not exist.  Simply append its text to the end of the file.
               
                try {
                    // Add all the file text
                    for (String lineString = bufferedReader.readLine(); lineString != null; lineString = bufferedReader.readLine()) {
                        newFileTextBuilder.append(lineString + "\n");
                    }
                } catch (IOException ioe) {
                    String message = "Couldn't read definition for \"" + entityName + "\".";
                    saveStatus.add(new Status(Status.Severity.ERROR, message, ioe));
                    return false;
                }
               
                // Add the gem definition.
                newFileTextBuilder.append(getDefinition(definitionText, beginNameString, endNameString));
               
            } else {
                // The gem exists.  Attempt to replace its text in the file.
               
                // Read in all the file text
                List<String> fileText = new ArrayList<String>();
                int beginIndex = -1;
                int endIndex = -1;
                boolean shouldEatOneMoreLine = false;
                try {
                    for (String lineString = bufferedReader.readLine(); lineString != null; lineString = bufferedReader.readLine()) {
                       
                        // Add the text to the List
                        fileText.add(lineString);
                        int lineIndex = fileText.size() - 1;            // ArrayList size is a (faster) variable lookup
                       
                        // Keep track of where to replace the gem text
                        if (beginIndex < 0){
                            if (lineString.startsWith(beginNameString)) {
                               
                                // Make sure that we didn't find part of another name
                                // Grab the part of the line string that starts with the gem name
                                String endLineString = lineString.substring(beginString.length());
                               
                                // the first token should be the gem's name
                                StringTokenizer tokenizer = new StringTokenizer(endLineString);
                                if (tokenizer.hasMoreElements() && tokenizer.nextToken().equals(entityName.getQualifiedName())) {
                                    beginIndex = lineIndex;
                                }
                            }
                           
                        } else if (endIndex < 0) {
                            if (lineString.startsWith(endNameString)) {
                               
                                // Make sure that we didn't find part of another name
                                // Grab the part of the line string that starts with the gem name
                                String endLineString = lineString.substring(endString.length());
                               
                                // the first token should be the gem's name
                                StringTokenizer tokenizer = new StringTokenizer(endLineString);
                                if (tokenizer.hasMoreElements() && tokenizer.nextToken().equals(entityName.getQualifiedName())) {
                                    endIndex = lineIndex;
                                }
                            }
                        }
                       
                        // See if the line following the line with the end marker is blank.
                        if (endIndex >= 0 && lineIndex == endIndex + 1) {
                           
                            // Convert to a char array
                            char[] charArray = lineString.toCharArray();
                           
                            // Now check each character (if any) to see if they're whitespace
                            boolean isBlank = true;
                            for (int i = 0; i < charArray.length; i++) {
                                if (!Character.isWhitespace(charArray[i])) {
                                    isBlank = false;
                                    break;
                                }
                            }
                            shouldEatOneMoreLine = isBlank;
                        }
                    }
                } catch (IOException ioe) {
                    String message = "Couldn't read definition for \"" + entityName + "\".";
                    saveStatus.add(new Status(Status.Severity.ERROR, message, ioe));
                    return false;
                }
               
                // Replace the line following the line with the end marker, if appropriate
                if (shouldEatOneMoreLine) {
                    endIndex++;
                }
               
                if (beginIndex < 0 || endIndex < 0) {
                    // couldn't find where to replace the lines..
                    // the finally clause should take care of closing everything
                    String markersString;
                    if (beginIndex < 0 && endIndex < 0) {
                        markersString = "begin or end";
                    } else if (beginIndex < 0) {
                        markersString = "begin";
                    } else {
                        markersString = "end";
                    }
                   
                    String message = "Couldn't find " + markersString + " marker for \"" + entityName + "\".";
                    saveStatus.add(new Status(Status.Severity.ERROR, message, null));
                    return false;
                }
               
                //
                // Add all the file text
                //
               
                List<String> beforeText = fileText.subList(0, beginIndex);
                List<String> afterText = fileText.subList(endIndex + 1, fileText.size());
               
                // Add text appearing before the gem definition
                for (final String writeString : beforeText) {
                    newFileTextBuilder.append(writeString + "\n");
                }
               
                // Add the gem definition
                newFileTextBuilder.append(getDefinition(definitionText, beginNameString, endNameString));
               
                // Add text appearing after the gem definition
                for (final String writeString : afterText) {
                    newFileTextBuilder.append(writeString + "\n");
                }
            }
       
            // Convert to a moduleSource.
            final String newFileTextString = newFileTextBuilder.toString();
           
            ModuleSourceDefinition sourceToSave = new StringModuleSourceDefinition(moduleName, newFileTextString);
           
            // Save..
            return saveSource(sourceToSave, saveStatus);
           
        } finally {
View Full Code Here

        } else {
            // Get the old module sources, remove the old source definition (if any) and add the new one.
            List<ModuleSourceDefinition> newModuleSources = new ArrayList<ModuleSourceDefinition>(Arrays.asList(sourceDefinitionGroup.getModuleSources()));
            for (Iterator<ModuleSourceDefinition> it = newModuleSources.iterator(); it.hasNext(); ) {
                ModuleSourceDefinition moduleSourceDefinition = it.next();
                if (moduleSourceDefinition.getModuleName().equals(moduleName)) {
                    it.remove();
                    break;
                }
            }
            ModuleSourceDefinition newModuleSourceDefinition = sourceManager.getSource(moduleName, syncStatus);
            newModuleSources.add(newModuleSourceDefinition);

            // Create the new source provider.
            ModuleSourceDefinition[] newModuleSourceArray = newModuleSources.toArray(ModuleSourceDefinition.EMPTY_ARRAY);
            this.sourceDefinitionGroup = new ModuleSourceDefinitionGroup(newModuleSourceArray);
View Full Code Here

TOP

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

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.