use of org.eclipse.jdt.core.dom.ITypeBinding in project che by eclipse.
the class Bindings method findMethodInHierarchy.
/**
* Finds the method specified by <code>methodName</code> and </code>parameters</code> in
* the type hierarchy denoted by the given type. Returns <code>null</code> if no such method
* exists. If the method is defined in more than one super type only the first match is
* returned. First the super class is examined and then the implemented interfaces.
*
* @param type The type to search the method in
* @param methodName The name of the method to find
* @param parameters The parameter types of the method to find. If <code>null</code> is passed, only the name is matched and parameters are ignored.
* @return the method binding representing the method
*/
public static IMethodBinding findMethodInHierarchy(ITypeBinding type, String methodName, ITypeBinding[] parameters) {
IMethodBinding method = findMethodInType(type, methodName, parameters);
if (method != null)
return method;
ITypeBinding superClass = type.getSuperclass();
if (superClass != null) {
method = findMethodInHierarchy(superClass, methodName, parameters);
if (method != null)
return method;
}
ITypeBinding[] interfaces = type.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
method = findMethodInHierarchy(interfaces[i], methodName, parameters);
if (method != null)
return method;
}
return null;
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project che by eclipse.
the class Bindings method collectSuperTypes.
private static void collectSuperTypes(ITypeBinding curr, Set<ITypeBinding> collection) {
if (collection.add(curr)) {
ITypeBinding[] interfaces = curr.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
collectSuperTypes(interfaces[i], collection);
}
ITypeBinding superClass = curr.getSuperclass();
if (superClass != null) {
collectSuperTypes(superClass, collection);
}
}
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project che by eclipse.
the class StubUtility method getParameterTypeNamesForSeeTag.
/*
* Returns the parameters type names used in see tags. Currently, these are always fully qualified.
*/
public static String[] getParameterTypeNamesForSeeTag(IMethodBinding binding) {
ITypeBinding[] typeBindings = binding.getParameterTypes();
String[] result = new String[typeBindings.length];
for (int i = 0; i < result.length; i++) {
ITypeBinding curr = typeBindings[i];
// Javadoc references use erased type
curr = curr.getErasure();
result[i] = curr.getQualifiedName();
}
return result;
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project che by eclipse.
the class StubUtility2 method createThrownExceptions.
private static void createThrownExceptions(MethodDeclaration decl, IMethodBinding method, ImportRewrite imports, ImportRewriteContext context, AST ast) {
ITypeBinding[] excTypes = method.getExceptionTypes();
if (ast.apiLevel() >= AST.JLS8) {
List<Type> thrownExceptions = decl.thrownExceptionTypes();
for (int i = 0; i < excTypes.length; i++) {
Type excType = imports.addImport(excTypes[i], ast, context);
thrownExceptions.add(excType);
}
} else {
List<Name> thrownExceptions = getThrownExceptions(decl);
for (int i = 0; i < excTypes.length; i++) {
String excTypeName = imports.addImport(excTypes[i], context);
thrownExceptions.add(ASTNodeFactory.newName(ast, excTypeName));
}
}
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project che by eclipse.
the class StubUtility2 method getDelegateCandidates.
// public static DelegateEntry[] getDelegatableMethods(ITypeBinding binding) {
// final List<DelegateEntry> tuples= new ArrayList<DelegateEntry>();
// final List<IMethodBinding> declared= new ArrayList<IMethodBinding>();
// IMethodBinding[] typeMethods= binding.getDeclaredMethods();
// for (int index= 0; index < typeMethods.length; index++)
// declared.add(typeMethods[index]);
// IVariableBinding[] typeFields= binding.getDeclaredFields();
// for (int index= 0; index < typeFields.length; index++) {
// IVariableBinding fieldBinding= typeFields[index];
// if (fieldBinding.isField() && !fieldBinding.isEnumConstant() && !fieldBinding.isSynthetic())
// getDelegatableMethods(new ArrayList<IMethodBinding>(declared), fieldBinding, fieldBinding.getType(), binding, tuples);
// }
// // list of tuple<IVariableBinding, IMethodBinding>
// return tuples.toArray(new DelegateEntry[tuples.size()]);
// }
//
// private static void getDelegatableMethods(List<IMethodBinding> methods, IVariableBinding fieldBinding, ITypeBinding typeBinding, ITypeBinding binding, List<DelegateEntry> result) {
// boolean match= false;
// if (typeBinding.isTypeVariable()) {
// ITypeBinding[] typeBounds= typeBinding.getTypeBounds();
// if (typeBounds.length > 0) {
// for (int i= 0; i < typeBounds.length; i++) {
// getDelegatableMethods(methods, fieldBinding, typeBounds[i], binding, result);
// }
// } else {
// ITypeBinding objectBinding= Bindings.findTypeInHierarchy(binding, "java.lang.Object"); //$NON-NLS-1$
// if (objectBinding != null) {
// getDelegatableMethods(methods, fieldBinding, objectBinding, binding, result);
// }
// }
// } else {
// IMethodBinding[] candidates= getDelegateCandidates(typeBinding, binding);
// for (int index= 0; index < candidates.length; index++) {
// match= false;
// final IMethodBinding methodBinding= candidates[index];
// for (int offset= 0; offset < methods.size() && !match; offset++) {
// if (Bindings.areOverriddenMethods(methods.get(offset), methodBinding))
// match= true;
// }
// if (!match) {
// result.add(new DelegateEntry(methodBinding, fieldBinding));
// methods.add(methodBinding);
// }
// }
// final ITypeBinding superclass= typeBinding.getSuperclass();
// if (superclass != null)
// getDelegatableMethods(methods, fieldBinding, superclass, binding, result);
// ITypeBinding[] superInterfaces= typeBinding.getInterfaces();
// for (int offset= 0; offset < superInterfaces.length; offset++)
// getDelegatableMethods(methods, fieldBinding, superInterfaces[offset], binding, result);
// }
// }
private static IMethodBinding[] getDelegateCandidates(ITypeBinding binding, ITypeBinding hierarchy) {
List<IMethodBinding> allMethods = new ArrayList<IMethodBinding>();
boolean isInterface = binding.isInterface();
IMethodBinding[] typeMethods = binding.getDeclaredMethods();
for (int index = 0; index < typeMethods.length; index++) {
final int modifiers = typeMethods[index].getModifiers();
if (!typeMethods[index].isConstructor() && !Modifier.isStatic(modifiers) && (isInterface || Modifier.isPublic(modifiers))) {
IMethodBinding result = Bindings.findOverriddenMethodInHierarchy(hierarchy, typeMethods[index]);
if (result != null && Flags.isFinal(result.getModifiers()))
continue;
ITypeBinding[] parameterBindings = typeMethods[index].getParameterTypes();
boolean upper = false;
for (int offset = 0; offset < parameterBindings.length; offset++) {
if (parameterBindings[offset].isWildcardType() && parameterBindings[offset].isUpperbound())
upper = true;
}
if (!upper)
allMethods.add(typeMethods[index]);
}
}
return allMethods.toArray(new IMethodBinding[allMethods.size()]);
}
Aggregations