Example usage for org.eclipse.jdt.core IJavaElement INITIALIZER

List of usage examples for org.eclipse.jdt.core IJavaElement INITIALIZER

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaElement INITIALIZER.

Prototype

int INITIALIZER

To view the source code for org.eclipse.jdt.core IJavaElement INITIALIZER.

Click Source Link

Document

Constant representing a stand-alone instance or class initializer.

Usage

From source file:com.redhat.ceylon.eclipse.code.explorer.PackageExplorerPart.java

License:Open Source License

private Object getVisibleParent(Object object) {
    // Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=19104
    if (object == null)
        return null;
    if (!(object instanceof IJavaElement))
        return object;
    IJavaElement element2 = (IJavaElement) object;
    switch (element2.getElementType()) {
    case IJavaElement.IMPORT_DECLARATION:
    case IJavaElement.PACKAGE_DECLARATION:
    case IJavaElement.IMPORT_CONTAINER:
    case IJavaElement.TYPE:
    case IJavaElement.METHOD:
    case IJavaElement.FIELD:
    case IJavaElement.INITIALIZER:
        // select parent cu/classfile
        element2 = (IJavaElement) element2.getOpenable();
        break;/*from  ww w.j a v a  2s  .c  o  m*/
    case IJavaElement.JAVA_MODEL:
        element2 = null;
        break;
    }
    return element2;
}

From source file:de.loskutov.bco.ui.actions.BytecodeAction.java

License:Open Source License

protected TypedElement createTypedElement(IJavaElement javaElement, BitSet modes) {
    String name;/*from w ww .  j  a  v  a2s . c o m*/
    IClassFile classFile = (IClassFile) javaElement.getAncestor(IJavaElement.CLASS_FILE);
    // existing read-only class files
    if (classFile != null) {
        name = classFile.getPath().toOSString();
        if (!name.endsWith(".class")) { //$NON-NLS-1$
            name += '/' + JdtUtils.getFullBytecodeName(classFile);
        }
    } else {
        // usual eclipse - generated bytecode
        name = JdtUtils.getByteCodePath(javaElement);
    }
    String methodName = null;
    if (javaElement.getElementType() == IJavaElement.METHOD
            || javaElement.getElementType() == IJavaElement.INITIALIZER) {
        methodName = JdtUtils.getMethodSignature(javaElement);
        if (methodName != null) {
            name += ":" + methodName;
        }
    }
    return new TypedElement(name, methodName, TypedElement.TYPE_BYTECODE, javaElement, modes);
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

public static IJavaElement getMethod(IParent parent, String signature) {
    try {/*from  w ww.java 2  s  . c  o  m*/
        IJavaElement[] children = parent.getChildren();
        for (int i = 0; i < children.length; i++) {
            IJavaElement javaElement = children[i];
            switch (javaElement.getElementType()) {
            case IJavaElement.INITIALIZER:
                // fall through
            case IJavaElement.METHOD:
                if (signature.equals(getMethodSignature(javaElement))) {
                    return javaElement;
                }
                break;
            default:
                break;
            }
            if (javaElement instanceof IParent) {
                javaElement = getMethod((IParent) javaElement, signature);
                if (javaElement != null) {
                    return javaElement;
                }
            }
        }
    } catch (JavaModelException e) {
        // just ignore it. Mostly caused by class files not on the class path
        // which is not a problem for us, but a big problem for JDT
    }
    return null;
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

/**
 * @param childEl// ww w.ja  v  a  2  s . c o m
 * @return method signature, if given java element is either initializer or method,
 * otherwise returns null.
 */
public static String getMethodSignature(IJavaElement childEl) {
    String methodName = null;
    if (childEl.getElementType() == IJavaElement.INITIALIZER) {
        IInitializer ini = (IInitializer) childEl;
        try {
            if (Flags.isStatic(ini.getFlags())) {
                methodName = "<clinit>()V";
            } else {
                methodName = "<init>()";
            }
        } catch (JavaModelException e) {
            // this is compilation problem - don't show the message
            BytecodeOutlinePlugin.log(e, IStatus.WARNING);
        }
    } else if (childEl.getElementType() == IJavaElement.METHOD) {
        IMethod iMethod = (IMethod) childEl;
        try {
            methodName = createMethodSignature(iMethod);
        } catch (JavaModelException e) {
            // this is compilation problem - don't show the message
            BytecodeOutlinePlugin.log(e, IStatus.WARNING);
        }
    }
    return methodName;
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

/**
 * @param innerType should be inner type.
 * @return true, if given element is a type defined in the initializer block
 *//*w ww  .  jav a  2 s .  c  om*/
private static boolean isFromInitBlock(IType type) {
    IJavaElement ancestor = type.getAncestor(IJavaElement.INITIALIZER);
    return ancestor != null;
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

/**
 * @param javaElement/*from www .j a va  2 s . c  o m*/
 * @param topAncestor
 * @param sb
 */
private static String getClassName(IJavaElement javaElement, IJavaElement topAncestor) {
    StringBuffer sb = new StringBuffer();
    if (!javaElement.equals(topAncestor)) {
        int elementType = javaElement.getElementType();
        if (elementType == IJavaElement.FIELD || elementType == IJavaElement.METHOD
                || elementType == IJavaElement.INITIALIZER) {
            // it's field or method
            javaElement = getFirstAncestor(javaElement);
        } else {
            boolean is50OrHigher = is50OrHigher(javaElement);
            if (!is50OrHigher && (isAnonymousType(javaElement) || isLocal(javaElement))) {
                // it's inner type
                sb.append(getElementName(topAncestor));
                sb.append(TYPE_SEPARATOR);
            } else {
                /*
                 * TODO there is an issue with < 1.5 compiler setting and with inner
                 * classes with the same name but defined in different methods in the same
                 * source file. Then compiler needs to generate *different* content for
                 *  A$1$B and A$1$B, which is not possible so therefore compiler generates
                 *  A$1$B and A$2$B. The naming order is the source range order of inner
                 *  classes, so the first inner B class will get A$1$B and the second
                 *  inner B class A$2$B etc.
                 */

                // override top ancestor with immediate ancestor
                topAncestor = getFirstAncestor(javaElement);
                while (topAncestor != null) {
                    sb.insert(0, getElementName(topAncestor) + TYPE_SEPARATOR);
                    topAncestor = getFirstAncestor(topAncestor);
                }
            }
        }
    }
    sb.append(getElementName(javaElement));
    return sb.toString();
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

/**
 * 1) from instance init 2) from deepest inner from instance init (deepest first) 3) from
 * static init 4) from deepest inner from static init (deepest first) 5) from deepest inner
 * (deepest first) 6) regular anon classes from main class
 *
 * <br>//from  ww  w  .j ava2 s  .c o m
 * Note, that nested inner anon. classes which do not have different non-anon. inner class
 * ancestors, are compiled in they nesting order, opposite to rule 2)
 *
 * @param javaElement
 * @return priority - lesser mean wil be compiled later, a value > 0
 * @throws JavaModelException
 */
private static int getAnonCompilePriority50(IJavaElement javaElement, IJavaElement firstAncestor,
        IJavaElement topAncestor) {

    // search for initializer block
    IJavaElement initBlock = getLastAncestor(javaElement, IJavaElement.INITIALIZER);
    // test is for anon. classes from initializer blocks
    if (initBlock != null) {
        return 10; // from inner from class init
    }

    // test for anon. classes from "regular" code
    return 5;
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

private static int getAnonCompilePriority(IJavaElement elt, IJavaElement firstAncestor,
        IJavaElement topAncestor, boolean is50OrHigher) {
    if (is50OrHigher) {
        return getAnonCompilePriority50(elt, firstAncestor, topAncestor);
    }//w  w w  . jav  a2s.c o m

    IJavaElement firstNonAnon = getFirstNonAnonymous(elt, topAncestor);

    // get rid of children from local types
    if (topAncestor != firstNonAnon && isLocal(firstNonAnon)) {
        return 5; // local anon. types have same prio as anon. from regular code
    }

    IJavaElement initBlock = getLastAncestor(elt, IJavaElement.INITIALIZER);
    // test is for anon. classes from initializer blocks
    if (initBlock != null) {
        if (isAnyParentLocal(firstAncestor, topAncestor)) {
            return 5; // init blocks from local types have same prio as regular
        }
        if (firstAncestor == topAncestor) {
            return 10; // instance init from top level type has top prio
        }
        if ( /*firstNonAnon != topAncestor && */!isStatic((IMember) firstNonAnon)) {
            return 8; // init blocks from non static types have top 2 prio
        }
        return 7; // init blocks from static classes
    }

    if (firstNonAnon != topAncestor) {
        if (!isStatic((IMember) firstNonAnon)) {
            return 7; // children of member types first
        }
        return 6; // childern of static types
    }

    // anon. types from "regular" code
    return 5;
}

From source file:de.loskutov.bco.views.BytecodeOutlineView.java

License:Open Source License

/**
 * @return IJavaElement which fits in the current selection in java editor
 *//*from w  w w. ja va  2  s  .co  m*/
private IJavaElement getCurrentJavaElement() {
    IJavaElement childEl = null;
    try {
        childEl = JdtUtils.getElementAtOffset(javaInput, currentSelection);
        if (childEl != null) {
            switch (childEl.getElementType()) {
            case IJavaElement.METHOD:
            case IJavaElement.FIELD:
            case IJavaElement.INITIALIZER:
            case IJavaElement.TYPE:
                break;
            case IJavaElement.LOCAL_VARIABLE:
                childEl = childEl.getAncestor(IJavaElement.METHOD);
                break;
            default:
                childEl = null;
                break;
            }
        }
    } catch (JavaModelException e) {
        // the exception is mostly occured if java structure was
        // changed and current element is not more exist in model
        // e.g. on rename/delete/move operation.
        // so it is not an error for user, but info for us
        BytecodeOutlinePlugin.log(e, IStatus.INFO);
        setJavaInput(null);
        lastChildElement = null;
    }
    return childEl;
}

From source file:de.tobject.findbugs.reporter.JdtUtils.java

License:Open Source License

private static int getAnonCompilePriority(IJavaElement elt, IJavaElement firstAncestor,
        IJavaElement topAncestor, boolean is50OrHigher) {
    if (is50OrHigher) {
        return getAnonCompilePriority50(elt, firstAncestor, topAncestor);
    }/*from www.j  a  v a  2 s  .c o m*/

    IJavaElement firstNonAnon = getFirstNonAnonymous(elt, topAncestor);

    // get rid of children from local types
    if (topAncestor != firstNonAnon && isLocal(firstNonAnon)) {
        return 5; // local anon. types have same prio as anon. from regular
                  // code
    }

    IJavaElement initBlock = getLastAncestor(elt, IJavaElement.INITIALIZER);
    // test is for anon. classes from initializer blocks
    if (initBlock != null) {
        if (isAnyParentLocal(firstAncestor, topAncestor)) {
            return 5; // init blocks from local types have same prio as
                      // regular
        }
        if (firstAncestor == topAncestor) {
            return 10; // instance init from top level type has top prio
        }
        if ( /* firstNonAnon != topAncestor && */!isStatic((IMember) firstNonAnon)) {
            return 8; // init blocks from non static types have top 2 prio
        }
        return 7; // init blocks from static classes
    }

    if (firstNonAnon != topAncestor) {
        if (!isStatic((IMember) firstNonAnon)) {
            return 7; // children of member types first
        }
        return 6; // children of static types
    }

    // anon. types from "regular" code
    return 5;
}