Search in sources :

Example 1 with PackageEntry

use of org.absmodels.abs.plugin.editor.outline.PackageEntry in project abstools by abstools.

the class AbsNature method addPackagesForTypeChecking.

/**
 * Add ABS package dependencies to {@link AbsNature#modelbuilder} for type checking
 * @throws TypecheckInternalException
 */
private void addPackagesForTypeChecking() throws TypecheckInternalException {
    try {
        Main m = new Main();
        m.setWithStdLib(true);
        List<CompilationUnit> units = new ArrayList<CompilationUnit>();
        for (PackageEntry entry : packageContainer.getPackages()) {
            File file = new File(entry.getPath());
            if (isABSPackage(file)) {
                units.addAll(m.parseABSPackageFile(file));
            }
        }
        modelbuilder.addCompilationUnits(units);
    } catch (IOException e) {
        throw new TypecheckInternalException(e);
    } catch (NoModelException e) {
    // ignore
    }
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) NoModelException(org.absmodels.abs.plugin.internal.NoModelException) PackageEntry(org.absmodels.abs.plugin.editor.outline.PackageEntry) TypecheckInternalException(org.absmodels.abs.plugin.internal.TypecheckInternalException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Main(abs.frontend.parser.Main) PackageAbsFile(org.absmodels.abs.plugin.editor.outline.PackageAbsFile) File(java.io.File)

Example 2 with PackageEntry

use of org.absmodels.abs.plugin.editor.outline.PackageEntry in project abstools by abstools.

the class AbsNature method initDependencies.

public void initDependencies() {
    try {
        if (project != null) {
            packageContainer.clear();
            File file = new File(project.getFile(PACKAGE_DEPENDENCIES).getLocationURI());
            Set<PackageEntry> entries = new HashSet<PackageEntry>();
            if (file.exists()) {
                Properties prop = new Properties();
                prop.loadFromXML(new FileInputStream(file));
                for (String qualified : prop.stringPropertyNames()) {
                    Boolean readonly = Boolean.valueOf(prop.getProperty(qualified));
                    File f = new File(qualified);
                    if (isABSPackage(f)) {
                        entries.add(new PackageEntry(packageContainer, f.getName(), qualified, readonly));
                    }
                }
                packageContainer.setPackages(entries);
                packageContainer.setProject(project);
            }
        }
    } catch (IOException e) {
        Activator.logException(e);
    }
}
Also used : PackageEntry(org.absmodels.abs.plugin.editor.outline.PackageEntry) IOException(java.io.IOException) Properties(java.util.Properties) PackageAbsFile(org.absmodels.abs.plugin.editor.outline.PackageAbsFile) File(java.io.File) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet)

Example 3 with PackageEntry

use of org.absmodels.abs.plugin.editor.outline.PackageEntry in project abstools by abstools.

the class UtilityFunctions method getPackageAbsFile.

/**
 * A convenient method to reconstruct a {@link PackageAbsFile} from the absolute
 * path to the ABS package and the name to the specific entry in the package.
 * @param proj the project which the package belongs to
 * @param pak
 * @param entry
 * @return
 */
public static PackageAbsFile getPackageAbsFile(IProject proj, String pak, String entry) {
    File file = new File(pak);
    try {
        if (new ABSPackageFile(file).isABSPackage()) {
            PackageEntry pentry = null;
            if (proj != null) {
                AbsNature nature = getAbsNature(proj);
                for (PackageEntry e : nature.getPackages().getPackages()) {
                    if (e.getPath().equals(file.getAbsolutePath())) {
                        pentry = e;
                        break;
                    }
                }
            }
            if (pentry == null) {
                PackageContainer container = new PackageContainer();
                container.setProject(proj);
                pentry = new PackageEntry(container, file.getName(), file.getAbsolutePath(), true);
            }
            return new PackageAbsFile(pentry, entry);
        }
    } catch (IOException e) {
    }
    return null;
}
Also used : ABSPackageFile(abs.frontend.parser.ABSPackageFile) PackageEntry(org.absmodels.abs.plugin.editor.outline.PackageEntry) PackageContainer(org.absmodels.abs.plugin.editor.outline.PackageContainer) PackageAbsFile(org.absmodels.abs.plugin.editor.outline.PackageAbsFile) ABSPackageFile(abs.frontend.parser.ABSPackageFile) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) PackageAbsFile(org.absmodels.abs.plugin.editor.outline.PackageAbsFile)

Aggregations

PackageAbsFile (org.absmodels.abs.plugin.editor.outline.PackageAbsFile)3 PackageEntry (org.absmodels.abs.plugin.editor.outline.PackageEntry)3 File (java.io.File)2 IOException (java.io.IOException)2 CompilationUnit (abs.frontend.ast.CompilationUnit)1 ABSPackageFile (abs.frontend.parser.ABSPackageFile)1 Main (abs.frontend.parser.Main)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)1 PackageContainer (org.absmodels.abs.plugin.editor.outline.PackageContainer)1 NoModelException (org.absmodels.abs.plugin.internal.NoModelException)1 TypecheckInternalException (org.absmodels.abs.plugin.internal.TypecheckInternalException)1