public int[] getSelectionStartAndEnd(ICompilationUnit iunit) { int[] offsets = new int[2]; CompilationUnit parsedUnit = ASTreeManipulationMethods.parseICompilationUnit(iunit); ASTNode nodeOne = ASTreeManipulationMethods.getASTNodeByIndex(parsedUnit, firstCutNodeIndex); ASTNode nodeTwo = ASTreeManipulationMethods.getASTNodeByIndex(parsedUnit, lastCutNodeIndex); offsets[0] = nodeOne.getStartPosition(); offsets[1] = nodeTwo.getStartPosition() + nodeTwo.getLength() - 1; return offsets; }
private int getCuttedASTNodeIndexInNodeTwo(ASTNode nodeOne, ASTNode nodeTwo) { int start = ExtractMethod.getLengthOfCommonnSubnodesFromStart(nodeOne, nodeTwo); ArrayList<ASTNode> childrenTwo = ASTreeManipulationMethods.getChildNodes(nodeTwo); ASTNode node; if (start != 0) node = childrenTwo.get(start - 1); else node = nodeTwo; int index = ASTreeManipulationMethods.getASTNodeIndexInCompilationUnit(node); return index; }
private int[] getCutASTNodeIndex(ASTNode nodeOne, ASTNode nodeTwo) { int[] index = new int[2]; ArrayList<ASTNode> childrenOne = ASTreeManipulationMethods.getChildNodes(nodeOne); ArrayList<ASTNode> childrenTwo = ASTreeManipulationMethods.getChildNodes(nodeTwo); int childrenOneSize = childrenOne.size(); int childrenTwoSize = childrenTwo.size(); int start = ExtractMethod.getLengthOfCommonnSubnodesFromStart(nodeOne, nodeTwo); int end = Math.min( ExtractMethod.getLengthOfCommonnSubnodesFromEnd(nodeOne, nodeTwo), childrenTwoSize - start); ASTNode firstDiffNode = childrenOne.get(start); ASTNode lastDiffNode = childrenOne.get(childrenOneSize - end - 1); index[0] = ASTreeManipulationMethods.getASTNodeIndexInCompilationUnit(firstDiffNode); index[1] = ASTreeManipulationMethods.getASTNodeIndexInCompilationUnit(lastDiffNode); return index; }
public int getRefactoringMarkerLine(ICompilationUnit unit) throws Exception { CompilationUnit tree = ASTreeManipulationMethods.parseICompilationUnit(unit); ASTNode node = ASTreeManipulationMethods.getASTNodeByIndex(tree, insertPlaceNodeIndex); int lineNo = tree.getLineNumber(node.getStartPosition()); return lineNo + 1; }