Java Code Examples for org.eclipse.xtext.util.ReplaceRegion#getOffset()
The following examples show how to use
org.eclipse.xtext.util.ReplaceRegion#getOffset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultTextEditComposer.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected List<TextEdit> getObjectEdits() { final Collection<EObject> modifiedObjects = getModifiedObjects(); Collection<EObject> topLevelObjects = EcoreUtil.filterDescendants(modifiedObjects); Iterable<EObject> containedModifiedObjects = Collections.emptyList(); if (!resource.getContents().isEmpty()) { final EObject root = resource.getContents().get(0); containedModifiedObjects = Iterables.filter(topLevelObjects, new Predicate<EObject>() { @Override public boolean apply(EObject input) { return EcoreUtil.isAncestor(root, input); } }); } List<TextEdit> edits = Lists.newArrayListWithExpectedSize(Iterables.size(containedModifiedObjects)); for (EObject modifiedObject : containedModifiedObjects) { ReplaceRegion replaceRegion = serializer.serializeReplacement(modifiedObject, getSaveOptions()); TextEdit edit = new ReplaceEdit(replaceRegion.getOffset(), replaceRegion.getLength(), replaceRegion.getText()); edits.add(edit); } return edits; }
Example 2
Source File: ImportsCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
private void addJavaDocReferences(final INode documentationNode, final ITextRegion selectedRegion, final ImportsAcceptor acceptor) { List<ReplaceRegion> _computeTypeRefRegions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(documentationNode); for (final ReplaceRegion docTypeReference : _computeTypeRefRegions) { { int _offset = docTypeReference.getOffset(); int _length = docTypeReference.getLength(); final TextRegion referenceRange = new TextRegion(_offset, _length); boolean _contains = selectedRegion.contains(referenceRange); if (_contains) { String docTypeText = docTypeReference.getText(); final EObject element = NodeModelUtils.findActualSemanticObjectFor(documentationNode); IScope scope = this.scopeProvider.getScope(element, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE); IEObjectDescription singleElement = scope.getSingleElement(QualifiedName.create(docTypeText)); JvmType referencedType = null; if ((singleElement != null)) { EObject _eObjectOrProxy = singleElement.getEObjectOrProxy(); referencedType = ((JvmType) _eObjectOrProxy); } if (((referencedType instanceof JvmDeclaredType) && (!referencedType.eIsProxy()))) { JvmDeclaredType casted = ((JvmDeclaredType) referencedType); boolean _equals = casted.getQualifiedName().equals(docTypeText); boolean _not = (!_equals); if (_not) { acceptor.acceptTypeImport(casted); } } } } } }
Example 3
Source File: TokenRegionProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public ReplaceRegion getTokenReplaceRegion(String changedText, ReplaceRegion replaceRegion) { int lengthDelta = replaceRegion.getText().length() - replaceRegion.getLength(); ITextRegion tokenRegion = getTokenRegion(changedText, new TextRegion(replaceRegion.getOffset(), replaceRegion .getText().length())); if (tokenRegion.getOffset() == replaceRegion.getOffset() && tokenRegion.getLength() == replaceRegion.getText().length()) return replaceRegion; else return new ReplaceRegion(tokenRegion.getOffset(), tokenRegion.getLength() - lengthDelta, changedText.substring(tokenRegion.getOffset(), tokenRegion.getOffset() + tokenRegion.getLength())); }
Example 4
Source File: MultiLineJavaDocTypeReferenceProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * {@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; }