@Override protected boolean visitNode(ASTNode node) { if (node.getStartPosition() > fSelection.getInclusiveEnd()) return true; if (fSelection.coveredBy(node)) return true; return false; } @Override
@Override public boolean visit(Assignment node) { boolean result = super.visit(node); Selection selection = getSelection(); ASTNode selectedNode = NodeFinder.perform(node, selection.getOffset(), selection.getLength()); if ((selectedNode != null && SnippetFinder.isLeftHandSideOfAssignment(selectedNode)) || (selection.covers(node.getLeftHandSide()) && !selection.covers(node.getRightHandSide()))) { invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_leftHandSideOfAssignment, JavaStatusContext.create(fCUnit, node)); return false; } return result; }
private ASTVisitor createVisitor() throws CoreException { fAnalyzer= new ExtractMethodAnalyzer(fCUnit, Selection.createFromStartLength(fSelectionStart, fSelectionLength)); return fAnalyzer; }
private Selection adjustSelection(char[] characters, Selection selection, int end) { int newEnd= selection.getInclusiveEnd(); for(int i= selection.getExclusiveEnd(); i <= end; i++) { char ch= characters[i]; if (ch != '\n' && ch != '\r') break; newEnd++; } return Selection.createFromStartEnd(selection.getOffset(), newEnd); }
/** * Creates an status entry context for the given type root and selection. * * @param typeRoot the type root containing the error * @param selection a selection denoting the source range that has caused the error * * @return the status entry context or <code>Context.NULL_CONTEXT</code> if the * context cannot be created */ public static RefactoringStatusContext create(ITypeRoot typeRoot, Selection selection) { ISourceRange range= null; if (selection != null) range= new SourceRange(selection.getOffset(), selection.getLength()); return create(typeRoot, range); }
public boolean visit(MethodDeclaration node) { Block body= node.getBody(); if (body == null) return false; Selection selection= getSelection(); int nodeStart= body.getStartPosition(); int nodeExclusiveEnd= nodeStart + body.getLength(); // if selection node inside of the method body ignore method if (!(nodeStart < selection.getOffset() && selection.getExclusiveEnd() < nodeExclusiveEnd)) return false; return super.visit(node); }
private boolean isSelected(ASTNode node) { return fSelection.getVisitSelectionMode(node) == Selection.SELECTED; } }
@Override public void endVisit(ConstructorInvocation node) { if (getSelection().getEndVisitSelectionMode(node) == Selection.SELECTED) { invalidSelection(JavaManipulationMessages.SurroundWithTryCatchAnalyzer_cannotHandleThis, JavaStatusContext.create(fCUnit, node)); } super.endVisit(node); }
private IVariableBinding[] removeSelectedDeclarations(IVariableBinding[] bindings) { List<IVariableBinding> result = new ArrayList<>(bindings.length); Selection selection = getSelection(); for (int i = 0; i < bindings.length; i++) { ASTNode decl = ((CompilationUnit) fEnclosingBodyDeclaration.getRoot()).findDeclaringNode(bindings[i]); if (!selection.covers(decl)) { result.add(bindings[i]); } } return result.toArray(new IVariableBinding[result.size()]); }
private void createLoopReentranceVisitor(ASTNode node) { if (fLoopReentranceVisitor == null && fDoLoopReentrance && fSelection.coveredBy(node)) { fLoopReentranceVisitor = new LoopReentranceVisitor(fFlowContext, fSelection, node); } }
@Override public boolean visit(Assignment node) { boolean result= super.visit(node); if ((getSelection().covers(node.getLeftHandSide()) && !getSelection().covers(node.getRightHandSide())) || getSelection().coveredBy(node.getLeftHandSide())) { invalidSelection( RefactoringCoreMessages.ExtractMethodAnalyzer_leftHandSideOfAssignment, JavaStatusContext.create(fCUnit, node)); return false; } return result; }
@Override protected boolean createReturnFlowInfo(ReturnStatement node) { // Make sure that the whole return statement is located after the selection. There can be cases like // return i + [x + 10] * 10; In this case we must not create a return info node. return node.getStartPosition() >= fSelection.getInclusiveEnd(); }
protected boolean createReturnFlowInfo(ReturnStatement node) { // Make sure that the whole return statement is selected or located before the selection. return node.getStartPosition() + node.getLength() <= fSelection.getExclusiveEnd(); } protected ASTNode getLoopNode() {
@Override public boolean visit(DoStatement node) { boolean result = super.visit(node); try { int actionStart = getTokenScanner().getTokenEndOffset(ITerminalSymbols.TokenNamedo, node.getStartPosition()); if (getSelection().getOffset() == actionStart) { invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_after_do_keyword, JavaStatusContext.create(fCUnit, getSelection())); return false; } } catch (CoreException e) { // ignore } return result; }
/** * Creates a new selection from the given start and length. * * @param s the start offset of the selection (inclusive) * @param l the length of the selection * @return the created selection object */ public static Selection createFromStartLength(int s, int l) { Assert.isTrue(s >= 0 && l >= 0); Selection result= new Selection(); result.fStart= s; result.fLength= l; result.fExclusiveEnd= s + l; return result; }
/** * Creates an status entry context for the given type root and selection. * * @param typeRoot the type root containing the error * @param selection a selection denoting the source range that has caused the error * * @return the status entry context or <code>Context.NULL_CONTEXT</code> if the * context cannot be created */ public static RefactoringStatusContext create(ITypeRoot typeRoot, Selection selection) { ISourceRange range= null; if (selection != null) range= new SourceRange(selection.getOffset(), selection.getLength()); return create(typeRoot, range); }
private Selection adjustSelection(char[] characters, Selection selection, int end) { int newEnd= selection.getInclusiveEnd(); for(int i= selection.getExclusiveEnd(); i <= end; i++) { char ch= characters[i]; if (ch != '\n' && ch != '\r') break; newEnd++; } return Selection.createFromStartEnd(selection.getOffset(), newEnd); }
@Override public boolean visit(MethodDeclaration node) { Block body= node.getBody(); if (body == null) return false; Selection selection= getSelection(); int nodeStart= body.getStartPosition(); int nodeExclusiveEnd= nodeStart + body.getLength(); // if selection node inside of the method body ignore method if (!(nodeStart < selection.getOffset() && selection.getExclusiveEnd() < nodeExclusiveEnd)) return false; return super.visit(node); }
private boolean isSelected(ASTNode node) { return fSelection.getVisitSelectionMode(node) == Selection.SELECTED; } }
@Override public void endVisit(ConstructorInvocation node) { if (getSelection().getEndVisitSelectionMode(node) == Selection.SELECTED) { invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_cannotHandleThis, JavaStatusContext.create(fCUnit, node)); } super.endVisit(node); }