public void update(int offset, int replacedTextLength, String newText) { if (!isLoaded()) { throw new IllegalStateException("You can't update an unloaded resource."); } try { isUpdating = true; IParseResult oldParseResult = parseResult; ReplaceRegion replaceRegion = new ReplaceRegion(new TextRegion(offset, replacedTextLength), newText); IParseResult newParseResult = parser.reparse(oldParseResult, replaceRegion); updateInternalState(oldParseResult, newParseResult); } finally { isUpdating = false; } }
@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); }
@Override public ITextRegion merge(ITextRegion other) { if (other instanceof ITextRegionWithLineInformation) return merge((ITextRegionWithLineInformation) other); return super.merge(other); }
@Override public String toString() { return "TextRegionWithLineInformation " + super.toString() + "[lineNumber=" + lineNumber + ", endLineNumber=" + endLineNumber + "]"; }
@Override public String toString() { return "TextRegionWithLineInformation " + super.toString() + "[lineNumber=" + lineNumber + ", endLineNumber=" + endLineNumber + "]"; }
/** * @return the cross referenced EObject under, right or left to the cursor (in that order) or * <code>null</code> if there is no cross referenced object next to the offset. */ public EObject resolveCrossReferencedElementAt(XtextResource resource, int offset) { INode node = getCrossReferenceNode(resource, new TextRegion(offset, 0)); if (node != null) return getCrossReferencedElement(node); return null; }
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 ITextRegion merge(ITextRegion other) { if (other instanceof ITextRegionWithLineInformation) return merge((ITextRegionWithLineInformation) other); return super.merge(other); }
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); }
public IOutlineNode createRoot(IXtextDocument document, ImageDescriptor imageDescriptor, Object text, IOutlineTreeStructureProvider provider) { DocumentRootNode documentNode = new DocumentRootNode(imageDescriptor, text, document, provider); documentNode.setTextRegion(new TextRegion(0, document.getLength())); return documentNode; }
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; } }
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 addSectionToAppend(IAcceptor<ReplaceRegion> acceptor) { StringBuilder importDeclarationsToAppend = getImportDeclarationsToAppend(); if (importDeclarationsToAppend.length() == 0) return; importRegion = regionUtil.addLeadingWhitespace(importRegion, resource); importRegion = regionUtil.addTrailingSingleWhitespace(importRegion, lineSeparator, resource); int insertOffset = importRegion.getOffset() + importRegion.getLength(); if (insertOffset != 0 && originalImportDeclarations.isEmpty()) importDeclarationsToAppend.insert(0, lineSeparator); importDeclarationsToAppend.append(lineSeparator); int insertLength = -importRegion.getLength(); insertLength += regionUtil.addTrailingWhitespace(importRegion, resource).getLength(); ReplaceRegion appendDeclarations = new ReplaceRegion(new TextRegion(insertOffset, insertLength), importDeclarationsToAppend.toString()); acceptor.accept(appendDeclarations); }
int _offset = selection.getOffset(); int _length = selection.getLength(); TextRegion _textRegion = new TextRegion(_offset, _length); regionWrapper.set(_textRegion); int _offset_1 = formattedRegion.getOffset(); int _length_1 = formattedRegion.getLength(); TextRegion _textRegion_1 = new TextRegion(_offset_1, _length_1); regionWrapper.set(_textRegion_1); } else {
public ITextRegion computeRegion(XtextResource resource) { XImportSection xImportSection = config.getImportSection(resource); // try to obtain the region from the text if it is not a synthetic region. if (xImportSection != null && xImportSection.eResource() != null) { INode node = NodeModelUtils.findActualNodeFor(xImportSection); if(node == null) LOG.error("Cannot detect node for original import section"); else return node.getTextRegion(); } return new TextRegion(config.getImportSectionOffset(resource), 0); }
public void createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) { INode crossRefNode = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(offset, 0)); if (crossRefNode == null) return; EObject crossLinkedEObject = eObjectAtOffsetHelper.getCrossReferencedElement(crossRefNode); if (crossLinkedEObject != null && !crossLinkedEObject.eIsProxy()) { createHyperlinksTo(resource, crossRefNode, crossLinkedEObject, acceptor); } }
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; }
@Override protected String getStringRepresentation(final Object object) { if ((object instanceof AbstractIdeTemplateProposalProvider.Variable)) { final String varName = ((AbstractIdeTemplateProposalProvider.Variable)object).name; int _offset = this.context.getReplaceRegion().getOffset(); int _currentOffset = this.getCurrentOffset(); final int offset = (_offset + _currentOffset); int _length = varName.length(); TextRegion _textRegion = new TextRegion(offset, _length); this.entry.getEditPositions().add(_textRegion); return varName; } else { if ((object instanceof AbstractIdeTemplateProposalProvider.Cursor)) { int _offset_1 = this.context.getReplaceRegion().getOffset(); int _currentOffset_1 = this.getCurrentOffset(); final int offset_1 = (_offset_1 + _currentOffset_1); this.entry.setEscapePosition(Integer.valueOf(offset_1)); return null; } else { return object.toString(); } } }
public IOutlineNode createRoot(IXtextDocument document) { DocumentRootNode documentNode = new DocumentRootNode(labelProvider.getImage(document), labelProvider.getText(document), document, this); documentNode.setTextRegion(new TextRegion(0, document.getLength())); return documentNode; }
protected void computeCommentFolding(IXtextDocument xtextDocument, IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor) { try { ITypedRegion[] typedRegions = xtextDocument.computePartitioning( IDocumentExtension3.DEFAULT_PARTITIONING, 0, xtextDocument.getLength(), false); for (ITypedRegion typedRegion : typedRegions) { if (tokenTypeToPartitionTypeMapperExtension.isMultiLineComment(typedRegion.getType())) { 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); foldingRegionAcceptor.accept(offset, length, significant); } else { foldingRegionAcceptor.accept(offset, length); } } } } catch (BadLocationException e) { log.error(e, e); } catch (BadPartitioningException e) { log.error(e, e); } catch (AssertionFailedException e) { // partioning failed log.error(e, e); } }