MCPcopy Index your code
hub / github.com/benfry/processing4 / resolveBinding

Method resolveBinding

java/src/processing/mode/java/ASTUtils.java:100–158  ·  view source on GitHub ↗
(SimpleName node)

Source from the content-addressed store, hash-verified

98
99
100 public static IBinding resolveBinding(SimpleName node) {
101 IBinding binding = node.resolveBinding();
102 if (binding == null) return null;
103
104 // Fix constructor call/declaration being resolved as type
105 if (binding.getKind() == IBinding.TYPE) {
106 ASTNode context = node;
107
108 // Go up until we find non Name or Type node
109 // stop if context is type argument (parent is also Name/Type, but unrelated)
110 while (isNameOrType(context) &&
111 !context.getLocationInParent().getId().equals("typeArguments")) {
112 context = context.getParent();
113 }
114
115 switch (context.getNodeType()) {
116 case ASTNode.METHOD_DECLARATION:
117 MethodDeclaration decl = (MethodDeclaration) context;
118 if (decl.isConstructor()) {
119 binding = decl.resolveBinding();
120 }
121 break;
122 case ASTNode.CLASS_INSTANCE_CREATION:
123 ClassInstanceCreation cic = (ClassInstanceCreation) context;
124 binding = cic.resolveConstructorBinding();
125 break;
126 }
127 }
128
129 if (binding == null) return null;
130
131 // Normalize parametrized and raw bindings into generic bindings
132 switch (binding.getKind()) {
133 case IBinding.TYPE:
134 ITypeBinding type = (ITypeBinding) binding;
135 if (type.isParameterizedType() || type.isRawType()) {
136 binding = type.getErasure();
137 }
138 break;
139 case IBinding.METHOD:
140 IMethodBinding method = (IMethodBinding) binding;
141 ITypeBinding declaringClass = method.getDeclaringClass();
142 if (declaringClass.isParameterizedType() ||
143 declaringClass.isRawType()) {
144 IMethodBinding[] methods = declaringClass.getErasure().getDeclaredMethods();
145 IMethodBinding generic = Arrays.stream(methods)
146 .filter(method::overrides)
147 .findAny().orElse(null);
148 if (generic != null) method = generic;
149 }
150 if (method.isParameterizedMethod() || method.isRawMethod()) {
151 method = method.getMethodDeclaration();
152 }
153 binding = method;
154 break;
155 }
156
157 return binding;

Callers 6

visitMethod · 0.95
handleShowUsageMethod · 0.95
handleRenameMethod · 0.80
handleInspectMethod · 0.80
searchDeclarationMethod · 0.80
searchReferenceMethod · 0.80

Calls 6

isNameOrTypeMethod · 0.95
getKindMethod · 0.80
getIdMethod · 0.80
equalsMethod · 0.45
getParentMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected