use of org.eclipse.jdt.internal.corext.dom.Selection in project che by eclipse.
the class ExtractMethodAnalyzer method visit.
@Override
public boolean visit(LambdaExpression node) {
Selection selection = getSelection();
int selectionStart = selection.getOffset();
int selectionExclusiveEnd = selection.getExclusiveEnd();
int lambdaStart = node.getStartPosition();
int lambdaExclusiveEnd = lambdaStart + node.getLength();
ASTNode body = node.getBody();
int bodyStart = body.getStartPosition();
int bodyExclusiveEnd = bodyStart + body.getLength();
boolean isValidSelection = false;
if ((body instanceof Block) && (bodyStart < selectionStart && selectionExclusiveEnd <= bodyExclusiveEnd)) {
// if selection is inside lambda body's block
isValidSelection = true;
} else if (body instanceof Expression) {
try {
TokenScanner scanner = new TokenScanner(fCUnit);
int arrowExclusiveEnd = scanner.getTokenEndOffset(ITerminalSymbols.TokenNameARROW, lambdaStart);
if (selectionStart >= arrowExclusiveEnd) {
isValidSelection = true;
}
} catch (CoreException e) {
// ignore
}
}
if (selectionStart <= lambdaStart && selectionExclusiveEnd >= lambdaExclusiveEnd) {
// if selection covers the lambda node
isValidSelection = true;
}
if (!isValidSelection) {
return false;
}
return super.visit(node);
}
use of org.eclipse.jdt.internal.corext.dom.Selection in project che by eclipse.
the class JavaTextSelection method resolveSelectedNodes.
public ASTNode[] resolveSelectedNodes() {
if (fNodesRequested)
return fSelectedNodes;
fNodesRequested = true;
CompilationUnit root = resolvePartialAstAtOffset();
if (root == null)
return null;
Selection ds = Selection.createFromStartLength(getOffset(), getLength());
SelectionAnalyzer analyzer = new SelectionAnalyzer(ds, false);
root.accept(analyzer);
fSelectedNodes = analyzer.getSelectedNodes();
fCoveringNode = analyzer.getLastCoveringNode();
return fSelectedNodes;
}
use of org.eclipse.jdt.internal.corext.dom.Selection in project che by eclipse.
the class ChangeSignatureProcessor method isValidExpression.
public static boolean isValidExpression(String string) {
String trimmed = string.trim();
if (//speed up for a common case //$NON-NLS-1$
"".equals(trimmed))
return false;
StringBuffer cuBuff = new StringBuffer();
cuBuff.append(CONST_CLASS_DECL).append(//$NON-NLS-1$
"Object").append(CONST_ASSIGN);
int offset = cuBuff.length();
cuBuff.append(trimmed).append(CONST_CLOSE);
ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
p.setSource(cuBuff.toString().toCharArray());
CompilationUnit cu = (CompilationUnit) p.createAST(null);
Selection selection = Selection.createFromStartLength(offset, trimmed.length());
SelectionAnalyzer analyzer = new SelectionAnalyzer(selection, false);
cu.accept(analyzer);
ASTNode selected = analyzer.getFirstSelectedNode();
return (selected instanceof Expression) && trimmed.equals(cuBuff.substring(cu.getExtendedStartPosition(selected), cu.getExtendedStartPosition(selected) + cu.getExtendedLength(selected)));
}
use of org.eclipse.jdt.internal.corext.dom.Selection in project che by eclipse.
the class ChangeSignatureProcessor method isValidVarargsExpression.
public static boolean isValidVarargsExpression(String string) {
String trimmed = string.trim();
if (//speed up for a common case //$NON-NLS-1$
"".equals(trimmed))
return true;
StringBuffer cuBuff = new StringBuffer();
//$NON-NLS-1$
cuBuff.append("class A{ {m(");
int offset = cuBuff.length();
cuBuff.append(trimmed).append(//$NON-NLS-1$
");}}");
ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
p.setSource(cuBuff.toString().toCharArray());
CompilationUnit cu = (CompilationUnit) p.createAST(null);
Selection selection = Selection.createFromStartLength(offset, trimmed.length());
SelectionAnalyzer analyzer = new SelectionAnalyzer(selection, false);
cu.accept(analyzer);
ASTNode[] selectedNodes = analyzer.getSelectedNodes();
if (selectedNodes.length == 0)
return false;
for (int i = 0; i < selectedNodes.length; i++) {
if (!(selectedNodes[i] instanceof Expression))
return false;
}
return true;
}
use of org.eclipse.jdt.internal.corext.dom.Selection in project che by eclipse.
the class CallInliner method flowAnalysis.
private void flowAnalysis() {
fInvocationScope = fRootScope.findScope(fTargetNode.getStartPosition(), fTargetNode.getLength());
fInvocationScope.setCursor(fTargetNode.getStartPosition());
fFlowContext = new FlowContext(0, fNumberOfLocals + 1);
fFlowContext.setConsiderAccessMode(true);
fFlowContext.setComputeMode(FlowContext.ARGUMENTS);
Selection selection = Selection.createFromStartLength(fInvocation.getStartPosition(), fInvocation.getLength());
switch(fBodyDeclaration.getNodeType()) {
case ASTNode.INITIALIZER:
case ASTNode.FIELD_DECLARATION:
case ASTNode.METHOD_DECLARATION:
case ASTNode.ENUM_CONSTANT_DECLARATION:
fFlowInfo = new InputFlowAnalyzer(fFlowContext, selection, true).perform(fBodyDeclaration);
break;
default:
//$NON-NLS-1$
Assert.isTrue(false, "Should not happen");
}
}
Aggregations