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 void initializeAndAdjustCompletionOffset(int offset) { completionOffset = offset; if (selection.getOffset() + selection.getLength() == offset) completionOffset = selection.getOffset(); }
public ITextRegion addTrailingSingleWhitespace(ITextRegion textRegion, String lineSeparator, XtextResource resource) { String text = resource.getParseResult().getRootNode().getText(); String theFollowing = text.substring(textRegion.getOffset() + textRegion.getLength()); if(!isEmpty(theFollowing)) { if(theFollowing.startsWith(lineSeparator)) return new TextRegion(textRegion.getOffset(), textRegion.getLength() + lineSeparator.length()); else if(Character.isWhitespace(theFollowing.charAt(0))) return new TextRegion(textRegion.getOffset(), textRegion.getLength() + 1); } return textRegion; } }
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; } }
public ITextRegion addTrailingWhitespace(ITextRegion textRegion, XtextResource resource) { String text = resource.getParseResult().getRootNode().getText(); int offset = textRegion.getOffset(); int length = textRegion.getLength(); while(offset + length < text.length() && Character.isWhitespace(text.charAt(offset+length))) { ++length; } return new TextRegion(offset, length); }
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); } }
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); }
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); }
@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 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 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 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 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 highlightNumberLiterals(XNumberLiteral literal, IHighlightedPositionAcceptor acceptor) { ICompositeNode node = NodeModelUtils.findActualNodeFor(literal); ITextRegion textRegion = node.getTextRegion(); acceptor.addPosition(textRegion.getOffset(), textRegion.getLength(), NUMBER_ID); }
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); }
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); }
@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); }
@Override public void run() { ITextSelection selection = (ITextSelection) xtextEditor.getSelectionProvider().getSelection(); ITextRegion currentEditorSelection = new TextRegion(selection.getOffset(), selection.getLength()); ITextRegion nextSelection = xtextEditor.getDocument().readOnly(createTextSelectionWork(currentEditorSelection)); if (nextSelection == null || nextSelection == ITextRegion.EMPTY_REGION || nextSelection.equals(currentEditorSelection)) { return; } xtextEditor.selectAndReveal(nextSelection.getOffset(), nextSelection.getLength()); }
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); }