use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.
the class OutlinePage method selectionChanged.
@Override
public void selectionChanged(final SelectionChangedEvent event) {
super.selectionChanged(event);
ISelection selection = event.getSelection();
if (selection.isEmpty()) {
return;
}
Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
Identifier identifier = null;
if (selectedElement instanceof IOutlineElement) {
identifier = ((IOutlineElement) selectedElement).getIdentifier();
}
if (identifier == null || identifier.getLocation() == null) {
return;
}
Location location = identifier.getLocation();
editor.selectAndReveal(location.getOffset(), location.getEndOffset() - location.getOffset());
}
use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.
the class VariantAttributeAnalyzer method parse.
public void parse(final RawAST rawAST, final AttributeSpecification specification, final int lengthMultiplier, final AtomicBoolean raw_found) {
VariantAttributeLexer lexer;
Location location = specification.getLocation();
StringReader reader = new StringReader(specification.getSpecification());
CharStream charStream = new UnbufferedCharStream(reader);
lexer = new VariantAttributeLexer(charStream);
lexer.setTokenFactory(new CommonTokenFactory(true));
TitanListener lexerListener = new TitanListener();
lexer.removeErrorListeners();
lexer.addErrorListener(lexerListener);
final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
VariantAttributeParser parser = new VariantAttributeParser(tokenStream);
parser.setBuildParseTree(false);
TitanListener parserListener = new TitanListener();
parser.removeErrorListeners();
parser.addErrorListener(parserListener);
parser.setActualFile((IFile) location.getFile());
parser.setLine(location.getLine());
parser.setOffset(location.getOffset() + 1);
MarkerHandler.markMarkersForRemoval(GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER, location.getFile(), location.getOffset(), location.getEndOffset());
parser.setRawAST(rawAST);
parser.setLengthMultiplier(lengthMultiplier);
parser.pr_AttribSpec();
if (!lexerListener.getErrorsStored().isEmpty()) {
for (int i = 0; i < lexerListener.getErrorsStored().size(); i++) {
Location temp = new Location(location);
temp.setOffset(temp.getOffset() + 1);
ParserMarkerSupport.createOnTheFlyMixedMarker((IFile) location.getFile(), lexerListener.getErrorsStored().get(i), IMarker.SEVERITY_ERROR, temp);
}
}
if (!parserListener.getErrorsStored().isEmpty()) {
for (int i = 0; i < parserListener.getErrorsStored().size(); i++) {
Location temp = new Location(location);
temp.setOffset(temp.getOffset() + 1);
ParserMarkerSupport.createOnTheFlyMixedMarker((IFile) location.getFile(), parserListener.getErrorsStored().get(i), IMarker.SEVERITY_ERROR, temp);
}
}
if (!raw_found.get()) {
raw_found.set(parser.getRawFound());
}
}
use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.
the class ExtensionAttributeAnalyzer method parse.
public void parse(final AttributeSpecification specification) {
ExtensionAttributeLexer lexer;
Location location = specification.getLocation();
StringReader reader = new StringReader(specification.getSpecification());
CharStream charStream = new UnbufferedCharStream(reader);
lexer = new ExtensionAttributeLexer(charStream);
lexer.setTokenFactory(new CommonTokenFactory(true));
TitanListener lexerListener = new TitanListener();
lexer.removeErrorListeners();
lexer.addErrorListener(lexerListener);
// 1. Previously it was UnbufferedTokenStream(lexer), but it was changed to BufferedTokenStream, because UnbufferedTokenStream seems to be unusable. It is an ANTLR 4 bug.
// Read this: https://groups.google.com/forum/#!topic/antlr-discussion/gsAu-6d3pKU
// pr_PatternChunk[StringBuilder builder, boolean[] uni]:
// $builder.append($v.text); <-- exception is thrown here: java.lang.UnsupportedOperationException: interval 85..85 not in token buffer window: 86..341
// 2. Changed from BufferedTokenStream to CommonTokenStream, otherwise tokens with "-> channel(HIDDEN)" are not filtered out in lexer.
final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
ExtensionAttributeParser parser = new ExtensionAttributeParser(tokenStream);
parser.setBuildParseTree(false);
TitanListener parserListener = new TitanListener();
parser.removeErrorListeners();
parser.addErrorListener(parserListener);
parser.setActualFile((IFile) location.getFile());
parser.setLine(location.getLine());
parser.setOffset(location.getOffset() + 1);
MarkerHandler.markMarkersForRemoval(GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER, location.getFile(), location.getOffset(), location.getEndOffset());
attributes = null;
attributes = parser.pr_ExtensionAttributeRoot().list;
if (!lexerListener.getErrorsStored().isEmpty()) {
String reportLevel = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTERRORSINEXTENSIONSYNTAX, GeneralConstants.WARNING, null);
int errorLevel;
if (GeneralConstants.ERROR.equals(reportLevel)) {
errorLevel = IMarker.SEVERITY_ERROR;
} else if (GeneralConstants.WARNING.equals(reportLevel)) {
errorLevel = IMarker.SEVERITY_WARNING;
} else {
return;
}
for (int i = 0; i < lexerListener.getErrorsStored().size(); i++) {
Location temp = new Location(location);
temp.setOffset(temp.getOffset() + 1);
ParserMarkerSupport.createOnTheFlyMixedMarker((IFile) location.getFile(), lexerListener.getErrorsStored().get(i), errorLevel, temp);
}
}
if (!parserListener.getErrorsStored().isEmpty()) {
String reportLevel = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTERRORSINEXTENSIONSYNTAX, GeneralConstants.WARNING, null);
int errorLevel;
if (GeneralConstants.ERROR.equals(reportLevel)) {
errorLevel = IMarker.SEVERITY_ERROR;
} else if (GeneralConstants.WARNING.equals(reportLevel)) {
errorLevel = IMarker.SEVERITY_WARNING;
} else {
return;
}
for (int i = 0; i < parserListener.getErrorsStored().size(); i++) {
Location temp = new Location(location);
temp.setOffset(temp.getOffset() + 1);
ParserMarkerSupport.createOnTheFlyMixedMarker((IFile) location.getFile(), parserListener.getErrorsStored().get(i), errorLevel, temp);
}
}
}
use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method createTextEdit.
private TextEdit[] createTextEdit(final IFile toVisit, final String fileContent, final Edit e, final Map<Edit, InsertEdit> editsDone) {
// check for multi-declaration statement
if (e.declSt.isMultiDeclaration()) {
final Location cutLoc = calculateMultiDeclarationCutLoc(fileContent, e.declSt);
final String moveContent = calculateMultiDeclarationMoveContent(fileContent, e.declSt);
// remove stmt from multi-declaration
e.declSt.removeFromMultiDeclaration();
// create remove edit
final int cutLen = cutLoc.getEndOffset() - cutLoc.getOffset();
final TextEdit cut = new DeleteEdit(cutLoc.getOffset(), cutLen);
// create insert edit
InsertEdit insert = null;
if (!e.isRemoveEdit()) {
// update insert location if the insertionPoint stmt was moved
int insertOffset = ((ILocateableNode) e.insertionPoint.getAstNode()).getLocation().getOffset();
for (Map.Entry<Edit, InsertEdit> ed : editsDone.entrySet()) {
if (ed.getKey().declSt.equals(e.insertionPoint)) {
insertOffset = ed.getValue().getOffset();
break;
}
}
//
insertOffset = findLineBeginningOffset(fileContent, insertOffset);
insert = new InsertEdit(insertOffset, moveContent);
editsDone.put(e, insert);
}
if (insert != null) {
return new TextEdit[] { insert, cut };
}
return new TextEdit[] { cut };
} else {
//
final Location cutLoc = findStatementLocation(fileContent, ((ILocateableNode) e.declSt.getAstNode()).getLocation(), true);
InsertEdit insert = null;
if (!e.isRemoveEdit()) {
final Location copyLoc = findStatementLocation(fileContent, ((ILocateableNode) e.declSt.getAstNode()).getLocation(), false);
// update insert location if the insertionPoint stmt was moved
final Location insPLoc = ((ILocateableNode) e.insertionPoint.getAstNode()).getLocation();
int insertOffset = insPLoc.getOffset();
for (Map.Entry<Edit, InsertEdit> ed : editsDone.entrySet()) {
if (ed.getKey().declSt.equals(e.insertionPoint)) {
insertOffset = ed.getValue().getOffset();
break;
}
}
//
final int prefixStartOffset = findLineBeginningOffset(fileContent, insertOffset);
final String insertText = fileContent.substring(copyLoc.getOffset(), copyLoc.getEndOffset()) + "\n";
String insertPrefix = fileContent.substring(prefixStartOffset, insertOffset);
// if prefix is not whitespace only, do not use the prefix
if (!insertPrefix.trim().equals("")) {
insertPrefix = "";
}
insert = new InsertEdit(prefixStartOffset, insertPrefix + insertText);
editsDone.put(e, insert);
}
final int cutLen = cutLoc.getEndOffset() - cutLoc.getOffset();
final TextEdit cut = new DeleteEdit(cutLoc.getOffset(), cutLen);
// System.err.println("DeleteEdit: " + fileContent.substring(cutLoc.getOffset(), cutLoc.getEndOffset()));
if (insert != null) {
return new TextEdit[] { insert, cut };
}
return new TextEdit[] { cut };
}
}
use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.
the class StatementNode method toString.
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("SN(").append(astNode.toString()).append("), loc: ");
if (astNode instanceof ILocateableNode) {
final Location loc = ((ILocateableNode) astNode).getLocation();
sb.append(loc.getOffset()).append('-').append(loc.getEndOffset()).append(';');
} else {
sb.append("<none>;");
}
sb.append(" parent: ");
if (parent == null) {
sb.append("<null>; ");
} else {
sb.append("BN(").append(parent.astNode.toString()).append("); ");
}
if (moved) {
sb.append("MOVED; ");
}
if (isDeclaration()) {
sb.append("declaration: " + declaredVar);
}
return sb.toString();
}
Aggregations