use of org.eclipse.jdt.core.dom.ITypeBinding in project che by eclipse.
the class StubUtility2 method getOverridableMethods.
public static IMethodBinding[] getOverridableMethods(AST ast, ITypeBinding typeBinding, boolean isSubType) {
List<IMethodBinding> allMethods = new ArrayList<IMethodBinding>();
IMethodBinding[] typeMethods = typeBinding.getDeclaredMethods();
for (int index = 0; index < typeMethods.length; index++) {
final int modifiers = typeMethods[index].getModifiers();
if (!typeMethods[index].isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers))
allMethods.add(typeMethods[index]);
}
ITypeBinding clazz = typeBinding.getSuperclass();
while (clazz != null) {
IMethodBinding[] methods = clazz.getDeclaredMethods();
for (int offset = 0; offset < methods.length; offset++) {
final int modifiers = methods[offset].getModifiers();
if (!methods[offset].isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) {
if (findOverridingMethod(methods[offset], allMethods) == null)
allMethods.add(methods[offset]);
}
}
clazz = clazz.getSuperclass();
}
clazz = typeBinding;
while (clazz != null) {
ITypeBinding[] superInterfaces = clazz.getInterfaces();
for (int index = 0; index < superInterfaces.length; index++) {
getOverridableMethods(ast, superInterfaces[index], allMethods);
}
clazz = clazz.getSuperclass();
}
if (typeBinding.isInterface())
//$NON-NLS-1$
getOverridableMethods(ast, ast.resolveWellKnownType("java.lang.Object"), allMethods);
if (!isSubType)
allMethods.removeAll(Arrays.asList(typeMethods));
int modifiers = 0;
if (!typeBinding.isInterface()) {
for (int index = allMethods.size() - 1; index >= 0; index--) {
IMethodBinding method = allMethods.get(index);
modifiers = method.getModifiers();
if (Modifier.isFinal(modifiers))
allMethods.remove(index);
}
}
return allMethods.toArray(new IMethodBinding[allMethods.size()]);
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project che by eclipse.
the class StubUtility2 method getVisibleConstructors.
public static IMethodBinding[] getVisibleConstructors(ITypeBinding binding, boolean accountExisting, boolean proposeDefault) {
List<IMethodBinding> constructorMethods = new ArrayList<IMethodBinding>();
List<IMethodBinding> existingConstructors = null;
ITypeBinding superType = binding.getSuperclass();
if (superType == null)
return new IMethodBinding[0];
if (accountExisting) {
IMethodBinding[] methods = binding.getDeclaredMethods();
existingConstructors = new ArrayList<IMethodBinding>(methods.length);
for (int index = 0; index < methods.length; index++) {
IMethodBinding method = methods[index];
if (method.isConstructor() && !method.isDefaultConstructor())
existingConstructors.add(method);
}
}
if (existingConstructors != null)
constructorMethods.addAll(existingConstructors);
IMethodBinding[] methods = binding.getDeclaredMethods();
IMethodBinding[] superMethods = superType.getDeclaredMethods();
for (int index = 0; index < superMethods.length; index++) {
IMethodBinding method = superMethods[index];
if (method.isConstructor()) {
if (Bindings.isVisibleInHierarchy(method, binding.getPackage()) && (!accountExisting || !Bindings.containsSignatureEquivalentConstructor(methods, method)))
constructorMethods.add(method);
}
}
if (existingConstructors != null)
constructorMethods.removeAll(existingConstructors);
if (constructorMethods.isEmpty()) {
superType = binding;
while (superType.getSuperclass() != null) superType = superType.getSuperclass();
//$NON-NLS-1$
IMethodBinding method = Bindings.findMethodInType(superType, "Object", new ITypeBinding[0]);
if (method != null) {
if ((proposeDefault || !accountExisting || existingConstructors == null || existingConstructors.isEmpty()) && (!accountExisting || !Bindings.containsSignatureEquivalentConstructor(methods, method)))
constructorMethods.add(method);
}
}
return constructorMethods.toArray(new IMethodBinding[constructorMethods.size()]);
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project che by eclipse.
the class Bindings method sameParameters.
//---- Helper methods to convert a method ---------------------------------------------
private static boolean sameParameters(IMethodBinding method, IMethod candidate) throws JavaModelException {
ITypeBinding[] methodParamters = method.getParameterTypes();
String[] candidateParameters = candidate.getParameterTypes();
if (methodParamters.length != candidateParameters.length)
return false;
IType scope = candidate.getDeclaringType();
for (int i = 0; i < methodParamters.length; i++) {
ITypeBinding methodParameter = methodParamters[i];
String candidateParameter = candidateParameters[i];
if (!sameParameter(methodParameter, candidateParameter, scope))
return false;
}
return true;
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project che by eclipse.
the class Bindings method isVisibleInHierarchy.
public static boolean isVisibleInHierarchy(IMethodBinding member, IPackageBinding pack) {
int otherflags = member.getModifiers();
ITypeBinding declaringType = member.getDeclaringClass();
if (Modifier.isPublic(otherflags) || Modifier.isProtected(otherflags) || (declaringType != null && declaringType.isInterface())) {
return true;
} else if (Modifier.isPrivate(otherflags)) {
return false;
}
return declaringType != null && pack == declaringType.getPackage();
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project che by eclipse.
the class Bindings method normalizeForDeclarationUse.
/**
* Normalizes the binding so that it can be used as a type inside a declaration (e.g. variable
* declaration, method return type, parameter type, ...).
* For null bindings, java.lang.Object is returned.
* For void bindings, <code>null</code> is returned.
*
* @param binding binding to normalize
* @param ast current AST
* @return the normalized type to be used in declarations, or <code>null</code>
*/
public static ITypeBinding normalizeForDeclarationUse(ITypeBinding binding, AST ast) {
if (binding.isNullType())
//$NON-NLS-1$
return ast.resolveWellKnownType("java.lang.Object");
if (binding.isPrimitive())
return binding;
binding = normalizeTypeBinding(binding);
if (binding == null || !binding.isWildcardType())
return binding;
ITypeBinding bound = binding.getBound();
if (bound == null || !binding.isUpperbound()) {
ITypeBinding[] typeBounds = binding.getTypeBounds();
if (typeBounds.length > 0) {
return typeBounds[0];
} else {
return binding.getErasure();
}
} else {
return bound;
}
}
Aggregations