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;
}
}
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);
}
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();
}
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;
}
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;
}
Aggregations