Search in sources :

Example 26 with ModuleDecl

use of abs.frontend.ast.ModuleDecl 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 27 with ModuleDecl

use of abs.frontend.ast.ModuleDecl 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 28 with ModuleDecl

use of abs.frontend.ast.ModuleDecl in project abstools by abstools.

the class JavaTabMain method getRunTargets.

private List<RunTarget> getRunTargets(IProject proj) {
    AbsNature n = UtilityFunctions.getAbsNature(proj);
    if (n == null) {
        return Collections.emptyList();
    }
    Model m = n.getCompleteModel();
    if (m == null) {
        return Collections.emptyList();
    }
    List<RunTarget> result = new ArrayList<RunTarget>();
    for (CompilationUnit cu : m.getCompilationUnits()) {
        for (ModuleDecl module : cu.getModuleDecls()) {
            if (module.getBlockOpt().hasChildren()) {
                if (module.getName().equals(ABSTestRunnerGenerator.RUNNER_MAIN)) {
                    // do not show generated unit test file
                    continue;
                }
                result.add(new RunTargetModule(module));
            }
        // TODO add unit test classes
        // for (Decl d : module.getDecls()) {
        // if (d.isInterface()) {
        // InterfaceDecl i = (InterfaceDecl) d;
        // for (Annotation annotation : i.getAnnotations()) {
        // if (annotation.getValue() )
        // }
        // }
        // }
        }
    }
    result.add(new RunTargetUnitTests());
    return result;
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) Model(abs.frontend.ast.Model) ArrayList(java.util.ArrayList) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 29 with ModuleDecl

use of abs.frontend.ast.ModuleDecl in project abstools by abstools.

the class ASTBasedABSTestRunnerGenerator method generateTestRunner.

@Override
public void generateTestRunner(PrintStream stream) {
    ModuleDecl module = new ModuleDecl();
    module.setName(RUNNER_MAIN);
    module.setImportList(generateImportsAST());
    module.setBlock(generateMainBlockAST(module.getImportList()));
    PrintWriter writer = new PrintWriter(stream, true);
    ABSFormatter formatter = new DefaultABSFormatter(writer);
    module.doPrettyPrint(writer, formatter);
}
Also used : DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) ABSFormatter(abs.frontend.tests.ABSFormatter) ModuleDecl(abs.frontend.ast.ModuleDecl) PrintWriter(java.io.PrintWriter)

Aggregations

ModuleDecl (abs.frontend.ast.ModuleDecl)29 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)10 InternalASTNode (org.absmodels.abs.plugin.util.InternalASTNode)8 Decl (abs.frontend.ast.Decl)7 Model (abs.frontend.ast.Model)7 ArrayList (java.util.ArrayList)7 ClassDecl (abs.frontend.ast.ClassDecl)6 CompilationUnit (abs.frontend.ast.CompilationUnit)6 ModulePath (org.absmodels.abs.plugin.navigator.ModulePath)5 IProject (org.eclipse.core.resources.IProject)5 InterfaceDecl (abs.frontend.ast.InterfaceDecl)4 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)4 Test (org.junit.Test)4 AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)3 List (abs.frontend.ast.List)2 MainBlock (abs.frontend.ast.MainBlock)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 EditorPosition (org.absmodels.abs.plugin.util.UtilityFunctions.EditorPosition)2 IFile (org.eclipse.core.resources.IFile)2