Search in sources :

Example 1 with AadlBaLocationReference

use of org.osate.ba.utils.AadlBaLocationReference in project osate2 by osate.

the class AadlBaParserAction method parseAnnexSubclause.

public AnnexSubclause parseAnnexSubclause(String annexName, String source, String filename, int line, int column, ParseErrorReporter errReporter) throws antlr.RecognitionException {
    if (false == ANNEX_NAME.equalsIgnoreCase(annexName)) {
        return null;
    }
    CharStream cs = new CaseInsensitiveCharStream(source);
    // AnnexOffset is the offset of the first token found in String source
    // considering the whole source file.
    int annexOffset = column;
    AadlBaHighlighter highlighter;
    // Set a Xtext highlighter if AADLBA Front End is running under OSATE2.
    if (Platform.isRunning()) {
        highlighter = XtextAadlBaHighlighter.getHighlighter(AnnexUtil.getCurrentAnnexSubclause());
    } else {
        // Default highlighter does nothing.
        highlighter = new DefaultAadlBaHighlighter();
    }
    AadlAntlrErrorReporter parserErrorReporter = new AadlAntlrErrorReporter(errReporter, filename);
    AadlBaLexer lexer = new AadlBaLexer(cs);
    lexer.setLine(line);
    lexer.setCharPositionInLine(column);
    lexer.removeErrorListeners();
    lexer.addErrorListener(parserErrorReporter);
    lexer.setHighlighter(highlighter);
    lexer.setAnnexOffset(annexOffset);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    AadlBaParser parser = new AadlBaParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(parserErrorReporter);
    try {
        // Build the primary AST: AST without AADLBA or declarative meta objects
        // Instanced.
        Behavior_annexContext bac = parser.behavior_annex();
        BehaviorAnnex ba = null;
        if (parser.getNumberOfSyntaxErrors() == 0) {
            AadlBaParserVisitor<Boolean> visitor = new AadlBaParserVisitor<Boolean>(filename, annexOffset);
            visitor.visit(bac);
            ba = bac.result;
        } else {
            // Create an empty behavior annex object in order to
            // highlight keywords even if there is some syntax errors.
            ba = AadlBaFactory.eINSTANCE.createBehaviorAnnex();
        }
        if (ba != null) {
            AadlBaLocationReference location = new AadlBaLocationReference(annexOffset, filename, line);
            location.setOffset(0);
            ba.setLocationReference(location);
        }
        return ba;
    }// Translates ANTLR runtime exception to ANTLR Exception.
     catch (org.antlr.v4.runtime.RecognitionException e) {
        int errLine = e.getOffendingToken().getLine();
        int errColumn = e.getOffendingToken().getCharPositionInLine();
        throw new antlr.RecognitionException(e.getMessage(), filename, errLine, errColumn);
    } catch (IllegalArgumentException e) {
        // Nothing to do as the parser is supposed to report any error.
        // DEBUG
        e.printStackTrace();
        return null;
    }
}
Also used : AadlBaLocationReference(org.osate.ba.utils.AadlBaLocationReference) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) Behavior_annexContext(org.osate.ba.parser.AadlBaParser.Behavior_annexContext) BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) CaseInsensitiveCharStream(org.osate.ba.utils.CaseInsensitiveCharStream) AadlBaParser(org.osate.ba.parser.AadlBaParser) CharStream(org.antlr.v4.runtime.CharStream) CaseInsensitiveCharStream(org.osate.ba.utils.CaseInsensitiveCharStream) DefaultAadlBaHighlighter(org.osate.ba.texteditor.DefaultAadlBaHighlighter) AadlAntlrErrorReporter(org.osate.ba.parser.AadlAntlrErrorReporter) AadlBaParserVisitor(org.osate.ba.parser.AadlBaParserVisitor) DefaultAadlBaHighlighter(org.osate.ba.texteditor.DefaultAadlBaHighlighter) AadlBaHighlighter(org.osate.ba.texteditor.AadlBaHighlighter) XtextAadlBaHighlighter(org.osate.ba.texteditor.XtextAadlBaHighlighter) AadlBaLexer(org.osate.ba.parser.AadlBaLexer)

Example 2 with AadlBaLocationReference

use of org.osate.ba.utils.AadlBaLocationReference in project osate2 by osate.

the class AadlBaParserVisitor method setLocationReference.

/**
 * Sets obj's location reference based on full token informations.
 *
 * @param obj the AObject to be set
 * @param src the token
 */
protected void setLocationReference(AObject obj, Token token) {
    int offset = ((CommonToken) token).getStartIndex();
    int length = token.getText().length();
    // Zero index based.
    int column = token.getCharPositionInLine() + 1;
    int line = token.getLine();
    AadlBaLocationReference location = new AadlBaLocationReference(_annexOffset, _filename, line, offset, length, column, behaviorElementId);
    obj.setLocationReference(location);
}
Also used : AadlBaLocationReference(org.osate.ba.utils.AadlBaLocationReference) CommonToken(org.antlr.v4.runtime.CommonToken)

Example 3 with AadlBaLocationReference

use of org.osate.ba.utils.AadlBaLocationReference in project osate2 by osate.

the class AadlBaSemanticHighlighter method highlightAnnexSubclause.

@Override
public void highlightAnnexSubclause(AnnexSubclause subclause, AnnexHighlighterPositionAcceptor acceptor) {
    XtextAadlBaHighlighter ht = XtextAadlBaHighlighter.getHighlighter(subclause);
    for (AadlBaLocationReference location : ht.getElementsToHighlitght()) {
        acceptor.addPosition(location.getRelativeOffset(), location.getLength(), location.getId());
    }
    ht.cleanup();
}
Also used : AadlBaLocationReference(org.osate.ba.utils.AadlBaLocationReference)

Example 4 with AadlBaLocationReference

use of org.osate.ba.utils.AadlBaLocationReference in project osate2 by osate.

the class AadlBaTextPositionResolver method resolveBehaviorAnnexElementAt.

private TextPositionInfo resolveBehaviorAnnexElementAt(int offset) {
    Element e = this.getLinkedElement(offset);
    if (e == null)
        return new TextPositionInfo(null, 0, 0);
    AadlBaLocationReference loc = this.getSourceOffsetElement(offset);
    TextPositionInfo positionInfo;
    if (e instanceof ElementHolder) {
        ElementHolder beh = (ElementHolder) e;
        positionInfo = new TextPositionInfo(beh.getElement(), loc.getOffset(), loc.getLength());
    } else {
        positionInfo = new TextPositionInfo(e, loc.getOffset(), loc.getLength());
    }
    return positionInfo;
}
Also used : AadlBaLocationReference(org.osate.ba.utils.AadlBaLocationReference) TextPositionInfo(org.osate.annexsupport.TextPositionInfo) Element(org.osate.aadl2.Element) ElementHolder(org.osate.ba.aadlba.ElementHolder)

Example 5 with AadlBaLocationReference

use of org.osate.ba.utils.AadlBaLocationReference in project osate2 by osate.

the class AadlBaTextPositionResolver method resolveBehaviorAnnexCrossReferencedElementAt.

private TextPositionInfo resolveBehaviorAnnexCrossReferencedElementAt(int offset) {
    Element e = this.getLinkedElement(offset);
    if (e == null)
        return new TextPositionInfo(null, offset, 0);
    AadlBaLocationReference loc = this.getSourceOffsetElement(offset);
    TextPositionInfo positionInfo;
    if (e instanceof ElementHolder) {
        ElementHolder beh = (ElementHolder) e;
        positionInfo = new TextPositionInfo(beh.getElement(), loc.getOffset(), loc.getLength());
    } else {
        positionInfo = new TextPositionInfo(e, loc.getOffset(), loc.getLength());
    }
    return positionInfo;
}
Also used : AadlBaLocationReference(org.osate.ba.utils.AadlBaLocationReference) TextPositionInfo(org.osate.annexsupport.TextPositionInfo) Element(org.osate.aadl2.Element) ElementHolder(org.osate.ba.aadlba.ElementHolder)

Aggregations

AadlBaLocationReference (org.osate.ba.utils.AadlBaLocationReference)6 CommonToken (org.antlr.v4.runtime.CommonToken)2 Element (org.osate.aadl2.Element)2 TextPositionInfo (org.osate.annexsupport.TextPositionInfo)2 ElementHolder (org.osate.ba.aadlba.ElementHolder)2 CharStream (org.antlr.v4.runtime.CharStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 BehaviorAnnex (org.osate.ba.aadlba.BehaviorAnnex)1 AadlAntlrErrorReporter (org.osate.ba.parser.AadlAntlrErrorReporter)1 AadlBaLexer (org.osate.ba.parser.AadlBaLexer)1 AadlBaParser (org.osate.ba.parser.AadlBaParser)1 Behavior_annexContext (org.osate.ba.parser.AadlBaParser.Behavior_annexContext)1 AadlBaParserVisitor (org.osate.ba.parser.AadlBaParserVisitor)1 AadlBaHighlighter (org.osate.ba.texteditor.AadlBaHighlighter)1 DefaultAadlBaHighlighter (org.osate.ba.texteditor.DefaultAadlBaHighlighter)1 XtextAadlBaHighlighter (org.osate.ba.texteditor.XtextAadlBaHighlighter)1 CaseInsensitiveCharStream (org.osate.ba.utils.CaseInsensitiveCharStream)1