use of org.eclipse.jdt.core.IMethod in project che by eclipse.
the class MethodOverrideTester method findOverridingMethodInType.
/**
* Finds an overriding method in a type.
* @param overridingType The type to find methods in
* @param overridden The overridden method
* @return The overriding method or <code>null</code> if no method is overriding.
* @throws JavaModelException if a problem occurs
*/
public IMethod findOverridingMethodInType(IType overridingType, IMethod overridden) throws JavaModelException {
int flags = overridden.getFlags();
if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overridden.isConstructor())
return null;
IMethod[] overridingMethods = overridingType.getMethods();
for (int i = 0; i < overridingMethods.length; i++) {
IMethod overriding = overridingMethods[i];
flags = overriding.getFlags();
if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor())
continue;
if (isSubsignature(overriding, overridden)) {
return overriding;
}
}
return null;
}
use of org.eclipse.jdt.core.IMethod in project che by eclipse.
the class MethodOverrideTester method findDeclaringMethod.
/**
* Finds the method that declares the given method. A declaring method is the 'original' method declaration that does
* not override nor implement a method. <code>null</code> is returned it the given method does not override
* a method. When searching, super class are examined before implemented interfaces.
* @param overriding the overriding method
* @param testVisibility If true the result is tested on visibility. Null is returned if the method is not visible.
* @return the declaring method, or <code>null</code>
* @throws JavaModelException if a problem occurs
*/
public IMethod findDeclaringMethod(IMethod overriding, boolean testVisibility) throws JavaModelException {
IMethod result = null;
IMethod overridden = findOverriddenMethod(overriding, testVisibility);
while (overridden != null) {
result = overridden;
overridden = findOverriddenMethod(result, testVisibility);
}
return result;
}
use of org.eclipse.jdt.core.IMethod in project che by eclipse.
the class MethodOverrideTester method getVariableErasure.
private String getVariableErasure(IMember context, String variableName) throws JavaModelException {
IType type;
if (context instanceof IMethod) {
String subst = getMethodSubstitions((IMethod) context).getErasure(variableName);
if (subst != null) {
return subst;
}
type = context.getDeclaringType();
} else {
type = (IType) context;
}
String subst = getTypeSubstitions(type).getErasure(variableName);
if (subst != null) {
return subst;
}
IJavaElement parent = type.getParent();
if (parent instanceof IMethod) {
return getVariableErasure((IMethod) parent, variableName);
} else if (type.getDeclaringType() != null) {
return getVariableErasure(type.getDeclaringType(), variableName);
}
// not a type variable
return variableName;
}
use of org.eclipse.jdt.core.IMethod in project che by eclipse.
the class MethodsSourcePositionComparator method compareInTheSameType.
private int compareInTheSameType(IMethodBinding firstMethodBinding, IMethodBinding secondMethodBinding) {
try {
IMethod firstMethod = (IMethod) firstMethodBinding.getJavaElement();
IMethod secondMethod = (IMethod) secondMethodBinding.getJavaElement();
if (firstMethod == null || secondMethod == null) {
return 0;
}
ISourceRange firstSourceRange = firstMethod.getSourceRange();
ISourceRange secondSourceRange = secondMethod.getSourceRange();
if (!SourceRange.isAvailable(firstSourceRange) || !SourceRange.isAvailable(secondSourceRange)) {
return firstMethod.getElementName().compareTo(secondMethod.getElementName());
} else {
return firstSourceRange.getOffset() - secondSourceRange.getOffset();
}
} catch (JavaModelException e) {
return 0;
}
}
use of org.eclipse.jdt.core.IMethod in project che by eclipse.
the class MethodOverrideTester method findOverriddenMethod.
/**
* Finds the method that is overridden by the given method.
* First the super class is examined and then the implemented interfaces.
* @param overriding the overriding method
* @param testVisibility If true the result is tested on visibility. Null is returned if the method is not visible.
* @return a method that is directly overridden by the given method, or <code>null</code>
* @throws JavaModelException if a problem occurs
*/
public IMethod findOverriddenMethod(IMethod overriding, boolean testVisibility) throws JavaModelException {
int flags = overriding.getFlags();
if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor()) {
return null;
}
IType type = overriding.getDeclaringType();
IType superClass = fHierarchy.getSuperclass(type);
if (superClass != null) {
IMethod res = findOverriddenMethodInHierarchy(superClass, overriding);
if (res != null) {
if (!testVisibility || JavaModelUtil.isVisibleInHierarchy(res, type.getPackageFragment())) {
return res;
}
}
}
IType[] interfaces = fHierarchy.getSuperInterfaces(type);
for (int i = 0; i < interfaces.length; i++) {
IMethod res = findOverriddenMethodInHierarchy(interfaces[i], overriding);
if (res != null) {
// methods from interfaces are always public and therefore visible
return res;
}
}
return null;
}
Aggregations