Search in sources :

Example 21 with CompilationUnit

use of abs.frontend.ast.CompilationUnit 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 22 with CompilationUnit

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

the class ModuleDecorator method hasModuleDeclErrors.

/**
 * Determines if a module declaration has any errors
 *
 * @param m
 *            the module declaration
 * @param nature
 *            the ABS nature
 * @return TRUE if the module declaration has errors, FALSE if not or m or
 *         nature is null
 */
public boolean hasModuleDeclErrors(ModuleDecl m, AbsNature nature) {
    synchronized (nature.modelLock) {
        if (m != null) {
            CompilationUnit cu = m.getCompilationUnit();
            EditorPosition pos = UtilityFunctions.getPosition(m);
            int startLine = pos.getLinestart();
            int endLine = pos.getLineend();
            List<ParserError> parserErrors = cu.getParserErrors();
            SemanticConditionList list = cu.getModel().getTypeErrors();
            if (checkParserErrorRange(startLine, endLine, parserErrors)) {
                return true;
            } else {
                return checkSemanticErrorRange(list, cu, startLine, endLine, nature);
            }
        }
        return false;
    }
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) EditorPosition(org.absmodels.abs.plugin.util.UtilityFunctions.EditorPosition) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) ParserError(abs.frontend.parser.ParserError)

Example 23 with CompilationUnit

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

the class ABSReconcilingStrategy method reconcile.

public synchronized CompilationUnit reconcile(AbsNature nature, boolean withTypechecks) {
    CompilationUnit compilationUnit = parseDocument();
    if (nature == null) {
        setParseErrorMarkers(compilationUnit.getParserErrors());
        editor.onCompilationUnitChange(compilationUnit);
        return compilationUnit;
    }
    if (compilationUnit.getParserErrors() == null) {
        compilationUnit.setParserErrors(Collections.<ParserError>emptyList());
    }
    setParseErrorMarkers(compilationUnit.getParserErrors());
    AbsModelManager manager = nature.getModelManager();
    manager.updateModel(compilationUnit, withTypechecks);
    editor.onCompilationUnitChange(manager.getCompilationUnit(editor.getAbsoluteFilePath()));
    return compilationUnit;
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit)

Example 24 with CompilationUnit

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

the class ABSReconcilingStrategy method parseDocument.

private CompilationUnit parseDocument() {
    String code = document.get();
    CompilationUnit compilationUnit = parse(code);
    if (compilationUnit == null || compilationUnit.getNumModuleDecl() + compilationUnit.getNumFeatureDecl() == 0) {
        try {
            // add semicolon to end of current line and try to parse again
            int caretPos = editor.getCaretPos();
            IRegion lineInfo = document.getLineInformationOfOffset(caretPos);
            int endOfLine = lineInfo.getOffset() + lineInfo.getLength();
            code = document.get(0, endOfLine) + ";" + document.get(endOfLine, document.getLength() - endOfLine);
            System.out.println(code);
            CompilationUnit compilationUnit2 = parse(code);
            if (compilationUnit2 != null && compilationUnit2.getNumModuleDecl() + compilationUnit2.getNumFeatureDecl() > 0) {
                // compilationUnit2 has better results, so use it
                compilationUnit = compilationUnit2;
            }
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
    }
    return compilationUnit;
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 25 with CompilationUnit

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

the class AbsModelManagerImpl method updateModel.

@Override
public synchronized void updateModel(CompilationUnit cu, boolean withTypechecks) {
    boolean added = false;
    for (int i = 0; i < model.getNumCompilationUnit(); i++) {
        CompilationUnit c = model.getCompilationUnit(i);
        if (c.getFileName().equals(cu.getFileName())) {
            // update compilation unit:
            model.setCompilationUnit(cu, i);
            added = true;
            break;
        }
    }
    if (!added) {
        model.addCompilationUnit(cu);
    }
    if (!model.hasParserErrors()) {
        if (withTypechecks) {
            extendedTypechecking();
        }
    }
    notifyChangeListeners();
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit)

Aggregations

CompilationUnit (abs.frontend.ast.CompilationUnit)27 Model (abs.frontend.ast.Model)7 ModuleDecl (abs.frontend.ast.ModuleDecl)6 File (java.io.File)5 Test (org.junit.Test)5 ClassDecl (abs.frontend.ast.ClassDecl)4 DeltaDecl (abs.frontend.ast.DeltaDecl)4 MethodSig (abs.frontend.ast.MethodSig)4 Main (abs.frontend.parser.Main)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)4 DeltaAccess (abs.frontend.ast.DeltaAccess)3 List (abs.frontend.ast.List)3 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)3 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)2 Block (abs.frontend.ast.Block)2 MethodImpl (abs.frontend.ast.MethodImpl)2 SkipStmt (abs.frontend.ast.SkipStmt)2 StringReader (java.io.StringReader)2