public static RewriteEvent[] listRewriteHandleGeneratedMethods(RewriteEvent parent) { RewriteEvent[] children = parent.getChildren(); List<RewriteEvent> newChildren = new ArrayList<RewriteEvent>(); List<RewriteEvent> modifiedChildren = new ArrayList<RewriteEvent>(); for (int i = 0; i < children.length; i++) { RewriteEvent child = children[i]; boolean isGenerated = isGenerated((org.eclipse.jdt.core.dom.ASTNode) child.getOriginalValue()); if (isGenerated) { boolean isReplacedOrRemoved = child.getChangeKind() == RewriteEvent.REPLACED || child.getChangeKind() == RewriteEvent.REMOVED; boolean convertingFromMethod = child.getOriginalValue() instanceof org.eclipse.jdt.core.dom.MethodDeclaration; if (isReplacedOrRemoved && convertingFromMethod && child.getNewValue() != null) { modifiedChildren.add(new NodeRewriteEvent(null, child.getNewValue())); } } else { newChildren.add(child); } } // Since Eclipse doesn't honor the "insert at specified location" for already existing members, // we'll just add them last newChildren.addAll(modifiedChildren); return newChildren.toArray(new RewriteEvent[newChildren.size()]); }
public static int getTokenEndOffsetFixed(TokenScanner scanner, int token, int startOffset, Object domNode) throws CoreException { boolean isGenerated = false; try { isGenerated = (Boolean) domNode.getClass().getField("$isGenerated").get(domNode); } catch (Exception e) { // If this fails, better to break some refactor scripts than to crash eclipse. } if (isGenerated) return -1; return scanner.getTokenEndOffset(token, startOffset); }
private boolean lineCommentSwallowsActualCode(int prevEnd) { if (ASTRewriteAnalyzer.this.getLineCommentEndOffsets().isEndOfLineComment(prevEnd)) { int lastEndOffset = getEndOfNode((ASTNode) this.list[this.list.length - 1].getOriginalValue()); LineInformation lInfo = ASTRewriteAnalyzer.this.getLineInformation(); try { return lInfo.getLineOfOffset(lastEndOffset) == lInfo.getLineOfOffset(getScanner().getNextStartOffset(lastEndOffset, false)); } catch (CoreException e) { // ignore } } return false; }
private int rewriteNodeList(ASTNode parent, StructuralPropertyDescriptor property, int pos, String keyword, String endKeyword, String separator) { RewriteEvent event= getEvent(parent, property); if (event != null && event.getChangeKind() != RewriteEvent.UNCHANGED) { return new ListRewriter().rewriteList(parent, property, pos, keyword, endKeyword, separator); } return doVisit(parent, property, pos); }
@Override public boolean visit(Block node) { if (getPlaceholders().isCollapsed(node)) { visitList(node, Block.STATEMENTS_PROPERTY, null); return false; } return super.visit(node); }
@Override protected String getSeparatorString(int nodeIndex) { ASTNode curr= getNewNode(nodeIndex); if (curr instanceof Annotation) { return this.annotationSeparation.getPrefix(getNodeIndent(nodeIndex + 1)); } return super.getSeparatorString(nodeIndex); } }
@Override protected String getSeparatorString(int nodeIndex) { int total = this.list.length; int nextNodeIndex = nodeIndex + 1; while (nextNodeIndex < total && this.list[nextNodeIndex].getChangeKind() == RewriteEvent.REMOVED) { nextNodeIndex++; } if (nextNodeIndex == total) { return super.getSeparatorString(nodeIndex); } return getSeparatorString(nodeIndex, nextNodeIndex); }
private boolean lineCommentSwallowsActualCode(int prevEnd) { if (ASTRewriteAnalyzer.this.getLineCommentEndOffsets().isEndOfLineComment(prevEnd)) { int lastEndOffset = getEndOfNode((ASTNode) this.list[this.list.length - 1].getOriginalValue()); LineInformation lInfo = ASTRewriteAnalyzer.this.getLineInformation(); try { return lInfo.getLineOfOffset(lastEndOffset) == lInfo.getLineOfOffset(getScanner().getNextStartOffset(lastEndOffset, false)); } catch (CoreException e) { // ignore } } return false; }
private int rewriteNodeList(ASTNode parent, StructuralPropertyDescriptor property, int pos, String keyword, String separator) { RewriteEvent event= getEvent(parent, property); if (event != null && event.getChangeKind() != RewriteEvent.UNCHANGED) { return new ListRewriter().rewriteList(parent, property, pos, keyword, separator); } return doVisit(parent, property, pos); }
public boolean visit(Block node) { if (getPlaceholders().isCollapsed(node)) { visitList(node, Block.STATEMENTS_PROPERTY, null); return false; } return super.visit(node); }
protected String getSeparatorString(int nodeIndex) { ASTNode curr= getNewNode(nodeIndex); if (curr instanceof Annotation) { return this.annotationSeparation.getPrefix(getNodeIndent(nodeIndex + 1)); } return super.getSeparatorString(nodeIndex); } }
protected String getSeparatorString(int nodeIndex) { int total = this.list.length; int nextNodeIndex = nodeIndex + 1; while (nextNodeIndex < total && this.list[nextNodeIndex].getChangeKind() == RewriteEvent.REMOVED) { nextNodeIndex++; } if (nextNodeIndex == total) { return super.getSeparatorString(nodeIndex); } return getSeparatorString(nodeIndex, nextNodeIndex); }
private boolean lineCommentSwallowsActualCode(int prevEnd) { if (ASTRewriteAnalyzer.this.getLineCommentEndOffsets().isEndOfLineComment(prevEnd)) { int lastEndOffset = getEndOfNode((ASTNode) this.list[this.list.length - 1].getOriginalValue()); LineInformation lInfo = ASTRewriteAnalyzer.this.getLineInformation(); try { return lInfo.getLineOfOffset(lastEndOffset) == lInfo.getLineOfOffset(getScanner().getNextStartOffset(lastEndOffset, false)); } catch (CoreException e) { // ignore } } return false; }
private int rewriteNodeList(ASTNode parent, StructuralPropertyDescriptor property, int pos, String keyword, String endKeyword, String separator) { RewriteEvent event= getEvent(parent, property); if (event != null && event.getChangeKind() != RewriteEvent.UNCHANGED) { return new ListRewriter().rewriteList(parent, property, pos, keyword, endKeyword, separator); } return doVisit(parent, property, pos); }
public boolean visit(Block node) { if (getPlaceholders().isCollapsed(node)) { visitList(node, Block.STATEMENTS_PROPERTY, null); return false; } return super.visit(node); }
private int rewriteNodeList(ASTNode parent, StructuralPropertyDescriptor property, int pos, String keyword, String separator) { RewriteEvent event= getEvent(parent, property); if (event != null && event.getChangeKind() != RewriteEvent.UNCHANGED) { return new ListRewriter().rewriteList(parent, property, pos, keyword, separator); } return doVisit(parent, property, pos); }
public boolean visit(Block node) { if (getPlaceholders().isCollapsed(node)) { visitList(node, Block.STATEMENTS_PROPERTY, null); return false; } return super.visit(node); }
private int rewriteNodeList(ASTNode parent, StructuralPropertyDescriptor property, int pos, String keyword, String separator) { RewriteEvent event= getEvent(parent, property); if (event != null && event.getChangeKind() != RewriteEvent.UNCHANGED) { return new ListRewriter().rewriteList(parent, property, pos, keyword, separator); } return doVisit(parent, property, pos); }
public boolean visit(Block node) { if (getPlaceholders().isCollapsed(node)) { visitList(node, Block.STATEMENTS_PROPERTY, null); return false; } return super.visit(node); }
private int rewriteNodeList(ASTNode parent, StructuralPropertyDescriptor property, int pos, String keyword, String endKeyword, String separator) { RewriteEvent event= getEvent(parent, property); if (event != null && event.getChangeKind() != RewriteEvent.UNCHANGED) { return new ListRewriter().rewriteList(parent, property, pos, keyword, endKeyword, separator); } return doVisit(parent, property, pos); }