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); }
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); }
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); }
/** * 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); }
/** * 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); }
@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); }
@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); }
@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); }
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; }
@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; }
@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; }
@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; }
@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; }
@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 void check(RefactoringStatus result, Selection selection, IScanner scanner, int start, int end) { char[] characters= scanner.getSource(); selection= adjustSelection(characters, selection, end); scanner.resetTo(start, end); int token= 0; try { loop: while (token != ITerminalSymbols.TokenNameEOF) { token= scanner.getNextToken(); switch(token) { case ITerminalSymbols.TokenNameCOMMENT_LINE: case ITerminalSymbols.TokenNameCOMMENT_BLOCK: case ITerminalSymbols.TokenNameCOMMENT_JAVADOC: if (checkStart(scanner, selection.getOffset())) { result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_starts_inside_comment); break loop; } if (checkEnd(scanner, selection.getInclusiveEnd())) { result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_ends_inside_comment); break loop; } break; } } } catch (InvalidInputException e) { result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_internal_error); } }
private void check(RefactoringStatus result, Selection selection, IScanner scanner, int start, int end) { char[] characters= scanner.getSource(); selection= adjustSelection(characters, selection, end); scanner.resetTo(start, end); int token= 0; try { loop: while (token != ITerminalSymbols.TokenNameEOF) { token= scanner.getNextToken(); switch(token) { case ITerminalSymbols.TokenNameCOMMENT_LINE: case ITerminalSymbols.TokenNameCOMMENT_BLOCK: case ITerminalSymbols.TokenNameCOMMENT_JAVADOC: if (checkStart(scanner, selection.getOffset())) { result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_starts_inside_comment); break loop; } if (checkEnd(scanner, selection.getInclusiveEnd())) { result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_ends_inside_comment); break loop; } break; } } } catch (InvalidInputException e) { result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_internal_error); } }
private void check(RefactoringStatus result, Selection selection, IScanner scanner, int start, int end) { char[] characters= scanner.getSource(); selection= adjustSelection(characters, selection, end); scanner.resetTo(start, end); int token= 0; try { loop: while (token != ITerminalSymbols.TokenNameEOF) { token= scanner.getNextToken(); switch(token) { case ITerminalSymbols.TokenNameCOMMENT_LINE: case ITerminalSymbols.TokenNameCOMMENT_BLOCK: case ITerminalSymbols.TokenNameCOMMENT_JAVADOC: if (checkStart(scanner, selection.getOffset())) { result.addFatalError(JavaManipulationMessages.CommentAnalyzer_starts_inside_comment); break loop; } if (checkEnd(scanner, selection.getInclusiveEnd())) { result.addFatalError(JavaManipulationMessages.CommentAnalyzer_ends_inside_comment); break loop; } break; } } } catch (InvalidInputException e) { result.addFatalError(JavaManipulationMessages.CommentAnalyzer_internal_error); } }
protected void checkSelectedNodes() { ASTNode[] nodes= getSelectedNodes(); if (nodes.length == 0) return; ASTNode node= nodes[0]; int selectionOffset= getSelection().getOffset(); try { int pos= fScanner.getNextStartOffset(selectionOffset, true); if (pos == node.getStartPosition()) { int lastNodeEnd= ASTNodes.getExclusiveEnd(nodes[nodes.length - 1]); pos= fScanner.getNextStartOffset(lastNodeEnd, true); int selectionEnd= getSelection().getInclusiveEnd(); if (pos <= selectionEnd) { ISourceRange range= new SourceRange(lastNodeEnd, pos - lastNodeEnd); invalidSelection(RefactoringCoreMessages.StatementAnalyzer_end_of_selection, JavaStatusContext.create(fCUnit, range)); } return; // success } } catch (CoreException e) { // fall through } ISourceRange range= new SourceRange(selectionOffset, node.getStartPosition() - selectionOffset + 1); invalidSelection(RefactoringCoreMessages.StatementAnalyzer_beginning_of_selection, JavaStatusContext.create(fCUnit, range)); }