use of org.eclipse.jdt.core.IMethod in project flux by eclipse.
the class Bindings method findMethod.
/**
* Finds a method for the given <code>IMethodBinding</code>. Returns
* <code>null</code> if the type doesn't contain a corresponding method.
* @param method the method to find
* @param type the type to look in
* @return the corresponding IMethod or <code>null</code>
* @throws JavaModelException if an error occurs in the Java model
* @deprecated Use {@link #findMethodInHierarchy(ITypeBinding, String, String[])} or {@link JavaModelUtil}
*/
public static IMethod findMethod(IMethodBinding method, IType type) throws JavaModelException {
method = method.getMethodDeclaration();
IMethod[] candidates = type.getMethods();
for (int i = 0; i < candidates.length; i++) {
IMethod candidate = candidates[i];
if (candidate.getElementName().equals(method.getName()) && sameParameters(method, candidate)) {
return candidate;
}
}
return null;
}
use of org.eclipse.jdt.core.IMethod in project che by eclipse.
the class IntroduceParameterObjectDescriptor method initializeFromMap.
private void initializeFromMap(Map map) throws IllegalArgumentException {
IMethod method = (IMethod) JavaRefactoringDescriptorUtil.getJavaElement(map, ATTRIBUTE_INPUT, getProject());
setMethod(method);
initializeParameter(map);
setClassName(JavaRefactoringDescriptorUtil.getString(map, CLASS_NAME, true));
setPackageName(JavaRefactoringDescriptorUtil.getString(map, PACKAGE_NAME, true));
setParameterName(JavaRefactoringDescriptorUtil.getString(map, PARAMETER_NAME, true));
setDelegate(JavaRefactoringDescriptorUtil.getBoolean(map, DELEGATE, fDelegate));
setDeprecateDelegate(JavaRefactoringDescriptorUtil.getBoolean(map, DEPRECATE_DELEGATE, fDeprecateDelegate));
setGetters(JavaRefactoringDescriptorUtil.getBoolean(map, GETTERS, fGetters));
setSetters(JavaRefactoringDescriptorUtil.getBoolean(map, SETTERS, fSetters));
setTopLevel(JavaRefactoringDescriptorUtil.getBoolean(map, TOP_LEVEL, fTopLevel));
}
use of org.eclipse.jdt.core.IMethod in project che by eclipse.
the class JavadocContentAccess2 method createSuperMethodReferences.
private static StringBuffer createSuperMethodReferences(final IMethod method, String urlPrefix) throws JavaModelException {
IType type = method.getDeclaringType();
ITypeHierarchy hierarchy = SuperTypeHierarchyCache.getTypeHierarchy(type);
final MethodOverrideTester tester = SuperTypeHierarchyCache.getMethodOverrideTester(type);
final ArrayList<IMethod> superInterfaceMethods = new ArrayList<IMethod>();
final IMethod[] superClassMethod = { null };
new InheritDocVisitor() {
@Override
public Object visit(IType currType) throws JavaModelException {
IMethod overridden = tester.findOverriddenMethodInType(currType, method);
if (overridden == null)
return InheritDocVisitor.CONTINUE;
if (currType.isInterface())
superInterfaceMethods.add(overridden);
else
superClassMethod[0] = overridden;
return STOP_BRANCH;
}
}.visitInheritDoc(type, hierarchy);
boolean hasSuperInterfaceMethods = superInterfaceMethods.size() != 0;
if (!hasSuperInterfaceMethods && superClassMethod[0] == null)
return null;
StringBuffer buf = new StringBuffer();
//$NON-NLS-1$
buf.append("<div>");
if (hasSuperInterfaceMethods) {
//$NON-NLS-1$
buf.append("<b>");
buf.append(JavaDocMessages.JavaDoc2HTMLTextReader_specified_by_section);
//$NON-NLS-1$
buf.append("</b> ");
for (Iterator<IMethod> iter = superInterfaceMethods.iterator(); iter.hasNext(); ) {
IMethod overridden = iter.next();
buf.append(createMethodInTypeLinks(overridden, urlPrefix));
if (iter.hasNext())
buf.append(JavaElementLabels.COMMA_STRING);
}
}
if (superClassMethod[0] != null) {
if (hasSuperInterfaceMethods)
buf.append(JavaElementLabels.COMMA_STRING);
//$NON-NLS-1$
buf.append("<b>");
buf.append(JavaDocMessages.JavaDoc2HTMLTextReader_overrides_section);
//$NON-NLS-1$
buf.append("</b> ");
buf.append(createMethodInTypeLinks(superClassMethod[0], urlPrefix));
}
//$NON-NLS-1$
buf.append("</div>");
return buf;
}
use of org.eclipse.jdt.core.IMethod in project che by eclipse.
the class JavadocContentAccess2 method findAttachedDocInHierarchy.
/**
* Finds the first available attached Javadoc in the hierarchy of the given method.
*
* @param method
* the method
* @return the inherited Javadoc from the Javadoc attachment, or <code>null</code> if none
* @throws org.eclipse.jdt.core.JavaModelException
* unexpected problem
*/
private static String findAttachedDocInHierarchy(final IMethod method) throws JavaModelException {
IType type = method.getDeclaringType();
ITypeHierarchy hierarchy = SuperTypeHierarchyCache.getTypeHierarchy(type);
final MethodOverrideTester tester = SuperTypeHierarchyCache.getMethodOverrideTester(type);
return (String) new InheritDocVisitor() {
@Override
public Object visit(IType currType) throws JavaModelException {
IMethod overridden = tester.findOverriddenMethodInType(currType, method);
if (overridden == null)
return InheritDocVisitor.CONTINUE;
if (overridden.getOpenable().getBuffer() == null) {
// only if no source available
//TODO: BaseURL for method can be wrong for attached Javadoc from overridden
// (e.g. when overridden is from rt.jar). Fix would be to add baseURL here.
String attachedJavadoc = overridden.getAttachedJavadoc(null);
if (attachedJavadoc != null)
return attachedJavadoc;
}
return CONTINUE;
}
}.visitInheritDoc(type, hierarchy);
}
use of org.eclipse.jdt.core.IMethod in project che by eclipse.
the class JavaElementLinks method resolveTypeVariable.
private static ITypeParameter resolveTypeVariable(IJavaElement baseElement, String typeVariableName) throws JavaModelException {
while (baseElement != null) {
switch(baseElement.getElementType()) {
case IJavaElement.METHOD:
IMethod method = (IMethod) baseElement;
ITypeParameter[] typeParameters = method.getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
ITypeParameter typeParameter = typeParameters[i];
if (typeParameter.getElementName().equals(typeVariableName)) {
return typeParameter;
}
}
break;
case IJavaElement.TYPE:
IType type = (IType) baseElement;
typeParameters = type.getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
ITypeParameter typeParameter = typeParameters[i];
if (typeParameter.getElementName().equals(typeVariableName)) {
return typeParameter;
}
}
break;
case IJavaElement.JAVA_MODEL:
case IJavaElement.JAVA_PROJECT:
case IJavaElement.PACKAGE_FRAGMENT:
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
case IJavaElement.CLASS_FILE:
case IJavaElement.COMPILATION_UNIT:
case IJavaElement.PACKAGE_DECLARATION:
case IJavaElement.IMPORT_CONTAINER:
case IJavaElement.IMPORT_DECLARATION:
return null;
default:
break;
}
// look for type parameters in enclosing members:
baseElement = baseElement.getParent();
}
return null;
}
Aggregations