Search in sources :

Example 16 with AbsNature

use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.

the class ModuleGroupContentProvider method getChildrenOf.

/**
 * Returns the children of a project.
 *
 * @param project
 * @return The children of the Project or an empty object array if the
 *         project is closed or not an ABS project or an Exception occurs
 */
private Object[] getChildrenOf(IProject project) {
    try {
        if (project.isAccessible() && project.hasNature(Constants.NATURE_ID)) {
            AbsNature nature = UtilityFunctions.getAbsNature(project);
            if (nature != null) {
                synchronized (nature.modelLock) {
                    ArrayList<InternalASTNode<?>> decls = new ArrayList<InternalASTNode<?>>();
                    Model model = nature.getCompleteModel();
                    // something could be compiled in the project (i.e. the project is not empty...)
                    if (model != null) {
                        Collection<ModuleDecl> moduleDecls = model.getModuleDecls();
                        for (ModuleDecl m : moduleDecls) {
                            String name = m.getName();
                            /* Don't show internal resources which would be read-only anyway.
								 * This is either the standard lib, or e.g. ABS.FLI, ABS.DC */
                            if (name.startsWith("ABS.")) {
                                continue;
                            }
                            decls.add(new InternalASTNode<ModuleDecl>(m, nature));
                        }
                    }
                    return decls.toArray();
                }
            }
        }
    } catch (CoreException ce) {
        ce.printStackTrace();
        return EMPTY_OBJECT_ARRAY;
    }
    return EMPTY_OBJECT_ARRAY;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ArrayList(java.util.ArrayList) Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 17 with AbsNature

use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.

the class SDAction method run.

/**
 * The action has been activated. The argument of the
 * method represents the 'real' action sitting
 * in the workbench UI.
 * @see IWorkbenchWindowActionDelegate#run
 */
public void run(IAction action) {
    /* 1. Get the project */
    IProject project = getCurrentProject();
    if (project == null)
        return;
    /* 2. Get the Console */
    MessageConsoleStream outConsole = findConsole().newMessageStream();
    outConsole.setActivateOnWrite(true);
    PrintStream out = new PrintStream(outConsole);
    /* 3. Get the model in a good shape (typed. For now, there is nothing we can do about deltas) */
    AbsNature nature = org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature(project);
    Model model = nature.getCompleteModel();
    model.typeCheck();
    /* 4. Perform the analysis */
    SDARun run = new SDARun(model, false, 3, 2, out);
    run.schedule();
}
Also used : PrintStream(java.io.PrintStream) Model(abs.frontend.ast.Model) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) IProject(org.eclipse.core.resources.IProject) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 18 with AbsNature

use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.

the class JavaJob method searchForMainBlockInCurrentFile.

/**
 * @return a module with a main block from the current file or null if no such module was found
 * @throws AbsJobException
 */
private ModuleDecl searchForMainBlockInCurrentFile() throws AbsJobException {
    if (currentFile == null) {
        return null;
    }
    AbsNature nature = UtilityFunctions.getAbsNature(project);
    if (nature == null) {
        throw new AbsJobException("Could not start the debugger, because selected file (" + currentFile.getName() + ") is not in an ABS project!");
    }
    synchronized (nature.modelLock) {
        CompilationUnit unit = nature.getCompilationUnit(currentFile);
        List<ModuleDecl> modules = findModulesWithMain(unit);
        // TODO: is the module still valid once you have returned the lock?
        return modules.size() == 0 ? null : modules.get(0);
    }
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 19 with AbsNature

use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.

the class JavaJob method getModuleByName.

/**
 * finds a module with a given name in the current
 * @param moduleName
 * @return
 * @throws AbsJobException
 */
private ModuleDecl getModuleByName(String moduleName) throws AbsJobException {
    AbsNature nature = UtilityFunctions.getAbsNature(project);
    if (nature == null) {
        throw new AbsJobException("Could not start the debugger, because selected file (" + currentFile.getName() + ") is not in an ABS project!");
    }
    synchronized (nature.modelLock) {
        Model model = nature.getCompleteModel();
        ModuleDecl result = model.lookupModule(moduleName);
        if (result == null) {
            throw new AbsJobException("Could not find a module with name " + moduleName + ".");
        }
        return result;
    }
}
Also used : Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 20 with AbsNature

use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.

the class MavenJob method runMavenUpdates.

public void runMavenUpdates() throws NoABSNatureException, AbsJobException, IOException {
    AbsNature nature = getAbsNature(project);
    if (nature == null) {
        throw new NoABSNatureException();
    }
    IFile pom = null;
    if (!(pom = getPom()).exists()) {
        throw new AbsJobException("POM for this project is not defined");
    }
    MsgConsole console = nature.getMavenConsole();
    console.clear();
    List<String> args = new ArrayList<String>();
    File file = new File(getMavenPath());
    if (!file.exists() || !file.isDirectory()) {
        throw new AbsJobException("Maven path is not defined");
    }
    String command;
    if (Platform.getOS().equals(Platform.OS_WIN32)) {
        command = new File(file, "bin\\mvn.bat").getAbsolutePath();
    } else {
        command = new File(file, "bin/mvn").getAbsolutePath();
    }
    args.add(command);
    args.add("-f");
    args.add(pom.getLocation().toFile().getAbsolutePath());
    args.add(goal);
    InputStream ins = null;
    OutputStream outs = null;
    try {
        if (!abort)
            process = Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
        ins = process.getInputStream();
        outs = console.getOutputStream(MessageType.MESSAGE_INFO);
        int d = 0;
        while ((d = ins.read()) != -1) {
            outs.write(d);
        }
        if (process.waitFor() != 0) {
            console.getOutputStream(MessageType.MESSAGE_ERROR).write("An error has occurred.");
        }
    } catch (InterruptedException e) {
        throw new AbsJobException(e.getMessage());
    } finally {
        if (ins != null)
            ins.close();
    }
}
Also used : NoABSNatureException(org.absmodels.abs.plugin.exceptions.NoABSNatureException) IFile(org.eclipse.core.resources.IFile) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) MsgConsole(org.absmodels.abs.plugin.console.MsgConsole) File(java.io.File) IFile(org.eclipse.core.resources.IFile) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Aggregations

AbsNature (org.absmodels.abs.plugin.builder.AbsNature)27 IProject (org.eclipse.core.resources.IProject)10 Model (abs.frontend.ast.Model)9 ModuleDecl (abs.frontend.ast.ModuleDecl)9 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)8 ArrayList (java.util.ArrayList)6 AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)6 InternalASTNode (org.absmodels.abs.plugin.util.InternalASTNode)6 CompilationUnit (abs.frontend.ast.CompilationUnit)4 IFile (org.eclipse.core.resources.IFile)4 CoreException (org.eclipse.core.runtime.CoreException)4 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)3 DeltaModellingException (abs.frontend.delta.DeltaModellingException)3 IOException (java.io.IOException)3 LocationType (abs.frontend.typechecker.locationtypes.LocationType)2 InferMain (abs.frontend.typechecker.locationtypes.infer.InferMain)2 LocationTypeVariable (abs.frontend.typechecker.locationtypes.infer.LocationTypeVariable)2 File (java.io.File)2 TypeCheckerException (org.absmodels.abs.plugin.exceptions.TypeCheckerException)2 NoModelException (org.absmodels.abs.plugin.internal.NoModelException)2