@Override public ITextRegion merge(ITextRegion other) { if (contains(other)) return this; if (other.contains(this)) return other; int newOffset = Math.min(offset, other.getOffset()); int newLength = Math.max(offset + length, other.getOffset() + other.getLength()) - newOffset; return new TextRegion(newOffset, newLength); }
protected IOutlineNode findBestNode(IOutlineNode input, ITextRegion selectedTextRegion) { ITextRegion textRegion = input.getFullTextRegion(); if (textRegion == null || textRegion.contains(selectedTextRegion)) { IOutlineNode currentBestNode = input; for (IOutlineNode child : input.getChildren()) { IOutlineNode candidate = findBestNode(child, selectedTextRegion); if (candidate != null && (currentBestNode.getFullTextRegion() == null || currentBestNode.getFullTextRegion() .getLength() >= candidate.getFullTextRegion().getLength())) { currentBestNode = candidate; } } return currentBestNode; } return null; }
protected void assertReplacementsAreInRegion(List<ITextReplacement> rep, Collection<ITextRegion> regions, String doc) { Set<ITextReplacement> invalid = Sets.newHashSet(); ALLOWED: for (ITextRegion allowed : regions) for (ITextReplacement r : rep) { if (allowed.contains(r)) continue ALLOWED; invalid.add(r); } if (!invalid.isEmpty()) { String visualized = new TextRegionsToString().addAllReplacements(invalid).toString(); fail("One or more TextReplacements are outside of the allowed region. Region: " + regions, visualized); } }
if (!featureNodes.isEmpty()) { INode featureNode = featureNodes.get(0); result = result.merge(toZeroBasedRegion(featureNode.getTextRegionWithLineInformation())); List<INode> targetNodes = NodeModelUtils.findNodesForFeature(owner, XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET); if (!targetNodes.isEmpty()) { INode targetNode = targetNodes.get(0); result = result.merge(toZeroBasedRegion(targetNode.getTextRegionWithLineInformation())); if (length != 0) { if (pending != null) { result.merge(toZeroBasedRegion(pending.getTextRegionWithLineInformation())); pending = null; pending = node; } else { result = result.merge(toZeroBasedRegion(node.getTextRegionWithLineInformation()));
protected boolean needsPreceedingBlankLine() { return regionUtil.addLeadingWhitespace(importRegion, resource).getOffset() != 0; }
public EObject getElementAt(final XtextResource resource, final int offset) { EObject crossLinkedEObject = this._eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, offset); if ((crossLinkedEObject != null)) { return crossLinkedEObject; } else { EObject containedEObject = this._eObjectAtOffsetHelper.resolveContainedElementAt(resource, offset); if ((containedEObject != null)) { final ITextRegion nameRegion = this._iLocationInFileProvider.getSignificantTextRegion(containedEObject); boolean _contains = nameRegion.contains(offset); if (_contains) { return containedEObject; } } } return null; } }
public EStructuralFeatureNode createEStructuralFeatureNode(IOutlineNode parentNode, EObject owner, EStructuralFeature feature, ImageDescriptor imageDescriptor, Object text, boolean isLeaf) { boolean isFeatureSet = owner.eIsSet(feature); EStructuralFeatureNode eStructuralFeatureNode = new EStructuralFeatureNode(owner, feature, parentNode, imageDescriptor, text, isLeaf || !isFeatureSet); if (isFeatureSet) { ITextRegion region = locationInFileProvider.getFullTextRegion(owner, feature, 0); if (feature.isMany()) { int numValues = ((Collection<?>) owner.eGet(feature)).size(); ITextRegion fullTextRegion = locationInFileProvider.getFullTextRegion(owner, feature, numValues - 1); if(fullTextRegion != null) region = region.merge(fullTextRegion); } eStructuralFeatureNode.setTextRegion(region); } return eStructuralFeatureNode; }
public ITextRegion merge(ITextRegion other) { if (contains(other)) return this; if (other.contains(this)) return other; int newOffset = Math.min(offset, other.getOffset()); int newLength = Math.max(offset + length, other.getOffset() + other.getLength()) - newOffset; return new TextRegion(newOffset, newLength); }
@Override public boolean existsConflict(String proposal, ContentAssistContext context) { // hidden node between lastCompleteNode and currentNode? INode lastCompleteNode = context.getLastCompleteNode(); ITextRegion replaceRegion = context.getReplaceRegion(); int nodeEnd = lastCompleteNode.getEndOffset(); if (nodeEnd < replaceRegion.getOffset()) return false; return existsConflict(lastCompleteNode, replaceRegion.getOffset(), proposal, context); }
protected Range getRange(final HoverContext it) { boolean _contains = it.getRegion().contains(it.getOffset()); boolean _not = (!_contains); if (_not) { return null; } return this._documentExtensions.newRange(it.getResource(), it.getRegion()); }
protected EStructuralFeatureNode createEStructuralFeatureNode(IOutlineNode parentNode, EObject owner, EStructuralFeature feature, Image image, Object text, boolean isLeaf) { boolean isFeatureSet = owner.eIsSet(feature); EStructuralFeatureNode eStructuralFeatureNode = new EStructuralFeatureNode(owner, feature, parentNode, image, text, isLeaf || !isFeatureSet); if (isFeatureSet) { ITextRegion region = locationInFileProvider.getFullTextRegion(owner, feature, 0); if (feature.isMany()) { int numValues = ((Collection<?>) owner.eGet(feature)).size(); ITextRegion fullTextRegion = locationInFileProvider.getFullTextRegion(owner, feature, numValues - 1); if (fullTextRegion != null) region = region.merge(fullTextRegion); } eStructuralFeatureNode.setTextRegion(region); } return eStructuralFeatureNode; }
protected String getIndentation(final ContentAssistContext context) { ICompositeNode _rootNode = context.getRootNode(); String _text = null; if (_rootNode!=null) { _text=_rootNode.getText(); } final String text = _text; if (((text != null) && (text.length() >= context.getOffset()))) { int lineStart = context.getReplaceRegion().getOffset(); int indentEnd = lineStart; while (((lineStart > 0) && (text.charAt((lineStart - 1)) != "\n".charAt(0)))) { { lineStart--; boolean _isWhitespace = Character.isWhitespace(text.charAt(lineStart)); boolean _not = (!_isWhitespace); if (_not) { indentEnd = lineStart; } } } return text.substring(lineStart, indentEnd); } return null; } }
/** * Collects import declarations in XtextResource for the given range (selectedRegion) */ public void collectImports(final XtextResource state, final ITextRegion selectedRegion, final ImportsAcceptor acceptor) { ICompositeNode rootNode = state.getParseResult().getRootNode(); final EObject selectedSemanticObj = this.findActualSemanticObjectFor(rootNode, selectedRegion); final Iterable<ILeafNode> contentsIterator = NodeModelUtils.findActualNodeFor(selectedSemanticObj).getLeafNodes(); for (final ILeafNode node : contentsIterator) { { final ITextRegion nodeRegion = node.getTotalTextRegion(); boolean _contains = selectedRegion.contains(nodeRegion); if (_contains) { final EObject semanticElement = node.getSemanticElement(); if ((semanticElement != null)) { this.visit(semanticElement, NodeModelUtils.findActualNodeFor(semanticElement), acceptor); } } if ((node.isHidden() && this.grammarAccess.getML_COMMENTRule().equals(node.getGrammarElement()))) { this.addJavaDocReferences(node, selectedRegion, acceptor); } } } }
protected ITextRegion createRegion(final List<INode> nodes) { ITextRegion result = ITextRegion.EMPTY_REGION; for (INode node : nodes) { if (!isHidden(node)) { int length = node.getLength(); if (length != 0) result = result.merge(new TextRegionWithLineInformation(node.getOffset(), length, node.getStartLine() - 1, node.getEndLine() - 1)); } } return result; }