Example usage for org.eclipse.jdt.core IMember getParent

List of usage examples for org.eclipse.jdt.core IMember getParent

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IMember getParent.

Prototype

IJavaElement getParent();

Source Link

Document

Returns the element directly containing this element, or null if this element has no parent.

Usage

From source file:com.aqua.wikiwizard.ObjectsJavaModel.java

License:Apache License

/**
 * Returns a name of the package this member belongs to
 * @param member//w w w.j  a  va2  s .  c o m
 *          Member for which the request is
 * @return
 *          String
 */
public static String getMemberPackageName(IMember member) {
    IJavaElement parent = member.getParent();
    while (parent != null) {
        if (parent instanceof IPackageFragment) {
            return parent.getElementName();
        }
        parent = parent.getParent();
    }
    return null;
}

From source file:com.aqua.wikiwizard.SystemObjectPage.java

License:Apache License

private static String getMemberName(IMember member) {
    String className = member.getElementName();
    String packageName = null;//from  ww w  .j a v  a 2s . c o m
    IJavaElement parent = member.getParent();
    while (parent != null) {
        if (parent instanceof IPackageFragment) {
            packageName = parent.getElementName();
            break;
        }
        parent = parent.getParent();
    }
    if (packageName == null) {
        return className;
    }

    // Build the name for easy sorting
    return className + " - " + packageName + "." + className;
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockUtil.java

License:Open Source License

private static void outputSymbol(IJavaElement elt, String what, String nm, String key, IvyXmlWriter xw) {
    if (what == null || nm == null)
        return;//from  w ww.j  a va 2s  .co m

    xw.begin("ITEM");
    xw.field("TYPE", what);
    xw.field("NAME", nm);
    xw.field("HANDLE", elt.getHandleIdentifier());

    xw.field("WORKING", (elt.getPrimaryElement() != elt));
    ICompilationUnit cu = (ICompilationUnit) elt.getAncestor(IJavaElement.COMPILATION_UNIT);
    if (cu != null) {
        xw.field("CUWORKING", cu.isWorkingCopy());
    }
    try {
        xw.field("KNOWN", elt.isStructureKnown());
    } catch (JavaModelException e) {
    }

    if (elt instanceof ISourceReference) {
        try {
            ISourceRange rng = ((ISourceReference) elt).getSourceRange();
            if (rng != null) {
                xw.field("STARTOFFSET", rng.getOffset());
                xw.field("ENDOFFSET", rng.getOffset() + rng.getLength());
                xw.field("LENGTH", rng.getLength());
            }
        } catch (JavaModelException e) {
            BedrockPlugin.logE("Problem getting source range: " + e);
        }
    }

    if (elt instanceof ILocalVariable) {
        ILocalVariable lcl = (ILocalVariable) elt;
        xw.field("SIGNATURE", lcl.getTypeSignature());
    }

    if (elt instanceof IMember) {
        try {
            IMember mem = ((IMember) elt);
            int fgs = mem.getFlags();
            if (mem.getParent() instanceof IType && !(elt instanceof IType)) {
                IType par = (IType) mem.getParent();
                if (par.isInterface()) {
                    if (elt instanceof IMethod)
                        fgs |= Flags.AccAbstract;
                    fgs |= Flags.AccPublic;
                }
                xw.field("QNAME", par.getFullyQualifiedName() + "." + nm);
            }
            xw.field("FLAGS", fgs);
        } catch (JavaModelException e) {
        }
    }

    if (elt instanceof IPackageFragment || elt instanceof IType) {
        Display d = BedrockApplication.getDisplay();
        if (d != null) {
            JavadocUrl ju = new JavadocUrl(elt);
            d.syncExec(ju);
            URL u = ju.getResult();
            if (u != null) {
                xw.field("JAVADOC", u.toString());
            }
        }
    }

    xw.field("SOURCE", "USERSOURCE");
    if (key != null)
        xw.field("KEY", key);

    boolean havepath = false;
    for (IJavaElement pe = elt.getParent(); pe != null; pe = pe.getParent()) {
        if (pe.getElementType() == IJavaElement.COMPILATION_UNIT) {
            IProject ip = elt.getJavaProject().getProject();
            File f = BedrockUtil.getFileForPath(elt.getPath(), ip);
            xw.field("PATH", f.getAbsolutePath());
            havepath = true;
            break;
        }
    }
    IJavaProject ijp = elt.getJavaProject();
    if (ijp != null)
        xw.field("PROJECT", ijp.getProject().getName());
    IPath p = elt.getPath();
    if (p != null) {
        xw.field("XPATH", p);
        if (!havepath) {
            IProject ip = elt.getJavaProject().getProject();
            File f = getFileForPath(elt.getPath(), ip);
            xw.field("PATH", f.getAbsolutePath());
        }
    }

    if (elt instanceof IMethod) {
        IMethod m = (IMethod) elt;
        try {
            xw.field("RESOLVED", m.isResolved());
            ISourceRange rng = m.getNameRange();
            if (rng != null) {
                xw.field("NAMEOFFSET", rng.getOffset());
                xw.field("NAMELENGTH", rng.getLength());
            }
            xw.field("RETURNTYPE", m.getReturnType());
            xw.field("NUMPARAM", m.getNumberOfParameters());
            String[] pnms = m.getParameterNames();
            String[] ptys = m.getParameterTypes();
            for (int i = 0; i < ptys.length; ++i) {
                xw.begin("PARAMETER");
                if (i < pnms.length)
                    xw.field("NAME", pnms[i]);
                xw.field("TYPE", ptys[i]);
                xw.end();
            }
            for (String ex : m.getExceptionTypes()) {
                xw.begin("EXCEPTION");
                xw.field("TYPE", ex);
                xw.end();
            }
        } catch (JavaModelException e) {
        }
    }

    // TODO: output parameters as separate elements with type and name

    if (elt instanceof IAnnotatable) {
        IAnnotatable ann = (IAnnotatable) elt;
        try {
            IAnnotation[] ans = ann.getAnnotations();
            for (IAnnotation an : ans) {
                xw.begin("ANNOTATION");
                xw.field("NAME", an.getElementName());
                xw.field("COUNT", an.getOccurrenceCount());
                try {
                    for (IMemberValuePair mvp : an.getMemberValuePairs()) {
                        xw.begin("VALUE");
                        xw.field("NAME", mvp.getMemberName());
                        if (mvp.getValue() != null)
                            xw.field("VALUE", mvp.getValue().toString());
                        xw.field("KIND", mvp.getValueKind());
                        xw.end("VALUE");
                    }
                } catch (JavaModelException e) {
                }
                xw.end("ANNOTATION");
            }
        } catch (JavaModelException e) {
        }
    }

    xw.end("ITEM");
}

From source file:edu.buffalo.cse.green.editor.model.filters.MemberVisibility.java

License:Open Source License

/**
 * @param member - The member to check the filter against.
 * @return true if the filter applied, false otherwise.
 */// w  w  w.ja  v  a  2s. co  m
public boolean match(IMember member) {
    if (_visibility == ANY._visibility)
        return true;

    try {
        // handle interfaces: public-only 
        if (member.getParent() instanceof IType) {
            IType parent = (IType) member.getParent();
            if (parent.isInterface()) {
                return (_visibility == AccPublic);
            }
        }

        return (member.getFlags() & _visibility) == _visibility;
    } catch (JavaModelException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:org.eclipse.ajdt.internal.ui.refactoring.pullout.PullOutRefactoring.java

License:Open Source License

private boolean isInTopLevelType(IMember member) {
    IJavaElement parent = member.getParent();
    Assert.isTrue(parent.getElementType() == IJavaElement.TYPE);
    return parent.getParent().getElementType() == IJavaElement.COMPILATION_UNIT;
}

From source file:org.eclipse.ajdt.internal.ui.refactoring.PushInRefactoring.java

License:Open Source License

/**
 * Removes all ITDs in the given compilation unit.
 * Will delete an aspect if it has no more members.
 * Will delete an {@link AJCompilationUnit} if all 
 * of its types are deleted./*from ww w.ja  v a 2  s  .  co  m*/
 * @param itdsForUnit the ITDs for the given unit
 * @param source 
 * @param ast used to calculate imports
 * @throws JavaModelException
 * @throws CoreException
 */
protected void rewriteAspectType(List<IMember> itdsForUnit, ICompilationUnit source, CompilationUnit ast)
        throws JavaModelException, CoreException {

    // used to keep track of aspect types that are deleted.
    Map<IType, Integer> removalStored = new HashMap<IType, Integer>();
    Map<IType, List<DeleteEdit>> typeDeletes = new HashMap<IType, List<DeleteEdit>>();

    // go through each ITD and create a delete edit for it
    for (IMember itd : itdsForUnit) {
        IType parentAspectType = (IType) itd.getParent();
        int numRemovals;
        if (removalStored.containsKey(parentAspectType)) {
            numRemovals = ((Integer) removalStored.get(parentAspectType)).intValue();
            removalStored.put(parentAspectType, new Integer(++numRemovals));
        } else {
            removalStored.put(parentAspectType, new Integer(1));
        }
        List<DeleteEdit> deletes;
        if (typeDeletes.containsKey(parentAspectType)) {
            deletes = typeDeletes.get(parentAspectType);
        } else {
            deletes = new LinkedList<DeleteEdit>();
            typeDeletes.put(parentAspectType, deletes);
        }

        DeleteEdit edit = new DeleteEdit(itd.getSourceRange().getOffset(),
                itd.getSourceRange().getLength() + 1);
        deletes.add(edit);
    }

    if (deleteTypes(ast, typeDeletes, removalStored)) {
        allChanges.put(source, new DeleteResourceChange(source.getResource().getFullPath(), false));
    } else {
        applyAspectEdits(source, typeDeletes);
    }
}

From source file:org.eclipse.mylyn.internal.sandbox.bridge.bugs.Util.java

License:Open Source License

/**
 * Get the bugzilla url used for searching for inexact matches
 * /*from  w w  w . ja  v  a  2s  . co m*/
 * @param je
 *            The IMember to create the query string for
 * @return A url string for the search
 */
public static String getInexactSearchURL(String repositoryUrl, IMember je) {
    StringBuffer sb = getQueryURLStart(repositoryUrl);

    String long_desc = "";

    // add the member, qualified with just its parents name
    if (!(je instanceof IType)) {
        long_desc += je.getParent().getElementName() + ".";
    }
    long_desc += je.getElementName();

    try {
        // encode the string to be used as a url
        sb.append(URLEncoder.encode(long_desc, Charset.defaultCharset().toString()));
    } catch (UnsupportedEncodingException e) {
        // should never get here since we are using the default encoding
    }
    sb.append(getQueryURLEnd(repositoryUrl));

    return sb.toString();
}

From source file:org.moreunit.handler.JumpActionExecutor.java

License:Open Source License

private void jumpToMember(IMember memberToJump) {
    if (memberToJump instanceof IMethod) {
        IMethod methodToJump = (IMethod) memberToJump;
        IEditorPart openedEditor = editorUI.open(methodToJump.getDeclaringType().getParent());
        revealInEditor(openedEditor, methodToJump);
    } else {/*from ww  w  .j  a v a 2 s .  c om*/
        editorUI.open(memberToJump.getParent());
    }
}