use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class DefaultSemanticHighlightingCalculator method provideHighlightingFor.
@Override
public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
if (resource == null)
return;
IParseResult parseResult = resource.getParseResult();
if (parseResult == null || parseResult.getRootASTElement() == null)
return;
doProvideHighlightingFor(resource, acceptor, cancelIndicator);
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class DefaultSemanticHighlightingCalculator method searchAndHighlightElements.
protected void searchAndHighlightElements(XtextResource resource, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
IParseResult parseResult = resource.getParseResult();
if (parseResult == null)
throw new IllegalStateException("resource#parseResult may not be null");
EObject element = parseResult.getRootASTElement();
highlightElementRecursively(element, acceptor, cancelIndicator);
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class DefaultDocumentHighlightService method getDocumentHighlights.
@Override
public List<DocumentHighlight> getDocumentHighlights(final XtextResource resource, final int offset) {
if (resource == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Resource was null.");
}
return emptyList();
}
final URI uri = resource.getURI();
if (offset < 0) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Invalid offset argument. Offset must be a non-negative integer for resource: " + uri);
}
return emptyList();
}
final IParseResult parseResult = resource.getParseResult();
if (parseResult == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Parse result was null for resource: " + uri);
}
return emptyList();
}
final ICompositeNode rootNode = parseResult.getRootNode();
final String docContent = rootNode.getText();
final int docLength = docContent.length();
if (offset >= docLength) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Offset exceeds document lenght. Document was " + docLength + " and offset was: " + offset + " for resource: " + uri);
}
return emptyList();
}
final EObject selectedElemnt = offsetHelper.resolveElementAt(resource, offset);
if (!isDocumentHighlightAvailableFor(selectedElemnt, resource, offset)) {
return emptyList();
}
final Supplier<Document> docSupplier = Suppliers.memoize(() -> new Document(UNUSED_VERSION, docContent));
Iterable<URI> targetURIs = getTargetURIs(selectedElemnt);
if (!(targetURIs instanceof TargetURIs)) {
final TargetURIs result = targetURIsProvider.get();
result.addAllURIs(targetURIs);
targetURIs = result;
}
final Builder<DocumentHighlight> resultBuilder = ImmutableList.<DocumentHighlight>builder();
final Acceptor acceptor = (Acceptor2) (source, sourceURI, eReference, index, targetOrProxy, targetURI) -> {
final ITextRegion region = locationInFileProvider.getSignificantTextRegion(source, eReference, index);
if (!isNullOrEmpty(region)) {
resultBuilder.add(textRegionTransformer.apply(docSupplier.get(), region, DocumentHighlightKind.Read));
}
};
referenceFinder.findReferences((TargetURIs) targetURIs, resource, acceptor, new NullProgressMonitor());
if (resource.equals(selectedElemnt.eResource())) {
final ITextRegion region = locationInFileProvider.getSignificantTextRegion(selectedElemnt);
if (!isNullOrEmpty(region)) {
resultBuilder.add(textRegionTransformer.apply(docSupplier.get(), region, DocumentHighlightKind.Write));
}
}
return FluentIterable.from(resultBuilder.build()).toSortedList(comparator);
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class HoverService method createContext.
protected HoverContext createContext(final Document document, final XtextResource resource, final int offset) {
final EObject crossLinkedEObject = this._eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, offset);
if ((crossLinkedEObject != null)) {
boolean _eIsProxy = crossLinkedEObject.eIsProxy();
if (_eIsProxy) {
return null;
}
final IParseResult parseResult = resource.getParseResult();
if ((parseResult == null)) {
return null;
}
ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset);
if ((((leafNode != null) && leafNode.isHidden()) && (leafNode.getOffset() == offset))) {
leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), (offset - 1));
}
if ((leafNode == null)) {
return null;
}
final ITextRegion leafRegion = leafNode.getTextRegion();
return new HoverContext(document, resource, offset, leafRegion, crossLinkedEObject);
}
final EObject element = this._eObjectAtOffsetHelper.resolveElementAt(resource, offset);
if ((element == null)) {
return null;
}
final ITextRegion region = this._iLocationInFileProvider.getSignificantTextRegion(element);
return new HoverContext(document, resource, offset, region, element);
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class PartialParsingProcessor method processFile.
@Override
public String processFile(String completeData, String data, int offset, int len, String change) throws Exception {
IParseResult initialParseResult = parser.parse(new StringReader(data));
String newData = applyDelta(data, offset, len, change);
ReplaceRegion replaceRegion = new ReplaceRegion(offset, len, change);
try {
IParseResult reparsed = parser.reparse(initialParseResult, replaceRegion);
IParseResult parsedFromScratch = parser.parse(new StringReader(newData));
assertEqual(data, newData, parsedFromScratch, reparsed);
return newData;
} catch (Throwable e) {
ComparisonFailure throwMe = new ComparisonFailure(e.getMessage(), newData, replaceRegion + DELIM + data);
throwMe.initCause(e);
throw throwMe;
}
}
Aggregations