use of org.eclipse.xtext.parser.IParseResult in project xtext-eclipse by eclipse.
the class XtextReconcilerDebugger method assertResouceParsedCorrectly.
public void assertResouceParsedCorrectly(XtextResource resource, final ReconcilerReplaceRegion region) {
IParseResult parseResult = resource.getParseResult();
if (parseResult != null) {
ICompositeNode rootNode = parseResult.getRootNode();
final String resourceContent = rootNode.getText();
IParseResult reparseResult = parser.parse(new StringReader(resourceContent));
if (!emfStructureComparator.isSameStructure(parseResult.getRootASTElement(), reparseResult.getRootASTElement())) {
new DisplayRunnable() {
@Override
protected void run() throws Exception {
LOG.error("PartialParsing produced wrong model");
LOG.error("Events: \n\t" + Joiner.on("\n\t").join(region.getDocumentEvents()));
LOG.error("ReplaceRegion: \n\t'" + region + "'");
MessageDialog.openError(Display.getCurrent().getActiveShell(), "XtextReconcilerDebugger", "PartialParsing produced wrong model." + "\n\nSee log for details.");
}
};
}
}
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-eclipse by eclipse.
the class XtextReconcilerDebugger method assertModelInSyncWithDocument.
public void assertModelInSyncWithDocument(IDocument document, XtextResource resource, final ReconcilerReplaceRegion region) {
if (document instanceof IDocumentExtension4 && resource != null) {
long beforeGet = ((IDocumentExtension4) document).getModificationStamp();
final String documentContent = document.get();
long afterGet = ((IDocumentExtension4) document).getModificationStamp();
if (beforeGet == afterGet && beforeGet == resource.getModificationStamp()) {
IParseResult parseResult = resource.getParseResult();
if (parseResult != null) {
ICompositeNode rootNode = parseResult.getRootNode();
final String resourceContent = rootNode.getText();
if (!resourceContent.equals(documentContent)) {
new DisplayRunnable() {
@Override
protected void run() throws Exception {
LOG.error("XtextDocument and XtextResource have run out of sync:\n" + DiffUtil.diff(documentContent, resourceContent));
LOG.error("Events: \n\t" + Joiner.on("\n\t").join(region.getDocumentEvents()));
LOG.error("ReplaceRegion: \n\t'" + region + "'");
MessageDialog.openError(Display.getCurrent().getActiveShell(), "XtextReconcilerDebugger", "XtextDocument and XtextResource have run out of sync." + "\n\nSee log for details.");
}
}.syncExec();
} else {
if (LOG.isDebugEnabled())
LOG.debug("Model and document are in sync");
}
}
}
}
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-eclipse by eclipse.
the class AstSelectionProvider method selectEnclosing.
public ITextRegion selectEnclosing(XtextResource resource, ITextRegion currentEditorSelection) {
Pair<EObject, EObject> currentlySelected = getSelectedAstElements(resource, currentEditorSelection);
if (currentlySelected == null) {
IParseResult parseResult = resource.getParseResult();
if (parseResult != null) {
ICompositeNode rootNode = parseResult.getRootNode();
int offset = getSelectionOffset(rootNode, currentEditorSelection);
INode node = findLeafNodeAtOffset(rootNode, offset);
if (node != null) {
ITextRegion fineGrainedRegion = computeInitialFineGrainedSelection(node, currentEditorSelection);
if (fineGrainedRegion != null) {
selectionHistory.clear();
register(currentEditorSelection);
return register(fineGrainedRegion);
}
EObject eObject = findSemanticObjectFor(node);
return register(getTextRegion(eObject));
}
}
} else {
EObject first = currentlySelected.getFirst();
if (first.eContainer() != null) {
return register(getTextRegion(first.eContainer()));
}
}
return ITextRegion.EMPTY_REGION;
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-eclipse by eclipse.
the class AstSelectionProvider method getEObjectAtOffset.
protected EObject getEObjectAtOffset(XtextResource resource, ITextRegion currentEditorSelection) {
IParseResult parseResult = resource.getParseResult();
if (parseResult != null) {
ICompositeNode rootNode = parseResult.getRootNode();
INode nodeAtOffset = findLeafNodeAtOffset(rootNode, currentEditorSelection.getOffset());
return findSemanticObjectFor(nodeAtOffset);
}
return null;
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-eclipse by eclipse.
the class ExpressionUtil method trimSelection.
protected ITextSelection trimSelection(XtextResource resource, ITextSelection selection) {
IParseResult parseResult = resource.getParseResult();
if (parseResult != null) {
String model = parseResult.getRootNode().getText();
String selectedText = model.substring(selection.getOffset(), selection.getOffset() + selection.getLength());
String trimmedSelection = selectedText.trim();
return new TextSelection(selection.getOffset() + selectedText.indexOf(trimmedSelection), trimmedSelection.length());
}
return null;
}
Aggregations