Example usage for org.eclipse.jdt.core IMethod getPrimaryElement

List of usage examples for org.eclipse.jdt.core IMethod getPrimaryElement

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IMethod getPrimaryElement.

Prototype

IJavaElement getPrimaryElement();

Source Link

Document

Returns the primary element (whose compilation unit is the primary compilation unit) this working copy element was created from, or this element if it is a descendant of a primary compilation unit or if it is not a descendant of a working copy (e.g.

Usage

From source file:org.eclipse.jst.j2ee.internal.common.operations.JavaModelUtil.java

License:Open Source License

private static IMethod toOriginalMethod(IMethod method) {
    ICompilationUnit cu = method.getCompilationUnit();
    if (cu == null || isPrimary(cu)) {
        return method;
    }//from   w w w . ja  v  a  2 s .c  o  m
    try {
        //use the workaround only if needed   
        if (!method.getElementName().equals(method.getDeclaringType().getElementName()))
            return (IMethod) method.getPrimaryElement();

        IType originalType = (IType) toOriginal(method.getDeclaringType());
        IMethod[] methods = originalType.findMethods(method);
        boolean isConstructor = method.isConstructor();
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].isConstructor() == isConstructor)
                return methods[i];
        }
        return null;
    } catch (JavaModelException e) {
        return null;
    }
}

From source file:org.eclipse.jst.jsf.common.ui.internal.utils.JavaModelUtil.java

License:Open Source License

private static IMethod toOriginalMethod(IMethod method) {
    ICompilationUnit cu = method.getCompilationUnit();
    if (cu == null || isPrimary(cu)) {
        return method;
    }//from   w w  w  .j a  v a  2s. c om
    try {
        // use the workaround only if needed
        if (!method.getElementName().equals(method.getDeclaringType().getElementName()))
            return (IMethod) method.getPrimaryElement();

        IType originalType = (IType) toOriginal(method.getDeclaringType());
        IMethod[] methods = originalType.findMethods(method);
        boolean isConstructor = method.isConstructor();
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].isConstructor() == isConstructor)
                return methods[i];
        }
        return null;
    } catch (JavaModelException e) {
        return null;
    }
}