private void validateIsExistingNode(ASTNode node) { if (node.getStartPosition() == -1) { throw new IllegalArgumentException("Node is not an existing node"); //$NON-NLS-1$ } }
private void addOffsets(int[] offsets, int start, Set<SimpleName> nodeSet) { int i= start; for (Iterator<SimpleName> iter= nodeSet.iterator(); iter.hasNext(); i++) { ASTNode node= iter.next(); offsets[i]= node.getStartPosition(); } }
protected boolean found(ASTNode node, ASTNode name) { if (name.getStartPosition() == this.rangeStart && name.getLength() == this.rangeLength) { this.foundNode = node; return true; } return false; }
private static boolean rangeEndsBetween(ISourceRange range, ASTNode first, ASTNode next) { int pos= Util.getEndExclusive(range); return first.getStartPosition() + first.getLength() <= pos && pos <= next.getStartPosition(); }
private int findFieldInsertIndex(List<BodyDeclaration> decls, int currPos) { for (int i= decls.size() - 1; i >= 0; i--) { ASTNode curr= decls.get(i); if (curr instanceof FieldDeclaration && currPos > curr.getStartPosition() + curr.getLength()) { return i + 1; } } return 0; }
private boolean isCovered(ASTNode node) { int begin= node.getStartPosition(); int end= begin + node.getLength(); return begin >= selectionBegin && end <= selectionEnd; } });
private int findMethodInsertIndex(List decls, int currPos) { int nDecls= decls.size(); for (int i= 0; i < nDecls; i++) { ASTNode curr= (ASTNode) decls.get(i); if (curr instanceof MethodDeclaration && currPos < curr.getStartPosition() + curr.getLength()) { return i + 1; } } return nDecls; }
protected void recordSourceReference( final ASTNode astNode, final Node jcrNode ) throws Exception { jcrNode.setProperty(ClassFileSequencerLexicon.START_POSITION, astNode.getStartPosition()); jcrNode.setProperty(ClassFileSequencerLexicon.LENGTH, astNode.getLength()); }
private boolean containsPosition(ASTNode node) { int startPosition= node.getStartPosition(); int endPosition = startPosition + node.getLength(); return startPosition <= fPosition && fPosition <= endPosition; }
private int getEndPositionExclusive() { List operands= getOperands(); ASTNode lastNode= (ASTNode) operands.get(operands.size() - 1); return lastNode.getStartPosition() + lastNode.getLength(); }
private CodeScopeBuilder(ASTNode node, IBinding ignore) { fScope = new Scope(null, node.getStartPosition(), node.getLength()); fScopes = new ArrayList<>(); fIgnoreBinding = ignore; }
protected static ISourceRange getSelectedNodeSourceRange(ISourceReference sr, ASTNode nodeToSelect) throws JavaModelException { int offset= nodeToSelect.getStartPosition(); int end= Math.min(sr.getSourceRange().getLength(), nodeToSelect.getStartPosition() + nodeToSelect.getLength() - 1); return createSourceRange(offset, end); }
public int firstIndexIn(ASTNode node, int tokenType) { int index = findIndex(node.getStartPosition(), tokenType, true); assert tokenInside(node, index); return index; }
public int getStartPosition() { if (this.group.isEmpty()) { return this.node.getStartPosition(); } IRegion coverage= TextEdit.getCoverage(this.group.getTextEdits()); if (coverage == null) { return this.node.getStartPosition(); } return coverage.getOffset(); }
public int getEndVisitSelectionMode(ASTNode node) { int nodeStart= node.getStartPosition(); int nodeEnd= nodeStart + node.getLength(); if (nodeEnd <= fStart) return BEFORE; else if (covers(node)) return SELECTED; else if (nodeEnd >= fExclusiveEnd) return AFTER; return INTERSECTS; }
private void searchNode(ASTNode node, String contents, String label, ArrayList<TextEditGroup> textedits) { int start= node.getStartPosition(); int length= node.getLength(); int trailing = findTrailingSemicolons(contents, start + length); if (trailing > 0) { ReplaceEdit edit = new ReplaceEdit(start + length, trailing, ""); //$NON-NLS-1$ textedits.add(new TextEditGroup(label, edit)); } }
private boolean handleEmptyParens(ASTNode nodeBeforeParens, boolean insertSpace) { int openingIndex = this.tm.findIndex(nodeBeforeParens.getStartPosition(), TokenNameLPAREN, true); if (this.tm.get(openingIndex + 1).tokenType == TokenNameRPAREN) { if (insertSpace) this.tm.get(openingIndex).spaceAfter(); return true; } return false; }
/** * Returns the extended source range for a node. * * @return an extended source range (never null) * @since 3.1 */ final SourceRange getExtendedRange(ASTNode node) { if (this.eventStore.isRangeCopyPlaceholder(node)) { return new SourceRange(node.getStartPosition(), node.getLength()); } return this.extendedSourceRangeComputer.computeSourceRange(node); }
protected static String getNewText(final ASTNode node, final ICompilationUnit declaringCu, final boolean removeIndentation) throws JavaModelException { final String result= declaringCu.getBuffer().getText(node.getStartPosition(), node.getLength()); if (removeIndentation) return getUnindentedText(result, declaringCu); return result; }
@Override public void updateNode() throws JavaModelException { int start= fNode.getStartPosition(); int length= fNode.getLength(); String msg= "Cannot update found node: nodeType=" + fNode.getNodeType() + "; " //$NON-NLS-1$//$NON-NLS-2$ + fNode.toString() + "[" + start + ", " + length + "] in " + fCuRewrite.getCu(); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ JavaPlugin.log(new Exception(msg + ":\n" + fCuRewrite.getCu().getSource().substring(start, start + length))); //$NON-NLS-1$ fResult.addError(msg, JavaStatusContext.create(fCuRewrite.getCu(), fNode)); } @Override