use of org.eclipse.xtext.util.ITextRegion in project xtext-eclipse by eclipse.
the class DefaultFoldingRegionProvider method computeObjectFolding.
/**
* @since 2.8
*/
protected void computeObjectFolding(EObject eObject, IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor, boolean initiallyFolded) {
ITextRegion region = locationInFileProvider.getFullTextRegion(eObject);
if (region != null) {
ITextRegion significant = locationInFileProvider.getSignificantTextRegion(eObject);
if (significant == null)
throw new NullPointerException("significant region may not be null");
int offset = region.getOffset();
((IFoldingRegionAcceptorExtension<ITextRegion>) foldingRegionAcceptor).accept(offset, region.getLength(), initiallyFolded, significant);
}
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-eclipse by eclipse.
the class DefaultFoldingRegionProvider method computeCommentFolding.
/**
* @since 2.8
*/
protected void computeCommentFolding(IXtextDocument xtextDocument, IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor, ITypedRegion typedRegion, boolean initiallyFolded) throws BadLocationException {
int offset = typedRegion.getOffset();
int length = typedRegion.getLength();
Matcher matcher = getTextPatternInComment().matcher(xtextDocument.get(offset, length));
if (matcher.find()) {
TextRegion significant = new TextRegion(offset + matcher.start(), 0);
((IFoldingRegionAcceptorExtension<ITextRegion>) foldingRegionAcceptor).accept(offset, length, initiallyFolded, significant);
} else {
((IFoldingRegionAcceptorExtension<ITextRegion>) foldingRegionAcceptor).accept(offset, length, initiallyFolded);
}
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-eclipse by eclipse.
the class AbstractEObjectHover method getXtextElementAt.
/**
* Call this method only from within an IUnitOfWork
*/
protected Pair<EObject, IRegion> getXtextElementAt(XtextResource resource, final int offset) {
// check for cross reference
EObject crossLinkedEObject = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, offset);
if (crossLinkedEObject != null) {
if (!crossLinkedEObject.eIsProxy()) {
IParseResult parseResult = resource.getParseResult();
if (parseResult != 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) {
ITextRegion leafRegion = leafNode.getTextRegion();
return Tuples.create(crossLinkedEObject, (IRegion) new Region(leafRegion.getOffset(), leafRegion.getLength()));
}
}
}
} else {
EObject o = eObjectAtOffsetHelper.resolveElementAt(resource, offset);
if (o != null) {
ITextRegion region = locationInFileProvider.getSignificantTextRegion(o);
final IRegion region2 = new Region(region.getOffset(), region.getLength());
if (TextUtilities.overlaps(region2, new Region(offset, 0)))
return Tuples.create(o, region2);
}
}
return null;
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-eclipse by eclipse.
the class TraceBasedOpenerContributor method collectOpeners.
private void collectOpeners(IEclipseTrace trace, ITextRegion region, IAcceptor<FileOpener> acceptor) {
Iterable<? extends ILocationInEclipseResource> locations = null;
if (region != null)
locations = trace.getAllAssociatedLocations(region);
if (locations == null || Iterables.isEmpty(locations))
locations = trace.getAllAssociatedLocations();
Map<IStorage, ITextRegion> result = Maps.newHashMap();
for (ILocationInEclipseResource location : locations) {
IStorage storage = location.getPlatformResource();
if (storage != null) {
ITextRegion old = result.put(storage, location.getTextRegion());
if (old != null) {
ITextRegion merged = old.merge(location.getTextRegion());
result.put(storage, merged);
}
}
}
for (Map.Entry<IStorage, ITextRegion> e : result.entrySet()) {
IStorage storage = e.getKey();
ITextRegion textRegion = e.getValue();
acceptor.accept(createStorageBasedTextEditorOpener(storage, textRegion));
}
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-eclipse by eclipse.
the class ParameterContextInformationProvider method getContextInformation.
@Override
public void getContextInformation(ContentAssistContext context, IContextInformationAcceptor acceptor) {
XExpression containerCall = getContainerCall(eObjectAtOffsetHelper.resolveContainedElementAt(context.getResource(), context.getOffset()));
LightweightTypeReferenceFactory factory = proposalProvider.getTypeConverter(context.getResource());
if (containerCall != null) {
ICompositeNode containerCallNode = NodeModelUtils.findActualNodeFor(containerCall);
ITextRegion containerCallRegion = containerCallNode.getTextRegion();
if (containerCallRegion.getOffset() > context.getOffset() || containerCallRegion.getOffset() + containerCallRegion.getLength() < context.getOffset())
return;
JvmIdentifiableElement calledFeature = getCalledFeature(containerCall);
if (calledFeature instanceof JvmExecutable) {
if (getParameterListOffset(containerCall) > context.getOffset())
return;
ParameterData parameterData = new ParameterData();
IScope scope = getScope(containerCall);
QualifiedName qualifiedName = QualifiedName.create(getCalledFeatureName(containerCall));
boolean candidatesFound = false;
for (IEObjectDescription element : scope.getElements(qualifiedName)) {
if (element instanceof IIdentifiableElementDescription) {
IIdentifiableElementDescription featureDescription = (IIdentifiableElementDescription) element;
JvmIdentifiableElement featureCandidate = featureDescription.getElementOrProxy();
if (featureCandidate instanceof JvmExecutable) {
JvmExecutable executable = (JvmExecutable) featureCandidate;
if (!executable.getParameters().isEmpty()) {
StyledString styledString = new StyledString();
proposalProvider.appendParameters(styledString, executable, featureDescription.getNumberOfIrrelevantParameters(), factory);
parameterData.addOverloaded(styledString.toString(), executable.isVarArgs());
candidatesFound = true;
}
}
}
}
if (candidatesFound) {
StyledString displayString = proposalProvider.getStyledDisplayString((JvmExecutable) calledFeature, true, 0, qualifiedNameConverter.toString(qualifiedNameProvider.getFullyQualifiedName(calledFeature)), calledFeature.getSimpleName(), factory);
ParameterContextInformation parameterContextInformation = new ParameterContextInformation(parameterData, displayString.toString(), getParameterListOffset(containerCall), context.getOffset());
acceptor.accept(parameterContextInformation);
}
}
}
}
Aggregations