public Range newRange(final Resource resource, final ITextRegion region) { if ((region == null)) { return null; } int _offset = region.getOffset(); int _offset_1 = region.getOffset(); int _length = region.getLength(); int _plus = (_offset_1 + _length); return this.newRange(resource, _offset, _plus); }
@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); }
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 void addOccurrenceAnnotation(String type, IDocument document, ITextRegion textRegion, Map<Annotation, Position> annotationMap) { try { if (textRegion != null && textRegion.getLength() > 0) { Annotation annotation = new Annotation(type, false, document.get(textRegion.getOffset(), textRegion.getLength())); annotationMap.put(annotation, new Position(textRegion.getOffset(), textRegion.getLength())); } } catch (BadLocationException e) { LOG.error("Error creating occurrence annotation", e); } }
protected boolean addImportDeclaration(final ContentAssistEntry entry, final ITextRegion importSectionRegion, final ITypeDescriptor typeDesc, final String qualifiedName, final ContentAssistContext context) { boolean _xblockexpression = false; { int _offset = importSectionRegion.getOffset(); int _length = importSectionRegion.getLength(); final int insertionOffset = (_offset + _length); final String declaration = ("\nimport " + qualifiedName); ArrayList<ReplaceRegion> _textReplacements = entry.getTextReplacements(); ReplaceRegion _replaceRegion = new ReplaceRegion(insertionOffset, 0, declaration); _xblockexpression = _textReplacements.add(_replaceRegion); } return _xblockexpression; } }
private boolean isIgnored(JvmType type, ITextRegion refRegion) { IParseResult parseResult = getResource().getParseResult(); if (parseResult == null) { return false; } String completeText = parseResult.getRootNode().getText(); CharSequence refText = completeText.subSequence(refRegion.getOffset(), refRegion.getOffset() + refRegion.getLength()); return type.getQualifiedName().equals(refText); }
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())); }
protected void computeObjectFolding(EObject eObject, IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor) { 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(); foldingRegionAcceptor.accept(offset, region.getLength(), significant); } }
@Nullable public ILocationInResource getBestAssociatedLocation(ITextRegion region, IStorage storage) { URI uri = getURIForStorage(storage); AbstractTraceRegion left = findTraceRegionAtLeftOffset(region.getOffset()); left = findParentByURI(left, uri); AbstractTraceRegion right = findTraceRegionAtRightOffset(region.getOffset() + region.getLength()); right = findParentByURI(right, uri); return mergeRegions(left, right); }
protected RefactoringStatusContext createContext(IFile file, ITextRegion textRegion) { if (file == null) return null; Region region = textRegion == null ? null : new Region(textRegion.getOffset(), textRegion.getLength()); return new FileStatusContext(file, region); }
@Override public DocumentHighlight apply(final Document document, final ITextRegion region, final DocumentHighlightKind kind) { Preconditions.checkNotNull(document, "document"); Preconditions.checkNotNull(region, "region"); Preconditions.checkNotNull(kind, "kind"); final int offset = region.getOffset(); final Position start = document.getPosition(offset); final Position end = document.getPosition(offset + region.getLength()); return new DocumentHighlight(new Range(start, end), kind); }
public ITextRegion addLeadingWhitespace(ITextRegion textRegion, XtextResource resource) { String text = resource.getParseResult().getRootNode().getText(); int offset = textRegion.getOffset(); int length = textRegion.getLength(); while(offset > 0 && Character.isWhitespace(text.charAt(offset-1)) ){ --offset; ++length; } return new TextRegion(offset, length); }
protected void createTextChange(ITextRegion referenceTextRegion, String newReferenceText, EObject referringElement, EObject newTargetElement, EReference reference, URI referringResourceURI, IRefactoringUpdateAcceptor updateAcceptor) { if (newReferenceText != null) { TextEdit referenceEdit = new ReplaceEdit(referenceTextRegion.getOffset(), referenceTextRegion.getLength(), newReferenceText); updateAcceptor.accept(referringResourceURI, referenceEdit); } }
protected void setSelection(ITextRegion textSelection, boolean reveal) { StyledText text = getSourceViewer().getTextWidget(); if (text.getText().length() >= textSelection.getOffset() + textSelection.getLength()) { getSourceViewer().setSelection(new TextSelection(textSelection.getOffset(), textSelection.getLength()), reveal); } }
protected ITextRegion getRegion(Pair<EObject, EObject> selection) { final ITextRegion firstRegion = getTextRegion(selection.getFirst()); if (selection.getFirst() == selection.getSecond()) { return firstRegion; } ITextRegion secondRegion = getTextRegion(selection.getSecond()); return new TextRegion(firstRegion.getOffset(), getEndOffset(secondRegion) - firstRegion.getOffset()); }
protected ITextRegion computeInitialFineGrainedSelection(INode node, ITextRegion currentEditorSelection) { if (node.getText().trim().length() > 0 && currentEditorSelection.getOffset() >= node.getOffset() && getEndOffset(currentEditorSelection) < node.getOffset() + node.getLength()) { //TODO enhance to just select a single word in a comment or string literal. return new TextRegion(node.getOffset(), node.getLength()); } return null; }
protected RefactoringStatusContext createContext(EObject eObject, ITextRegion textRegion) { IRegion region = null; if (textRegion != null) region = new Region(textRegion.getOffset(), textRegion.getLength()); IFile file = projectUtil.findFileStorage(EcoreUtil2.getPlatformResourceOrNormalizedURI(eObject), false); if(file == null) return null; return new FileStatusContext(file, region); }
protected FoldedPosition newFoldedPosition(IRegion region, ITextRegion significantRegion) { if (region == null) return null; if (significantRegion != null) return new DefaultFoldedPosition(region.getOffset(), region.getLength(), significantRegion.getOffset() - region.getOffset(), significantRegion.getLength()); return new DefaultFoldedPosition(region.getOffset(), region.getLength(), DefaultFoldedPosition.UNSET, DefaultFoldedPosition.UNSET); }