use of org.eclipse.jdt.core.dom.IVariableBinding in project che by eclipse.
the class ExtractTempRefactoring method isReferringToLocalVariableFromFor.
private static boolean isReferringToLocalVariableFromFor(Expression expression) {
ASTNode current = expression;
ASTNode parent = current.getParent();
while (parent != null && !(parent instanceof BodyDeclaration)) {
if (parent instanceof ForStatement) {
ForStatement forStmt = (ForStatement) parent;
if (forStmt.initializers().contains(current) || forStmt.updaters().contains(current) || forStmt.getExpression() == current) {
List<Expression> initializers = forStmt.initializers();
if (initializers.size() == 1 && initializers.get(0) instanceof VariableDeclarationExpression) {
List<IVariableBinding> forInitializerVariables = getForInitializedVariables((VariableDeclarationExpression) initializers.get(0));
ForStatementChecker checker = new ForStatementChecker(forInitializerVariables);
expression.accept(checker);
if (checker.isReferringToForVariable())
return true;
}
}
}
current = parent;
parent = current.getParent();
}
return false;
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project che by eclipse.
the class ExtractTempRefactoring method getForInitializedVariables.
// return List<IVariableBinding>
private static List<IVariableBinding> getForInitializedVariables(VariableDeclarationExpression variableDeclarations) {
List<IVariableBinding> forInitializerVariables = new ArrayList<IVariableBinding>(1);
for (Iterator<VariableDeclarationFragment> iter = variableDeclarations.fragments().iterator(); iter.hasNext(); ) {
VariableDeclarationFragment fragment = iter.next();
IVariableBinding binding = fragment.resolveBinding();
if (binding != null)
forInitializerVariables.add(binding);
}
return forInitializerVariables;
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project AutoRefactor by JnRouvignac.
the class HotSpotIntrinsicedAPIsRefactoring method visit.
@Override
public boolean visit(ForStatement node) {
final SystemArrayCopyParams params = new SystemArrayCopyParams();
collectUniqueIndex(node, params);
final IVariableBinding incrementedIdx = getUniqueIncrementedVariable(node);
final List<Statement> stmts = asList(node.getBody());
if (equalNotNull(params.indexVarBinding, incrementedIdx) && stmts.size() == 1) {
collectLength(node.getExpression(), incrementedIdx, params);
final Assignment as = asExpression(stmts.get(0), Assignment.class);
if (hasOperator(as, ASSIGN)) {
final Expression lhs = as.getLeftHandSide();
final Expression rhs = as.getRightHandSide();
if (lhs instanceof ArrayAccess && rhs instanceof ArrayAccess) {
final ArrayAccess aaLHS = (ArrayAccess) lhs;
final ArrayAccess aaRHS = (ArrayAccess) rhs;
params.destArrayExpr = aaLHS.getArray();
params.srcArrayExpr = aaRHS.getArray();
if (haveSameType(params.srcArrayExpr, params.destArrayExpr)) {
params.destPos = calcIndex(aaLHS.getIndex(), params);
params.srcPos = calcIndex(aaRHS.getIndex(), params);
return replaceWithSystemArrayCopyCloneAll(node, params);
}
}
}
}
return VISIT_SUBTREE;
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project AutoRefactor by JnRouvignac.
the class AllInOneMethodRatherThanLoopRefactoring method visit.
@Override
public boolean visit(EnhancedForStatement node) {
final Expression iterable = node.getExpression();
final List<Statement> stmts = asList(node.getBody());
if (stmts.size() != 1) {
return VISIT_SUBTREE;
}
final MethodInvocation mi = asExpression(stmts.get(0), MethodInvocation.class);
final IVariableBinding foreachVariable = node.getParameter().resolveBinding();
// As we replace only one, there should be no more than one occurrence
if (getVariableUseCount(foreachVariable, node.getBody()) == 1) {
if (instanceOf(iterable, "java.util.Collection")) {
if (isMethod(mi, "java.util.Collection", "add", "java.lang.Object")) {
return maybeReplaceWithCollectionMethod(node, iterable, "addAll", mi);
} else if (isMethod(mi, "java.util.Collection", "remove", "java.lang.Object")) {
return maybeReplaceWithCollectionMethod(node, iterable, "removeAll", mi);
}
} else if (isArray(iterable) && isMethod(mi, "java.util.Collection", "add", "java.lang.Object") && areTypeCompatible(mi.getExpression(), iterable) && isSameLocalVariable(foreachVariable, arg0(mi))) {
replaceWithCollectionsAddAll(node, iterable, mi);
return DO_NOT_VISIT_SUBTREE;
}
}
return VISIT_SUBTREE;
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project j2objc by google.
the class JdtTypeElement method getEnclosedElements.
@Override
public List<? extends Element> getEnclosedElements() {
ITypeBinding decl = (ITypeBinding) binding;
List<Element> toReturn = new ArrayList<>();
for (IVariableBinding i : decl.getDeclaredFields()) {
toReturn.add(BindingConverter.getElement(i));
}
for (IMethodBinding i : decl.getDeclaredMethods()) {
toReturn.add(BindingConverter.getElement(i));
}
for (ITypeBinding i : decl.getDeclaredTypes()) {
toReturn.add(BindingConverter.getElement(i));
}
return toReturn;
}
Aggregations