/** * Creates a document template context. * * @param type the context type * @param document the document this context applies to * @param offset the offset of the document region * @param length the length of the document region */ public DocumentTemplateContext(TemplateContextType type, IDocument document, int offset, int length) { this(type, document, new Position(offset, length)); }
private static Position[] createPositions(int[] positions) { Position[] p = null; if (positions != null) { p = new Position[positions.length]; for (int i = 0; i < positions.length; i++) { p[i] = new Position(positions[i], 0); } } return p; } }
private JavaMethodParameterCodeMining(ASTNode node, Expression parameter, int parameterIndex, CompilationUnit cu, ICodeMiningProvider provider, boolean showName, boolean showType, boolean showParameterByUsingFilters) { super(new Position(parameter.getStartPosition(), 1), provider, null); this.cu = cu; this.node = node; this.parameter = parameter; this.parameterIndex = parameterIndex; this.showName = showName; this.showType = showType; this.showParameterByUsingFilters = showParameterByUsingFilters; }
public String getPrefix(int indent) { Position pos= new Position(this.start, this.length); String str= this.string; TextEdit res= formatString(this.kind, str, 0, str.length(), indent); if (res != null) { str= evaluateFormatterEdit(str, res, new Position[] { pos }); } return str.substring(pos.offset + 1, pos.offset + pos.length - 1); } }
public String getPrefix(int indent) { Position pos= new Position(this.start, this.length); String str= this.string; TextEdit res= formatString(this.kind, str, 0, str.length(), indent); if (res != null) { str= evaluateFormatterEdit(str, res, new Position[] { pos }); } return str.substring(pos.offset + 1, pos.offset + pos.length - 1); } }
public String getPrefix(int indent) { Position pos= new Position(this.start, this.length); String str= this.string; TextEdit res= formatString(this.kind, str, 0, str.length(), indent); if (res != null) { str= evaluateFormatterEdit(str, res, new Position[] { pos }); } return str.substring(pos.offset + 1, pos.offset + pos.length - 1); } }
public String[] getPrefixAndSuffix(int indent, ASTNode node, RewriteEventStore events) { String nodeString= ASTRewriteFlattener.asString(node, events); String str= this.prefix + nodeString; Position pos= new Position(this.start, this.prefix.length() + 1 - this.start); TextEdit res= formatString(CodeFormatter.K_STATEMENTS, str, 0, str.length(), indent); if (res != null) { str= evaluateFormatterEdit(str, res, new Position[] { pos }); } return new String[] { str.substring(pos.offset + 1, pos.offset + pos.length - 1), ""}; //$NON-NLS-1$ } }
@Override public String[] getPrefixAndSuffix(int indent, ASTNode node, RewriteEventStore events) { String nodeString= ASTRewriteFlattener.asString(node, events); String str= this.prefix + nodeString; Position pos= new Position(this.start, this.prefix.length() + 1 - this.start); TextEdit res= formatString(CodeFormatter.K_STATEMENTS, str, 0, str.length(), indent); if (res != null) { str= evaluateFormatterEdit(str, res, new Position[] { pos }); } return new String[] { str.substring(pos.offset + 1, pos.offset + pos.length - 1), ""}; //$NON-NLS-1$ } }
/** * Sets the extent of this range. * * @param range the extent of this range */ public void setRange(IRegion range) { fPosition= new Position(range.getOffset(), range.getLength()); }
private static Position getPosition(ASTNode node, IDocument document) { int offset = node.getStartPosition(); try { IRegion region = document.getLineInformationOfOffset(offset); return new Position(region.getOffset() + region.getLength(), 1); } catch (BadLocationException e) { return new Position(offset, 1); } }
/** * Sets the extent of this range. * * @param range the extent of this range */ public void setRange(IRegion range) { fPosition= new Position(range.getOffset(), range.getLength()); }
protected Position createPositionFromProblem(IProblem problem) { int start = problem.getOffset(); if (start >= 0) { int length = problem.getLength(); if (length >= 0) return new Position(start, length); } return null; }
private void registerPositionUpdater(int start, int length) { fBaseDocument.addPositionCategory(RANGE_CATEGORY); fRange= new Position(start, length); try { fBaseDocument.addPosition(RANGE_CATEGORY, fRange); } catch (BadPositionCategoryException ex) { CompareUIPlugin.log(ex); } catch (BadLocationException ex) { CompareUIPlugin.log(ex); } }
@Override public void documentAboutToBeChanged(DocumentEvent event) { if (fActiveRegion != null) { fRememberedPosition= new Position(fActiveRegion.getOffset(), fActiveRegion.getLength()); try { event.getDocument().addPosition(fRememberedPosition); } catch (BadLocationException x) { fRememberedPosition= null; } } }
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); } }
@Override protected Position getSourceRange(IType type, IDocument doc, IReference reference) throws CoreException, BadLocationException { ISourceRange range = type.getNameRange(); Position pos = null; if (range != null) { pos = new Position(range.getOffset(), range.getLength()); } if (pos == null) { return defaultSourcePosition(type, reference); } return pos; }
private void registerPositionUpdater(int start, int length) { fBaseDocument.addPositionCategory(RANGE_CATEGORY); fRange= new Position(start, length); try { fBaseDocument.addPosition(RANGE_CATEGORY, fRange); } catch (BadPositionCategoryException ex) { CompareUIPlugin.log(ex); } catch (BadLocationException ex) { CompareUIPlugin.log(ex); } }
private void calculateLightBulb(IAnnotationModel model, IInvocationContext context) { boolean needsAnnotation= JavaCorrectionProcessor.hasAssists(context); if (fIsAnnotationShown) { model.removeAnnotation(fAnnotation); } if (needsAnnotation) { model.addAnnotation(fAnnotation, new Position(context.getSelectionOffset(), context.getSelectionLength())); } fIsAnnotationShown= needsAnnotation; }
public static Position convertToCharacterPosition(Position linePosition, IDocument doc) throws BadLocationException { int lineOffset= linePosition.getOffset(); int lineLength= linePosition.getLength(); int charOffset= doc.getLineOffset(lineOffset); int charLength= 0; if (lineLength > 0) { int lastLine= lineOffset+lineLength-1; int endPosition= doc.getLineOffset(lastLine)+doc.getLineLength(lastLine); charLength= endPosition-charOffset; } return new Position(charOffset, charLength); }
public static Position convertToCharacterPosition(Position linePosition, IDocument doc) throws BadLocationException { int lineOffset= linePosition.getOffset(); int lineLength= linePosition.getLength(); int charOffset= doc.getLineOffset(lineOffset); int charLength= 0; if (lineLength > 0) { int lastLine= lineOffset+lineLength-1; int endPosition= doc.getLineOffset(lastLine)+doc.getLineLength(lastLine); charLength= endPosition-charOffset; } return new Position(charOffset, charLength); }