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

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

Introduction

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

Prototype

String getElementName();

Source Link

Document

Returns the name of this element.

Usage

From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.search.JavaElementsSearcher.java

License:Open Source License

/**
 * Returns all potential JAX-RS providers in the given scope (ex : javaProject), ie, types annotated with
 * <code>javax.ws.rs.ext.Provider</code> annotation or extending some expected interfaces.
 * /*w w  w . j  ava 2  s  .  co  m*/
 * 
 * @param scope
 *            the search scope (project, compilation unit, type, etc.)
 * @param includeLibraries
 *            include project libraries in search scope or not
 * @param progressMonitor
 *            the progress monitor
 * @return providers the JAX-RS provider types
 * @throws CoreException
 *             in case of exception
 */
public static Set<IType> findProviderTypes(final IJavaElement scope, final IProgressMonitor progressMonitor)
        throws CoreException {
    final long start = System.currentTimeMillis();
    try {
        final Set<IType> providerTypes = new HashSet<IType>();
        final IJavaSearchScope searchScope = createSearchScope(scope);
        final Set<IType> annotatedTypes = searchForAnnotatedTypes(PROVIDER, searchScope, progressMonitor);
        providerTypes.addAll(annotatedTypes);
        // also search for one or more provider subtypes
        providerTypes.addAll(findSubtypes(scope, MESSAGE_BODY_READER, progressMonitor));
        providerTypes.addAll(findSubtypes(scope, MESSAGE_BODY_WRITER, progressMonitor));
        providerTypes.addAll(findSubtypes(scope, EXCEPTION_MAPPER, progressMonitor));
        providerTypes.addAll(findSubtypes(scope, CONTAINER_REQUEST_FILTER, progressMonitor));
        providerTypes.addAll(findSubtypes(scope, CONTAINER_RESPONSE_FILTER, progressMonitor));
        providerTypes.addAll(findSubtypes(scope, ENTITY_READER_INTERCEPTOR, progressMonitor));
        providerTypes.addAll(findSubtypes(scope, ENTITY_WRITER_INTERCEPTOR, progressMonitor));
        return providerTypes;
    } finally {
        final long end = System.currentTimeMillis();
        Logger.tracePerf("Found Provider types in scope {} in {}ms", scope.getElementName(), (end - start));
    }
}

From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.search.JavaElementsSearcher.java

License:Open Source License

/**
 * Returns all potential JAX-RS ParamConverter Providers in the given scope (ex : javaProject), ie, types annotated with
 * <code>javax.ws.rs.ext.Provider</code> annotation or implementing {@code java.ws.rs.ext.ParamConverterProvider}.
 * //  ww  w.  j a  va2 s . co m
 * 
 * @param scope
 *            the search scope (project, compilation unit, type, etc.)
 * @param includeLibraries
 *            include project libraries in search scope or not
 * @param progressMonitor
 *            the progress monitor
 * @return the JAX-RS ParamConverter types
 * @throws CoreException
 *             in case of exception
 */
public static Set<IType> findParamConverterProviderTypes(final IJavaElement scope,
        final IProgressMonitor progressMonitor) throws CoreException {
    final long start = System.currentTimeMillis();
    try {
        final Set<IType> paramConverterTypes = new HashSet<IType>();
        final IJavaSearchScope searchScope = createSearchScope(scope);
        final Set<IType> annotatedTypes = searchForAnnotatedTypes(PROVIDER, searchScope, progressMonitor);
        paramConverterTypes.addAll(annotatedTypes);
        // also search for subtypes 
        final List<IType> paramConverterProviderSubtypes = findSubtypes(scope, PARAM_CONVERTER_PROVIDER,
                progressMonitor);
        paramConverterTypes
                .addAll(CollectionUtils.difference(paramConverterProviderSubtypes, paramConverterTypes));
        return paramConverterTypes;
    } finally {
        final long end = System.currentTimeMillis();
        Logger.tracePerf("Found Provider types in scope {} in {}ms", scope.getElementName(), (end - start));
    }
}

From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.search.JavaElementsSearcher.java

License:Open Source License

/**
 * Returns all potential JAX-RS Parameter Aggregators in the given scope (ex : javaProject), ie, types with fields or methods annotated with .
 * //  ww w .  j a v  a  2 s  . c  o  m
 * 
 * @param scope
 *            the search scope (project, compilation unit, type, etc.)
 * @param includeLibraries
 *            include project libraries in search scope or not
 * @param progressMonitor
 *            the progress monitor
 * @return providers the JAX-RS provider types
 * @throws CoreException
 *             in case of exception
 */
public static Set<IType> findParameterAggregatorTypes(IJavaElement scope, IProgressMonitor progressMonitor)
        throws CoreException {
    final long start = System.currentTimeMillis();
    try {
        final Set<IType> types = new HashSet<IType>();
        final IJavaSearchScope searchScope = createSearchScope(scope);
        final Set<IMethod> annotatedMethods = searchForAnnotatedMethods(JaxrsParamAnnotations.PARAM_ANNOTATIONS,
                searchScope, progressMonitor);
        for (IMethod annotatedMethod : annotatedMethods) {
            types.add((IType) annotatedMethod.getAncestor(IJavaElement.TYPE));
        }
        final Set<IField> annotatedFields = searchForAnnotatedFields(JaxrsParamAnnotations.PARAM_ANNOTATIONS,
                searchScope, progressMonitor);
        for (IField annotatedField : annotatedFields) {
            types.add((IType) annotatedField.getAncestor(IJavaElement.TYPE));
        }
        return types;
    } finally {
        final long end = System.currentTimeMillis();
        Logger.tracePerf("Found Provider types in scope {} in {}ms", scope.getElementName(), (end - start));
    }
}

From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.search.JavaElementsSearcher.java

License:Open Source License

/**
 * Returns all JAX-RS resources types// w  ww. j  a  v a 2  s .  c  o m
 * in the given scope (ex : javaProject).
 * 
 * @param scope
 *            the search scope (project, compilation unit, type, etc.)
 * @param progressMonitor
 *            the progress monitor
 * @return Set of JAX-RS resource types
 * @throws CoreException
 *             in case of underlying exception
 */
public static Set<IType> findResourceTypes(final IJavaElement scope, final IProgressMonitor progressMonitor)
        throws CoreException {
    final long start = System.currentTimeMillis();
    try {
        final IJavaSearchScope searchScope = createSearchScope(scope);
        return searchForAnnotatedTypes(PATH, searchScope, progressMonitor);
    } finally {
        final long end = System.currentTimeMillis();
        Logger.tracePerf("Found Resource types in scope {} in {}ms", scope.getElementName(), (end - start));
    }
}

From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.search.JavaElementsSearcher.java

License:Open Source License

/**
 * Returns all HTTP Methods (ie, annotation meta-annotated with the <code>javax.ws.rs.HttpMethod</code> annotation)
 * in the given scope (ex : javaProject).
 * /* w w w. j  a v a  2 s . co  m*/
 * @param scope
 *            the search scope (project, compilation unit, type, etc.)
 * @param progressMonitor
 *            the progress monitor
 * @return The found types
 * @throws CoreException
 *             in case of underlying exceptions.
 */
public static Set<IType> findHttpMethodTypes(final IJavaElement scope, final IProgressMonitor progressMonitor)
        throws CoreException {
    final long start = System.currentTimeMillis();
    try {
        final IJavaSearchScope searchScope = createSearchScope(scope);
        return searchForAnnotatedTypes(HTTP_METHOD, searchScope, progressMonitor);
    } finally {
        final long end = System.currentTimeMillis();
        Logger.tracePerf("Found HTTP Method types in scope {} in {}ms", scope.getElementName(), (end - start));
    }
}

From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.search.JavaElementsSearcher.java

License:Open Source License

/**
 * Returns all Name Bindings (ie, annotation meta-annotated with the <code>javax.ws.rs.NameBinding</code> annotation)
 * in the given scope (ex : javaProject).
 * /*  www . j ava2 s . c  o  m*/
 * @param scope
 *            the search scope (project, compilation unit, type, etc.)
 * @param progressMonitor
 *            the progress monitor
 * @return The found types
 * @throws CoreException
 *             in case of underlying exceptions.
 */
public static Set<IType> findNameBindingTypes(final IJavaElement scope, final IProgressMonitor progressMonitor)
        throws CoreException {
    final long start = System.currentTimeMillis();
    try {
        final IJavaSearchScope searchScope = createSearchScope(scope);
        return searchForAnnotatedTypes(NAME_BINDING, searchScope, progressMonitor);
    } finally {
        final long end = System.currentTimeMillis();
        Logger.tracePerf("Found NameBinding types in scope {} in {}ms", scope.getElementName(), (end - start));
    }
}

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.TypeDeclaration)
 *//*from www.j ava 2 s.  co  m*/
@Override
public boolean visit(AnnotationTypeDeclaration node) {
    final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.TYPE);
    if (ancestor != null && ancestor.exists()
            && ancestor.getElementName().equals(node.getName().getFullyQualifiedName())) {
        // keep searching
        return true;
    }
    // wrong path, stop searching from this branch of the AST
    return false;
}

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.TypeDeclaration)
 *//*  www  .j av a2s . co  m*/
@Override
public boolean visit(TypeDeclaration node) {
    final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.TYPE);
    if (ancestor != null && ancestor.exists()
            && ancestor.getElementName().equals(node.getName().getFullyQualifiedName())) {
        // keep searching
        return true;
    }
    // wrong path, stop searching from this branch of the AST
    return false;
}

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.FieldDeclaration)
 *//*  ww w  . j  a  va 2 s.c om*/
@Override
public boolean visit(VariableDeclarationFragment node) {
    final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.FIELD);
    if (ancestor != null && ancestor.exists()
            && ancestor.getElementName().equals(node.getName().getFullyQualifiedName())) {
        // keep searching
        return true;
    }
    // wrong path, stop searching from this branch of the AST
    return false;
}

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.MethodInvocation)
 *///from  w ww . j  a  v a 2  s  .  co  m
@Override
public boolean visit(MethodDeclaration node) {
    final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.METHOD);
    if (ancestor != null && ancestor.exists()
            && ancestor.getElementName().equals(node.getName().getFullyQualifiedName())) {
        // keep searching
        return true;
    }
    // wrong path, stop searching from this branch of the AST
    return false;
}