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

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

Introduction

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

Prototype

int IMPORT_CONTAINER

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

Click Source Link

Document

Constant representing all import declarations within a compilation unit.

Usage

From source file:org.eclipse.pde.api.tools.ui.internal.JavaElementActionFilter.java

License:Open Source License

/**
 * @see org.eclipse.ui.IActionFilter#testAttribute(Object, String, String)
 *///from w  w w . j a  v  a2 s  .  co m
@Override
public boolean testAttribute(Object target, String name, String value) {
    if (name.equals("JavaElementActionFilter")) { //$NON-NLS-1$
        if (target instanceof IJavaElement) {
            IJavaElement javaElement = (IJavaElement) target;
            if (value.equals("isEnabled")) { //$NON-NLS-1$
                while (javaElement != null) {
                    switch (javaElement.getElementType()) {
                    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                        IPackageFragmentRoot root = (IPackageFragmentRoot) javaElement;
                        return !root.isArchive();
                    case IJavaElement.PACKAGE_FRAGMENT:
                    case IJavaElement.COMPILATION_UNIT:
                    case IJavaElement.CLASS_FILE:
                    case IJavaElement.TYPE:
                        javaElement = javaElement.getParent();
                        break;
                    case IJavaElement.ANNOTATION:
                    case IJavaElement.FIELD:
                    case IJavaElement.IMPORT_CONTAINER:
                    case IJavaElement.IMPORT_DECLARATION:
                    case IJavaElement.INITIALIZER:
                    case IJavaElement.JAVA_MODEL:
                    case IJavaElement.LOCAL_VARIABLE:
                    case IJavaElement.METHOD:
                    case IJavaElement.PACKAGE_DECLARATION:
                    case IJavaElement.TYPE_PARAMETER:
                        return false;
                    case IJavaElement.JAVA_PROJECT:
                        return true;
                    default:
                        break;
                    }
                }
                return true;
            }
        }
    }
    return false;
}

From source file:org.eclipse.recommenders.internal.rcp.JavaElementSelections.java

License:Open Source License

public static JavaElementSelectionLocation resolveSelectionLocationFromJavaElement(final IJavaElement element) {
    ensureIsNotNull(element);/*www  . j a v a 2s  . c o m*/

    switch (element.getElementType()) {
    case IJavaElement.CLASS_FILE:
    case IJavaElement.COMPILATION_UNIT:
    case IJavaElement.PACKAGE_DECLARATION:
    case IJavaElement.IMPORT_DECLARATION:
    case IJavaElement.IMPORT_CONTAINER:
    case IJavaElement.TYPE:
        return TYPE_DECLARATION;
    case IJavaElement.METHOD:
    case IJavaElement.INITIALIZER:
        return METHOD_DECLARATION;
    case IJavaElement.FIELD:
        return FIELD_DECLARATION;
    case IJavaElement.LOCAL_VARIABLE:
        // shouldn't happen in a viewer selection, right?
        return METHOD_BODY;
    case IJavaElement.JAVA_MODEL:
    case IJavaElement.PACKAGE_FRAGMENT:
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
    case IJavaElement.ANNOTATION:
    default:
        return JavaElementSelectionLocation.UNKNOWN;
    }
}

From source file:org.jboss.tools.vscode.java.internal.handlers.DocumentSymbolHandler.java

License:Open Source License

public static int mapKind(IJavaElement element) {
    //      /**//from  w w  w  .java  2  s.  c o  m
    //      * A symbol kind.
    //      */
    //      export enum SymbolKind {
    //        File = 1,
    //        Module = 2,
    //        Namespace = 3,
    //        Package = 4,
    //        Class = 5,
    //        Method = 6,
    //        Property = 7,
    //        Field = 8,
    //        Constructor = 9,
    //        Enum = 10,
    //        Interface = 11,
    //        Function = 12,
    //        Variable = 13,
    //        Constant = 14,
    //        String = 15,
    //        Number = 16,
    //        Boolean = 17,
    //        Array = 18,
    //      }
    switch (element.getElementType()) {
    case IJavaElement.ANNOTATION:
        return 7; // TODO: find a better mapping 
    case IJavaElement.CLASS_FILE:
    case IJavaElement.COMPILATION_UNIT:
        return 1;
    case IJavaElement.FIELD:
        return 8;
    case IJavaElement.IMPORT_CONTAINER:
    case IJavaElement.IMPORT_DECLARATION:
        return 2;
    case IJavaElement.INITIALIZER:
        return 9;
    case IJavaElement.LOCAL_VARIABLE:
    case IJavaElement.TYPE_PARAMETER:
        return 13;
    case IJavaElement.METHOD:
        return 12;
    case IJavaElement.PACKAGE_DECLARATION:
        return 3;
    case IJavaElement.TYPE:
        try {
            return (((IType) element).isInterface() ? 11 : 5);
        } catch (JavaModelException e) {
            return 5; //fallback 
        }
    }
    return 15;
}