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

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

Introduction

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

Prototype

int ANNOTATION

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

Click Source Link

Document

Constant representing an annotation.

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)
 *//*  w  w  w .  j a va  2s  .c  o 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);//from ww  w.ja va2 s  .  co 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 .  ja v  a  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;
}

From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel.java

License:Open Source License

/**
 * Process a single Java Element change//  w  ww.  j a  va2s .c  om
 * 
 * @param delta
 * @param progressMonitor
 * @throws CoreException
 */
public void processJavaElementChange(final JavaElementChangedEvent delta,
        final IProgressMonitor progressMonitor) throws CoreException {
    try {
        Logger.debug("Processing {}", delta);
        readWriteLock.writeLock().lock();
        final IJavaElement element = delta.getElement();
        final CompilationUnit ast = delta.getCompilationUnitAST();
        final int deltaKind = delta.getKind();
        switch (element.getElementType()) {
        case IJavaElement.JAVA_PROJECT:
        case IJavaElement.PACKAGE_FRAGMENT_ROOT:
            processProject(progressMonitor);
            break;
        case IJavaElement.ANNOTATION:
            processJavaAnnotationChange((IAnnotation) element, deltaKind, ast, progressMonitor);
            break;
        case IJavaElement.COMPILATION_UNIT:
        case IJavaElement.TYPE:
        case IJavaElement.METHOD:
        case IJavaElement.FIELD:
            processJavaElementChange(element, deltaKind, ast, progressMonitor);
            break;
        default:
            // ignore
            break;
        }
    } finally {
        this.initializing = false;
        progressMonitor.done();
        readWriteLock.writeLock().unlock();
        setBuildStatus(Status.OK_STATUS);
        Logger.debug("Done processing Java changes: " + getStatus());
    }
}

From source file:org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils.java

License:Open Source License

/**
 * @return an {@link Annotation} from the given node if it is an
 *         {@link org.eclipse.jdt.core.dom.Annotation}, or recursively calls
 *         with the given node's parent until match, or return null
 * @param node/*from  w w  w  .  j  a  v a  2s. co m*/
 *            the current node
 * @param location the location in the Root {@link ASTNode}
 * @throws JavaModelException 
 */
private static Annotation findAnnotation(final ASTNode node, final int location) throws JavaModelException {
    if (node == null) {
        return null;
    } else if (!(node instanceof org.eclipse.jdt.core.dom.Annotation)) {
        return findAnnotation(node.getParent(), location);
    }
    final IAnnotationBinding annotationBinding = ((org.eclipse.jdt.core.dom.Annotation) node)
            .resolveAnnotationBinding();
    if (annotationBinding.getJavaElement() != null
            && annotationBinding.getJavaElement().getElementType() == IJavaElement.ANNOTATION) {
        return toAnnotation(annotationBinding, (IAnnotation) annotationBinding.getJavaElement());
    }
    if (node.getParent().getNodeType() == ASTNode.SINGLE_VARIABLE_DECLARATION) {
        final SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) node.getParent();
        final IVariableBinding variableDeclarationBinding = variableDeclaration.resolveBinding();
        final IAnnotationBinding[] annotationBindings = variableDeclarationBinding.getAnnotations();
        // retrieve the parameter index in the parent method
        final IMethod parentMethod = (IMethod) variableDeclarationBinding.getDeclaringMethod().getJavaElement();
        final ILocalVariable localVariable = getLocalVariable(variableDeclarationBinding, parentMethod);
        if (localVariable != null) {
            final IAnnotation[] variableAnnotations = localVariable.getAnnotations();
            for (int j = 0; j < annotationBindings.length; j++) {
                final IAnnotation javaAnnotation = variableAnnotations[j];
                if (RangeUtils.matches(javaAnnotation.getSourceRange(), location)) {
                    final IAnnotationBinding javaAnnotationBinding = annotationBindings[j];
                    return toAnnotation(javaAnnotationBinding, javaAnnotation);
                }
            }
        }

    }
    return null;
}

From source file:org.jboss.tools.ws.jaxrs.core.jdt.MemberValuePairLocationRetriever.java

License:Open Source License

/**
 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.NormalAnnotation)
 *//*from   www.  j a  va  2 s.co  m*/
@Override
public boolean visit(NormalAnnotation node) {
    final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.ANNOTATION);
    if (ancestor != null && ancestor.exists()
            && ancestor.getElementName().equals(node.getTypeName().getFullyQualifiedName())) {
        // keep searching
        return true;
    }
    // wrong path, stop searching from this branch of the AST
    return false;
}