List of usage examples for org.eclipse.jdt.core IMethod getAncestor
IJavaElement getAncestor(int ancestorType);
From source file:org.eclipse.jst.ws.internal.conformance.JDTResolver.java
License:Open Source License
/** * Returns the JDT IType object for the return type * of the given method, or null if the method is void. * @param jdtMethod The method to analyze. * @return The method return type, or null if none. * @throws JavaModelException If the JDT engine fails to * analyze the given method to satisfy this request. */// w ww . ja va 2s . c o m public IType getReturnType(IMethod jdtMethod) throws JavaModelException { IJavaElement elem = jdtMethod.getAncestor(IJavaElement.TYPE); IType ancestor = elem instanceof IType ? (IType) elem : null; String signature = jdtMethod.getReturnType(); String typeName = getTypeNameFromSignature(signature); return findType(typeName, ancestor); }
From source file:org.eclipse.jst.ws.internal.conformance.JDTResolver.java
License:Open Source License
/** * Returns the type name for the return type * of the given method, or null if the method is void. * @param jdtMethod The method to analyze. * @return The method return type name, or null if none. * @throws JavaModelException If the JDT engine fails to * analyze the given method to satisfy this request. */// www .j ava 2s . c o m public String getReturnTypeName(IMethod jdtMethod) throws JavaModelException { IJavaElement elem = jdtMethod.getAncestor(IJavaElement.TYPE); IType ancestor = elem instanceof IType ? (IType) elem : null; String signature = jdtMethod.getReturnType(); String typeName = getTypeNameFromSignature(signature); return resolveType(typeName, ancestor); }
From source file:org.eclipse.jst.ws.internal.conformance.JDTResolver.java
License:Open Source License
/** * Returns an array of zero or more JDT IType objects * for the parameters of the given method. * @param jdtMethod The method to analyze. * @return An array of zero or more parameter types. * @throws JavaModelException If the JDT engine fails to * analyze the given method to satisfy this request. */// w w w . j av a 2s. c om public IType[] getParameterTypes(IMethod jdtMethod) throws JavaModelException { IJavaElement elem = jdtMethod.getAncestor(IJavaElement.TYPE); IType ancestor = elem instanceof IType ? (IType) elem : null; String[] signatures = jdtMethod.getParameterTypes(); IType[] types = new IType[signatures.length]; for (int s = 0; s < signatures.length; s++) { String typeName = getTypeNameFromSignature(signatures[s]); types[s] = findType(typeName, ancestor); } return types; }
From source file:org.eclipse.jst.ws.internal.conformance.JDTResolver.java
License:Open Source License
/** * Returns an array of zero or more type names * for the parameters of the given method. * @param jdtMethod The method to analyze. * @return An array of zero or more parameter type names. * @throws JavaModelException If the JDT engine fails to * analyze the given method to satisfy this request. *///from www . j av a2 s . co m public String[] getParameterTypeNames(IMethod jdtMethod) throws JavaModelException { IJavaElement elem = jdtMethod.getAncestor(IJavaElement.TYPE); IType ancestor = elem instanceof IType ? (IType) elem : null; String[] signatures = jdtMethod.getParameterTypes(); String[] typeNames = new String[signatures.length]; for (int s = 0; s < signatures.length; s++) { String typeName = getTypeNameFromSignature(signatures[s]); typeNames[s] = resolveType(typeName, ancestor); } return typeNames; }
From source file:org.eclipse.jst.ws.internal.conformance.JDTResolver.java
License:Open Source License
/** * Returns an array of zero or more JDT IType objects * for the exceptions thrown by the given method. * @param jdtMethod The method to analyze. * @return An array of zero or more exception types. * @throws JavaModelException If the JDT engine fails to * analyze the given method to satisfy this request. *///from w ww . j a v a 2s . c om public IType[] getExceptionTypes(IMethod jdtMethod) throws JavaModelException { IJavaElement elem = jdtMethod.getAncestor(IJavaElement.TYPE); IType ancestor = elem instanceof IType ? (IType) elem : null; String[] signatures = jdtMethod.getExceptionTypes(); IType[] types = new IType[signatures.length]; for (int s = 0; s < signatures.length; s++) { String typeName = getTypeNameFromSignature(signatures[s]); types[s] = findType(typeName, ancestor); } return types; }
From source file:org.eclipse.jst.ws.internal.conformance.JDTResolver.java
License:Open Source License
/** * Returns an array of zero or more type names * for the exceptions thrown by the given method. * @param jdtMethod The method to analyze. * @return An array of zero or more exception type names. * @throws JavaModelException If the JDT engine fails to * analyze the given method to satisfy this request. *///from w w w.j a v a 2 s. c o m public String[] getExceptionTypeNames(IMethod jdtMethod) throws JavaModelException { IJavaElement elem = jdtMethod.getAncestor(IJavaElement.TYPE); IType ancestor = elem instanceof IType ? (IType) elem : null; String[] signatures = jdtMethod.getExceptionTypes(); String[] typeNames = new String[signatures.length]; for (int s = 0; s < signatures.length; s++) { String typeName = getTypeNameFromSignature(signatures[s]); typeNames[s] = resolveType(typeName, ancestor); } return typeNames; }
From source file:org.eclipse.objectteams.otdt.internal.refactoring.util.RefactoringUtil.java
License:Open Source License
public static MethodDeclaration methodToDeclaration(IMethod method, CompilationUnit node) throws JavaModelException { ICompilationUnit methodCU = (ICompilationUnit) method.getAncestor(IJavaElement.COMPILATION_UNIT); if (!methodCU.equals(node.getJavaElement())) { node = RefactoringASTParser.parseWithASTProvider(methodCU, true, null); }/*from w w w. j a v a2s . c o m*/ Name result = (Name) NodeFinder.perform(node, method.getNameRange()); return (MethodDeclaration) getParent(result, MethodDeclaration.class); }
From source file:org.eclipse.recommenders.internal.models.rcp.ProjectCoordinateProvider.java
License:Open Source License
@Override public Optional<ProjectCoordinate> resolve(IMethod method) { if (method == null) { return absent(); }/*from ww w .j a va 2 s .c o m*/ IPackageFragmentRoot root = cast(method.getAncestor(PACKAGE_FRAGMENT_ROOT)); return resolve(root); }
From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsElementFactory.java
License:Open Source License
/** * Attempts to create a JAX-RS Resource Method from the given * {@link IMethod}, and if needed, also creates the parent JAX-RS Resource. * /*from w ww . j av a2 s.co m*/ * @param javaMethod * @param ast * @param metamodel * @param progressMonitor * @return * @throws CoreException */ private static Set<IJaxrsElement> createElements(final IMethod javaMethod, final CompilationUnit ast, final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws CoreException { final Map<String, Annotation> methodAnnotations = JdtUtils.resolveAllAnnotations(javaMethod, ast); final Set<IJaxrsElement> elements = new HashSet<IJaxrsElement>(); // attempt to create a JaxrsParameterAggregatorProperty or a Resource Property from the give Java method. if (JaxrsParamAnnotations.matchesAtLeastOne(methodAnnotations.keySet())) { final IType parentType = (IType) javaMethod.getAncestor(IJavaElement.TYPE); final IJaxrsElement parentElement = metamodel.findElement(parentType); if (parentElement == null) { elements.addAll(internalCreateElements(parentType, ast, metamodel, progressMonitor)); } // Parameter Aggregator Method else if (parentElement.getElementKind().getCategory() == EnumElementCategory.PARAMETER_AGGREGATOR) { final JaxrsParameterAggregator parentParameterAggregator = (JaxrsParameterAggregator) parentElement; final JaxrsParameterAggregatorProperty parameterAggregatorMethod = JaxrsParameterAggregatorProperty .from(javaMethod, ast).buildInParentAggregator(parentParameterAggregator); if (parameterAggregatorMethod != null) { elements.add(parameterAggregatorMethod); // now, check if the parent resource should also be added to the // metamodel /*if (resourceMethod.getParentResource() != null && !metamodel.containsElement(resourceMethod.getParentResource())) { elements.add(resourceMethod.getParentResource()); }*/ } } // Resource Property else if (parentElement.getElementKind().getCategory() == EnumElementCategory.RESOURCE) { final JaxrsResource parentResource = (JaxrsResource) parentElement; final JaxrsResourceProperty resourceProperty = JaxrsResourceProperty.from(javaMethod, ast) .buildInResource(parentResource); if (resourceProperty != null) { elements.add(resourceProperty); } } } // attempt to create a JaxrsResourceMethod from the give Java method. else if (CollectionUtils.hasIntersection(methodAnnotations.keySet(), metamodel.findAllHttpMethodNames()) || methodAnnotations.keySet().contains(JaxrsClassnames.PATH)) { final IType parentType = (IType) javaMethod.getAncestor(IJavaElement.TYPE); final IJaxrsElement parentElement = metamodel.findElement(parentType); if (parentElement == null) { elements.addAll(internalCreateElements(parentType, ast, metamodel, progressMonitor)); } else if (parentElement.getElementKind().getCategory() == EnumElementCategory.RESOURCE) { final JaxrsResource parentResource = (JaxrsResource) parentElement; final JaxrsResourceMethod resourceMethod = JaxrsResourceMethod .from(javaMethod, ast, metamodel.findAllHttpMethodNames()).buildInResource(parentResource); if (resourceMethod != null) { elements.add(resourceMethod); // now, check if the parent resource should also be added to the // metamodel /*if (resourceMethod.getParentResource() != null && !metamodel.containsElement(resourceMethod.getParentResource())) { elements.add(resourceMethod.getParentResource()); }*/ } } } return elements; }
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 . * /*w w w. ja va 2 s . c om*/ * * @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)); } }