use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class ScopeAnalyzer method getDeclarationsInScope.
public IBinding[] getDeclarationsInScope(SimpleName selector, int flags) {
try {
// special case for switch on enum
if (selector.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) {
ITypeBinding binding = ((SwitchStatement) selector.getParent().getParent()).getExpression().resolveTypeBinding();
if (binding != null && binding.isEnum()) {
return getEnumContants(binding);
}
}
ITypeBinding parentTypeBinding = Bindings.getBindingOfParentType(selector);
if (parentTypeBinding != null) {
ITypeBinding binding = getQualifier(selector);
DefaultBindingRequestor requestor = new DefaultBindingRequestor(parentTypeBinding, flags);
if (binding == null) {
addLocalDeclarations(selector, flags, requestor);
addTypeDeclarations(parentTypeBinding, flags, requestor);
} else {
addInherited(binding, flags, requestor);
}
List<IBinding> result = requestor.getResult();
return result.toArray(new IBinding[result.size()]);
}
return NO_BINDING;
} finally {
clearLists();
}
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class ScopeAnalyzer method getDeclarationsAfter.
public IBinding[] getDeclarationsAfter(int offset, int flags) {
try {
org.eclipse.jdt.core.dom.NodeFinder finder = new org.eclipse.jdt.core.dom.NodeFinder(fRoot, offset, 0);
ASTNode node = finder.getCoveringNode();
if (node == null) {
return null;
}
ASTNode declaration = ASTResolving.findParentStatement(node);
while (declaration instanceof Statement && declaration.getNodeType() != ASTNode.BLOCK) {
declaration = declaration.getParent();
}
if (declaration instanceof Block) {
DefaultBindingRequestor requestor = new DefaultBindingRequestor();
DeclarationsAfterVisitor visitor = new DeclarationsAfterVisitor(node.getStartPosition(), flags, requestor);
declaration.accept(visitor);
List<IBinding> result = requestor.getResult();
return result.toArray(new IBinding[result.size()]);
}
return NO_BINDING;
} finally {
clearLists();
}
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class CodeStyleFix method getUnqualifiedFieldAccessResolveOperation.
private static AddThisQualifierOperation getUnqualifiedFieldAccessResolveOperation(CompilationUnit compilationUnit, IProblemLocation problem) {
SimpleName name = getName(compilationUnit, problem);
if (name == null)
return null;
IBinding binding = name.resolveBinding();
if (binding == null || binding.getKind() != IBinding.VARIABLE)
return null;
ImportRewrite imports = StubUtility.createImportRewrite(compilationUnit, true);
String replacement = getThisExpressionQualifier(((IVariableBinding) binding).getDeclaringClass(), imports, name);
if (replacement == null)
return null;
if (replacement.length() == 0)
replacement = null;
return new AddThisQualifierOperation(replacement, name);
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class CodeStyleFix method createToStaticAccessOperations.
private static ToStaticAccessOperation[] createToStaticAccessOperations(CompilationUnit astRoot, HashMap<ASTNode, Block> createdBlocks, IProblemLocation problem, boolean conservative) {
ASTNode selectedNode = problem.getCoveringNode(astRoot);
if (selectedNode == null) {
return null;
}
Expression qualifier = null;
IBinding accessBinding = null;
if (selectedNode instanceof SimpleName) {
selectedNode = selectedNode.getParent();
}
if (selectedNode instanceof QualifiedName) {
QualifiedName name = (QualifiedName) selectedNode;
qualifier = name.getQualifier();
accessBinding = name.resolveBinding();
} else if (selectedNode instanceof MethodInvocation) {
MethodInvocation methodInvocation = (MethodInvocation) selectedNode;
qualifier = methodInvocation.getExpression();
accessBinding = methodInvocation.getName().resolveBinding();
} else if (selectedNode instanceof FieldAccess) {
FieldAccess fieldAccess = (FieldAccess) selectedNode;
qualifier = fieldAccess.getExpression();
accessBinding = fieldAccess.getName().resolveBinding();
}
if (accessBinding != null && qualifier != null) {
if (conservative && ASTResolving.findParentStatement(qualifier) == null)
return null;
ToStaticAccessOperation declaring = null;
ITypeBinding declaringTypeBinding = getDeclaringTypeBinding(accessBinding);
if (declaringTypeBinding != null) {
// use generic to avoid any type arguments
declaringTypeBinding = declaringTypeBinding.getTypeDeclaration();
declaring = new ToStaticAccessOperation(declaringTypeBinding, qualifier, createdBlocks);
}
ToStaticAccessOperation instance = null;
ITypeBinding instanceTypeBinding = Bindings.normalizeTypeBinding(qualifier.resolveTypeBinding());
if (instanceTypeBinding != null) {
// use generic to avoid any type arguments
instanceTypeBinding = instanceTypeBinding.getTypeDeclaration();
if (instanceTypeBinding.getTypeDeclaration() != declaringTypeBinding) {
instance = new ToStaticAccessOperation(instanceTypeBinding, qualifier, createdBlocks);
}
}
if (declaring != null && instance != null) {
return new ToStaticAccessOperation[] { declaring, instance };
} else {
return new ToStaticAccessOperation[] { declaring };
}
}
return null;
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class ConvertForLoopOperation method convertBody.
private void convertBody(Statement body, final IBinding indexBinding, final IBinding arrayBinding, final String parameterName, final ASTRewrite rewrite, final TextEditGroup editGroup, final LinkedProposalPositionGroup pg) {
final AST ast = body.getAST();
body.accept(new GenericVisitor() {
@Override
public boolean visit(ArrayAccess node) {
IBinding binding = getBinding(node.getArray());
if (arrayBinding.equals(binding)) {
IBinding index = getBinding(node.getIndex());
if (indexBinding.equals(index)) {
replaceAccess(node);
}
}
return super.visit(node);
}
private void replaceAccess(ASTNode node) {
if (fElementDeclaration != null && node.getLocationInParent() == VariableDeclarationFragment.INITIALIZER_PROPERTY) {
VariableDeclarationFragment fragment = (VariableDeclarationFragment) node.getParent();
IBinding targetBinding = fragment.getName().resolveBinding();
if (targetBinding != null) {
VariableDeclarationStatement statement = (VariableDeclarationStatement) fragment.getParent();
if (statement.fragments().size() == 1) {
rewrite.remove(statement, editGroup);
} else {
ListRewrite listRewrite = rewrite.getListRewrite(statement, VariableDeclarationStatement.FRAGMENTS_PROPERTY);
listRewrite.remove(fragment, editGroup);
}
} else {
SimpleName name = ast.newSimpleName(parameterName);
rewrite.replace(node, name, editGroup);
pg.addPosition(rewrite.track(name), true);
}
} else {
SimpleName name = ast.newSimpleName(parameterName);
rewrite.replace(node, name, editGroup);
pg.addPosition(rewrite.track(name), true);
}
}
});
}
Aggregations