use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class ScopeAnalyzer method getDeclarationsInScope.
public IBinding[] getDeclarationsInScope(int offset, int flags) {
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 NO_BINDING;
}
if (node instanceof SimpleName) {
return getDeclarationsInScope((SimpleName) node, flags);
}
try {
ITypeBinding binding = Bindings.getBindingOfParentType(node);
DefaultBindingRequestor requestor = new DefaultBindingRequestor(binding, flags);
addLocalDeclarations(node, offset, flags, requestor);
if (binding != null) {
addTypeDeclarations(binding, flags, requestor);
}
List<IBinding> result = requestor.getResult();
return result.toArray(new IBinding[result.size()]);
} finally {
clearLists();
}
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class GetterSetterCorrectionSubProcessor method addGetterSetterProposal.
private static boolean addGetterSetterProposal(IInvocationContext context, ASTNode coveringNode, Collection<ICommandAccess> proposals, int relevance) {
if (!(coveringNode instanceof SimpleName)) {
return false;
}
SimpleName sn = (SimpleName) coveringNode;
IBinding binding = sn.resolveBinding();
if (!(binding instanceof IVariableBinding))
return false;
IVariableBinding variableBinding = (IVariableBinding) binding;
if (!variableBinding.isField())
return false;
if (proposals == null)
return true;
ChangeCorrectionProposal proposal = getProposal(context.getCompilationUnit(), sn, variableBinding, relevance);
if (proposal != null)
proposals.add(proposal);
return true;
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class JavadocTagsSubProcessor method getInvalidQualificationProposals.
public static void getInvalidQualificationProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode node = problem.getCoveringNode(context.getASTRoot());
if (!(node instanceof Name)) {
return;
}
Name name = (Name) node;
IBinding binding = name.resolveBinding();
if (!(binding instanceof ITypeBinding)) {
return;
}
ITypeBinding typeBinding = (ITypeBinding) binding;
AST ast = node.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
rewrite.replace(name, ast.newName(typeBinding.getQualifiedName()), null);
String label = CorrectionMessages.JavadocTagsSubProcessor_qualifylinktoinner_description;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.QUALIFY_INNER_TYPE_NAME, image);
proposals.add(proposal);
}
use of org.eclipse.jdt.core.dom.IBinding in project flux by eclipse.
the class StubUtility method getBaseNameFromExpression.
private static String getBaseNameFromExpression(IJavaProject project, Expression assignedExpression, int variableKind) {
String name = null;
if (assignedExpression instanceof CastExpression) {
assignedExpression = ((CastExpression) assignedExpression).getExpression();
}
if (assignedExpression instanceof Name) {
Name simpleNode = (Name) assignedExpression;
IBinding binding = simpleNode.resolveBinding();
if (binding instanceof IVariableBinding)
return getBaseName((IVariableBinding) binding, project);
return ASTNodes.getSimpleNameIdentifier(simpleNode);
} else if (assignedExpression instanceof MethodInvocation) {
name = ((MethodInvocation) assignedExpression).getName().getIdentifier();
} else if (assignedExpression instanceof SuperMethodInvocation) {
name = ((SuperMethodInvocation) assignedExpression).getName().getIdentifier();
} else if (assignedExpression instanceof FieldAccess) {
return ((FieldAccess) assignedExpression).getName().getIdentifier();
} else if (variableKind == NamingConventions.VK_STATIC_FINAL_FIELD && (assignedExpression instanceof StringLiteral || assignedExpression instanceof NumberLiteral)) {
String string = assignedExpression instanceof StringLiteral ? ((StringLiteral) assignedExpression).getLiteralValue() : ((NumberLiteral) assignedExpression).getToken();
StringBuffer res = new StringBuffer();
boolean needsUnderscore = false;
for (int i = 0; i < string.length(); i++) {
char ch = string.charAt(i);
if (Character.isJavaIdentifierPart(ch)) {
if (res.length() == 0 && !Character.isJavaIdentifierStart(ch) || needsUnderscore) {
res.append('_');
}
res.append(ch);
needsUnderscore = false;
} else {
needsUnderscore = res.length() > 0;
}
}
if (res.length() > 0) {
return res.toString();
}
}
if (name != null) {
for (int i = 0; i < KNOWN_METHOD_NAME_PREFIXES.length; i++) {
String curr = KNOWN_METHOD_NAME_PREFIXES[i];
if (name.startsWith(curr)) {
if (name.equals(curr)) {
// don't suggest 'get' as variable name
return null;
} else if (Character.isUpperCase(name.charAt(curr.length()))) {
return name.substring(curr.length());
}
}
}
}
return name;
}
use of org.eclipse.jdt.core.dom.IBinding in project flux by eclipse.
the class LinkedNodeFinder method findByNode.
/**
* Find all nodes connected to the given name node. If the node has a binding then all nodes connected
* to this binding are returned. If the node has no binding, then all nodes that also miss a binding and have
* the same name are returned.
* @param root The root of the AST tree to search
* @param name The node to find linked nodes for
* @return Return
*/
public static SimpleName[] findByNode(ASTNode root, SimpleName name) {
IBinding binding = name.resolveBinding();
if (binding != null) {
return findByBinding(root, binding);
}
SimpleName[] names = findByProblems(root, name);
if (names != null) {
return names;
}
int parentKind = name.getParent().getNodeType();
if (parentKind == ASTNode.LABELED_STATEMENT || parentKind == ASTNode.BREAK_STATEMENT || parentKind == ASTNode.CONTINUE_STATEMENT) {
ArrayList<SimpleName> res = new ArrayList<SimpleName>();
LabelFinder nodeFinder = new LabelFinder(name, res);
root.accept(nodeFinder);
return res.toArray(new SimpleName[res.size()]);
}
return new SimpleName[] { name };
}
Aggregations