Hi, I have a static scanner which uses JDT. If I have a method invocation, I open it (actually not everytime, but it doesn't matter). "Open" means that I find CFG of this method in local bundle and perform scanning. And the question is how to optimize searching process.
To find a method, I must have IMethodBinding. Using that binding, I receive ITypeBinding of the declaring class. After I search the class in local bundle:
for(int i = 0; i < sortedClasses.size(); i++) {
Class clazz = sortedClasses.get(i);
if(clazz.getClassBinding() != null && clazz.getClassBinding().isEqualTo(classBinding)) {
return clazz;
}
}
return null;
But I'm sure it could be done much more faster, but have no idea how.
Let's verify that I cannot use == operator, equals() method, hash codes, only isEqualTo() is allowed to compare bindings. Maybe you have any ideas how to make it better? I mean something like
Map<IBinding, Class> map = ...;
...
ITypeBinding declaringClass = methodBinding.getDeclaringClass();
Class clazz = map.get(declaringClass);
[Updated on: Wed, 13 July 2016 07:15] by Moderator