Author: xcoulon
Date: 2012-01-10 05:36:02 -0500 (Tue, 10 Jan 2012)
New Revision: 37739
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.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/PathParamAnnotationValueCompletionProposalComputer.java
Log:
Preventing errors when the java syntax of the underlying resource is incorrect
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-01-10
09:33:23 UTC (rev 37738)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactory.java 2012-01-10
10:36:02 UTC (rev 37739)
@@ -231,15 +231,18 @@
final Annotation producesAnnotation = annotations.get(Produces.class.getName());
final Annotation consumesAnnotation = annotations.get(Consumes.class.getName());
final JavaMethodSignature methodSignature =
JdtUtils.resolveMethodSignature(javaMethod, ast);
- final Builder builder = new JaxrsResourceMethod.Builder(javaMethod, parentResource,
metamodel)
- .pathTemplate(pathAnnotation).consumes(consumesAnnotation).produces(producesAnnotation)
- .httpMethod(httpMethod).returnType(methodSignature.getReturnedType());
- for (JavaMethodParameter methodParam : methodSignature.getMethodParameters()) {
- builder.methodParameter(methodParam);
+ // avoid creating Resource Method when the Java Method cannot be parsed (ie,
syntax/compilation error)
+ if (methodSignature != null) {
+ final Builder builder = new JaxrsResourceMethod.Builder(javaMethod, parentResource,
metamodel)
+ .pathTemplate(pathAnnotation).consumes(consumesAnnotation).produces(producesAnnotation)
+ .httpMethod(httpMethod).returnType(methodSignature.getReturnedType());
+ for (JavaMethodParameter methodParam : methodSignature.getMethodParameters()) {
+ builder.methodParameter(methodParam);
+ }
+ final JaxrsResourceMethod resourceMethod = builder.build();
+
+ return resourceMethod;
}
- final JaxrsResourceMethod resourceMethod = builder.build();
-
- return resourceMethod;
}
return null;
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/PathParamAnnotationValueCompletionProposalComputer.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/PathParamAnnotationValueCompletionProposalComputer.java 2012-01-10
09:33:23 UTC (rev 37738)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/PathParamAnnotationValueCompletionProposalComputer.java 2012-01-10
10:36:02 UTC (rev 37739)
@@ -45,8 +45,7 @@
import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
/**
- * Computes proposals for <code>java.ws.rs.PathParam</code> annotation values
in
- * the compilation unit context.
+ * Computes proposals for <code>java.ws.rs.PathParam</code> annotation values
in the compilation unit context.
*
* @author xcoulon
*/
@@ -80,18 +79,22 @@
IJavaElement invocationElement = javaContext.getCompilationUnit().getElementAt(
context.getInvocationOffset());
if (invocationElement.getElementType() == IJavaElement.METHOD) {
- IJaxrsResourceMethod resourceMethod = metamodel.getElement(invocationElement,
IJaxrsResourceMethod.class);
- for (JavaMethodParameter methodParameter : resourceMethod.getJavaMethodParameters())
{
- for (Annotation annotation : methodParameter.getAnnotations()) {
- final TypedRegion region = annotation.getRegion();
- if (annotation.getName().equals(PathParam.class.getName()) && region !=
null
- && context.getInvocationOffset() >= region.getOffset()
- && context.getInvocationOffset() < (region.getOffset() +
region.getLength())) {
- // completion proposal on @PathParam method
- // annotation
- return internalComputePathParamProposals(javaContext, annotation,
resourceMethod);
+ IJaxrsResourceMethod resourceMethod = metamodel.getElement(invocationElement,
+ IJaxrsResourceMethod.class);
+ // the java method must be associated with a JAX-RS Resource Method.
+ if (resourceMethod != null) {
+ for (JavaMethodParameter methodParameter : resourceMethod.getJavaMethodParameters())
{
+ for (Annotation annotation : methodParameter.getAnnotations()) {
+ final TypedRegion region = annotation.getRegion();
+ if (annotation.getName().equals(PathParam.class.getName()) && region !=
null
+ && context.getInvocationOffset() >= region.getOffset()
+ && context.getInvocationOffset() < (region.getOffset() +
region.getLength())) {
+ // completion proposal on @PathParam method
+ // annotation
+ return internalComputePathParamProposals(javaContext, annotation,
resourceMethod);
+ }
+
}
-
}
}
}
@@ -102,13 +105,12 @@
}
/**
- * Computes the valid proposals for the <code>javax.ws.rs.PathParam</code>
- * annotation value. The proposals are based on:
+ * Computes the valid proposals for the <code>javax.ws.rs.PathParam</code>
annotation value. The proposals are based
+ * on:
* <ul>
- * <li>The values of the <code>javax.ws.rs.Path</code> annotations,
both at
- * the method and at the type level (inclusion),</li>
- * <li>The values of the sibling <code>javax.ws.rs.PathParam</code>
- * annotations (exclusion).
+ * <li>The values of the <code>javax.ws.rs.Path</code> annotations,
both at the method and at the type level
+ * (inclusion),</li>
+ * <li>The values of the sibling <code>javax.ws.rs.PathParam</code>
annotations (exclusion).
* </ul>
*
* @param javaContext
@@ -130,7 +132,7 @@
final ITypedRegion region = getRegion(javaContext);
String matchValue = javaContext.getDocument().get(region.getOffset(),
javaContext.getInvocationOffset() - region.getOffset());
- if(matchValue.charAt(0) == '\"') {
+ if (matchValue.charAt(0) == '\"') {
matchValue = matchValue.substring(1);
}
List<String> proposals = resourceMethod.getPathParamValueProposals();
@@ -154,8 +156,7 @@
}
/**
- * Resolves the typed region for the given java content assist invocation
- * context.
+ * Resolves the typed region for the given java content assist invocation context.
*
* @param javaContext
* the java content assist invocation context
Show replies by date