Search in sources :

Example 31 with IMethod

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;
}
Also used : IMethod(org.eclipse.jdt.core.IMethod)

Example 32 with IMethod

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));
}
Also used : IMethod(org.eclipse.jdt.core.IMethod)

Example 33 with IMethod

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;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) MethodOverrideTester(org.eclipse.jdt.internal.corext.util.MethodOverrideTester) ArrayList(java.util.ArrayList) IType(org.eclipse.jdt.core.IType) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) IMethod(org.eclipse.jdt.core.IMethod)

Example 34 with IMethod

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);
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) MethodOverrideTester(org.eclipse.jdt.internal.corext.util.MethodOverrideTester) IMethod(org.eclipse.jdt.core.IMethod) IType(org.eclipse.jdt.core.IType)

Example 35 with IMethod

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;
}
Also used : ITypeParameter(org.eclipse.jdt.core.ITypeParameter) IMethod(org.eclipse.jdt.core.IMethod) IType(org.eclipse.jdt.core.IType)

Aggregations

IMethod (org.eclipse.jdt.core.IMethod)160 IType (org.eclipse.jdt.core.IType)87 IJavaElement (org.eclipse.jdt.core.IJavaElement)36 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)29 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)28 ArrayList (java.util.ArrayList)24 Test (org.junit.Test)22 IField (org.eclipse.jdt.core.IField)21 ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)14 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)13 IMember (org.eclipse.jdt.core.IMember)13 JavaModelException (org.eclipse.jdt.core.JavaModelException)12 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)12 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)11 HashSet (java.util.HashSet)8 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)8 ILocalVariable (org.eclipse.jdt.core.ILocalVariable)7 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)7 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)7 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)7