Author: xcoulon
Date: 2012-10-05 03:01:03 -0400 (Fri, 05 Oct 2012)
New Revision: 44331
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorDelegate.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsPreferencesMessages.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsPreferencesMessages.properties
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsValidatorConfigurationBlockDescriptionProvider.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorTestCase.java
Log:
Fixed - JBIDE-12804
Report an error when a JAX-RS @HttpMethod annotation has an invalid value
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorDelegate.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorDelegate.java 2012-10-05
06:54:35 UTC (rev 44330)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorDelegate.java 2012-10-05
07:01:03 UTC (rev 44331)
@@ -17,6 +17,7 @@
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.common.validation.TempMarkerManager;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsHttpMethod;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.quickfix.JaxrsValidationQuickFixes;
import org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences;
@@ -36,7 +37,8 @@
@Override
public void validate() throws CoreException {
final JaxrsHttpMethod httpMethod = getElement();
- deleteJaxrsMarkers(httpMethod.getResource());
+ JaxrsMetamodelValidator.deleteJaxrsMarkers(httpMethod);
+ Logger.debug("Validating element {}", getElement());
if (!httpMethod.isBuiltIn()) {
validateHttpMethodAnnotation(httpMethod);
validateRetentionAnnotation(getElement());
@@ -55,8 +57,8 @@
if (annotation != null) { // if annotation is null, the resource is not a
JaxrsHttpMethod anymore.
final String httpValue = annotation.getValue("value");
if (httpValue == null || httpValue.isEmpty()) {
- addProblem(JaxrsValidationMessages.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE,
- JaxrsPreferences.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE, new String[0],
annotation
+ addProblem(JaxrsValidationMessages.HTTP_METHOD_INVALID_HTTP_METHOD_ANNOTATION_VALUE,
+ JaxrsPreferences.HTTP_METHOD_INVALID_HTTP_METHOD_ANNOTATION_VALUE, new String[0],
annotation
.getSourceRange().getLength(), annotation.getSourceRange().getOffset(),
httpMethod.getResource());
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsPreferencesMessages.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsPreferencesMessages.java 2012-10-05
06:54:35 UTC (rev 44330)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsPreferencesMessages.java 2012-10-05
07:01:03 UTC (rev 44331)
@@ -20,6 +20,7 @@
public class JaxrsPreferencesMessages extends NLS {
private static final String BUNDLE_NAME =
"org.jboss.tools.ws.jaxrs.ui.preferences.JaxrsPreferencesMessages";
//$NON-NLS-1$
+
public static String JAXRS_SETTINGS_PREFERENCE_PAGE_JAXRS_SUPPORT;
// Validator Preference page
@@ -38,6 +39,7 @@
// Section HTTP Method
public static String JaxrsValidatorConfigurationBlock_section_httpMethods;
+ public static String
JaxrsValidatorConfigurationBlock_pb_httpMethodInvalidHttpMethodAnnotationValue_label;
public static String
JaxrsValidatorConfigurationBlock_pb_httpMethodMissingRetentionAnnotation_label;
public static String
JaxrsValidatorConfigurationBlock_pb_httpMethodInvalidRetentionAnnotationValue_label;
public static String
JaxrsValidatorConfigurationBlock_pb_httpMethodMissingTargetAnnotation_label;
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsPreferencesMessages.properties
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsPreferencesMessages.properties 2012-10-05
06:54:35 UTC (rev 44330)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsPreferencesMessages.properties 2012-10-05
07:01:03 UTC (rev 44331)
@@ -26,6 +26,7 @@
#Section HTTP Methods
JaxrsValidatorConfigurationBlock_section_httpMethods=User-defined HTTP Methods
+JaxrsValidatorConfigurationBlock_pb_httpMethodInvalidHttpMethodAnnotationValue_label=Empty
@HttpMethod annotation value
JaxrsValidatorConfigurationBlock_pb_httpMethodMissingRetentionAnnotation_label=Missing
@Retention annotation:
JaxrsValidatorConfigurationBlock_pb_httpMethodInvalidRetentionAnnotationValue_label=Invalid
@Retention annotation value:
JaxrsValidatorConfigurationBlock_pb_httpMethodMissingTargetAnnotation_label=Missing
@Target annotation:
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsValidatorConfigurationBlockDescriptionProvider.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsValidatorConfigurationBlockDescriptionProvider.java 2012-10-05
06:54:35 UTC (rev 44330)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsValidatorConfigurationBlockDescriptionProvider.java 2012-10-05
07:01:03 UTC (rev 44331)
@@ -47,6 +47,7 @@
private SectionDescription SECTION_HTTP_METHODS = new SectionDescription(
JaxrsPreferencesMessages.JaxrsValidatorConfigurationBlock_section_httpMethods,
new String[][]{
+ {JaxrsPreferences.HTTP_METHOD_INVALID_HTTP_METHOD_ANNOTATION_VALUE,
JaxrsPreferencesMessages.JaxrsValidatorConfigurationBlock_pb_httpMethodInvalidHttpMethodAnnotationValue_label},
{JaxrsPreferences.HTTP_METHOD_MISSING_RETENTION_ANNOTATION,
JaxrsPreferencesMessages.JaxrsValidatorConfigurationBlock_pb_httpMethodMissingRetentionAnnotation_label},
{JaxrsPreferences.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE,
JaxrsPreferencesMessages.JaxrsValidatorConfigurationBlock_pb_httpMethodInvalidRetentionAnnotationValue_label},
{JaxrsPreferences.HTTP_METHOD_MISSING_RETENTION_ANNOTATION,
JaxrsPreferencesMessages.JaxrsValidatorConfigurationBlock_pb_httpMethodMissingTargetAnnotation_label},
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorTestCase.java 2012-10-05
06:54:35 UTC (rev 44330)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorTestCase.java 2012-10-05
07:01:03 UTC (rev 44331)
@@ -13,8 +13,14 @@
import static org.hamcrest.Matchers.equalTo;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.changeAnnotation;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getAnnotation;
+import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation.MarkerUtils.deleteJaxrsMarkers;
+import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation.MarkerUtils.findJaxrsMarkers;
+import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation.MarkerUtils.hasPreferenceKey;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.HTTP_METHOD;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.TARGET;
+import static
org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences.HTTP_METHOD_INVALID_HTTP_METHOD_ANNOTATION_VALUE;
+import static
org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE;
+import static
org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences.HTTP_METHOD_MISSING_TARGET_ANNOTATION;
import static org.junit.Assert.assertThat;
import java.util.HashSet;
@@ -63,13 +69,13 @@
// preconditions
final IType fooType =
WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject);
final JaxrsBaseElement httpMethod = (JaxrsBaseElement) metamodel.getElement(fooType);
- assertThat(MarkerUtils.findJaxrsMarkers(httpMethod).length, equalTo(0));
- MarkerUtils.deleteJaxrsMarkers(httpMethod);
+ assertThat(findJaxrsMarkers(httpMethod).length, equalTo(0));
+ deleteJaxrsMarkers(httpMethod);
// operation
new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project,
validationHelper, context,
validatorManager, reporter);
// validation
- assertThat(MarkerUtils.findJaxrsMarkers(httpMethod).length, equalTo(0));
+ assertThat(findJaxrsMarkers(httpMethod).length, equalTo(0));
}
@Test
@@ -79,13 +85,14 @@
final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType,
JaxrsHttpMethod.class);
final Annotation httpAnnotation = changeAnnotation(fooType, HTTP_METHOD.qualifiedName,
new String[0]);
httpMethod.addOrUpdateAnnotation(httpAnnotation);
- MarkerUtils.deleteJaxrsMarkers(httpMethod);
+ deleteJaxrsMarkers(httpMethod);
// operation
new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project,
validationHelper, context,
validatorManager, reporter);
// validation
- final IMarker[] markers = MarkerUtils.findJaxrsMarkers(httpMethod);
+ final IMarker[] markers = findJaxrsMarkers(httpMethod);
assertThat(markers.length, equalTo(1));
+ assertThat(markers,
hasPreferenceKey(HTTP_METHOD_INVALID_HTTP_METHOD_ANNOTATION_VALUE));
}
@Test
@@ -95,12 +102,14 @@
final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType,
JaxrsHttpMethod.class);
final Annotation httpAnnotation = changeAnnotation(fooType, HTTP_METHOD.qualifiedName,
(String) null);
httpMethod.addOrUpdateAnnotation(httpAnnotation);
- MarkerUtils.deleteJaxrsMarkers(httpMethod);
+ deleteJaxrsMarkers(httpMethod);
// operation
new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project,
validationHelper, context,
validatorManager, reporter);
// validation
- assertThat(MarkerUtils.findJaxrsMarkers(httpMethod).length, equalTo(1));
+ final IMarker[] markers = findJaxrsMarkers(httpMethod);
+ assertThat(markers.length, equalTo(1));
+ assertThat(markers,
hasPreferenceKey(HTTP_METHOD_INVALID_HTTP_METHOD_ANNOTATION_VALUE));
}
@Test
@@ -110,12 +119,14 @@
final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType,
JaxrsHttpMethod.class);
final Annotation targetAnnotation = getAnnotation(fooType, TARGET.qualifiedName);
httpMethod.removeAnnotation(targetAnnotation);
- MarkerUtils.deleteJaxrsMarkers(httpMethod);
+ deleteJaxrsMarkers(httpMethod);
// operation
new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project,
validationHelper, context,
validatorManager, reporter);
// validation
- assertThat(MarkerUtils.findJaxrsMarkers(httpMethod).length, equalTo(1));
+ final IMarker[] markers = findJaxrsMarkers(httpMethod);
+ assertThat(markers.length, equalTo(1));
+ assertThat(markers, hasPreferenceKey(HTTP_METHOD_MISSING_TARGET_ANNOTATION));
}
@Test
@@ -126,13 +137,14 @@
final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType,
JaxrsHttpMethod.class);
final Annotation targetAnnotation = changeAnnotation(fooType, TARGET.qualifiedName,
(String) null);
httpMethod.addOrUpdateAnnotation(targetAnnotation);
- MarkerUtils.deleteJaxrsMarkers(httpMethod);
+ deleteJaxrsMarkers(httpMethod);
// operation
new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project,
validationHelper, context,
validatorManager, reporter);
// validation
- assertThat(MarkerUtils.findJaxrsMarkers(httpMethod).length, equalTo(1));
-
+ final IMarker[] markers = findJaxrsMarkers(httpMethod);
+ assertThat(markers.length, equalTo(1));
+ assertThat(markers, hasPreferenceKey(HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE));
}
@Test
@@ -143,12 +155,14 @@
final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType,
JaxrsHttpMethod.class);
final Annotation targetAnnotation = changeAnnotation(fooType, TARGET.qualifiedName,
"FOO");
httpMethod.addOrUpdateAnnotation(targetAnnotation);
- MarkerUtils.deleteJaxrsMarkers(httpMethod);
+ deleteJaxrsMarkers(httpMethod);
// operation
new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project,
validationHelper, context,
validatorManager, reporter);
// validation
- assertThat(MarkerUtils.findJaxrsMarkers(httpMethod).length, equalTo(1));
+ final IMarker[] markers = findJaxrsMarkers(httpMethod);
+ assertThat(markers.length, equalTo(1));
+ assertThat(markers, hasPreferenceKey(HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE));
}
}