本文整理匯總了Java中org.eclipse.jdt.core.dom.SimpleName.resolveBinding方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleName.resolveBinding方法的具體用法?Java SimpleName.resolveBinding怎麽用?Java SimpleName.resolveBinding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.SimpleName
的用法示例。
在下文中一共展示了SimpleName.resolveBinding方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findByNode
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
/**
* 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<>();
LabelFinder nodeFinder= new LabelFinder(name, res);
root.accept(nodeFinder);
return res.toArray(new SimpleName[res.size()]);
}
return new SimpleName[] { name };
}
示例2: visit
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
@Override
public boolean visit(SimpleName node) {
IBinding binding= node.resolveBinding();
if (binding == null) {
return false;
}
binding= getDeclaration(binding);
if (fBinding == binding) {
fResult.add(node);
} else if (binding.getKind() != fBinding.getKind()) {
return false;
} else if (binding.getKind() == IBinding.METHOD) {
IMethodBinding curr= (IMethodBinding) binding;
IMethodBinding methodBinding= (IMethodBinding) fBinding;
if (methodBinding.overrides(curr) || curr.overrides(methodBinding)) {
fResult.add(node);
}
}
return false;
}
示例3: addStaticImports
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
private void addStaticImports(
Collection<SimpleName> staticReferences,
ImportRewrite importRewrite,
UnresolvableImportMatcher unresolvableImportMatcher) {
for (SimpleName name : staticReferences) {
IBinding binding= name.resolveBinding();
if (binding != null) {
importRewrite.addStaticImport(binding);
} else {
// This could be an unresolvable reference to a static member.
String identifier= name.getIdentifier();
Set<String> unresolvableImports= unresolvableImportMatcher.matchStaticImports(identifier);
for (String unresolvableImport : unresolvableImports) {
int lastDotIndex= unresolvableImport.lastIndexOf('.');
// It's OK to skip invalid imports.
if (lastDotIndex != -1) {
String declaringTypeName= unresolvableImport.substring(0, lastDotIndex);
String simpleName= unresolvableImport.substring(lastDotIndex + 1);
// Whether name refers to a field or to a method is unknown.
boolean isField= false;
importRewrite.addStaticImport(declaringTypeName, simpleName, isField, UNRESOLVABLE_IMPORT_CONTEXT);
}
}
}
}
}
示例4: createUnusedMemberFix
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
public static UnusedCodeFix createUnusedMemberFix(CompilationUnit compilationUnit, IProblemLocation problem, boolean removeAllAssignements) {
if (isUnusedMember(problem)) {
SimpleName name= getUnusedName(compilationUnit, problem);
if (name != null) {
IBinding binding= name.resolveBinding();
if (binding != null) {
if (isFormalParameterInEnhancedForStatement(name)) {
return null;
}
String label= getDisplayString(name, binding, removeAllAssignements);
RemoveUnusedMemberOperation operation= new RemoveUnusedMemberOperation(new SimpleName[] { name }, removeAllAssignements);
return new UnusedCodeFix(label, compilationUnit, new CompilationUnitRewriteOperation[] { operation }, getCleanUpOptions(binding, removeAllAssignements));
}
}
}
return null;
}
示例5: endVisit
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
@Override
public void endVisit(SimpleName node) {
if (skipNode(node) || node.isDeclaration()) {
return;
}
IBinding binding = node.resolveBinding();
if (binding instanceof IVariableBinding) {
IVariableBinding variable = (IVariableBinding) binding;
if (!variable.isField()) {
setFlowInfo(node, new LocalFlowInfo(variable, FlowInfo.READ, fFlowContext));
}
} else if (binding instanceof ITypeBinding) {
ITypeBinding type = (ITypeBinding) binding;
if (type.isTypeVariable()) {
setFlowInfo(node, new TypeVariableFlowInfo(type, fFlowContext));
}
}
}
示例6: addGetterSetterProposal
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
private static boolean addGetterSetterProposal(IInvocationContext context, ASTNode coveringNode, Collection<CUCorrectionProposal> proposals) {
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;
}
CUCorrectionProposal proposal = getProposal(context.getCompilationUnit(), sn, variableBinding);
if (proposal != null) {
proposals.add(proposal);
}
return true;
}
示例7: visit
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
@Override
public boolean visit(SimpleName node) {
if (currentMethod == null)
return false;
IBinding binding = node.resolveBinding();
if (binding == null)
return false;
if (node.isDeclaration())
return true;
if (node.resolveBinding() instanceof IVariableBinding) {
IVariableBinding iVariableBinding = (IVariableBinding) node.resolveBinding();
if (iVariableBinding.isField()) {
IVariableBinding variableDeclarationBinding = iVariableBinding.getVariableDeclaration();
if (variableDeclarationBinding.getDeclaringClass() != null) {
IJavaElement accessedField = variableDeclarationBinding.getJavaElement();
if (accessedField instanceof IField) {
if (!((IField) accessedField).isReadOnly())
methodDetails.addAccess((IField) accessedField);
}
}
}
}
return true;
}
示例8: visit
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
public boolean visit(MethodInvocation node) {
try {
SimpleName simpleName = node.getName();
IBinding bding = simpleName.resolveBinding();
if (bding instanceof IMethodBinding) {
IMethodBinding imb = (IMethodBinding) bding;
if (isContext(imb.getReturnType())) {
this.value = imb.getReturnType().getQualifiedName().toString();
}
}
} catch (Throwable e) {
}
return false;
}
示例9: add
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
/**
* Tries to find the given type name and add it to the import structure.
* @param ref the name node
*/
public void add(SimpleName ref) {
String typeName= ref.getIdentifier();
if (fImportsAdded.contains(typeName)) {
return;
}
IBinding binding= ref.resolveBinding();
if (binding != null) {
if (binding.getKind() != IBinding.TYPE) {
return;
}
ITypeBinding typeBinding= (ITypeBinding) binding;
if (typeBinding.isArray()) {
typeBinding= typeBinding.getElementType();
}
typeBinding= typeBinding.getTypeDeclaration();
if (!typeBinding.isRecovered()) {
if (needsImport(typeBinding, ref)) {
fImpStructure.addImport(typeBinding);
fImportsAdded.add(typeName);
}
return;
}
} else {
if (fDoIgnoreLowerCaseNames && typeName.length() > 0) {
char ch= typeName.charAt(0);
if (Strings.isLowerCase(ch) && Character.isLetter(ch)) {
return;
}
}
}
fImportsAdded.add(typeName);
fUnresolvedTypes.put(typeName, new UnresolvedTypeData(ref));
}
示例10: createUnusedTypeParameterFix
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
public static UnusedCodeFix createUnusedTypeParameterFix(CompilationUnit compilationUnit, IProblemLocation problemLoc) {
if (problemLoc.getProblemId() == IProblem.UnusedTypeParameter) {
SimpleName name= getUnusedName(compilationUnit, problemLoc);
if (name != null) {
IBinding binding= name.resolveBinding();
if (binding != null) {
String label= FixMessages.UnusedCodeFix_RemoveUnusedTypeParameter_description;
RemoveUnusedTypeParameterOperation operation= new RemoveUnusedTypeParameterOperation(name);
return new UnusedCodeFix(label, compilationUnit, new CompilationUnitRewriteOperation[] { operation }, getCleanUpOptions(binding, false));
}
}
}
return null;
}
示例11: getPotentialRemoves
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
private HashMap<String, IBinding> getPotentialRemoves(List<SimpleName> removedRefs) {
HashMap<String, IBinding>potentialRemoves= new HashMap<>();
for (Iterator<SimpleName> iterator= removedRefs.iterator(); iterator.hasNext();) {
SimpleName name= iterator.next();
if (fAddedImports.contains(name.getIdentifier()) || hasAddedStaticImport(name)) {
continue;
}
IBinding binding= name.resolveBinding();
if (binding != null) {
potentialRemoves.put(name.getIdentifier(), binding);
}
}
return potentialRemoves;
}
示例12: hasAddedStaticImport
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
private boolean hasAddedStaticImport(SimpleName name) {
IBinding binding= name.resolveBinding();
if (binding instanceof IVariableBinding) {
IVariableBinding variable= (IVariableBinding) binding;
return hasAddedStaticImport(variable.getDeclaringClass().getQualifiedName(), variable.getName(), true);
} else if (binding instanceof IMethodBinding) {
IMethodBinding method= (IMethodBinding) binding;
return hasAddedStaticImport(method.getDeclaringClass().getQualifiedName(), method.getName(), false);
}
return false;
}
示例13: match
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
@Override
public boolean match(SimpleName candidate, Object s) {
if (!(s instanceof SimpleName)) {
return false;
}
SimpleName snippet = (SimpleName) s;
if (candidate.isDeclaration() != snippet.isDeclaration()) {
return false;
}
IBinding cb = candidate.resolveBinding();
IBinding sb = snippet.resolveBinding();
if (cb == null || sb == null) {
return false;
}
IVariableBinding vcb = ASTNodes.getVariableBinding(candidate);
IVariableBinding vsb = ASTNodes.getVariableBinding(snippet);
if (vcb == null || vsb == null) {
return Bindings.equals(cb, sb);
}
if (!vcb.isField() && !vsb.isField() && Bindings.equals(vcb.getType(), vsb.getType())) {
SimpleName mapped = fMatch.getMappedName(vsb);
if (mapped != null) {
IVariableBinding mappedBinding = ASTNodes.getVariableBinding(mapped);
if (!Bindings.equals(vcb, mappedBinding)) {
return false;
}
}
fMatch.addLocal(vsb, candidate);
return true;
}
return Bindings.equals(cb, sb);
}
示例14: visit
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
@Override
public boolean visit(SimpleName node) {
if (node.isDeclaration()) {
return true;
}
IBinding binding = node.resolveBinding();
if (binding instanceof ITypeBinding) {
processLocalTypeBinding((ITypeBinding) binding, fSelection.getVisitSelectionMode(node));
}
return true;
}
示例15: visit
import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
@Override
public boolean visit(MethodDeclaration methodDecl) {
int modifiers = methodDecl.getModifiers();
if(Modifier.isPublic(modifiers) && !methodDecl.isConstructor() && !methodDecl.getReturnType2().isPrimitiveType()){
Block body = methodDecl.getBody();
if(body!=null){
List<Statement> statements = body.statements();
for (Statement stmnt : statements) {
if(stmnt instanceof ReturnStatement){
ReturnStatement retStmnt = (ReturnStatement)stmnt;
Expression expression = retStmnt.getExpression();
if(expression instanceof SimpleName){
SimpleName simpleExpr = (SimpleName)expression;
IBinding resolveBinding = simpleExpr.resolveBinding();
Variable variable = context.getAllBindingKeyToVariableMap(resolveBinding.getKey());
if(variable!=null){
context.removeEncapsulatedVariable(variable);
}
}
}
}
}
}
return super.visit(methodDecl);
}