use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class PartialParserTest method testInsertSlashInSecondNode.
@Test
public void testInsertSlashInSecondNode() throws Exception {
IParseResult parseResult = resource.getParser().reparse(this.parseResult, new ReplaceRegion(model.indexOf('6'), 0, "/"));
assertFalse(parseResult.hasSyntaxErrors());
assertEquals(0, parseResult.getRootNode().getTotalOffset());
assertSame(resource.getParseResult().getRootNode(), parseResult.getRootNode());
String newModel = "a.b.c.d: 123;\n" + "e.f.g.h: 45/6;";
EmfAssert.assertEObjectsEqual(getModel(newModel), resource.getParseResult().getRootASTElement());
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class AbstractPackratParser method parse.
protected final IParseResult parse(INonTerminalConsumer consumer) {
if (activeMarker != null)
throw new IllegalStateException("cannot parse now. Active marker is already assigned.");
IMarker rootMarker = mark();
IRootConsumerListener listener = new RootConsumerListener();
try {
consumer.consumeAsRoot(listener);
IParseResult result = getParseResultFactory().createParseResult(activeMarker, input);
rootMarker.commit();
if (activeMarker != null)
throw new IllegalStateException("cannot finish parse: active marker is still present.");
return result;
} catch (Exception e) {
throw new WrappedException(e);
}
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class MultiLineJavaDocTypeReferenceProvider method computeEObjectReferencedInComment.
/**
* {@inheritDoc}
*/
@Override
public EObjectInComment computeEObjectReferencedInComment(XtextResource resource, int offset) {
IParseResult parseResult = resource.getParseResult();
if (parseResult != null) {
INode rootNode = parseResult.getRootNode();
INode node = NodeModelUtils.findLeafNodeAtOffset(rootNode, offset);
EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(node);
if (semanticObject != null) {
EReference reference = getEReference(semanticObject, node, offset);
if (reference != null) {
IScope scope = getScope(semanticObject, reference, node, offset);
List<ReplaceRegion> eObjectReferences = computeTypeRefRegions(node);
for (ReplaceRegion eObjectReference : eObjectReferences) {
if (eObjectReference.getOffset() <= offset && offset <= eObjectReference.getEndOffset()) {
String eObjectReferenceText = eObjectReference.getText();
if (!Strings.isNullOrEmpty(eObjectReferenceText)) {
ITextRegion region = new TextRegion(eObjectReference.getOffset(), eObjectReference.getLength());
IEObjectDescription candidate = getElementFromScope(scope, node, region, eObjectReferenceText);
if (candidate != null) {
EObject eObject = candidate.getEObjectOrProxy();
if (eObject != null) {
return new EObjectInComment(eObject, region);
}
}
}
}
}
}
}
}
return null;
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class Bug419429Test method replaceAndReparse.
protected void replaceAndReparse(String model, int offset, int length, String change, String expectedReparseRegion) throws Exception {
IParseResult parseResult = getParseResultAndExpect(model, UNKNOWN_EXPECTATION);
PartialParsingPointers parsingPointers = getPartialParser().calculatePartialParsingPointers(parseResult, offset, length);
String reparseRegion = getPartialParser().insertChangeIntoReplaceRegion(parsingPointers.getDefaultReplaceRootNode(), new ReplaceRegion(offset, length, change));
assertEquals(expectedReparseRegion, reparseRegion);
final Wrapper<Boolean> unloaded = Wrapper.wrap(Boolean.FALSE);
getPartialParser().setUnloader(new IReferableElementsUnloader() {
@Override
public void unloadRoot(EObject root) {
unloaded.set(Boolean.TRUE);
}
});
IParseResult partiallyReparse = reparse(parseResult, offset, length, change);
assertTrue("unloaded", unloaded.get());
String expectedReparseModel = model.substring(0, offset) + change + model.substring(offset + length);
assertEquals(expectedReparseModel, partiallyReparse.getRootNode().getText());
compareWithFullParse(model, offset, length, change);
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class DefaultTaskFinder method findTasks.
@Override
public List<Task> findTasks(Resource resource) {
TaskTags taskTags = taskTagProvider.getTaskTags(resource);
if (isEmpty(taskTags) || !(resource instanceof XtextResource)) {
return emptyList();
}
IParseResult parseResult = ((XtextResource) resource).getParseResult();
if (parseResult == null || parseResult.getRootNode() == null) {
return emptyList();
}
List<Task> tasks = findTasks(parseResult.getRootNode(), taskTags);
return unmodifiableList(tasks);
}
Aggregations