Search in sources :

Example 11 with CompilationUnit

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

the class ModuleDecorator method checkSemanticErrorRange.

private boolean checkSemanticErrorRange(SemanticConditionList list, CompilationUnit c, int startLine, int endLine, AbsNature nature) {
    synchronized (nature.modelLock) {
        if (list != null) {
            if (list.containsErrors()) {
                for (SemanticCondition err : list) {
                    ASTNode<?> node = err.getNode();
                    int line = err.getLine();
                    CompilationUnit cu = node.getCompilationUnit();
                    if (c == cu && checkLine(line, startLine, endLine)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) SemanticCondition(abs.frontend.analyser.SemanticCondition)

Example 12 with CompilationUnit

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

the class OpenTypeHierarchyDelegate method getNodeUnderCursor.

InternalASTNode<?> getNodeUnderCursor(ABSEditor abseditor, TextSelection sel) {
    InternalASTNode<CompilationUnit> cu = abseditor.getCompilationUnit();
    if (cu == null) {
        return null;
    }
    IDocument doc = abseditor.getDocumentProvider().getDocument(editor.getEditorInput());
    synchronized (cu.getNature()) {
        try {
            ASTNode<?> node = UtilityFunctions.getASTNodeOfOffset(doc, cu.getASTNode(), sel.getOffset());
            return new InternalASTNode(node, cu.getNature());
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 13 with CompilationUnit

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

the class IncrementalModelBuilder method addCompilationUnit.

/**
 * Creates an empty model with only the stdlib when you pass null.
 */
public synchronized void addCompilationUnit(CompilationUnit cu) {
    if (model == null) {
        model = new Model();
        model.addCompilationUnit(getStdLibCompilationUnit());
        if (// just give us the stdlib
        cu != null)
            model.addCompilationUnit(cu);
        return;
    }
    if (cu == null)
        return;
    String filename = cu.getFileName();
    assert filename != null;
    CompilationUnit cuold = null;
    try {
        cuold = getCompilationUnit(filename);
    } catch (NoModelException e) {
        // we're pretty sure there's a model.
        assert false;
    }
    List<CompilationUnit> culist = model.getCompilationUnitList();
    int cindex = culist.getIndexOfChild(cuold);
    if (cindex > 0) {
        model.setCompilationUnit(cu, cindex);
    } else {
        model.addCompilationUnit(cu);
    }
    // model.flushCache();
    flushAll(model);
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) Model(abs.frontend.ast.Model)

Example 14 with CompilationUnit

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

the class IncrementalModelBuilder method getStdLibCompilationUnit.

private CompilationUnit getStdLibCompilationUnit() {
    CompilationUnit stdLib;
    File bundle;
    try {
        stdLib = new Main().getStdLib();
        bundle = FileLocator.getBundleFile(Platform.getBundle(ABSFRONTEND_PLUGIN_ID));
    } catch (IOException e) {
        Activator.logException(e);
        // Your plugin is probably busted.
        return null;
    } catch (InternalBackendException e) {
        Activator.logException(e);
        // Your plugin is probably busted.
        return null;
    }
    File src = new File(bundle, stdLib.getFileName());
    if (!src.exists()) {
        src = new File(bundle, "src/" + stdLib.getFileName());
    }
    stdLib.setName(src.getAbsolutePath());
    return stdLib;
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) InternalBackendException(abs.backend.common.InternalBackendException) IOException(java.io.IOException) File(java.io.File) Main(abs.frontend.parser.Main)

Example 15 with CompilationUnit

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

the class IncrementalModelBuilder method getCompilationUnit.

public synchronized CompilationUnit getCompilationUnit(String fileName) throws NoModelException {
    if (model == null)
        throw new NoModelException();
    Iterator<CompilationUnit> iter = model.getCompilationUnits().iterator();
    // normalize representation:
    fileName = normalizePath(fileName);
    while (iter.hasNext()) {
        CompilationUnit cu = iter.next();
        String cuFileName = cu.getFileName();
        // normalize representation:
        cuFileName = normalizePath(cuFileName);
        if (fileName.equals(cuFileName)) {
            return cu;
        }
    }
    return null;
}
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