Author: xcoulon
Date: 2012-10-12 05:42:09 -0400 (Fri, 12 Oct 2012)
New Revision: 44470
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactory.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationsScanner.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationScannerTestCase.java
Log:
Fixed - JBIDE-12817 - NPE when adding JAX-RS support
https://issues.jboss.org/browse/JBIDE-12817
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessor.java 2012-10-12
09:10:19 UTC (rev 44469)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessor.java 2012-10-12
09:42:09 UTC (rev 44470)
@@ -203,20 +203,24 @@
final JaxrsResource resource = resourceMethod.getParentResource();
final IProgressMonitor progressMonitor = new NullProgressMonitor();
final IType resourceType = resource.getJavaElement();
- final ITypeHierarchy returnTypeHierarchy = JdtUtils.resolveTypeHierarchy(resourceType,
resourceType.getJavaProject(), false, progressMonitor);
- final List<String> supertypesHandlers =
extractHandlers(returnTypeHierarchy.getAllSupertypes(resourceType));
- for (IJaxrsResource otherResource : metamodel.getAllResources()) {
- if (((JaxrsResource) otherResource).isRootResource()) {
- for (JaxrsResourceMethod otherResourceMethod : ((JaxrsResource)
otherResource).getMethods().values()) {
- if (otherResourceMethod.getElementKind() == EnumElementKind.SUBRESOURCE_LOCATOR) {
- final String returnTypeHandler = (otherResourceMethod.getReturnType() != null) ?
otherResourceMethod
- .getReturnType().getHandleIdentifier() : null;
- if (returnTypeHandler != null &&
supertypesHandlers.contains(returnTypeHandler)) {
- final LinkedList<JaxrsResourceMethod> resourceMethods = new
LinkedList<JaxrsResourceMethod>(
- Arrays.asList(otherResourceMethod, resourceMethod));
- final JaxrsEndpoint endpoint = new JaxrsEndpoint(metamodel, httpMethod,
resourceMethods);
- if (metamodel.add(endpoint)) {
- changes.add(new JaxrsEndpointDelta(endpoint, ADDED));
+ if(resourceType != null) {
+ final ITypeHierarchy returnTypeHierarchy =
JdtUtils.resolveTypeHierarchy(resourceType,
+ resourceType.getJavaProject(), false, progressMonitor);
+ final List<String> supertypesHandlers =
extractHandlers(returnTypeHierarchy.getAllSupertypes(resourceType));
+ for (IJaxrsResource otherResource : metamodel.getAllResources()) {
+ if (((JaxrsResource) otherResource).isRootResource()) {
+ for (JaxrsResourceMethod otherResourceMethod : ((JaxrsResource)
otherResource).getMethods()
+ .values()) {
+ if (otherResourceMethod.getElementKind() == EnumElementKind.SUBRESOURCE_LOCATOR) {
+ final String returnTypeHandler = (otherResourceMethod.getReturnType() != null) ?
otherResourceMethod
+ .getReturnType().getHandleIdentifier() : null;
+ if (returnTypeHandler != null &&
supertypesHandlers.contains(returnTypeHandler)) {
+ final LinkedList<JaxrsResourceMethod> resourceMethods = new
LinkedList<JaxrsResourceMethod>(
+ Arrays.asList(otherResourceMethod, resourceMethod));
+ final JaxrsEndpoint endpoint = new JaxrsEndpoint(metamodel, httpMethod,
resourceMethods);
+ if (metamodel.add(endpoint)) {
+ changes.add(new JaxrsEndpointDelta(endpoint, ADDED));
+ }
}
}
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactory.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactory.java 2012-10-12
09:10:19 UTC (rev 44469)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactory.java 2012-10-12
09:42:09 UTC (rev 44470)
@@ -446,7 +446,7 @@
* @return a representation of the given provider or null in case of invalid type (ie,
not a valid JAX-RS Provider)
*/
public JaxrsProvider createProvider(final IType javaType, final CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor ) throws
CoreException {
- if(!javaType.exists()) {
+ if(javaType == null || !javaType.exists()) {
return null;
}
final Map<String, Annotation> annotations = JdtUtils.resolveAnnotations(javaType,
ast, PROVIDER.qualifiedName,
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationsScanner.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationsScanner.java 2012-10-12
09:10:19 UTC (rev 44469)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationsScanner.java 2012-10-12
09:42:09 UTC (rev 44470)
@@ -32,6 +32,7 @@
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.SearchParticipant;
import org.eclipse.jdt.core.search.SearchPattern;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
/**
@@ -72,12 +73,16 @@
final List<IType> applicationTypes =
searchForAnnotatedTypes(APPLICATION_PATH.qualifiedName, searchScope, progressMonitor);
// the search result also includes all subtypes of javax.ws.rs.core.Application (while
avoiding duplicate results)
final IType applicationType = JdtUtils.resolveType(APPLICATION.qualifiedName,
scope.getJavaProject(), progressMonitor);
- final ITypeHierarchy applicationTypeHierarchy =
JdtUtils.resolveTypeHierarchy(applicationType, scope, false, progressMonitor);
- final IType[] allSubtypes = applicationTypeHierarchy.getAllSubtypes(applicationType);
- for(IType subtype : allSubtypes) {
- if(subtype.getJavaProject().equals(scope.getJavaProject()) &&
!applicationTypes.contains(subtype)) {
- applicationTypes.add(subtype);
+ if(applicationType != null) {
+ final ITypeHierarchy applicationTypeHierarchy =
JdtUtils.resolveTypeHierarchy(applicationType, scope, false, progressMonitor);
+ final IType[] allSubtypes = applicationTypeHierarchy.getAllSubtypes(applicationType);
+ for(IType subtype : allSubtypes) {
+ if(subtype.getJavaProject().equals(scope.getJavaProject()) &&
!applicationTypes.contains(subtype)) {
+ applicationTypes.add(subtype);
+ }
}
+ } else {
+ Logger.warn("Could not find type '"+APPLICATION.qualifiedName +
"' in project's classpath.");
}
return applicationTypes;
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java 2012-10-12
09:10:19 UTC (rev 44469)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java 2012-10-12
09:42:09 UTC (rev 44470)
@@ -455,7 +455,7 @@
}
/**
- * Returns the hierarchy for the given type.
+ * Returns the hierarchy for the given type, or null if it could not be
'computed'.
*
* @param baseType
* the base type for the hierarchy
@@ -482,7 +482,7 @@
| IJavaSearchScope.REFERENCED_PROJECTS);
CreateTypeHierarchyOperation operation = new CreateTypeHierarchyOperation(baseType,
null, searchScope, true);
ITypeHierarchy hierarchy = operation.getResult();
- if (hierarchy.exists()) {
+ if (hierarchy != null && hierarchy.exists()) {
hierarchy.refresh(progressMonitor);
return hierarchy;
}
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationScannerTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationScannerTestCase.java 2012-10-12
09:10:19 UTC (rev 44469)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationScannerTestCase.java 2012-10-12
09:42:09 UTC (rev 44470)
@@ -9,6 +9,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
@@ -192,4 +193,16 @@
// verifications
assertThat(applications.size(), equalTo(0));
}
+
+ @Test
+ public void shouldNotFailWhenJaxrsCoreApplicationTypeIsMissing() throws CoreException,
OperationCanceledException, InterruptedException {
+ // pre-conditions: remove Appllication from project classpath
+ WorkbenchUtils.removeClasspathEntry(javaProject,
+ "jaxrs-api-2.0.1.GA.jar", null);
+ // operation
+ final List<IType> applications =
JaxrsAnnotationsScanner.findApplicationTypes(javaProject,
+ new NullProgressMonitor());
+ // verifications
+ assertThat(applications.size(), equalTo(1));
+ }
}