Author: xcoulon
Date: 2012-02-08 16:06:10 -0500 (Wed, 08 Feb 2012)
New Revision: 38524
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/quickfix/
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/JaxrsMarkerResolutionGenerator.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/MethodParametersCompletionProposal.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/MethodParametersCompletionProposalComputer.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScanner.java
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/JaxrsBaseElement.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsEndpoint.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodParameter.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignature.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/.options
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/META-INF/MANIFEST.MF
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateCategory.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateElement.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/Logger.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_3-with-servlet-mapping.xml
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessorTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessorTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java
Log:
FIXED -
https://issues.jboss.org/browse/JBIDE-10287 - Support JAX-RS Applications
FIXED -
https://issues.jboss.org/browse/JBIDE-10748 - Sometimes there is no update in
JAX-RS explorer as it should be
FIXED -
https://issues.jboss.org/browse/JBIDE-10686 - [Validation] Show error when trying
to inject unsupported type with @Context
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScanner.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScanner.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScanner.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -36,7 +36,6 @@
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaElementDelta;
-import org.eclipse.jdt.core.IOpenable;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.compiler.IProblem;
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-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessor.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -214,8 +214,7 @@
if (returnTypeHandler != null &&
supertypesHandlers.contains(returnTypeHandler)) {
final LinkedList<JaxrsResourceMethod> resourceMethods = new
LinkedList<JaxrsResourceMethod>(
Arrays.asList(otherResourceMethod, resourceMethod));
- final JaxrsEndpoint endpoint = new JaxrsEndpoint(metamodel.getApplication(),
httpMethod,
- resourceMethods);
+ final JaxrsEndpoint endpoint = new JaxrsEndpoint(metamodel, httpMethod,
resourceMethods);
if (metamodel.add(endpoint)) {
changes.add(new JaxrsEndpointDelta(endpoint, ADDED));
}
@@ -231,7 +230,7 @@
final JaxrsMetamodel metamodel) {
final JaxrsHttpMethod httpMethod =
metamodel.getHttpMethod(resourceMethod.getHttpMethodAnnotation());
final List<JaxrsEndpointDelta> changes = new
ArrayList<JaxrsEndpointDelta>();
- final JaxrsEndpoint endpoint = new JaxrsEndpoint(metamodel.getApplication(),
httpMethod, resourceMethod);
+ final JaxrsEndpoint endpoint = new JaxrsEndpoint(metamodel, httpMethod,
resourceMethod);
if (metamodel.add(endpoint)) {
changes.add(new JaxrsEndpointDelta(endpoint, ADDED));
}
@@ -263,8 +262,8 @@
.getHttpMethodAnnotation());
final LinkedList<JaxrsResourceMethod> resourceMethods = new
LinkedList<JaxrsResourceMethod>(
Arrays.asList(subresourceLocator, resourceMethod));
- final JaxrsEndpoint endpoint = new JaxrsEndpoint(metamodel.getApplication(),
- httpMethod, resourceMethods);
+ 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/JaxrsBaseElement.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsBaseElement.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsBaseElement.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -3,6 +3,7 @@
import java.util.List;
import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.wst.validation.ValidatorMessage;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
@@ -51,7 +52,7 @@
public abstract IResource getResource();
- public abstract List<ValidatorMessage> validate();
+ public abstract List<ValidatorMessage> validate() throws JavaModelException;
public abstract String getName();
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsEndpoint.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsEndpoint.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsEndpoint.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -11,6 +11,7 @@
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.F_CONSUMED_MEDIATYPES_VALUE;
+import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.F_HTTP_METHOD_VALUE;
import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.F_PATH_VALUE;
import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.F_PRODUCED_MEDIATYPES_VALUE;
@@ -35,24 +36,29 @@
public class JaxrsEndpoint implements IJaxrsEndpoint {
- private final JaxrsHttpMethod httpMethod;
+ private final JaxrsMetamodel metamodel;
+ private JaxrsHttpMethod httpMethod;
+
private final LinkedList<JaxrsResourceMethod> resourceMethods;
private IJaxrsApplication application = null;
-
+
private String uriPathTemplate = null;
private List<String> consumedMediaTypes = null;
private List<String> producedMediaTypes = null;
- public JaxrsEndpoint(final IJaxrsApplication application, final JaxrsHttpMethod
httpMethod, final JaxrsResourceMethod resourceMethod) {
- this(application, httpMethod, new
LinkedList<JaxrsResourceMethod>(Arrays.asList(resourceMethod)));
+ public JaxrsEndpoint(final JaxrsMetamodel metamodel, final JaxrsHttpMethod httpMethod,
+ final JaxrsResourceMethod resourceMethod) {
+ this(metamodel, httpMethod, new
LinkedList<JaxrsResourceMethod>(Arrays.asList(resourceMethod)));
}
- public JaxrsEndpoint(final IJaxrsApplication application, final JaxrsHttpMethod
httpMethod, final LinkedList<JaxrsResourceMethod> resourceMethods) {
- this.application = application;
+ public JaxrsEndpoint(final JaxrsMetamodel metamodel, final JaxrsHttpMethod httpMethod,
+ final LinkedList<JaxrsResourceMethod> resourceMethods) {
+ this.metamodel = metamodel;
+ this.application = (metamodel != null ? metamodel.getApplication() : null);
this.httpMethod = httpMethod;
this.resourceMethods = resourceMethods;
refreshUriPathTemplate();
@@ -62,7 +68,6 @@
/*
* (non-Javadoc)
- *
* @see java.lang.Object#toString()
*/
@Override
@@ -75,7 +80,6 @@
/*
* (non-Javadoc)
- *
* @see java.lang.Object#hashCode()
*/
@Override
@@ -92,7 +96,6 @@
/*
* (non-Javadoc)
- *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@@ -148,28 +151,31 @@
/**
* Triggers a refresh when changes occurred on the application element (whatever
operation).
*
- * @return true if the endpoint is still valid, false otherwise (it should
- * be removed from the metamodel)
+ * @return true if the endpoint is still valid, false otherwise (it should be removed
from the metamodel)
*/
public boolean refresh(IJaxrsApplication application) {
this.application = application;
refreshUriPathTemplate();
return true;
}
-
+
/**
- * Triggers a refresh when changes occurred on one or more elements
- * (HttpMethod and/or ResourcMethods) of the endpoint.
+ * Triggers a refresh when changes occurred on one or more elements (HttpMethod and/or
ResourcMethods) of the
+ * endpoint.
*
- * @return true if the endpoint is still valid, false otherwise (it should
- * be removed from the metamodel)
+ * @return true if the endpoint is still valid, false otherwise (it should be removed
from the metamodel)
*/
public boolean refresh(IJaxrsResourceMethod changedResourceMethod, int flags) {
// check if the chain of resource methods still match
/*
- * if ((flags & F_ELEMENT_KIND) > 0 && changedResourceMethod.getKind()
- * == EnumKind.SUBRESOURCE_LOCATOR) { return false; }
+ * if ((flags & F_ELEMENT_KIND) > 0 && changedResourceMethod.getKind()
== EnumKind.SUBRESOURCE_LOCATOR) { return
+ * false; }
*/
+
+ if ((flags & F_HTTP_METHOD_VALUE) > 0) {
+ refreshHttpMethod();
+ }
+
if ((flags & F_PATH_VALUE) > 0) {
refreshUriPathTemplate();
}
@@ -187,6 +193,14 @@
return true;
}
+ private void refreshHttpMethod() {
+ final JaxrsResourceMethod resourceMethod = resourceMethods.getLast();
+ final Annotation httpMethodAnnotation = resourceMethod.getHttpMethodAnnotation();
+ if (httpMethodAnnotation != null) {
+ this.httpMethod = metamodel.getHttpMethod(httpMethodAnnotation);
+ }
+ }
+
private void refreshProducedMediaTypes() {
final JaxrsResourceMethod resourceMethod = resourceMethods.getLast();
final JaxrsResource resource = resourceMethod.getParentResource();
@@ -214,7 +228,7 @@
private void refreshUriPathTemplate() {
// compute the URI Path Template from the chain of Methods/Resources
StringBuilder uriPathTemplateBuilder = new StringBuilder();
- if(application != null) {
+ if (application != null) {
uriPathTemplateBuilder.append(application.getApplicationPath());
}
for (JaxrsResourceMethod resourceMethod : resourceMethods) {
@@ -293,10 +307,7 @@
/*
* (non-Javadoc)
- *
- * @see
- * org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.IJaxrsEndpoint
- * #getHttpMethod()
+ * @see org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.IJaxrsEndpoint
#getHttpMethod()
*/
@Override
public IJaxrsHttpMethod getHttpMethod() {
@@ -321,8 +332,7 @@
/**
* Convenient method to check if this endpoint uses this ResourceMethod.
*
- * @return true if this endpoint's ResourceMethod is the one given in
- * parameter
+ * @return true if this endpoint's ResourceMethod is the one given in parameter
*/
public boolean match(IJaxrsResourceMethod resourceMethod) {
return this.resourceMethods.contains(resourceMethod);
@@ -330,10 +340,7 @@
/*
* (non-Javadoc)
- *
- * @see
- * org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.IJaxrsEndpoint
- * #getUriPathTemplate()
+ * @see org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.IJaxrsEndpoint
#getUriPathTemplate()
*/
@Override
public String getUriPathTemplate() {
@@ -342,10 +349,7 @@
/*
* (non-Javadoc)
- *
- * @see
- * org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.IJaxrsEndpoint
- * #getConsumedMediaTypes()
+ * @see org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.IJaxrsEndpoint
#getConsumedMediaTypes()
*/
@Override
public List<String> getConsumedMediaTypes() {
@@ -354,10 +358,7 @@
/*
* (non-Javadoc)
- *
- * @see
- * org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.IJaxrsEndpoint
- * #getProducedMediaTypes()
+ * @see org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.IJaxrsEndpoint
#getProducedMediaTypes()
*/
@Override
public List<String> getProducedMediaTypes() {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -23,6 +23,7 @@
import javax.ws.rs.Produces;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.wst.validation.ValidatorMessage;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
@@ -229,7 +230,7 @@
}
@Override
- public List<ValidatorMessage> validate() {
+ public List<ValidatorMessage> validate() throws JavaModelException {
List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
// delegating the validation to the undelying resource methods
for (Entry<String, JaxrsResourceMethod> entry : resourceMethods.entrySet()) {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -16,16 +16,23 @@
import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.F_NONE;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.wst.validation.ValidatorMessage;
@@ -42,11 +49,16 @@
/** @author xcoulon */
public class JaxrsResourceMethod extends JaxrsResourceElement<IMethod> implements
IJaxrsResourceMethod {
+ /** The parameter type names that can be annotated with {@link Context}. */
+ private final static List<String> CONTEXT_TYPE_NAMES = new
ArrayList<String>(Arrays.asList(
+ "javax.ws.rs.core.HttpHeaders", "javax.ws.rs.core.UriInfo",
"javax.ws.rs.core.Request",
+ "javax.servlet.HttpServletRequest",
"javax.servlet.HttpServletResponse", "javax.servlet.ServletConfig",
+ "javax.servlet.ServletContext",
"javax.ws.rs.core.SecurityContext"));
+
private final JaxrsResource parentResource;
/**
- * return type of the java javaMethod. Null if this is not a subresource
- * locator.
+ * return type of the java javaMethod. Null if this is not a subresource locator.
*/
private IType returnedJavaType = null;
@@ -182,9 +194,92 @@
}
@Override
- public List<ValidatorMessage> validate() {
- List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ public List<ValidatorMessage> validate() throws JavaModelException {
+ final List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ messages.addAll(validateMissingPathValueInPathParamAnnotations());
+ messages.addAll(validateMissingPathParamAnnotations());
+ messages.addAll(validateParamsWithContextAnnotation());
+ messages.addAll(validateSingleParamWithoutAnnotation());
+ return messages;
+ }
+
+ /**
+ * Validate that only one method parameter is not annotated with a JAX-RS annotation.
This non-annotated parameter
+ * is the "Entity parameter", coming from the client's request body,
unmarshalled by the appropriate
+ * {@link MesssageBodyReader}.
+ *
+ * @return
+ */
+ private List<ValidatorMessage> validateSingleParamWithoutAnnotation() {
+ final List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ return messages;
+ }
+
+ /**
+ * Validates that the method parameters annotated with {@link Context} are of the
supported types in the spec:
+ * {@link UriInfo}, {@link HttpHeaders}, {@link ServletConfig}, {@link ServletContext},
{@link HttpServletRequest},
+ * {@link Request}, {@link HttpServletResponse} and {@link Response}.
+ *
+ * @return
+ */
+ private List<ValidatorMessage> validateParamsWithContextAnnotation() {
+ final List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ for (JavaMethodParameter parameter : this.javaMethodParameters) {
+ final Annotation annotation = parameter.getAnnotation(Context.class.getName());
+ final String typeName = parameter.getTypeName();
+ if (annotation != null && typeName != null &&
!CONTEXT_TYPE_NAMES.contains(typeName)) {
+ final ValidatorMessage message = ValidatorMessage.create("This parameter type
(" + typeName
+ + ") cannot be annotated with @Context", this.getResource());
+ message.setAttribute(IMarker.MARKER, JaxrsMetamodelBuilder.JAXRS_PROBLEM);
+ message.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ message.setAttribute(IMarker.CHAR_START, parameter.getRegion().getOffset());
+ message.setAttribute(IMarker.CHAR_END, parameter.getRegion().getOffset()
+ + parameter.getRegion().getLength());
+ messages.add(message);
+ Logger.debug("Validation message for {}: {}",
this.getJavaElement().getElementName(),
+ message.getAttribute(IMarker.MESSAGE));
+ }
+ }
+ return messages;
+ }
+
+ private List<ValidatorMessage> validateMissingPathParamAnnotations() throws
JavaModelException {
+ final List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
final List<String> pathParamValueProposals = getPathParamValueProposals();
+ for (String proposal : pathParamValueProposals) {
+ boolean matching = false;
+ for (JavaMethodParameter parameter : this.javaMethodParameters) {
+ final Annotation annotation = parameter.getAnnotation(PathParam.class.getName());
+ if (annotation != null &&
annotation.getValue("value").equals(proposal)) {
+ matching = true;
+ break;
+ }
+ }
+ if (!matching) {
+ final ValidatorMessage message = ValidatorMessage.create("Missing @PathParam
value: expected "
+ + proposal, this.getResource());
+ message.setAttribute(IMarker.MARKER, JaxrsMetamodelBuilder.JAXRS_PROBLEM);
+ message.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ final ISourceRange nameRange = getJavaElement().getNameRange();
+ message.setAttribute(IMarker.CHAR_START, nameRange.getOffset());
+ message.setAttribute(IMarker.CHAR_END, nameRange.getOffset() +
nameRange.getLength());
+ messages.add(message);
+ Logger.debug("Validation message for {}: {}",
this.getJavaElement().getElementName(),
+ message.getAttribute(IMarker.MESSAGE));
+ }
+ }
+ return messages;
+ }
+
+ /**
+ * Checks that the {@link PathParam} annotation values match the params in the {@link
Path} annotations at the
+ * method and the parent type levels.
+ *
+ * @return errors in case of mismatch, empty list otherwise.
+ */
+ private List<ValidatorMessage> validateMissingPathValueInPathParamAnnotations() {
+ final List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ final List<String> pathParamValueProposals = getPathParamValueProposals();
for (JavaMethodParameter parameter : this.javaMethodParameters) {
final Annotation annotation = parameter.getAnnotation(PathParam.class.getName());
if (annotation != null) {
@@ -198,7 +293,8 @@
message.setAttribute(IMarker.CHAR_END, annotation.getRegion().getOffset()
+ annotation.getRegion().getLength());
messages.add(message);
- Logger.debug("Validation message for {}: {}",
this.getJavaElement().getElementName(), message.getAttribute(IMarker.MESSAGE));
+ Logger.debug("Validation message for {}: {}",
this.getJavaElement().getElementName(),
+ message.getAttribute(IMarker.MESSAGE));
}
}
}
@@ -207,10 +303,7 @@
/*
* (non-Javadoc)
- *
- * @see
- * org.jboss.tools.ws.jaxrs.core.internal.metamodel.IResourceMethod#hasErrors
- * (boolean)
+ * @see org.jboss.tools.ws.jaxrs.core.internal.metamodel.IResourceMethod#hasErrors
(boolean)
*/
@Override
public void hasErrors(final boolean h) {
@@ -222,10 +315,7 @@
/*
* (non-Javadoc)
- *
- * @see
- * org.jboss.tools.ws.jaxrs.core.internal.metamodel.IResourceMethod#getKind
- * ()
+ * @see org.jboss.tools.ws.jaxrs.core.internal.metamodel.IResourceMethod#getKind ()
*/
@Override
public final EnumKind getKind() {
@@ -243,9 +333,7 @@
/*
* (non-Javadoc)
- *
- * @see org.jboss.tools.ws.jaxrs.core.internal.metamodel.IResourceMethod#
- * getParentResource()
+ * @see org.jboss.tools.ws.jaxrs.core.internal.metamodel.IResourceMethod#
getParentResource()
*/
@Override
public final JaxrsResource getParentResource() {
@@ -315,16 +403,15 @@
public List<JavaMethodParameter> getJavaMethodParameters() {
return javaMethodParameters;
}
-
+
/*
* (non-Javadoc)
- *
* @see java.lang.Object#toString()
*/
@Override
public final String toString() {
- return "ResourceMethod '" + parentResource.getName() + "."
- + getJavaElement().getElementName() + "' (" + getKind().toString() +
")";
+ return "ResourceMethod '" + parentResource.getName() + "." +
getJavaElement().getElementName() + "' ("
+ + getKind().toString() + ")";
}
@Override
@@ -344,8 +431,7 @@
}
/**
- * Extracts all the character sequences inside of curly braces ('{' and
'}')
- * and returns them as a list of strings
+ * Extracts all the character sequences inside of curly braces ('{' and
'}') and returns them as a list of strings
*
* @param value
* the given value
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -14,6 +14,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
@@ -26,7 +27,7 @@
public static IFolder getWebInfFolder(IProject project) {
IVirtualComponent component = ComponentCore.createComponent(project);
- if(component == null) {
+ if (component == null) {
return null;
}
IVirtualFolder contentFolder = component.getRootFolder();
@@ -57,7 +58,7 @@
*/
public static String getApplicationPath(IProject project, String applicationTypeName)
throws CoreException {
IFolder webInfFolder = getWebInfFolder(project);
- if(webInfFolder == null) {
+ if (webInfFolder == null) {
return null;
}
IResource webxmlResource = webInfFolder.findMember("web.xml");
@@ -65,34 +66,44 @@
Logger.debug("No deployment descriptor found in project '{}'",
project.getName());
return null;
}
- /*if (webxmlResource.isSynchronized(IResource.DEPTH_INFINITE)) {
+ if (!webxmlResource.isSynchronized(IResource.DEPTH_INFINITE)) {
Logger.debug("Resource is not in sync'");
webxmlResource.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
- }*/
- // cannot use the WebTools WebArtifact Edit APIs because the web.xml configuration does
not require a servlet,
- // but just a servlet-mapping element.
+ }
+
/*
- * WebArtifactEdit webArtifactEdit =
WebArtifactEdit.getWebArtifactEditForRead(javaProject.getProject()); //
- * webArtifactEdit.getDeploymentDescriptorRoot().eResource().unload(); if
(!webArtifactEdit.isValid()) { return
- * null; } webArtifactEdit.getDeploymentDescriptorRoot(); WebApp webApp =
webArtifactEdit.getWebApp();
- * EList<ServletMapping> servletMappings = webApp.getServletMappings(); for
(ServletMapping servletMapping :
- * servletMappings) { if (servletMapping.getName().equals(applicationTypeName)) {
return
- * servletMapping.getUrlPattern(); } }
+ * WebArtifactEdit webArtifactEdit =
WebArtifactEdit.getWebArtifactEditForRead(project); // if
+ * (!webArtifactEdit.isValid()) { return null; } WebPackageImpl.eINSTANCE.getWebApp();
IModelProvider provider =
+ * ModelProviderManager.getModelProvider(project); Object mObj =
provider.getModelObject(); if (mObj instanceof
+ * org.eclipse.jst.j2ee.webapplication.WebApp) {
org.eclipse.jst.j2ee.webapplication.WebApp webApp =
+ * (org.eclipse.jst.j2ee.webapplication.WebApp) mObj; } else if (mObj instanceof
+ * org.eclipse.jst.javaee.web.WebApp) { org.eclipse.jst.javaee.web.WebApp webApp =
+ * (org.eclipse.jst.javaee.web.WebApp) mObj; }
*/
+ // final List<Servlet> servlets = webApp.getServlets();
+ /*
+ * webArtifactEdit.getDeploymentDescriptorRoot().eResource().unload();
+ * webArtifactEdit.getDeploymentDescriptorRoot(); WebApp webApp =
webArtifactEdit.getWebApp();
+ * @SuppressWarnings("unchecked") EList<ServletMapping> servletMappings
= webApp.getServletMappings(); for
+ * (ServletMapping servletMapping : servletMappings) { if
(servletMapping.getName().equals(applicationTypeName))
+ * { return servletMapping.getUrlPattern(); } }
+ */
// using a good old xpath expression to scan the file.
-
+
try {
- DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
- domFactory.setNamespaceAware(false); // never forget this!
- domFactory.setValidating(false);
- DocumentBuilder builder = domFactory.newDocumentBuilder();
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(false); // never forget this!
+ dbf.setValidating(false);
+
dbf.setFeature("http://xml.org/sax/features/namespaces", false);
+
dbf.setFeature("http://xml.org/sax/features/validation", false);
+
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dt...;,
false);
+
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-ex...;,
false);
+ DocumentBuilder builder = dbf.newDocumentBuilder();
final FileInputStream fileInputStream = new
FileInputStream(webxmlResource.getLocation().toFile());
InputSource inputSource = new InputSource(fileInputStream);
Document doc = builder.parse(inputSource);
-
XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "//servlet-mapping[servlet-name=\"" +
applicationTypeName + "\"]/url-pattern/text()";
-
XPathExpression expr = xpath.compile(expression);
Node urlPattern = (Node) expr.evaluate(doc, XPathConstants.NODE);
if (urlPattern != null) {
@@ -117,7 +128,7 @@
*/
public static boolean isWebDeploymentDescriptor(IResource resource) {
final IFolder webinfFolder = getWebInfFolder(resource.getProject());
- if(webinfFolder == null) {
+ if (webinfFolder == null) {
return false;
}
final IFile file = webinfFolder.getFile("web.xml");
@@ -135,7 +146,7 @@
*/
public static boolean hasWebDeploymentDescriptor(IProject project) {
final IFolder webinfFolder = getWebInfFolder(project);
- if(webinfFolder == null) {
+ if (webinfFolder == null) {
return false;
}
final IFile file = webinfFolder.getFile("web.xml");
@@ -145,7 +156,7 @@
public static IResource getWebDeploymentDescriptor(IProject project) {
final IFolder webinfFolder = getWebInfFolder(project);
final IFile file = webinfFolder.getFile("web.xml");
- if(file != null && file.exists()) {
+ if (file != null && file.exists()) {
return project.findMember(file.getProjectRelativePath());
}
return null;
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodParameter.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodParameter.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodParameter.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -15,6 +15,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.TypedRegion;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.IValidable;
public class JavaMethodParameter implements IValidable {
@@ -23,9 +24,12 @@
private final List<Annotation> annotations;
- public JavaMethodParameter(String name, String typeName, List<Annotation>
annotations) {
+ private final TypedRegion region;
+
+ public JavaMethodParameter(String name, String typeName, List<Annotation>
annotations, final TypedRegion region) {
this.typeName = typeName;
this.annotations = annotations;
+ this.region = region;
}
@Override
@@ -42,15 +46,41 @@
return annotations;
}
+ public Annotation getAnnotation(String name) {
+ for (Annotation annotation : annotations) {
+ if (annotation.getName().equals(name)) {
+ return annotation;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return the region
+ */
+ public TypedRegion getRegion() {
+ return region;
+ }
+
@Override
+ public String toString() {
+ return "ResourceMethodAnnotatedParameter [type=" + typeName + ",
annotations=" + annotations + "]";
+ }
+
+ @Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((annotations == null) ? 0 : annotations.hashCode());
+ //result = prime * result + ((region == null) ? 0 : region.hashCode());
result = prime * result + ((typeName == null) ? 0 : typeName.hashCode());
return result;
}
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
@Override
public boolean equals(Object obj) {
if (this == obj) {
@@ -62,7 +92,7 @@
if (getClass() != obj.getClass()) {
return false;
}
- final JavaMethodParameter other = (JavaMethodParameter) obj;
+ JavaMethodParameter other = (JavaMethodParameter) obj;
if (annotations == null) {
if (other.annotations != null) {
return false;
@@ -70,6 +100,13 @@
} else if (!annotations.equals(other.annotations)) {
return false;
}
+ /*if (region == null) {
+ if (other.region != null) {
+ return false;
+ }
+ } else if (!region.equals(other.region)) {
+ return false;
+ }*/
if (typeName == null) {
if (other.typeName != null) {
return false;
@@ -80,23 +117,4 @@
return true;
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "ResourceMethodAnnotatedParameter [type=" + typeName + ",
annotations=" + annotations + "]";
- }
-
- public Annotation getAnnotation(String name) {
- for (Annotation annotation : annotations) {
- if (annotation.getName().equals(name)) {
- return annotation;
- }
- }
- return null;
- }
-
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignature.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignature.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignature.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -44,7 +44,11 @@
@Override
public String toString() {
StringBuilder stb = new StringBuilder("JavaMethodSignature ");
- stb.append(returnedType.getElementName()).append(" ");
+ if (returnedType != null) {
+ stb.append(returnedType.getElementName()).append(" ");
+ } else {
+ stb.append("void ");
+ }
stb.append(javaMethod.getElementName()).append("(");
for (Iterator<JavaMethodParameter> paramIterator = methodParameters.iterator();
paramIterator.hasNext();) {
JavaMethodParameter methodParam = (JavaMethodParameter) paramIterator.next();
@@ -96,7 +100,7 @@
} else if (!methodParameters.equals(other.methodParameters)) {
return false;
}
-
+
if (returnedType == null) {
if (other.returnedType != null)
return false;
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -108,7 +108,9 @@
annotationElements, typedRegion));
}
}
- methodParameters.add(new JavaMethodParameter(paramName, paramTypeName,
paramAnnotations));
+ final TypedRegion typedRegion = new TypedRegion(parameter.getStartPosition(),
+ parameter.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
+ methodParameters.add(new JavaMethodParameter(paramName, paramTypeName,
paramAnnotations, typedRegion));
}
// TODO : add support for thrown exceptions
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/.options
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/.options 2012-02-08 20:47:32 UTC (rev
38523)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/.options 2012-02-08 21:06:10 UTC (rev
38524)
@@ -1,2 +1,3 @@
# This file enables runtime tracing
-org.jboss.tools.ws.jaxrs.ui/debug=true
\ No newline at end of file
+org.jboss.tools.ws.jaxrs.ui/debug=true
+org.jboss.tools.ws.jaxrs.ui/trace=false
\ No newline at end of file
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/META-INF/MANIFEST.MF 2012-02-08 20:47:32
UTC (rev 38523)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/META-INF/MANIFEST.MF 2012-02-08 21:06:10
UTC (rev 38524)
@@ -6,7 +6,8 @@
Bundle-SymbolicName: org.jboss.tools.ws.jaxrs.ui;singleton:=true
Bundle-Version: 1.2.2.qualifier
Bundle-Activator: org.jboss.tools.ws.jaxrs.ui.JBossJaxrsUIPlugin
-Require-Bundle: org.eclipse.ui;bundle-version="3.6.0",
+Require-Bundle: org.eclipse.ui;bundle-version="3.7.0",
+ org.eclipse.ui.ide;bundle-version="3.7.0",
org.eclipse.core.runtime;visibility:=reexport,
org.eclipse.jdt.core;bundle-version="3.6.0",
org.eclipse.jdt.core.manipulation;bundle-version="1.3.0",
@@ -31,7 +32,6 @@
org.eclipse.jdt.core.manipulation;bundle-version="1.4.0",
org.eclipse.ui.editors;bundle-version="3.7.0",
org.eclipse.core.commands;bundle-version="3.6.0",
- org.eclipse.ui;bundle-version="3.7.0",
org.eclipse.ltk.core.refactoring;bundle-version="3.5.200",
org.eclipse.wst.validation;bundle-version="1.2.300"
Bundle-ActivationPolicy: lazy
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml 2012-02-08 20:47:32 UTC (rev
38523)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml 2012-02-08 21:06:10 UTC (rev
38524)
@@ -262,7 +262,7 @@
</extension>
<extension
- id="org.jboss.tools.ws.jaxrs.ui.javaCompetionProposalComputer"
+
id="org.jboss.tools.ws.jaxrs.ui.pathParamAnnotationValueCompletionProposalComputer"
point="org.eclipse.jdt.ui.javaCompletionProposalComputer">
<javaCompletionProposalComputer
activate="true"
@@ -276,6 +276,27 @@
</partition>
</javaCompletionProposalComputer>
</extension>
+ <!--extension
+
id="org.jboss.tools.ws.jaxrs.ui.methodParametersCompletionProposalComputer"
+ point="org.eclipse.jdt.ui.javaCompletionProposalComputer">
+ <javaCompletionProposalComputer
+ activate="true"
+ categoryId="org.eclipse.jdt.ui.defaultProposalCategory"
+
class="org.jboss.tools.ws.jaxrs.ui.contentassist.MethodParametersCompletionProposalComputer">
+ <partition
+ type="__dftl_partition_content_type">
+ </partition>
+ <partition
+ type="__java_string">
+ </partition>
+ </javaCompletionProposalComputer>
+ </extension-->
+ <!--extension
+ point="org.eclipse.ui.ide.markerResolution">
+ <markerResolutionGenerator
+
class="org.jboss.tools.ws.jaxrs.ui.contentassist.JaxrsMarkerResolutionGenerator">
+ </markerResolutionGenerator>
+ </extension-->
<!-- see
https://bugs.eclipse.org/bugs/show_bug.cgi?id=338898 -->
</plugin>
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -159,7 +159,7 @@
if (viewer != null) {
TreePath[] treePaths = viewer.getExpandedTreePaths();
Logger.debug("*** Refreshing the viewer at target level: {} (viewer busy: {})
***", target, viewer.isBusy());
- viewer.refresh(target);
+ viewer.refresh();
viewer.setExpandedTreePaths(treePaths);
Logger.debug("*** Refreshing the viewer... done ***");
} else {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateCategory.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateCategory.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateCategory.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -54,9 +54,11 @@
// LinkedList<IJaxrsResourceMethod> resourceMethods =
// endpoint.getResourceMethods();
if (element == null) {
+ Logger.trace("Creating element for endpoint {} ('cause not found in
wrapperCache)", endpoint);
element = new UriPathTemplateElement(endpoint, this);
wrapperCache.put(endpoint, element);
}
+ Logger.trace("Adding element for endpoint {}", endpoint);
uriPathTemplateElements.add(element);
}
return uriPathTemplateElements.toArray();
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateElement.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateElement.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateElement.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -19,6 +19,7 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsEndpoint;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
import
org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateMediaTypeMappingElement.EnumCapabilityType;
+import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
public class UriPathTemplateElement implements ITreeContentProvider {
@@ -43,10 +44,6 @@
return elements.toArray();
}
- public void refresh(IJaxrsEndpoint endpoint2) {
- // TODO Auto-generated method stub
-
- }
@Override
public Object getParent(Object element) {
return uriPathTemplateCategory;
@@ -69,7 +66,7 @@
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// TODO Auto-generated method stub
-
+ Logger.trace("Input changed: {} -> {}", oldInput, newInput);
}
public boolean hasErrors() {
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/JaxrsMarkerResolutionGenerator.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/JaxrsMarkerResolutionGenerator.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/JaxrsMarkerResolutionGenerator.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -0,0 +1,21 @@
+package org.jboss.tools.ws.jaxrs.ui.contentassist;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IMarkerResolutionGenerator2;
+
+public class JaxrsMarkerResolutionGenerator implements IMarkerResolutionGenerator2 {
+
+ @Override
+ public IMarkerResolution[] getResolutions(IMarker marker) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean hasResolutions(IMarker marker) {
+
+ return false;
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/JaxrsMarkerResolutionGenerator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/MethodParametersCompletionProposal.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/MethodParametersCompletionProposal.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/MethodParametersCompletionProposal.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -0,0 +1,278 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Coulon - Initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.ws.jaxrs.ui.contentassist;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import
org.eclipse.jdt.internal.ui.text.java.hover.JavadocBrowserInformationControlInput;
+import org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover;
+import org.eclipse.jdt.ui.PreferenceConstants;
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
+import org.eclipse.jface.internal.text.html.BrowserInformationControl;
+import org.eclipse.jface.internal.text.html.HTMLPrinter;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension3;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension4;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension5;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension6;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchSite;
+import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
+import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
+import org.osgi.framework.Bundle;
+
+@SuppressWarnings("restriction")
+public class MethodParametersCompletionProposal implements ICompletionProposal,
ICompletionProposalExtension,
+ ICompletionProposalExtension3, ICompletionProposalExtension4,
ICompletionProposalExtension5,
+ ICompletionProposalExtension6, IJavaCompletionProposal {
+
+ /** The maximum relevance value, to ensure the proposal is at the top of the
+ * list. */
+ public static final int MAX_RELEVANCE = 1000;
+
+ private String additionalProposalInfo;
+
+ private final IMember member;
+
+ private final String replacementString;
+
+ private final int replacementOffset;
+
+ private final int replacementLength;
+
+ private final Image icon;
+
+ private final StyledString displayStyledString;
+
+ private final int relevance;
+
+ private final int cursorPosition;
+
+ private String fgCSSStyles;
+
+ private IInformationControlCreator creator;
+
+ public MethodParametersCompletionProposal(final String replacementString, final
StyledString displayStyledString,
+ final ITypedRegion region, final Image icon, final IMember member) {
+ this.replacementString = replacementString;
+ this.replacementOffset = region.getOffset();
+ this.replacementLength = region.getLength();
+ this.icon = icon;
+ this.displayStyledString = displayStyledString;
+ this.cursorPosition = replacementString.length();
+ this.relevance = MAX_RELEVANCE;
+ this.member = member;
+ }
+
+ @Override
+ public Point getSelection(IDocument document) {
+ return new Point(replacementOffset + cursorPosition, 0);
+ }
+
+ @Override
+ public void apply(IDocument document) {
+ apply(document, (char) 0, 0);
+ }
+
+ @Override
+ public void apply(IDocument document, char trigger, int offset) {
+ try {
+ document.replace(replacementOffset, replacementLength, replacementString);
+ // cursorPosition++;
+ } catch (BadLocationException e) {
+ Logger.warn("Failed to replace document content with selected proposal",
e);
+ }
+ }
+
+ @Override
+ public String getAdditionalProposalInfo() {
+ if (additionalProposalInfo == null) {
+ additionalProposalInfo = ((JavadocBrowserInformationControlInput)
getAdditionalProposalInfo(new NullProgressMonitor()))
+ .getHtml();
+ }
+ return additionalProposalInfo.toString();
+ }
+
+ @Override
+ public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
+ CompilationUnit compilationUnit;
+ try {
+ compilationUnit = JdtUtils.parse(member, monitor);
+ MemberDeclarationVisitor memberDeclarationVisitor = new
MemberDeclarationVisitor(member);
+ compilationUnit.accept(memberDeclarationVisitor);
+ String sourceOverview = memberDeclarationVisitor.getSourceOverview();
+ StringBuffer buffer = new StringBuffer();
+ HTMLPrinter.insertPageProlog(buffer, 0, getCSSStyles());
+ buffer.append("Matching URI Template mapping defined in the
<strong>@Path</strong> annotation value below:</br></br>");
+ buffer.append(sourceOverview.replaceFirst("(a)Path.*\n",
"<strong>$0</strong>").replaceAll("\n",
"<br/>")
+ .replaceAll("\t", " ").replaceAll("<br/>\\s*",
"<br/>"));
+ HTMLPrinter.addPageEpilog(buffer);
+ this.additionalProposalInfo = buffer.toString();
+ return new JavadocBrowserInformationControlInput(null, null,
this.additionalProposalInfo, 0);
+ } catch (JavaModelException e) {
+ // do nothing
+ }
+ return null;
+ }
+
+ /** Returns the style information for displaying HTML (Javadoc) content.
+ *
+ * @return the CSS styles
+ * @since 3.3 */
+ protected String getCSSStyles() {
+ if (fgCSSStyles == null) {
+ Bundle bundle = Platform.getBundle(JavaPlugin.getPluginId());
+ URL url = bundle.getEntry("/JavadocHoverStyleSheet.css"); //$NON-NLS-1$
+ if (url != null) {
+ BufferedReader reader = null;
+ try {
+ url = FileLocator.toFileURL(url);
+ reader = new BufferedReader(new InputStreamReader(url.openStream()));
+ StringBuffer buffer = new StringBuffer(200);
+ String line = reader.readLine();
+ while (line != null) {
+ buffer.append(line);
+ buffer.append('\n');
+ line = reader.readLine();
+ }
+ fgCSSStyles = buffer.toString();
+ } catch (IOException ex) {
+ JavaPlugin.log(ex);
+ } finally {
+ try {
+ if (reader != null)
+ reader.close();
+ } catch (IOException e) {
+ }
+ }
+
+ }
+ }
+ String css = fgCSSStyles;
+ if (css != null) {
+ FontData fontData = JFaceResources.getFontRegistry().getFontData(
+ PreferenceConstants.APPEARANCE_JAVADOC_FONT)[0];
+ css = HTMLPrinter.convertTopLevelFont(css, fontData);
+ }
+ return css;
+ }
+
+ @Override
+ public boolean isAutoInsertable() {
+ return false;
+ }
+
+ @Override
+ public String getDisplayString() {
+ return displayStyledString.getString();
+ }
+
+ @Override
+ public StyledString getStyledDisplayString() {
+ return displayStyledString;
+ }
+
+ @Override
+ public Image getImage() {
+ return icon;
+ }
+
+ @Override
+ public IContextInformation getContextInformation() {
+ return null;
+ }
+
+ @Override
+ public int getRelevance() {
+ return relevance;
+ }
+
+ @Override
+ public boolean isValidFor(IDocument document, int offset) {
+ return false;
+ }
+
+ @Override
+ public char[] getTriggerCharacters() {
+ return null;
+ }
+
+ /*
+ * @see ICompletionProposalExtension#getContextInformationPosition()
+ */
+ @Override
+ public int getContextInformationPosition() {
+ if (getContextInformation() == null) {
+ return replacementOffset - 1;
+ }
+ return replacementOffset + cursorPosition;
+ }
+
+ @Override
+ public IInformationControlCreator getInformationControlCreator() {
+ Shell shell = JavaPlugin.getActiveWorkbenchShell();
+ if (shell == null || !BrowserInformationControl.isAvailable(shell)) {
+ return null;
+ }
+ if (creator == null) {
+ JavadocHover.PresenterControlCreator presenterControlCreator = new
JavadocHover.PresenterControlCreator(
+ getSite());
+ creator = new JavadocHover.HoverControlCreator(presenterControlCreator, true);
+ }
+ return creator;
+ }
+
+ private IWorkbenchSite getSite() {
+ IWorkbenchPage page = JavaPlugin.getActivePage();
+ if (page != null) {
+ IWorkbenchPart part = page.getActivePart();
+ if (part != null)
+ return part.getSite();
+ }
+ return null;
+ }
+
+ @Override
+ public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) {
+ return null;
+ }
+
+ @Override
+ public int getPrefixCompletionStart(IDocument document, int completionOffset) {
+ return 0;
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/MethodParametersCompletionProposal.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/MethodParametersCompletionProposalComputer.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/MethodParametersCompletionProposalComputer.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/MethodParametersCompletionProposalComputer.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -0,0 +1,106 @@
+package org.jboss.tools.ws.jaxrs.ui.contentassist;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.ui.text.IJavaPartitions;
+import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
+import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentExtension3;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.TypedRegion;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.swt.graphics.Image;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsMetamodel;
+import org.jboss.tools.ws.jaxrs.core.metamodel.JaxrsMetamodelLocator;
+import org.jboss.tools.ws.jaxrs.ui.JBossJaxrsUIPlugin;
+import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
+
+/**
+ * Computes proposals for method parameters based on the Path values found on the method
and on the parent type. Also,
+ * depending on the HttpMethod, a single content object may be proposed, too. For
example, with @POST and @PUT request,
+ * there should be a body to process, but not in @GET and @DELETE, nor in @HEAD and
@OPTIONS.
+ * If the java method is annotated with a custom HttpMethod, then the content object will
be proposed, too.
+ *
+ *
+ * @author xcoulon
+ */
+public class MethodParametersCompletionProposalComputer implements
IJavaCompletionProposalComputer {
+
+ /** Icon for completion proposals. */
+ private final Image icon =
JBossJaxrsUIPlugin.getDefault().createImage("url_mapping.gif");
+
+ /** {@inheritDoc} */
+ @Override
+ public void sessionStarted() {
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void sessionEnded() {
+ }
+
+ @Override
+ public List<ICompletionProposal>
computeCompletionProposals(ContentAssistInvocationContext context,
+ IProgressMonitor monitor) {
+ final List<ICompletionProposal> proposals = new
ArrayList<ICompletionProposal>();
+ final JavaContentAssistInvocationContext javaContext =
(JavaContentAssistInvocationContext) context;
+ try {
+ final IJavaProject project = javaContext.getProject();
+ final IJaxrsMetamodel metamodel = JaxrsMetamodelLocator.get(project);
+ // skip if the JAX-RS Nature is not configured for this project
+ if (metamodel == null) {
+ return Collections.emptyList();
+ }
+ final IJavaElement invocationElement = javaContext.getCompilationUnit().getElementAt(
+ context.getInvocationOffset());
+ if (invocationElement.getElementType() == IJavaElement.TYPE) {
+ final ITypedRegion region = new TypedRegion(javaContext.getInvocationOffset(), 0,
null);
+ proposals.add(new MethodParametersCompletionProposal("Foo !", new
StyledString("Foo!"), region, icon, (IMember) invocationElement));
+ }
+ } catch (Exception e) {
+ Logger.error("Failed to compute completion proposal", e);
+ }
+ return proposals;
+ }
+
+ /**
+ * Resolves the typed region for the given java content assist invocation context.
+ *
+ * @param javaContext
+ * the java content assist invocation context
+ * @return the typed region
+ */
+ private ITypedRegion getRegion(final JavaContentAssistInvocationContext javaContext) {
+ IDocument document = javaContext.getDocument();
+ IDocumentPartitioner documentPartitioner = ((IDocumentExtension3) document)
+ .getDocumentPartitioner(IJavaPartitions.JAVA_PARTITIONING);
+ return documentPartitioner.getPartition(javaContext.getInvocationOffset());
+ }
+
+
+
+ /** {@inheritDoc} */
+ @Override
+ public final List<IContextInformation> computeContextInformation(final
ContentAssistInvocationContext context,
+ final IProgressMonitor monitor) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public final String getErrorMessage() {
+ return null;
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/MethodParametersCompletionProposalComputer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/Logger.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/Logger.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/Logger.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -30,6 +30,9 @@
/** The debug name, matching the .options file. */
private static final String DEBUG = JBossJaxrsUIPlugin.PLUGIN_ID + "/debug";
+ /** The trace name, matching the .options file. */
+ private static final String TRACE = JBossJaxrsUIPlugin.PLUGIN_ID + "/trace";
+
private static final ThreadLocal<DateFormat> dateFormatter = new
ThreadLocal<DateFormat>() {
@Override
protected DateFormat initialValue() {
@@ -101,27 +104,50 @@
}
/**
- * Outputs a debug message in the trace file (not the error view of the
- * runtime workbench). Traces must be activated for this plugin in order to
- * see the output messages.
+ * Outputs a 'debug' level message in the .log file (not the error view of
+ * the runtime workbench). Traces must be activated for this plugin in order
+ * to see the output messages.
*
* @param message
* the message to trace.
*/
public static void debug(final String message, Object... items) {
- String debugOption = Platform.getDebugOption(DEBUG);
- String valuedMessage = message;
- if (JBossJaxrsUIPlugin.getDefault() != null &&
JBossJaxrsUIPlugin.getDefault().isDebugging()
- && "true".equalsIgnoreCase(debugOption)) {
- if (items != null) {
- for (Object item : items) {
- valuedMessage = valuedMessage.replaceFirst("\\{\\}", (item != null ?
item.toString() : "null"));
+ log(DEBUG, message, items);
+ }
+
+ /**
+ * Outputs a 'trace' level message in the .log file (not the error view of
+ * the runtime workbench). Traces must be activated for this plugin in order
+ * to see the output messages.
+ *
+ * @param message
+ * the message to trace.
+ */
+ public static void trace(final String message, final Object... items) {
+ log(TRACE, message, items);
+ }
+
+ private static void log(final String level, final String message, final Object... items)
{
+ try {
+ String debugOption = Platform.getDebugOption(level);
+ String valuedMessage = message;
+ if (JBossJaxrsUIPlugin.getDefault() != null &&
JBossJaxrsUIPlugin.getDefault().isDebugging()
+ && "true".equalsIgnoreCase(debugOption)) {
+ if (items != null) {
+ for (Object item : items) {
+ valuedMessage = valuedMessage.replaceFirst("\\{\\}", (item != null ?
item.toString()
+ .replaceAll("\\$", ".") : "null"));
+ }
}
+ System.out.println(dateFormatter.get().format(new Date()) + " [" +
Thread.currentThread().getName()
+ + "] " + valuedMessage);
}
- System.out.println(dateFormatter.get().format(new Date()) + " [" +
Thread.currentThread().getName() + "] "
- + valuedMessage);
+ } catch (RuntimeException e) {
+ System.err.println("Failed to write proper debug message with template:\n "
+ message + "\n and items:");
+ for (Object item : items) {
+ System.err.println(" " + item);
+ }
}
-
}
}
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_3-with-servlet-mapping.xml
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_3-with-servlet-mapping.xml 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_3-with-servlet-mapping.xml 2012-02-08
21:06:10 UTC (rev 38524)
@@ -4,6 +4,9 @@
"http://java.sun.com/dtd/web-app_2_3.dtd">
<!-- A sample web.xml file validated by the web-app DTD in version 2.3 -->
<web-app>
+ <servlet>
+ <servlet-class></servlet-class>
+ </servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/hello/*</url-pattern>
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessorTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessorTestCase.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessorTestCase.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -1874,9 +1874,9 @@
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "getCustomer");
- final JavaMethodParameter pathParameter = new JavaMethodParameter("id",
Integer.class.getName(), null);
+ final JavaMethodParameter pathParameter = new JavaMethodParameter("id",
Integer.class.getName(), null, null);
final JavaMethodParameter contextParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(),
- Arrays.asList(createAnnotation(Context.class, null)));
+ Arrays.asList(createAnnotation(Context.class, null)), null);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(getAnnotation(method, GET.class))
.returnType(getType(Response.class.getName(),
javaProject)).methodParameter(pathParameter)
@@ -1907,9 +1907,9 @@
// JAX-RS Resource Method
final IMethod method = getMethod(type, "getCustomer");
final JavaMethodParameter pathParameter = new JavaMethodParameter("id",
Integer.class.getName(),
- Arrays.asList(createAnnotation(PathParam.class, "foo!")));
+ Arrays.asList(createAnnotation(PathParam.class, "foo!")), null);
final JavaMethodParameter contextParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(),
- Arrays.asList(createAnnotation(Context.class, null)));
+ Arrays.asList(createAnnotation(Context.class, null)), null);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(getAnnotation(method, GET.class))
.returnType(getType(Response.class.getName(),
javaProject)).methodParameter(pathParameter)
@@ -1940,10 +1940,10 @@
// JAX-RS Resource Method
final IMethod method = getMethod(type, "updateCustomer");
final JavaMethodParameter pathParameter = new JavaMethodParameter("id",
Integer.class.getName(),
- Arrays.asList(createAnnotation(PathParam.class, "id")));
+ Arrays.asList(createAnnotation(PathParam.class, "id")), null);
final JavaMethodParameter customerParameter = new
JavaMethodParameter("update",
"org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
Arrays.asList(createAnnotation(
- PathParam.class, "foo")));
+ PathParam.class, "foo")), null);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(getAnnotation(method, PUT.class)).returnType(getType("void",
javaProject))
.methodParameter(pathParameter).methodParameter(customerParameter).build();
@@ -1973,9 +1973,9 @@
// JAX-RS Resource Method (size param is not declared)
final IMethod method = getMethod(type, "getCustomers");
final JavaMethodParameter startParameter = new JavaMethodParameter("start",
"int",
- Arrays.asList(createAnnotation(QueryParam.class, "start")));
+ Arrays.asList(createAnnotation(QueryParam.class, "start")), null);
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(),
- Arrays.asList(createAnnotation(Context.class, null)));
+ Arrays.asList(createAnnotation(Context.class, null)), null);
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.util.List", javaProject))
.methodParameter(startParameter).methodParameter(uriInfoParameter).build();
@@ -2006,7 +2006,7 @@
// JAX-RS Resource Method (color param is not declared)
final IMethod method = getMethod(type, "getPicture");
final JavaMethodParameter pathParameter = new JavaMethodParameter("id",
String.class.getName(),
- Arrays.asList(createAnnotation(PathParam.class, null)));
+ Arrays.asList(createAnnotation(PathParam.class, null)), null);
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.pathTemplate(getAnnotation(method, Path.class)).methodParameter(pathParameter)
.returnType(getType("java.lang.Object", javaProject)).build();
@@ -2037,11 +2037,11 @@
// JAX-RS Resource Method (@QueryParam on 'size' param is not declared)
final IMethod method = getMethod(type, "getCustomers");
final JavaMethodParameter startParameter = new JavaMethodParameter("start",
"int",
- Arrays.asList(createAnnotation(QueryParam.class, "start")));
+ Arrays.asList(createAnnotation(QueryParam.class, "start")), null);
final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int",
- Arrays.asList(createAnnotation(DefaultValue.class, "2")));
+ Arrays.asList(createAnnotation(DefaultValue.class, "2")), null);
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(),
- Arrays.asList(createAnnotation(Context.class, null)));
+ Arrays.asList(createAnnotation(Context.class, null)), null);
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.util.List", javaProject))
.methodParameter(startParameter).methodParameter(sizeParameter).methodParameter(uriInfoParameter)
@@ -2073,11 +2073,11 @@
// "size" on second param)
final IMethod method = getMethod(type, "getCustomers");
final JavaMethodParameter startParameter = new JavaMethodParameter("start",
"int",
- Arrays.asList(createAnnotation(QueryParam.class, "start")));
+ Arrays.asList(createAnnotation(QueryParam.class, "start")), null);
final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(
- createAnnotation(QueryParam.class, "length"),
createAnnotation(DefaultValue.class, "2")));
+ createAnnotation(QueryParam.class, "length"),
createAnnotation(DefaultValue.class, "2")), null);
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(),
- Arrays.asList(createAnnotation(Context.class, null)));
+ Arrays.asList(createAnnotation(Context.class, null)), null);
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.util.List", javaProject))
.methodParameter(startParameter).methodParameter(sizeParameter).methodParameter(uriInfoParameter)
@@ -2108,11 +2108,11 @@
// JAX-RS Resource Method (with an extra @Queryparam annotation on 'uriInfo'
param)
final IMethod method = getMethod(type, "getCustomers");
final JavaMethodParameter startParameter = new JavaMethodParameter("start",
"int",
- Arrays.asList(createAnnotation(QueryParam.class, "start")));
+ Arrays.asList(createAnnotation(QueryParam.class, "start")), null);
final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(
- createAnnotation(QueryParam.class, "size"),
createAnnotation(DefaultValue.class, "2")));
+ createAnnotation(QueryParam.class, "size"),
createAnnotation(DefaultValue.class, "2")), null);
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(),
- Arrays.asList(createAnnotation(QueryParam.class, "foo"),
createAnnotation(Context.class, null)));
+ Arrays.asList(createAnnotation(QueryParam.class, "foo"),
createAnnotation(Context.class, null)), null);
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.util.List", javaProject))
.methodParameter(startParameter).methodParameter(sizeParameter).methodParameter(uriInfoParameter)
@@ -2143,9 +2143,9 @@
// JAX-RS Resource Method (MatrixParam annotation on second parameter is not declared)
final IMethod method = getMethod(type, "getPicture");
final JavaMethodParameter startParameter = new JavaMethodParameter("id",
Integer.class.getName(),
- Arrays.asList(createAnnotation(PathParam.class, "id")));
+ Arrays.asList(createAnnotation(PathParam.class, "id")), null);
final JavaMethodParameter sizeParameter = new JavaMethodParameter("color",
String.class.getName(),
- new ArrayList<Annotation>());
+ new ArrayList<Annotation>(), null);
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.lang.Object", javaProject))
.methodParameter(startParameter).methodParameter(sizeParameter).build();
@@ -2175,9 +2175,9 @@
// JAX-RS Resource Method (MatrixParam value is different: "foo" vs
"color" on second param)
final IMethod method = getMethod(type, "getPicture");
final JavaMethodParameter startParameter = new JavaMethodParameter("id",
Integer.class.getName(),
- Arrays.asList(createAnnotation(PathParam.class, "id")));
+ Arrays.asList(createAnnotation(PathParam.class, "id")), null);
final JavaMethodParameter sizeParameter = new JavaMethodParameter("color",
String.class.getName(),
- Arrays.asList(createAnnotation(MatrixParam.class, "foo")));
+ Arrays.asList(createAnnotation(MatrixParam.class, "foo")), null);
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.lang.Object", javaProject))
.methodParameter(startParameter).methodParameter(sizeParameter).build();
@@ -2207,7 +2207,7 @@
// JAX-RS Resource Method (an extra MatrixParam annotation on 'id' param)
final IMethod method = getMethod(type, "getProduct");
final JavaMethodParameter pathParameter = new JavaMethodParameter("id",
Integer.class.getName(), Arrays.asList(
- createAnnotation(MatrixParam.class, "foo"),
createAnnotation(PathParam.class, "id")));
+ createAnnotation(MatrixParam.class, "foo"),
createAnnotation(PathParam.class, "id")), null);
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(getAnnotation(method, GET.class))
.returnType(getType("org.jboss.tools.ws.jaxrs.sample.domain.Book",
javaProject))
@@ -2239,11 +2239,11 @@
// 'javax.ws.rs.Response')
final IMethod method = getMethod(type, "getCustomers");
final JavaMethodParameter startParameter = new JavaMethodParameter("start",
"int",
- Arrays.asList(createAnnotation(QueryParam.class, "start")));
+ Arrays.asList(createAnnotation(QueryParam.class, "start")), null);
final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(
- createAnnotation(QueryParam.class, "size"),
createAnnotation(DefaultValue.class, "2")));
+ createAnnotation(QueryParam.class, "size"),
createAnnotation(DefaultValue.class, "2")), null);
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(),
- Arrays.asList(createAnnotation(Context.class, null)));
+ Arrays.asList(createAnnotation(Context.class, null)), null);
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(getAnnotation(method, GET.class))
.returnType(getType(Response.class.getName(),
javaProject)).methodParameter(startParameter)
@@ -2278,10 +2278,10 @@
// JAX-RS Resource Method (@Context is not declared on 'uriInfo' param)
final IMethod method = getMethod(type, "getCustomers");
final JavaMethodParameter startParameter = new JavaMethodParameter("start",
"int",
- Arrays.asList(createAnnotation(QueryParam.class, "start")));
+ Arrays.asList(createAnnotation(QueryParam.class, "start")), null);
final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(
- createAnnotation(QueryParam.class, "length"),
createAnnotation(DefaultValue.class, "2")));
- final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(), null);
+ createAnnotation(QueryParam.class, "length"),
createAnnotation(DefaultValue.class, "2")), null);
+ final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(), null, null);
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.methodParameter(startParameter).methodParameter(sizeParameter).methodParameter(uriInfoParameter)
.build();
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessorTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessorTestCase.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessorTestCase.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -120,8 +120,8 @@
return httpMethod;
}
- private JaxrsEndpoint createEndpoint(JaxrsJavaApplication application, JaxrsHttpMethod
httpMethod, JaxrsResourceMethod... resourceMethods) {
- JaxrsEndpoint endpoint = new JaxrsEndpoint(application, httpMethod, new
LinkedList<JaxrsResourceMethod>(
+ private JaxrsEndpoint createEndpoint(JaxrsMetamodel metamodel, JaxrsHttpMethod
httpMethod, JaxrsResourceMethod... resourceMethods) {
+ JaxrsEndpoint endpoint = new JaxrsEndpoint(metamodel, httpMethod, new
LinkedList<JaxrsResourceMethod>(
Arrays.asList(resourceMethods)));
metamodel.add(endpoint);
return endpoint;
@@ -382,7 +382,7 @@
final JaxrsResource customerResource =
createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
final JaxrsResourceMethod customerResourceMethod =
createResourceMethod("getCustomer", customerResource,
GET.class);
- final JaxrsEndpoint endpoint = createEndpoint(application, httpMethod,
customerResourceMethod);
+ final JaxrsEndpoint endpoint = createEndpoint(metamodel, httpMethod,
customerResourceMethod);
assertThat(endpoint.getUriPathTemplate(), equalTo("/app/customers/{id}"));
// operation
final Annotation annotation = getAnnotation(application.getJavaElement(),
ApplicationPath.class, "/foo");
@@ -503,7 +503,7 @@
final JaxrsResource customerResource =
createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
final JaxrsResourceMethod customerResourceMethod =
createResourceMethod("getCustomer", customerResource,
GET.class);
- final JaxrsEndpoint endpoint = createEndpoint(application, httpMethod,
customerResourceMethod);
+ final JaxrsEndpoint endpoint = createEndpoint(metamodel, httpMethod,
customerResourceMethod);
assertThat(endpoint.getUriPathTemplate(), equalTo("/app/customers/{id}"));
// operation : no 'application' left in the metamodel
metamodel.remove(application);
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java 2012-02-08
20:47:32 UTC (rev 38523)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java 2012-02-08
21:06:10 UTC (rev 38524)
@@ -83,7 +83,7 @@
// operation
final List<ValidatorMessage> validationMessages = customerResource.validate();
// validation
- assertThat(validationMessages.size(), equalTo(1));
+ assertThat(validationMessages.size(), equalTo(2));
}
}