Author: xcoulon
Date: 2012-10-12 05:10:19 -0400 (Fri, 12 Oct 2012)
New Revision: 44469
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/Comparison.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/BindingUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/DOMUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaAnnotationLocator.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/MemberValuePairLocationRetriever.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/AddRetentionAnnotationMarkerResolution.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/UpdateRetentionAnnotationValueMarkerResolution.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/UpdateTargetAnnotationValueMarkerResolution.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsBuiltinHttpMethod.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactory.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaElement.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.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/metamodel/validation/JaxrsHttpMethodValidatorDelegate.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceMethodValidatorDelegate.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationMessages.properties
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/EnumJaxrsClassname.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaAnnotationsVisitor.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.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsResourceMethod.java
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/preferences/JaxrsValidatorConfigurationBlock.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/AddTargetAnnotationMarkerResolution.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/JaxrsMarkerResolutionGenerator.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/JaxrsQuickFixMessages.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/JaxrsQuickFixMessages.properties
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/BarResource.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/CustomerResource.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java
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/JavaElementDeltaScannerTestCase.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/builder/ResourceChangedProcessorTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactoryTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodelTestCase.java
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/JaxrsResourceValidatorTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionUtilsTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/CompilationUnitsRepositoryTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtilsTestCase.java
Log:
Fixed - JBIDE-12806 - Annotations location in the JAX-RS Metamodel are not updated after
code changes
https://issues.jboss.org/browse/JBIDE-12806
Fixed - JBIDE-12593 - Improve quick fixes for @HttpMethod validation errors
https://issues.jboss.org/browse/JBIDE-12593
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -343,7 +343,6 @@
* @param progressMonitor
* @throws CoreException
*/
- // FIXME : same code as method processAddition(annotation, etc..) ?!?
private List<JaxrsElementDelta> processChange(final IAnnotation javaAnnotation,
final CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws
CoreException {
final List<JaxrsElementDelta> changes = new
ArrayList<JaxrsElementDelta>();
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessor.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessor.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -165,24 +165,24 @@
if (resource == null) {
return results;
}
- final IJavaElement scope = JavaCore.create(resource);
+ final IJavaElement javaElement = JavaCore.create(resource);
final JaxrsMetamodel metamodel = JaxrsMetamodelLocator.get(resource.getProject());
final int deltaKind = event.getDeltaKind();
- if (scope != null &&
+ if (javaElement != null &&
// ignore changes on binary files (added/removed/changed jars to improve builder
performances)
- !(scope.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT &&
((IPackageFragmentRoot)scope).isArchive())) {
+ !(javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT &&
((IPackageFragmentRoot)javaElement).isArchive())) {
switch (deltaKind) {
case ADDED:
case CHANGED:
- results.addAll(processApplicationChangesOnScopeAdditionOrChange(scope, metamodel,
progressMonitor));
- results.addAll(processHttpMethodChangesOnScopeAdditionOrChange(scope, metamodel,
progressMonitor));
- results.addAll(processResourceChangesOnScopeAdditionOrChange(scope, metamodel,
deltaKind,
+ results.addAll(processApplicationChangesOnScopeAdditionOrChange(javaElement,
metamodel, progressMonitor));
+ results.addAll(processHttpMethodChangesOnScopeAdditionOrChange(javaElement,
metamodel, progressMonitor));
+ results.addAll(processResourceChangesOnScopeAdditionOrChange(javaElement, metamodel,
deltaKind,
progressMonitor));
break;
case REMOVED:
- results.addAll(processApplicationChangesOnScopeRemoval(scope, metamodel,
progressMonitor));
- results.addAll(processHttpMethodChangesOnScopeRemoval(scope, metamodel,
progressMonitor));
- results.addAll(processResourceChangesOnScopeRemoval(scope, metamodel,
progressMonitor));
+ results.addAll(processApplicationChangesOnScopeRemoval(javaElement, metamodel,
progressMonitor));
+ results.addAll(processHttpMethodChangesOnScopeRemoval(javaElement, metamodel,
progressMonitor));
+ results.addAll(processResourceChangesOnScopeRemoval(javaElement, metamodel,
progressMonitor));
break;
}
} else if (WtpUtils.isWebDeploymentDescriptor(resource)) {
@@ -803,6 +803,7 @@
metamodel.remove(removedMethod);
changes.add(new JaxrsElementDelta(removedMethod, REMOVED));
}
+
return changes;
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsBuiltinHttpMethod.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsBuiltinHttpMethod.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsBuiltinHttpMethod.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -33,7 +33,7 @@
private final String httpVerb;
public JaxrsBuiltinHttpMethod(String annotationName, String annotationValue) {
- super(null, Arrays.asList(new Annotation(null, annotationName, annotationValue, null)),
null);
+ super(null, Arrays.asList(new Annotation(null, annotationName, annotationValue)),
null);
this.annotationName = annotationName;
this.httpVerb = annotationValue;
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactory.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactory.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactory.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -34,6 +34,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@@ -61,6 +62,11 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
+/**
+ * Factory for JAX-RS elements that should be created from Java elements.
+ * @author Xavier Coulon
+ *
+ */
public class JaxrsElementFactory {
/**
@@ -79,7 +85,7 @@
if(annotation == null) { // annotation on package declaration are ignored
return null;
}
- final String annotationName = annotation.getName();
+ final String annotationName = annotation.getFullyQualifiedName();
if (annotationName.equals(HTTP_METHOD.qualifiedName)) {
final JaxrsHttpMethod httpMethod = createHttpMethod(annotation, ast, metamodel);
return httpMethod;
@@ -253,8 +259,8 @@
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);
+ for (Entry<String, JavaMethodParameter> methodParamEntry :
methodSignature.getMethodParameters().entrySet()) {
+ builder.methodParameter(methodParamEntry.getValue());
}
final JaxrsResourceMethod resourceMethod = builder.build();
@@ -301,7 +307,7 @@
public JaxrsHttpMethod createHttpMethod(final Annotation annotation, final
CompilationUnit ast,
final JaxrsMetamodel metamodel) throws CoreException {
if (annotation.getJavaParent() != null &&
annotation.getJavaParent().getElementType() == IJavaElement.TYPE
- && annotation.getName().equals(HTTP_METHOD.qualifiedName)) {
+ && annotation.getFullyQualifiedName().equals(HTTP_METHOD.qualifiedName)) {
//return new JaxrsHttpMethod.Builder((IType) annotation.getJavaParent(),
metamodel).httpMethod(annotation).build();
return createHttpMethod((IType) annotation.getJavaParent(), ast, metamodel);
}
@@ -341,7 +347,7 @@
final JaxrsMetamodel metamodel) throws CoreException {
final IJavaElement javaParent = annotation.getJavaParent();
if (javaParent != null && javaParent.getElementType() == IJavaElement.TYPE
- && annotation.getName().equals(APPLICATION_PATH.qualifiedName)) {
+ && annotation.getFullyQualifiedName().equals(APPLICATION_PATH.qualifiedName))
{
final IType javaType = (IType) javaParent;
return createApplication(javaType, annotation, metamodel);
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaElement.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaElement.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaElement.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -95,7 +95,7 @@
this.javaElement = element;
if (annotations != null) {
for (Annotation annotation : annotations) {
- this.annotations.put(annotation.getName(), annotation);
+ this.annotations.put(annotation.getFullyQualifiedName(), annotation);
}
}
}
@@ -124,11 +124,11 @@
}
boolean changed = false;
final EnumElementKind previousKind = getElementKind();
- final String annotationName = annotation.getName();
- if (annotations.containsKey(annotation.getName())) {
- changed = annotations.get(annotation.getName()).update(annotation);
+ final String annotationName = annotation.getFullyQualifiedName();
+ if (annotations.containsKey(annotation.getFullyQualifiedName())) {
+ changed = annotations.get(annotation.getFullyQualifiedName()).update(annotation);
} else {
- annotations.put(annotation.getName(), annotation);
+ annotations.put(annotation.getFullyQualifiedName(), annotation);
changed = true;
}
if (changed) {
@@ -140,15 +140,14 @@
public int updateAnnotations(Map<String, Annotation> otherAnnotations) {
int flags = 0;
- // keep values in the 'otherAnnotations' map
+ // added annotations (ie: found in 'otherAnnotation' but not this.annotations)
final Map<String, Annotation> addedAnnotations =
CollectionUtils.difference(otherAnnotations, this.annotations);
- // keep values in the 'this.annotations' map
+ // removed annotations (ie: found in this.annotations but not in
'otherAnnotation')
final Map<String, Annotation> removedAnnotations =
CollectionUtils.difference(this.annotations,
otherAnnotations);
- // keep values in the 'otherAnnotations' map
+ // may-be-changed annotations (ie: available in both collections, but not sure all
values are equal)
final Map<String, Annotation> changedAnnotations =
CollectionUtils.intersection(otherAnnotations,
this.annotations);
-
for (Entry<String, Annotation> entry : addedAnnotations.entrySet()) {
flags += this.addOrUpdateAnnotation(entry.getValue());
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -685,7 +685,7 @@
if (httpMethodAnnotation != null) {
for (IJaxrsHttpMethod httpMethod : httpMethods) {
final String handleIdentifier1 = httpMethod.getJavaClassName();
- final String handleIdentifier2 = httpMethodAnnotation.getName();
+ final String handleIdentifier2 = httpMethodAnnotation.getFullyQualifiedName();
if (handleIdentifier1.equals(handleIdentifier2)) {
return (JaxrsHttpMethod) httpMethod;
}
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-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -19,12 +19,19 @@
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.PRODUCES;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtils;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtils.MapComparison;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.jdt.JavaMethodParameter;
import org.jboss.tools.ws.jaxrs.core.jdt.JavaMethodSignature;
@@ -45,8 +52,9 @@
*/
private IType returnedJavaType = null;
- private final List<JavaMethodParameter> javaMethodParameters = new
ArrayList<JavaMethodParameter>();
+ private final Map<String, JavaMethodParameter> javaMethodParameters = new
HashMap<String, JavaMethodParameter>();
+
public static class Builder {
private final IMethod javaMethod;
@@ -144,7 +152,9 @@
this.parentResource = parentResource;
this.returnedJavaType = returnedJavaType;
if (javaMethodParameters != null) {
- this.javaMethodParameters.addAll(javaMethodParameters);
+ for (JavaMethodParameter javaMethodParameter : javaMethodParameters) {
+ this.javaMethodParameters.put(javaMethodParameter.getName(), javaMethodParameter);
+ }
}
this.parentResource.addMethod(this);
}
@@ -152,27 +162,56 @@
public int update(JavaMethodSignature methodSignature)
throws JavaModelException {
int flag = F_NONE;
- // method parameters, including annotations
- final List<JavaMethodParameter> methodParameters = methodSignature
- .getMethodParameters();
- if (!this.javaMethodParameters.equals(methodParameters)) {
- this.javaMethodParameters.clear();
- this.javaMethodParameters.addAll(methodParameters);
- flag = F_METHOD_PARAMETERS;
- }
+ // method parameters, including their own annotations
+ flag += updateMethodParameters(methodSignature);
// method return type
+ flag += updateReturnedType(methodSignature);
+ // TODO: method thrown exceptions..
+ return flag;
+ }
+
+ /**
+ * @param the methodSignature to use to update this one's returned type.
+ * @return the flag indicating some change ({@link
JaxrsElementDelta.F_METHOD_RETURN_TYPE}) or no change ({@link JaxrsElementDelta.F_NONE})
+ */
+ private int updateReturnedType(JavaMethodSignature methodSignature) {
final IType returnedType = methodSignature.getReturnedType();
if ((this.returnedJavaType != null && returnedType == null)
|| (this.returnedJavaType == null && returnedType != null)
|| (this.returnedJavaType != null && returnedType != null &&
!this.returnedJavaType
.equals(returnedType))) {
this.returnedJavaType = returnedType;
- flag += F_METHOD_RETURN_TYPE;
+ return F_METHOD_RETURN_TYPE;
}
- // TODO: method thrown exceptions..
- return flag;
+ return F_NONE;
}
+ /**
+ * @param the methodSignature to use to update this one's method parameters.
+ * @return the flag indicating some change ({@link
JaxrsElementDelta.F_METHOD_PARAMETERS}) or no change ({@link JaxrsElementDelta.F_NONE})
+ */
+ private int updateMethodParameters(final JavaMethodSignature methodSignature) {
+ final Map<String, JavaMethodParameter> otherMethodParameters =
methodSignature.getMethodParameters();
+ final MapComparison<String, JavaMethodParameter> comparison =
CollectionUtils.compare(this.javaMethodParameters, otherMethodParameters);
+ boolean changed = false; // track changes. "true" means at least 1 method
parameter changed
+ for (Entry<String, JavaMethodParameter> entry :
comparison.getAddedItems().entrySet()) {
+ javaMethodParameters.put(entry.getKey(), entry.getValue());
+ changed = true;
+ }
+ for (Entry<String, JavaMethodParameter> entry :
comparison.getItemsInCommon().entrySet()) {
+ final JavaMethodParameter thisMethodParameter =
this.javaMethodParameters.get(entry.getKey());
+ final JavaMethodParameter otherMethodParameter =
otherMethodParameters.get(entry.getKey());
+ if(thisMethodParameter != null &&
thisMethodParameter.updateAnnotations(otherMethodParameter)) {
+ changed = true;
+ }
+ }
+ for (Entry<String, JavaMethodParameter> entry :
comparison.getRemovedItems().entrySet()) {
+ javaMethodParameters.remove(entry.getKey());
+ changed = true;
+ }
+ return changed ? F_METHOD_PARAMETERS : F_NONE;
+ }
+
public IType getReturnType() {
return this.returnedJavaType;
}
@@ -298,9 +337,19 @@
/** @return the javaMethodParameters */
@Override
public List<JavaMethodParameter> getJavaMethodParameters() {
- return javaMethodParameters;
+ return Collections.unmodifiableList(new
ArrayList<JavaMethodParameter>(javaMethodParameters.values()));
}
+
+ /**
+ * Returns the {@link JavaMethodParameter} whose name is equal to the given elementName,
or null if this resource method has no such parameter
+ * @param elementName
+ * @return
+ */
+ public JavaMethodParameter getJavaMethodParameter(String elementName) {
+ return javaMethodParameters.get(elementName);
+ }
+
/*
* (non-Javadoc)
*
@@ -352,4 +401,5 @@
return params;
}
+
}
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-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorDelegate.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -14,11 +14,13 @@
import java.lang.annotation.RetentionPolicy;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ISourceRange;
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.jdt.JdtUtils;
import org.jboss.tools.ws.jaxrs.core.metamodel.quickfix.JaxrsValidationQuickFixes;
import org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences;
@@ -52,15 +54,16 @@
* @param messages
* @throws JavaModelException
*/
- private void validateHttpMethodAnnotation(final JaxrsHttpMethod httpMethod) {
+ private void validateHttpMethodAnnotation(final JaxrsHttpMethod httpMethod) throws
JavaModelException {
final Annotation annotation = httpMethod.getHttpMethodAnnotation();
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()) {
+ final ISourceRange range =
JdtUtils.resolveMemberPairValueRange(annotation.getJavaAnnotation(),
+ annotation.getFullyQualifiedName(), "value");
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());
+ JaxrsPreferences.HTTP_METHOD_INVALID_HTTP_METHOD_ANNOTATION_VALUE, new String[0],
+ range.getLength(), range.getOffset(), httpMethod.getResource());
}
}
}
@@ -71,22 +74,30 @@
* @param messages
* @throws JavaModelException
*/
- private void validateTargetAnnotation(final JaxrsHttpMethod httpMethod) {
+ private void validateTargetAnnotation(final JaxrsHttpMethod httpMethod) throws
JavaModelException {
final Annotation targetAnnotation = httpMethod.getTargetAnnotation();
- final Annotation httpMethodAnnotation = httpMethod.getHttpMethodAnnotation();
if (targetAnnotation == null) {
+ final ISourceRange range = httpMethod.getJavaElement().getNameRange();
addProblem(JaxrsValidationMessages.HTTP_METHOD_MISSING_TARGET_ANNOTATION,
- JaxrsPreferences.HTTP_METHOD_MISSING_TARGET_ANNOTATION, new String[0],
httpMethodAnnotation
- .getSourceRange().getLength(), httpMethodAnnotation.getSourceRange().getOffset(),
- httpMethod.getResource(),
JaxrsValidationQuickFixes.HTTP_METHOD_MISSING_TARGET_ANNOTATION_ID);
+ JaxrsPreferences.HTTP_METHOD_MISSING_TARGET_ANNOTATION, new String[0],
range.getLength(),
+ range.getOffset(), httpMethod.getResource(),
+ JaxrsValidationQuickFixes.HTTP_METHOD_MISSING_TARGET_ANNOTATION_ID);
} else {
final String annotationValue = targetAnnotation.getValue("value");
- if (annotationValue == null || !annotationValue.equals(ElementType.METHOD.name())) {
+ if (annotationValue == null) {
+ final ISourceRange range = targetAnnotation.getJavaAnnotation().getNameRange();
addProblem(JaxrsValidationMessages.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE,
- JaxrsPreferences.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE, new String[0],
- httpMethodAnnotation.getSourceRange().getLength(),
httpMethodAnnotation.getSourceRange()
- .getOffset(), httpMethod.getResource(),
+ JaxrsPreferences.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE, new String[0],
range.getLength(),
+ range.getOffset(), httpMethod.getResource(),
JaxrsValidationQuickFixes.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE_ID);
+ } else if (!annotationValue.equals(ElementType.METHOD.name())) {
+ final ISourceRange range =
JdtUtils.resolveMemberPairValueRange(targetAnnotation.getJavaAnnotation(),
+ targetAnnotation.getFullyQualifiedName(), "value");
+ addProblem(JaxrsValidationMessages.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE,
+ JaxrsPreferences.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE, new String[0],
range.getLength(),
+ range.getOffset(), httpMethod.getResource(),
+ JaxrsValidationQuickFixes.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE_ID);
+
}
}
}
@@ -97,22 +108,30 @@
* @param messages
* @throws JavaModelException
*/
- private void validateRetentionAnnotation(final JaxrsHttpMethod httpMethod) {
+ private void validateRetentionAnnotation(final JaxrsHttpMethod httpMethod) throws
JavaModelException {
final Annotation retentionAnnotation = httpMethod.getRetentionAnnotation();
- final Annotation httpMethodAnnotation = httpMethod.getHttpMethodAnnotation();
if (retentionAnnotation == null) {
+ final ISourceRange range = httpMethod.getJavaElement().getNameRange();
addProblem(JaxrsValidationMessages.HTTP_METHOD_MISSING_RETENTION_ANNOTATION,
- JaxrsPreferences.HTTP_METHOD_MISSING_RETENTION_ANNOTATION, new String[0],
httpMethodAnnotation
- .getSourceRange().getLength(), httpMethodAnnotation.getSourceRange().getOffset(),
- httpMethod.getResource(),
JaxrsValidationQuickFixes.HTTP_METHOD_MISSING_RETENTION_ANNOTATION_ID);
+ JaxrsPreferences.HTTP_METHOD_MISSING_RETENTION_ANNOTATION, new String[0],
range.getLength(),
+ range.getOffset(), httpMethod.getResource(),
+ JaxrsValidationQuickFixes.HTTP_METHOD_MISSING_RETENTION_ANNOTATION_ID);
} else {
final String annotationValue = retentionAnnotation.getValue("value");
- if (annotationValue == null ||
!annotationValue.equals(RetentionPolicy.RUNTIME.name())) {
+ if (annotationValue == null) {
+ final ISourceRange range = retentionAnnotation.getJavaAnnotation().getNameRange();
addProblem(JaxrsValidationMessages.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE,
- JaxrsPreferences.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE, new String[0],
- httpMethodAnnotation.getSourceRange().getLength(),
httpMethodAnnotation.getSourceRange()
- .getOffset(), httpMethod.getResource(),
+ JaxrsPreferences.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE, new String[0],
range.getLength(),
+ range.getOffset(), httpMethod.getResource(),
JaxrsValidationQuickFixes.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE_ID);
+ } else if (!annotationValue.equals(RetentionPolicy.RUNTIME.name())) {
+ final ISourceRange range =
JdtUtils.resolveMemberPairValueRange(retentionAnnotation.getJavaAnnotation(),
+ retentionAnnotation.getFullyQualifiedName(), "value");
+ addProblem(JaxrsValidationMessages.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE,
+ JaxrsPreferences.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE, new String[0],
range.getLength(),
+ range.getOffset(), httpMethod.getResource(),
+ JaxrsValidationQuickFixes.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE_ID);
+
}
}
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceMethodValidatorDelegate.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceMethodValidatorDelegate.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceMethodValidatorDelegate.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -16,6 +16,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
import java.util.regex.Pattern;
import org.eclipse.jdt.core.Flags;
@@ -27,6 +28,7 @@
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.jdt.JavaMethodParameter;
+import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
import org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences;
/**
@@ -81,7 +83,7 @@
for (JavaMethodParameter parameter : resourceMethod.getJavaMethodParameters()) {
// Should count parameters annotated with:
// @MatrixParam, @QueryParam, @PathParam, @CookieParam, @HeaderParam, @Context or
@FormParam
- final List<Annotation> jaxrsAnnotations = parameter.getAnnotations();
+ final Map<String, Annotation> jaxrsAnnotations = parameter.getAnnotations();
if (jaxrsAnnotations.size() == 0) {
counter++;
}
@@ -104,15 +106,17 @@
* @return
* @throws JavaModelException
*/
- private void validateNoUnauthorizedContextAnnotationOnJavaMethodParameters(final
JaxrsResourceMethod resourceMethod) {
+ private void validateNoUnauthorizedContextAnnotationOnJavaMethodParameters(final
JaxrsResourceMethod resourceMethod)
+ throws JavaModelException {
for (JavaMethodParameter parameter : resourceMethod.getJavaMethodParameters()) {
final Annotation contextAnnotation = parameter.getAnnotation(CONTEXT.qualifiedName);
final String typeName = parameter.getTypeName();
if (contextAnnotation != null && typeName != null &&
!CONTEXT_TYPE_NAMES.contains(typeName)) {
+ final ISourceRange range = contextAnnotation.getJavaAnnotation().getSourceRange();
addProblem(JaxrsValidationMessages.RESOURCE_METHOD_ILLEGAL_CONTEXT_ANNOTATION,
JaxrsPreferences.RESOURCE_METHOD_ILLEGAL_CONTEXT_ANNOTATION,
- new String[] { CONTEXT_TYPE_NAMES.toString() },
contextAnnotation.getSourceRange().getLength(),
- contextAnnotation.getSourceRange().getOffset(), resourceMethod.getResource());
+ new String[] { CONTEXT_TYPE_NAMES.toString() }, range.getLength(),
+ range.getOffset(), resourceMethod.getResource());
resourceMethod.hasErrors(true);
}
}
@@ -130,6 +134,7 @@
throws JavaModelException {
final List<String> pathParamValueProposals =
resourceMethod.getPathParamValueProposals();
final List<String> pathParamValues = new ArrayList<String>();
+ // retrieve all @Path
for (JavaMethodParameter parameter : resourceMethod.getJavaMethodParameters()) {
final Annotation annotation = parameter.getAnnotation(PATH_PARAM.qualifiedName);
if (annotation != null && annotation.getValue() != null) {
@@ -159,22 +164,24 @@
throws JavaModelException {
final List<String> pathParamValueProposals =
resourceMethod.getPathParamValueProposals();
for (JavaMethodParameter parameter : resourceMethod.getJavaMethodParameters()) {
- final Annotation annotation = parameter.getAnnotation(PATH_PARAM.qualifiedName);
- if (annotation != null) {
- final String pathParamValue = annotation.getValue("value");
+ final Annotation pathParamAnnotation =
parameter.getAnnotation(PATH_PARAM.qualifiedName);
+ if (pathParamAnnotation != null) {
+ final String pathParamValue = pathParamAnnotation.getValue("value");
if (pathParamValue != null) {
if (!pattern.matcher(pathParamValue).matches()) {
- final ISourceRange sourceRange = annotation.getSourceRange();
+ final ISourceRange range =
JdtUtils.resolveMemberPairValueRange(pathParamAnnotation.getJavaAnnotation(),
+ pathParamAnnotation.getFullyQualifiedName(), "value");
addProblem(JaxrsValidationMessages.RESOURCE_METHOD_UNBOUND_PATHPARAM_ANNOTATION_VALUE,
JaxrsPreferences.RESOURCE_METHOD_UNBOUND_PATHPARAM_ANNOTATION_VALUE,
- new String[] { pathParamValue }, sourceRange.getLength(),
sourceRange.getOffset(),
+ new String[] { pathParamValue }, range.getLength(), range.getOffset(),
resourceMethod.getResource());
resourceMethod.hasErrors(true);
} else if (!pathParamValueProposals.contains(pathParamValue)) {
- final ISourceRange sourceRange = annotation.getSourceRange();
+ final ISourceRange range =
JdtUtils.resolveMemberPairValueRange(pathParamAnnotation.getJavaAnnotation(),
+ pathParamAnnotation.getFullyQualifiedName(), "value");
addProblem(JaxrsValidationMessages.RESOURCE_METHOD_UNBOUND_PATHPARAM_ANNOTATION_VALUE,
JaxrsPreferences.RESOURCE_METHOD_UNBOUND_PATHPARAM_ANNOTATION_VALUE,
- new String[] { pathParamValue }, sourceRange.getLength(),
sourceRange.getOffset(),
+ new String[] { pathParamValue }, range.getLength(), range.getOffset(),
resourceMethod.getResource());
resourceMethod.hasErrors(true);
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationMessages.properties
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationMessages.properties 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationMessages.properties 2012-10-12
09:10:19 UTC (rev 44469)
@@ -16,6 +16,6 @@
RESOURCE_METHOD_ILLEGAL_CONTEXT_ANNOTATION=@Context annotation is only allowed on method
parameters of type ''{0}''.
RESOURCE_METHOD_MORE_THAN_ONE_UNANNOTATED_PARAMETER=At most one method parameter may be
declared without any JAX-RS annotation to map the incoming request entity body.
RESOURCE_METHOD_UNBOUND_PATHPARAM_ANNOTATION_VALUE=@PathParam value
''{0}'' does not match any @Path annotation template parameters of the
java method and the enclosing java type.
-RESOURCE_METHOD_UNBOUND_PATH_ANNOTATION_TEMPLATE_PARAMETER=The @Path template parameter
''{0}'' is not bound to any @Path template parameter.
+RESOURCE_METHOD_UNBOUND_PATH_ANNOTATION_TEMPLATE_PARAMETER=The @Path template parameter
''{0}'' is not bound to any method parameter annotated with @PathParam.
RESOURCE_METHOD_INVALID_PATHPARAM_ANNOTATION_VALUE=The @PathParam annotation value
''{0}'' should be alphanumeric.
RESOURCE_METHOD_NO_PUBLIC_MODIFIER=The method ''{0}'' should be public.
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionUtils.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionUtils.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -11,6 +11,7 @@
package org.jboss.tools.ws.jaxrs.core.internal.utils;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -23,19 +24,54 @@
*/
public class CollectionUtils {
- /** Private constructor of the utility class. */
+ /** Private constructor of this utility class. */
private CollectionUtils() {
}
/**
+ * Handy method to initializes a map of String/List of String with the given key/value
pair.
+ *
+ * @param key
+ * the key in the returned map
+ * @param value
+ * the value put in the list value in the returned map
+ * @return a map containing a single entry identified by 'key' and a list of
values, whose only value is the given
+ * value.
+ */
+ public static Map<String, List<String>> toMap(final String key, final String
value) {
+ Map<String, List<String>> map = new HashMap<String,
List<String>>();
+ map.put("value", Arrays.asList(value));
+ return map;
+ }
+
+ /**
+ * Compares the content of the two given maps (using difference and intersection
approaches, based on
+ * <code>equals<code> comparison of each elements in both maps).
+ *
+ * @param control
+ * the 'control' (or 'original') map
+ * @param test
+ * the 'test' (or 'modified') map
+ * @return a structure that indicates the items that were added in the 'test',
removed from 'control' or are in
+ * common in the two maps. In case of the 'itemsInCommon', the returned
items are those of the 'control'
+ * map.
+ */
+ public static <K, V> MapComparison<K, V> compare(Map<K, V> control,
Map<K, V> test) {
+ final Map<K, V> addedItems = CollectionUtils.difference(test, control);
+ final Map<K, V> removedItems = CollectionUtils.difference(control, test);
+ final Map<K, V> itemsInCommon = CollectionUtils.intersection(control, test);
+ return new MapComparison<K, V>(addedItems, itemsInCommon, removedItems);
+ }
+
+ /**
* Compute the difference of elements between the 2 given maps
*
* @param control
* the control collection
* @param test
* the test collection
- * @return the elements of the control map that are not part of the test
- * map. The process works with keys and does not compare the values.
+ * @return the elements of the control map that are not part of the test map. The
process works with keys and does
+ * not compare the values.
*/
public static <K, V> Map<K, V> difference(Map<K, V> control, Map<K,
V> test) {
if (control == null) {
@@ -53,49 +89,66 @@
}
/**
- * Compute the difference of elements between the 2 given collections
+ * Compute the intersection of elements between the 2 given maps
*
* @param control
* the control collection
* @param test
* the test collection
- * @return the elements of the control collection that are not part of the
- * test collection.
+ * @return the elements of the control map that whose keys are part of the test map. The
process works with keys and
+ * does not compare the values.
*/
- public static <T> List<T> difference(Collection<T> control,
Collection<T> test) {
+ public static <K, V> Map<K, V> intersection(Map<K, V> control,
Map<K, V> test) {
if (control == null) {
return null;
}
- List<T> result = new ArrayList<T>(control);
- if (test != null) {
- result.removeAll(test);
+ if (test == null) {
+ return control;
}
+ Collection<K> keys = intersection(control.keySet(), test.keySet());
+ Map<K, V> result = new HashMap<K, V>();
+ for (K key : keys) {
+ result.put(key, control.get(key));
+ }
return result;
}
/**
- * Compute the intersection of elements between the 2 given maps
+ * Compares the content of the two given collections (using difference and intersection
approaches, based on
+ * <code>equals<code> comparison of each elements in both maps).
*
* @param control
+ * the 'control' (or 'original') collection
+ * @param test
+ * the 'test' (or 'modified') collection
+ * @return a structure that indicates the items that were added in the 'test',
removed from 'control' or are in
+ * common in the two collections. In case of the 'itemsInCommon', the
returned items are those of the
+ * 'control' collection.
+ */
+ public static <T> CollectionComparison<T> compare(Collection<T>
control, Collection<T> test) {
+ final Collection<T> addedItems = CollectionUtils.difference(test, control);
+ final Collection<T> removedItems = CollectionUtils.difference(control, test);
+ final Collection<T> itemsInCommon = CollectionUtils.intersection(control, test);
+ return new CollectionComparison<T>(addedItems, itemsInCommon, removedItems);
+ }
+
+ /**
+ * Compute the difference of elements between the 2 given collections
+ *
+ * @param control
* the control collection
* @param test
* the test collection
- * @return the elements of the control map that whose keys are part of the
- * test map. The process works with keys and does not compare the
- * values.
+ * @return the elements of the control collection that are not part of the test
collection.
*/
- public static <K, V> Map<K, V> intersection(Map<K, V> control,
Map<K, V> test) {
+ public static <T> List<T> difference(Collection<T> control,
Collection<T> test) {
if (control == null) {
return null;
}
- if (test == null) {
- return control;
+ List<T> result = new ArrayList<T>(control);
+ if (test != null) {
+ result.removeAll(test);
}
- Collection<K> keys = intersection(control.keySet(), test.keySet());
- Map<K, V> result = new HashMap<K, V>();
- for (K key : keys) {
- result.put(key, control.get(key));
- }
return result;
}
@@ -106,8 +159,7 @@
* the control collection
* @param test
* the test collection
- * @return the elements of the control collection that are not part of the
- * test collection.
+ * @return the elements of the control collection that are also part of the test
collection.
*/
public static <T> Collection<T> intersection(Collection<T> control,
Collection<T> test) {
if (control == null) {
@@ -119,29 +171,105 @@
}
return result;
}
-
+
public static <T> T[] append(T[] sourceArray, T extraElement, T[] targetArray) {
System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);
- targetArray[targetArray.length -1] = extraElement;
+ targetArray[targetArray.length - 1] = extraElement;
return targetArray;
}
-
+
/**
* Returns true if the given source contains the given element, false otherwise
- * @param source the array of elements
- * @param element the element to find in the array
+ *
+ * @param source
+ * the array of elements
+ * @param element
+ * the element to find in the array
* @return true if found, false otherwise
*/
public static <T> boolean contains(T[] source, T element) {
- if(element == null || source == null) {
+ if (element == null || source == null) {
return false;
}
- for(T item : source) {
- if(item.equals(element)) {
+ for (T item : source) {
+ if (item.equals(element)) {
return true;
}
}
return false;
}
+ public static class MapComparison<K, V> {
+
+ private final Map<K, V> addedItems;
+
+ private final Map<K, V> itemsInCommon;
+
+ private final Map<K, V> removedItems;
+
+ MapComparison(final Map<K, V> addedItems, Map<K, V> itemsInCommon,
Map<K, V> removedItems) {
+ this.addedItems = addedItems;
+ this.itemsInCommon = itemsInCommon;
+ this.removedItems = removedItems;
+ }
+
+ /**
+ * @return the items found in the 'test' map, but which were not in the
'control' one.
+ */
+ public Map<K, V> getAddedItems() {
+ return addedItems;
+ }
+
+ /**
+ * @return the items in common, retrieved from the 'control' map.
+ */
+ public Map<K, V> getItemsInCommon() {
+ return itemsInCommon;
+ }
+
+ /**
+ * @return the items that were in the 'control' map, but not in the
'test' map.
+ */
+ public Map<K, V> getRemovedItems() {
+ return removedItems;
+ }
+ }
+
+ public static class CollectionComparison<T> {
+
+ private final Collection<T> addedItems;
+
+ private final Collection<T> itemsInCommon;
+
+ private final Collection<T> removedItems;
+
+ CollectionComparison(final Collection<T> addedItems, Collection<T>
itemsInCommon, Collection<T> removedItems) {
+ this.addedItems = addedItems;
+ this.itemsInCommon = itemsInCommon;
+ this.removedItems = removedItems;
+ }
+
+ /**
+ * @return the items found in the 'test' collection, but which were not in the
'control' one.
+ */
+ public Collection<T> getAddedItems() {
+ return addedItems;
+ }
+
+ /**
+ * @return the items in common, retrieved from the 'control' collection.
+ */
+ public Collection<T> getItemsInCommon() {
+ return itemsInCommon;
+ }
+
+ /**
+ * @return the items that were in the 'control' collection, but not in the
'test' collection.
+ */
+ public Collection<T> getRemovedItems() {
+ return removedItems;
+ }
+
+ }
+
}
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/Comparison.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/Comparison.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/Comparison.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.core.internal.utils;
+
+/**
+ * @author Xavier Coulon
+ *
+ */
+public class Comparison<K, V> {
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/Comparison.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -10,15 +10,24 @@
******************************************************************************/
package org.jboss.tools.ws.jaxrs.core.jdt;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.JavaModelException;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtils;
+/**
+ * Annotation wrapper for IAnnotation on types, fields, methods and method parameters as
well. Annotation wrappers
+ * should follow the same lifecycle as their underlying java elements, which means that
in the particular case of the
+ * ILocalVariable wrapper (java method parameter), the Annotation maybe
destroy/re-created as the ILocalVariable is
+ * re-created, too.
+ *
+ * @author Xavier Coulon
+ *
+ */
public class Annotation {
private final IAnnotation javaAnnotation;
@@ -27,8 +36,6 @@
private final Map<String, List<String>> javaAnnotationElements;
- private ISourceRange sourceRange;
-
/**
* Full constructor
*
@@ -36,15 +43,15 @@
* @param annotationName
* @param annotationElements
* @param sourceRange
+ * @throws JavaModelException
*/
- public Annotation(final IAnnotation annotation, final String annotationName, final
Map<String, List<String>> annotationElements,
- final ISourceRange sourceRange) {
+ public Annotation(final IAnnotation annotation, final String annotationName,
+ final Map<String, List<String>> annotationElements) {
this.javaAnnotation = annotation;
this.javaAnnotationName = annotationName;
this.javaAnnotationElements = new HashMap<String,
List<String>>(annotationElements);
- this.sourceRange = sourceRange;
}
-
+
/**
* Full constructor with a single unnamed 'value'
*
@@ -52,30 +59,27 @@
* @param annotationName
* @param annotationValue
* @param sourceRange
+ * @throws JavaModelException
*/
- public Annotation(final IAnnotation annotation, final String annotationName, final
String annotationValue,
- final ISourceRange sourceRange) {
- this.javaAnnotation = annotation;
- this.javaAnnotationName = annotationName;
- this.javaAnnotationElements = new HashMap<String, List<String>>();
- this.javaAnnotationElements.put("value", Arrays.asList(annotationValue));
- this.sourceRange = sourceRange;
+ public Annotation(final IAnnotation annotation, final String annotationName, final
String annotationValue) {
+ this(annotation, annotationName, CollectionUtils.toMap("value",
annotationValue));
}
- public boolean update(Annotation annotation) {
- assert annotation != null;
-
- if (this.javaAnnotationElements.equals(annotation.getJavaAnnotationElements())) {
+ /**
+ * Update this Annotation from the given other annotation.
+ * @param otherAnnotation
+ * @return true if some updates in the annotation elements (member pair values) were
performed, false otherwise.
+ */
+ public boolean update(final Annotation otherAnnotation) {
+ assert otherAnnotation != null;
+ if (this.javaAnnotationElements.equals(otherAnnotation.getJavaAnnotationElements())) {
return false;
}
this.javaAnnotationElements.clear();
- this.javaAnnotationElements.putAll(annotation.getJavaAnnotationElements());
- if (annotation.getSourceRange() != null) {
- this.sourceRange = annotation.getSourceRange();
- }
+ this.javaAnnotationElements.putAll(otherAnnotation.getJavaAnnotationElements());
return true;
}
-
+
public IAnnotation getJavaAnnotation() {
return javaAnnotation;
}
@@ -84,7 +88,7 @@
return javaAnnotation.getParent();
}
- public String getName() {
+ public String getFullyQualifiedName() {
return javaAnnotationName;
}
@@ -92,10 +96,6 @@
return javaAnnotationElements;
}
- public ISourceRange getSourceRange() {
- return sourceRange;
- }
-
/** @return the value */
public List<String> getValues(final String elementName) {
return javaAnnotationElements.get(elementName);
@@ -112,7 +112,7 @@
}
return null;
}
-
+
/** @return the value */
public String getValue(final String elementName) {
final List<String> values = javaAnnotationElements.get(elementName);
@@ -127,7 +127,6 @@
/*
* (non-Javadoc)
- *
* @see java.lang.Object#toString()
*/
@Override
@@ -137,7 +136,6 @@
/*
* (non-Javadoc)
- *
* @see java.lang.Object#hashCode()
*/
@Override
@@ -152,7 +150,6 @@
/*
* (non-Javadoc)
- *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@@ -184,4 +181,5 @@
return true;
}
+
}
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/BindingUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/BindingUtils.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/BindingUtils.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.core.jdt;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.dom.IAnnotationBinding;
+import org.eclipse.jdt.core.dom.IMemberValuePairBinding;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.IVariableBinding;
+
+/**
+ * @author Xavier Coulon
+ *
+ */
+public class BindingUtils {
+
+ /**
+ * Private constructor for this utility class.
+ */
+ private BindingUtils() {
+ }
+
+ /**
+ * Creates a instance of {@link Annotation} from the given annotation binding.
+ * @param annotationBinding
+ * @return
+ */
+ public static Annotation toAnnotation(final IAnnotationBinding annotationBinding) {
+ return toAnnotation(annotationBinding, (IAnnotation)
annotationBinding.getJavaElement());
+ }
+
+ /**
+ * Creates a instance of {@link Annotation} from the given annotation binding,
specifically using the given javaAnnotation instead of the one that could be retrieved
from the binding.
+ * @param annotationBinding
+ * @param javaAnnotation
+ * @return
+ */
+ public static Annotation toAnnotation(IAnnotationBinding annotationBinding, IAnnotation
javaAnnotation) {
+ final String annotationName =
annotationBinding.getAnnotationType().getQualifiedName();
+ final Map<String, List<String>> annotationElements =
BindingUtils.resolveAnnotationElements(annotationBinding);
+ return new Annotation(javaAnnotation, annotationName, annotationElements);
+ }
+
+
+ public static Map<String, List<String>>
resolveAnnotationElements(IAnnotationBinding annotationBinding) {
+ final Map<String, List<String>> annotationElements = new HashMap<String,
List<String>>();
+ try {
+ for (IMemberValuePairBinding binding : annotationBinding.getAllMemberValuePairs()) {
+ final List<String> values = new ArrayList<String>();
+ if(binding.getValue() != null) {
+ if (binding.getValue() instanceof Object[]) {
+ for (Object v : (Object[]) binding.getValue()) {
+ values.add(toString(v));
+ }
+ } else {
+ values.add(toString(binding.getValue()));
+ }
+ }
+ annotationElements.put(binding.getName(), values);
+ }
+ // if the code is not valid, the underlying DefaultValuePairBinding
+ // may throw a NPE:
+ // at
+ //
org.eclipse.jdt.core.dom.DefaultValuePairBinding.<init>(DefaultValuePairBinding.java:31)
+ // at
+ //
org.eclipse.jdt.core.dom.AnnotationBinding.getAllMemberValuePairs(AnnotationBinding.java:98)
+ } catch (Throwable e) {
+ // silently ignore
+ }
+ return annotationElements;
+ }
+
+ /**
+ * Converts the given value into String. The actual types that are supported are:
+ * java.lang.Class - the ITypeBinding for the class object
+ * java.lang.String - the string value itself
+ * enum type - the IVariableBinding for the enum constant
+ * annotation type - an IAnnotationBinding
+ * for other types, the <code>java.lang.Object{@link #toString()}</code>
method is used.
+ * @param value
+ * @return litteral value
+ */
+ public static String toString(Object value) {
+ if(value instanceof ITypeBinding) {
+ return ((ITypeBinding)value).getQualifiedName();
+ } else if(value instanceof IVariableBinding) {
+ return ((IVariableBinding)value).getName();
+ } else if(value instanceof IAnnotationBinding) {
+ return ((IAnnotationBinding)value).getName();
+ }
+ return value.toString();
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/BindingUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/DOMUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/DOMUtils.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/DOMUtils.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.core.jdt;
+
+import java.util.List;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+
+/**
+ * @author Xavier Coulon Utility class with a few handy methods on ASTNodes
+ */
+public class DOMUtils {
+
+ /**
+ * private constructor for this utility class
+ */
+ private DOMUtils() {
+ }
+
+ /**
+ * Returns true if the given ASTNode's position in the source code matches with the
given position parameter, false
+ * otherwise.
+ *
+ * @param node
+ * @param position
+ * @return
+ */
+ static boolean nodeMatches(ASTNode node, int position) {
+ final int endPosition = node.getStartPosition() + node.getLength();
+ final int startPosition = node.getStartPosition();
+ return startPosition <= position && position <= endPosition;
+ }
+
+ /**
+ * Returns the ASTNode associated with the given java Element expectedType and found at
the given location. This method will
+ * perform faster as the initial parentNode is precisely defined (eg : TypeDeclaration
or MethodDeclaration instead of
+ * CompilationUnit)
+ *
+ * @param compilationUnit
+ * @param elementType
+ * @param position
+ * @return
+ * @see {@link IJavaElement}
+ */
+ //FIXME: this should be part of the visitor.
+ static ASTNode getASTNodeByTypeAndLocation(final ASTNode parentNode, final int
expectedType, final int location) {
+ switch (parentNode.getNodeType()) {
+ case ASTNode.COMPILATION_UNIT:
+ @SuppressWarnings("unchecked")
+ final List<ASTNode> types = ((CompilationUnit) parentNode).types();
+ for (ASTNode type : types) {
+ if (nodeMatches(type, location)) {
+ if (expectedType == IJavaElement.TYPE) {
+ return type;
+ }
+ // could also be ANNOTATION_TYPE_DECLARATION, which doesn't need to trigger
recursive call to this
+ // method.
+ if (type.getNodeType() == CompilationUnit.TYPE_DECLARATION) {
+ return getASTNodeByTypeAndLocation(type, expectedType, location);
+ }
+ }
+ }
+ break;
+ case ASTNode.TYPE_DECLARATION:
+ final FieldDeclaration[] fieldDeclarations = ((TypeDeclaration)
parentNode).getFields();
+ for (FieldDeclaration fieldDeclaration : fieldDeclarations) {
+ if (nodeMatches(fieldDeclaration, location)) {
+ if (expectedType == IJavaElement.FIELD) {
+ return fieldDeclaration;
+ }
+ }
+ }
+ final MethodDeclaration[] methodDeclarations = ((TypeDeclaration)
parentNode).getMethods();
+ for (MethodDeclaration methodDeclaration : methodDeclarations) {
+ if (nodeMatches(methodDeclaration, location)) {
+ if (expectedType == IJavaElement.METHOD) {
+ return methodDeclaration;
+ }
+ return getASTNodeByTypeAndLocation(methodDeclaration, expectedType, location);
+
+ }
+ }
+ return null;
+ case ASTNode.METHOD_DECLARATION:
+ @SuppressWarnings("unchecked")
+ final List<ASTNode> parameters = ((MethodDeclaration) parentNode).parameters();
+ for (ASTNode parameter : parameters) {
+ if (nodeMatches(parameter, location)) {
+ if (expectedType == IJavaElement.LOCAL_VARIABLE) {
+ return parameter;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+
+
+}
\ No newline at end of file
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/DOMUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/EnumJaxrsClassname.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/EnumJaxrsClassname.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/EnumJaxrsClassname.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -81,16 +81,16 @@
public final String qualifiedName;
- public final String annotationName;
+ public final String simpleName;
private EnumJaxrsClassname(final String qualifiedName) {
this.qualifiedName = qualifiedName;
- this.annotationName = null;
+ this.simpleName = null;
}
- private EnumJaxrsClassname(final String qualifiedName, final String annotationName) {
+ private EnumJaxrsClassname(final String qualifiedName, final String simpleName) {
this.qualifiedName = qualifiedName;
- this.annotationName = annotationName;
+ this.simpleName = simpleName;
}
}
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaAnnotationLocator.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaAnnotationLocator.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaAnnotationLocator.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.core.jdt;
+
+import java.util.List;
+
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.IAnnotationBinding;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+
+/**
+ * @author Xavier Coulon
+ *
+ */
+public class JavaAnnotationLocator extends ASTVisitor {
+
+ private final int location;
+ private Annotation locatedAnnotation;
+
+ public JavaAnnotationLocator(final int location) {
+ this.location = location;
+ }
+
+ /**
+ * @return the locatedJavaAnnotation
+ */
+ public Annotation getLocatedAnnotation() {
+ return locatedAnnotation;
+ }
+
+ /**
+ * @see
org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.AnnotationTypeDeclaration)
+ */
+ @Override
+ public boolean visit(AnnotationTypeDeclaration node) {
+ visitExtendedModifiers((List<?>)
node.getStructuralProperty(AnnotationTypeDeclaration.MODIFIERS2_PROPERTY));
+ // no need to visit furthermore
+ return false;
+ }
+
+ /**
+ * @see
org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.FieldDeclaration)
+ */
+ @Override
+ public boolean visit(FieldDeclaration node) {
+ visitExtendedModifiers((List<?>)
node.getStructuralProperty(FieldDeclaration.MODIFIERS2_PROPERTY));
+ // no need to visit furthermore
+ return false;
+ }
+
+ /**
+ * @see
org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodDeclaration)
+ */
+ @Override
+ public boolean visit(MethodDeclaration node) {
+ visitExtendedModifiers((List<?>)
node.getStructuralProperty(MethodDeclaration.MODIFIERS2_PROPERTY));
+ // visit children to look for SingleVariableDeclaration
+ return true;
+ }
+
+ /**
+ * @see
org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TypeDeclaration)
+ */
+ @Override
+ public boolean visit(TypeDeclaration node) {
+ visitExtendedModifiers((List<?>)
node.getStructuralProperty(TypeDeclaration.MODIFIERS2_PROPERTY));
+ // no need to visit furthermore
+ return false;
+ }
+
+ /**
+ * @see
org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SingleVariableDeclaration)
+ */
+ @Override
+ public boolean visit(SingleVariableDeclaration node) {
+ visitExtendedModifiers((List<?>)
node.getStructuralProperty(SingleVariableDeclaration.MODIFIERS2_PROPERTY));
+ // no need to visit furthermore
+ return false;
+ }
+
+ /**
+ * Visits the modifiers.
+ *
+ * @param modifiers
+ * the modifiers
+ */
+ private void visitExtendedModifiers(final List<?> modifiers) {
+ for (Object modifier : modifiers) {
+ if (modifier instanceof org.eclipse.jdt.core.dom.Annotation) {
+ final org.eclipse.jdt.core.dom.Annotation annotation =
(org.eclipse.jdt.core.dom.Annotation) modifier;
+ if (DOMUtils.nodeMatches(annotation, location)) {
+ final IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
+ if (annotationBinding != null) {
+ this.locatedAnnotation = BindingUtils.toAnnotation(annotationBinding);
+ }
+ }
+ }
+ }
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaAnnotationLocator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaAnnotationsVisitor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaAnnotationsVisitor.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaAnnotationsVisitor.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -16,20 +16,14 @@
import java.util.List;
import java.util.Map;
-import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
-import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.SourceRange;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.IAnnotationBinding;
-import org.eclipse.jdt.core.dom.IMemberValuePairBinding;
-import org.eclipse.jdt.core.dom.ITypeBinding;
-import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
@@ -181,20 +175,13 @@
private void visitExtendedModifiers(final List<?> modifiers) {
for (Object modifier : modifiers) {
if (modifier instanceof org.eclipse.jdt.core.dom.Annotation) {
- final org.eclipse.jdt.core.dom.Annotation annotation =
(org.eclipse.jdt.core.dom.Annotation) modifier;
IAnnotationBinding annotationBinding = ((org.eclipse.jdt.core.dom.Annotation)
modifier)
.resolveAnnotationBinding();
if (annotationBinding != null) {
final String qualifiedName =
annotationBinding.getAnnotationType().getQualifiedName();
final String name = annotationBinding.getAnnotationType().getName();
if (annotationNames.contains(qualifiedName) || annotationNames.contains(name)) {
- final String annotationName =
annotationBinding.getAnnotationType().getQualifiedName();
- final Map<String, List<String>> annotationElements =
resolveAnnotationElements(annotationBinding);
- final ISourceRange sourceRange = new SourceRange(annotation.getStartPosition(),
- annotation.getLength());
- final IAnnotation javaAnnotation = (IAnnotation)
annotationBinding.getJavaElement();
- annotations
- .add(new Annotation(javaAnnotation, annotationName, annotationElements,
sourceRange));
+ annotations.add(BindingUtils.toAnnotation(annotationBinding));
}
}
}
@@ -229,56 +216,11 @@
public final Map<String, Annotation> getResolvedAnnotations() throws
JavaModelException {
final Map<String, Annotation> resolvedJavaAnnotations = new HashMap<String,
Annotation>();
for (Annotation annotation : annotations) {
- resolvedJavaAnnotations.put(annotation.getName(), annotation);
+ resolvedJavaAnnotations.put(annotation.getFullyQualifiedName(), annotation);
}
return resolvedJavaAnnotations;
}
- private static Map<String, List<String>>
resolveAnnotationElements(IAnnotationBinding annotationBinding) {
- final Map<String, List<String>> annotationElements = new HashMap<String,
List<String>>();
- try {
- for (IMemberValuePairBinding binding : annotationBinding.getAllMemberValuePairs()) {
- final List<String> values = new ArrayList<String>();
- if (binding.getValue() instanceof Object[]) {
- for (Object v : (Object[]) binding.getValue()) {
- values.add(toString(v));
- }
- } else {
- values.add(toString(binding.getValue()));
- }
- annotationElements.put(binding.getName(), values);
- }
- // if the code is not valid, the underlying DefaultValuePairBinding
- // may throw a NPE:
- // at
- //
org.eclipse.jdt.core.dom.DefaultValuePairBinding.<init>(DefaultValuePairBinding.java:31)
- // at
- //
org.eclipse.jdt.core.dom.AnnotationBinding.getAllMemberValuePairs(AnnotationBinding.java:98)
- } catch (Throwable e) {
- // silently ignore
- }
- return annotationElements;
- }
+
- /**
- * Converts the given value into String. The actual types that are supported are:
- * java.lang.Class - the ITypeBinding for the class object
- * java.lang.String - the string value itself
- * enum type - the IVariableBinding for the enum constant
- * annotation type - an IAnnotationBinding
- * for other types, the <code>java.lang.Object{@link #toString()}</code>
method is used.
- * @param value
- * @return litteral value
- */
- private static String toString(Object value) {
- if(value instanceof ITypeBinding) {
- return ((ITypeBinding)value).getQualifiedName();
- } else if(value instanceof IVariableBinding) {
- return ((IVariableBinding)value).getName();
- } else if(value instanceof IAnnotationBinding) {
- return ((IAnnotationBinding)value).getName();
- }
- return value.toString();
- }
-
}
\ No newline at end of file
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-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodParameter.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -11,49 +11,97 @@
package org.jboss.tools.ws.jaxrs.core.jdt;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
-import org.eclipse.jdt.core.ISourceRange;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtils;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtils.MapComparison;
+/**
+ * Wrapper for a method parameter, exposing its name, type (fully qualified name) and
annotations.
+ * @author Xavier Coulon
+ *
+ */
public class JavaMethodParameter {
+ /** Parameter name (can change, it doesn't matter). */
+ private String name;
+
+ /** Parameter fully qualified type name. */
private final String typeName;
- private final List<Annotation> annotations;
+ /** Parameter annotations, indexed by their fully qualified name. */
+ private final Map<String, Annotation> annotations;
- private final ISourceRange sourceRange;
-
- public JavaMethodParameter(String name, String typeName, List<Annotation>
annotations, final ISourceRange sourceRange) {
+ /**
+ * Full constructor.
+ * @param name
+ * @param typeName
+ * @param annotations
+ */
+ public JavaMethodParameter(final String name, final String typeName, final
List<Annotation> annotations) {
+ this.name = name;
this.typeName = typeName;
- this.annotations = annotations;
- this.sourceRange = sourceRange;
+ this.annotations = new HashMap<String, Annotation>(annotations.size() * 2);
+ for (Annotation annotation : annotations) {
+ this.annotations.put(annotation.getFullyQualifiedName(), annotation);
+ }
}
- /** @return the parameterType */
+ /** @return the parameter name */
+ public String getName() {
+ return this.name;
+ }
+
+ /** @return the parameter fully qualified type name */
public String getTypeName() {
return this.typeName;
}
- public List<Annotation> getAnnotations() {
+ /**
+ * @return all annotations.
+ */
+ public Map<String, Annotation> getAnnotations() {
return annotations;
}
- public Annotation getAnnotation(String name) {
- for (Annotation annotation : annotations) {
- if (annotation.getName().equals(name)) {
- return annotation;
- }
- }
- return null;
+ /**
+ * Return the annotation whose name matches the given fully qualified name
+ * @param fullyQualifiedName
+ * @return the annotation or null if this method parameter has no such annotation.
+ */
+ public Annotation getAnnotation(String fullyQualifiedName) {
+ return annotations.get(fullyQualifiedName);
}
-
+
/**
- * @return the region
+ * Update this method parameter annotations from the given method parameter, including
their location.
+ *
+ * @param otherMethodParameter
*/
- public ISourceRange getRegion() {
- return sourceRange;
+ public boolean updateAnnotations(final JavaMethodParameter otherMethodParameter) {
+ final Map<String, Annotation> otherAnnotations =
otherMethodParameter.getAnnotations();
+ final MapComparison<String, Annotation> comparison =
CollectionUtils.compare(this.annotations, otherAnnotations);
+ boolean changes = false; // track changes. "true" means at least 1 method
parameter changed
+ for (Entry<String, Annotation> entry : comparison.getAddedItems().entrySet()) {
+ this.annotations.put(entry.getKey(), entry.getValue());
+ changes = true;
+ }
+ for (Entry<String, Annotation> entry : comparison.getRemovedItems().entrySet())
{
+ this.annotations.remove(entry.getKey());
+ changes = true;
+ }
+ // update the remaining annotations'location
+ for (Entry<String, Annotation> entry : comparison.getItemsInCommon().entrySet())
{
+ if(this.annotations.get(entry.getKey()).update(otherAnnotations.get(entry.getKey())))
{
+ changes = true;
+ }
+ }
+ return changes;
}
-
+
@Override
public String toString() {
return "ResourceMethodAnnotatedParameter [type=" + typeName + ",
annotations=" + annotations + "]";
@@ -63,9 +111,9 @@
public int hashCode() {
final int prime = 31;
int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((typeName == null) ? 0 : typeName.hashCode());
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;
}
@@ -85,20 +133,9 @@
return false;
}
JavaMethodParameter other = (JavaMethodParameter) obj;
- if (annotations == null) {
- if (other.annotations != null) {
- return false;
- }
- } else if (!annotations.equals(other.annotations)) {
+ if(!this.name.equals(other.name)) {
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;
@@ -106,6 +143,13 @@
} else if (!typeName.equals(other.typeName)) {
return false;
}
+ if (annotations == null) {
+ if (other.annotations != null) {
+ return false;
+ }
+ } else if (!annotations.equals(other.annotations)) {
+ return false;
+ }
return true;
}
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-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignature.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -10,22 +10,31 @@
******************************************************************************/
package org.jboss.tools.ws.jaxrs.core.jdt;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
public class JavaMethodSignature {
+ /** Underlying java method. */
private final IMethod javaMethod;
+ /** Java method return type.*/
private final IType returnedType;
- private final List<JavaMethodParameter> methodParameters;
+ /** Method parameters, indexed by their own name.*/
+ private final Map<String, JavaMethodParameter> methodParameters;
public JavaMethodSignature(IMethod javaMethod, IType returnedType,
List<JavaMethodParameter> methodParameters) {
this.javaMethod = javaMethod;
this.returnedType = returnedType;
- this.methodParameters = methodParameters;
+ this.methodParameters = new HashMap<String,
JavaMethodParameter>(methodParameters.size()*2);
+ for (JavaMethodParameter javaMethodParameter : methodParameters) {
+ this.methodParameters.put(javaMethodParameter.getName(), javaMethodParameter);
+ }
}
/** @return the method */
@@ -33,11 +42,18 @@
return javaMethod;
}
+ /**
+ * @return the java method return type.
+ */
public IType getReturnedType() {
return returnedType;
}
- public List<JavaMethodParameter> getMethodParameters() {
+ /**
+ * The java method parameters.
+ * @return
+ */
+ public Map<String, JavaMethodParameter> getMethodParameters() {
return methodParameters;
}
@@ -50,10 +66,10 @@
stb.append("void ");
}
stb.append(javaMethod.getElementName()).append("(");
- for (Iterator<JavaMethodParameter> paramIterator = methodParameters.iterator();
paramIterator.hasNext();) {
+ for (Iterator<JavaMethodParameter> paramIterator =
methodParameters.values().iterator(); paramIterator.hasNext();) {
JavaMethodParameter methodParam = (JavaMethodParameter) paramIterator.next();
- for (Annotation annotation : methodParam.getAnnotations()) {
- stb.append(annotation).append(" ");
+ for (Entry<String, Annotation> entry : methodParam.getAnnotations().entrySet())
{
+ stb.append(entry.getValue()).append(" ");
}
stb.append(methodParam.getTypeName());
if (paramIterator.hasNext()) {
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-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -11,21 +11,17 @@
package org.jboss.tools.ws.jaxrs.core.jdt;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
+import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.ILocalVariable;
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.jdt.core.SourceRange;
import org.eclipse.jdt.core.dom.ASTVisitor;
-import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.IAnnotationBinding;
-import org.eclipse.jdt.core.dom.IMemberValuePairBinding;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration;
@@ -89,28 +85,23 @@
List<JavaMethodParameter> methodParameters = new
ArrayList<JavaMethodParameter>();
@SuppressWarnings("unchecked")
List<SingleVariableDeclaration> parameters = declaration.parameters();
- for (SingleVariableDeclaration parameter : parameters) {
+ for (int i = 0; i < parameters.size(); i++) {
+ final SingleVariableDeclaration parameter = parameters.get(i);
final String paramName = parameter.getName().getFullyQualifiedName();
final IVariableBinding paramBinding = parameter.resolveBinding();
final String paramTypeName = paramBinding.getType().getQualifiedName();
- final List<org.jboss.tools.ws.jaxrs.core.jdt.Annotation> paramAnnotations =
new ArrayList<org.jboss.tools.ws.jaxrs.core.jdt.Annotation>();
- final List<?> modifiers = (List<?>) (parameter
- .getStructuralProperty(SingleVariableDeclaration.MODIFIERS2_PROPERTY));
- for (Object modifier : modifiers) {
- if (modifier instanceof Annotation) {
- final Annotation annotation = (Annotation) modifier;
- IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
- final String annotationName =
annotationBinding.getAnnotationType().getQualifiedName();
- final Map<String, List<String>> annotationElements =
resolveAnnotationElements(annotationBinding);
- final ISourceRange sourceRange = new SourceRange(annotation.getStartPosition(),
- annotation.getLength());
- paramAnnotations.add(new org.jboss.tools.ws.jaxrs.core.jdt.Annotation(null,
annotationName,
- annotationElements, sourceRange));
- }
+ final List<Annotation> paramAnnotations = new ArrayList<Annotation>();
+ final IAnnotationBinding[] annotationBindings = paramBinding.getAnnotations();
+ for(int j = 0; j < annotationBindings.length; j++) {
+ final ILocalVariable localVariable = method.getParameters()[i];
+ final IAnnotation javaAnnotation = localVariable.getAnnotations()[j];
+ final IAnnotationBinding javaAnnotationBinding = annotationBindings[j];
+ paramAnnotations.add(BindingUtils.toAnnotation(javaAnnotationBinding,
javaAnnotation));
}
- final ISourceRange sourceRange = new SourceRange(parameter.getStartPosition(),
parameter.getLength());
- methodParameters.add(new JavaMethodParameter(paramName, paramTypeName,
paramAnnotations, sourceRange));
+ //final ISourceRange sourceRange = new SourceRange(parameter.getStartPosition(),
parameter.getLength());
+ methodParameters.add(new JavaMethodParameter(paramName, paramTypeName,
paramAnnotations));
}
+
// TODO : add support for thrown exceptions
this.methodSignatures.add(new JavaMethodSignature(method, returnedType,
methodParameters));
@@ -133,24 +124,6 @@
return null;
}
- private static Map<String, List<String>>
resolveAnnotationElements(IAnnotationBinding annotationBinding) {
- final Map<String, List<String>> annotationElements = new HashMap<String,
List<String>>();
- for (IMemberValuePairBinding binding : annotationBinding.getAllMemberValuePairs()) {
- final List<String> values = new ArrayList<String>();
- if(binding.getValue() != null) {
- if (binding.getValue() instanceof Object[]) {
- for (Object v : (Object[]) binding.getValue()) {
- values.add(v.toString());
- }
- } else {
- values.add(binding.getValue().toString());
- }
- }
- annotationElements.put(binding.getName(), values);
- }
- return annotationElements;
- }
-
/** @return the methodDeclarations */
public JavaMethodSignature getMethodSignature() {
if (this.methodSignatures.size() == 0) {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -35,11 +35,13 @@
import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeHierarchy;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.ITypeBinding;
@@ -283,10 +285,9 @@
throws JavaModelException {
if (member.isBinary()) {
IAnnotatable javaElement = (IAnnotatable) member;
- final IAnnotation annotation = javaElement.getAnnotation(annotationName);
- if (annotation != null && annotation.exists()) {
- return new Annotation(annotation, annotation.getElementName(),
resolveAnnotationElements(annotation),
- null);
+ final IAnnotation javaAnnotation = javaElement.getAnnotation(annotationName);
+ if (javaAnnotation != null && javaAnnotation.exists()) {
+ return new Annotation(javaAnnotation, javaAnnotation.getElementName(),
resolveAnnotationElements(javaAnnotation));
}
return null;
}
@@ -330,10 +331,10 @@
IAnnotatable javaElement = (IAnnotatable) member;
final Map<String, Annotation> annotations = new HashMap<String,
Annotation>();
for (String annotationName : annotationNames) {
- final IAnnotation annotation = javaElement.getAnnotation(annotationName);
- if (annotation.exists()) {
- annotations.put(annotationName, new Annotation(annotation,
annotation.getElementName(),
- resolveAnnotationElements(annotation), null));
+ final IAnnotation javaAnnotation = javaElement.getAnnotation(annotationName);
+ if (javaAnnotation.exists()) {
+ annotations.put(annotationName, new Annotation(javaAnnotation,
javaAnnotation.getElementName(),
+ resolveAnnotationElements(javaAnnotation)));
}
}
return annotations;
@@ -353,29 +354,60 @@
* @return
* @throws JavaModelException
*/
- public static Annotation resolveAnnotation(IMember member, CompilationUnit ast,
Class<?> annotationClass)
+ public static Annotation resolveAnnotation(final IAnnotation javaAnnotation, final
CompilationUnit ast)
throws JavaModelException {
- return resolveAnnotation(member, ast, annotationClass.getName());
- }
-
- /**
- * Resolves the annotation given its type.
- *
- * @param type
- * @param ast
- * @param annotationClass
- * @return
- * @throws JavaModelException
- */
- public static Annotation resolveAnnotation(IAnnotation javaAnnotation, CompilationUnit
ast)
- throws JavaModelException {
if (javaAnnotation.getParent() instanceof IMember) {
return resolveAnnotation((IMember) javaAnnotation.getParent(), ast,
javaAnnotation.getElementName());
}
return null;
}
+
+ /**
+ * Locates the annotation located at the given position in the compilation unit, with a
hint on the search scope provided by the given eponym parameter.
+ * @param location
+ * @param scope
+ * @return the {@link IAnnotation} or null if the element at the given location is not
an IJavaAnnotation
+ * @throws JavaModelException
+ */
+ public static Annotation resolveAnnotationAt(final int location, final ICompilationUnit
compilationUnit) throws JavaModelException {
+ final CompilationUnit ast =
CompilationUnitsRepository.getInstance().getAST(compilationUnit);
+ if (ast != null) {
+ final IJavaElement element = compilationUnit.getElementAt(location);
+ final ASTNode astChildNode = DOMUtils.getASTNodeByTypeAndLocation(ast,
element.getElementType(), location);
+ if (astChildNode != null) {
+ final JavaAnnotationLocator annotationLocator = new JavaAnnotationLocator(location);
+ astChildNode.accept(annotationLocator);
+ return annotationLocator.getLocatedAnnotation();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the source range for the MemberValuePair whose name is the given memberName,
in the given annotation.
+ * @param annotation
+ * @param memberName
+ * @return the sourceRange or null if it could not be evaluated.
+ * @throws JavaModelException
+ */
+ public static ISourceRange resolveMemberPairValueRange(final IAnnotation annotation,
final String annotationQualifiedName,
+ final String memberName) throws JavaModelException {
+ final IType ancestor = (IType) annotation.getAncestor(IJavaElement.TYPE);
+ if(ancestor != null && ancestor.exists()) {
+ final ICompilationUnit compilationUnit = ancestor.getCompilationUnit();
+ final CompilationUnit ast =
CompilationUnitsRepository.getInstance().getAST(compilationUnit);
+ if (ast != null) {
+ MemberValuePairLocationRetriever locationRetriever = new
MemberValuePairLocationRetriever(annotation,
+ annotationQualifiedName, memberName);
+ ast.accept(locationRetriever);
+ return locationRetriever.getMemberValuePairSourceRange();
+ }
+ }
+ return null;
+ }
+
private static Map<String, List<String>>
resolveAnnotationElements(IAnnotation annotation)
throws JavaModelException {
final Map<String, List<String>> annotationElements = new HashMap<String,
List<String>>();
@@ -614,6 +646,5 @@
}
-
}
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/MemberValuePairLocationRetriever.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/MemberValuePairLocationRetriever.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/MemberValuePairLocationRetriever.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.core.jdt;
+
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.SourceRange;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
+import org.eclipse.jdt.core.dom.IAnnotationBinding;
+import org.eclipse.jdt.core.dom.MemberValuePair;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.NormalAnnotation;
+import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+
+/**
+ * Visitor that will "visit" an ASTNode and its children until it finds the
expected MemberValue pair to retain its
+ * location in the compilation unit source code
+ *
+ * @author Xavier Coulon
+ */
+public class MemberValuePairLocationRetriever extends ASTVisitor {
+
+ private final IAnnotation javaAnnotation;
+ private final String annotationName;
+ private final String memberName;
+
+ private ISourceRange locatedSourceRange = null;
+
+ /**
+ * Constructor
+ */
+ public MemberValuePairLocationRetriever(final IAnnotation javaAnnotation, final String
annotationName,
+ final String memberName) {
+ this.javaAnnotation = javaAnnotation;
+ this.annotationName = annotationName;
+ this.memberName = memberName;
+ }
+
+ public ISourceRange getMemberValuePairSourceRange() {
+ return locatedSourceRange;
+ }
+
+ /**
+ * @see
org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TypeDeclaration)
+ */
+ @Override
+ public boolean visit(AnnotationTypeDeclaration node) {
+ final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.TYPE);
+ if(ancestor != null && ancestor.exists() &&
ancestor.getElementName().equals(node.getName().getFullyQualifiedName())) {
+ // keep searching
+ return true;
+ }
+ // wrong path, stop searching from this branch of the AST
+ return false;
+ }
+
+ /**
+ * @see
org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TypeDeclaration)
+ */
+ @Override
+ public boolean visit(TypeDeclaration node) {
+ final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.TYPE);
+ if(ancestor != null && ancestor.exists() &&
ancestor.getElementName().equals(node.getName().getFullyQualifiedName())) {
+ // keep searching
+ return true;
+ }
+ // wrong path, stop searching from this branch of the AST
+ return false;
+ }
+
+ /**
+ * @see
org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.FieldDeclaration)
+ */
+ @Override
+ public boolean visit(VariableDeclarationFragment node) {
+ final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.FIELD);
+ if(ancestor != null && ancestor.exists() &&
ancestor.getElementName().equals(node.getName().getFullyQualifiedName())) {
+ // keep searching
+ return true;
+ }
+ // wrong path, stop searching from this branch of the AST
+ return false;
+ }
+
+ /**
+ * @see
org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodInvocation)
+ */
+ @Override
+ public boolean visit(MethodDeclaration node) {
+ final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.METHOD);
+ if(ancestor != null && ancestor.exists() &&
ancestor.getElementName().equals(node.getName().getFullyQualifiedName())) {
+ // keep searching
+ return true;
+ }
+ // wrong path, stop searching from this branch of the AST
+ return false;
+ }
+
+ /**
+ * @see
org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SingleMemberAnnotation)
+ */
+ @Override
+ public boolean visit(SingleMemberAnnotation node) {
+ final IAnnotationBinding annotationBinding = node.resolveAnnotationBinding();
+ if (annotationBinding != null) {
+ final String nodeName = annotationBinding.getAnnotationType().getQualifiedName();
+ if (nodeName.equals(this.annotationName)) {
+ this.locatedSourceRange = new SourceRange(node.getValue().getStartPosition(),
node.getValue()
+ .getLength());
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @see
org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.NormalAnnotation)
+ */
+ @Override
+ public boolean visit(NormalAnnotation node) {
+ final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.ANNOTATION);
+ if(ancestor != null && ancestor.exists() &&
ancestor.getElementName().equals(node.getTypeName().getFullyQualifiedName())) {
+ // keep searching
+ return true;
+ }
+ // wrong path, stop searching from this branch of the AST
+ return false;
+ }
+
+ /**
+ * @see
org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MemberValuePair)
+ */
+ @Override
+ public boolean visit(MemberValuePair node) {
+ if (node.getName().getFullyQualifiedName().equals(memberName)) {
+ this.locatedSourceRange = new SourceRange(node.getStartPosition(), node.getLength());
+ }
+ // no need to drill down from here anyway
+ return false;
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/MemberValuePairLocationRetriever.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsResourceMethod.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsResourceMethod.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsResourceMethod.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -28,9 +28,9 @@
* @param h
* : true if the java element has errors, false otherwise
*/
- public abstract void hasErrors(final boolean h);
+ abstract void hasErrors(final boolean h);
- public abstract EnumElementKind getElementKind();
+ abstract EnumElementKind getElementKind();
abstract String getPathTemplate();
@@ -40,7 +40,7 @@
abstract List<String> getProducedMediaTypes();
- List<JavaMethodParameter> getJavaMethodParameters();
+ abstract List<JavaMethodParameter> getJavaMethodParameters();
/**
* Determines the proposals for the PathParam annotated method parameters of
@@ -49,8 +49,8 @@
*
* @return
*/
- List<String> getPathParamValueProposals();
+ abstract List<String> getPathParamValueProposals();
- boolean hasPathTemplate();
+ abstract boolean hasPathTemplate();
}
\ No newline at end of file
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-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/PathParamAnnotationValueCompletionProposalComputer.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -19,10 +19,9 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
-import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.ui.text.IJavaPartitions;
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
@@ -37,7 +36,7 @@
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.swt.graphics.Image;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
-import org.jboss.tools.ws.jaxrs.core.jdt.JavaMethodParameter;
+import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsMetamodel;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
import org.jboss.tools.ws.jaxrs.core.metamodel.JaxrsMetamodelLocator;
@@ -76,29 +75,40 @@
if (metamodel == null) {
return Collections.emptyList();
}
- IJavaElement invocationElement = javaContext.getCompilationUnit().getElementAt(
- context.getInvocationOffset());
- // ICompilationUnit.getElementAt(int) method may return null
- if (invocationElement != null && invocationElement.getElementType() ==
IJavaElement.METHOD) {
- IJaxrsResourceMethod resourceMethod = metamodel.getElement(invocationElement,
+// final IJavaElement invocationElement =
javaContext.getCompilationUnit().getElementAt(
+// context.getInvocationOffset());
+//
+// // ICompilationUnit.getElementAt(int) method may return null
+// if (invocationElement != null && invocationElement.getElementType() ==
IJavaElement.METHOD) {
+// 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().values()) {
+// final ISourceRange range = annotation.getSourceRange();
+// if (annotation.getFullyQualifiedName().equals(PATH_PARAM.qualifiedName)
&& range != null
+// && context.getInvocationOffset() >= range.getOffset()
+// && context.getInvocationOffset() < (range.getOffset() +
range.getLength())) {
+// // completion proposal on @PathParam method
+// // annotation
+// return internalComputePathParamProposals(javaContext, resourceMethod);
+// }
+//
+// }
+// }
+// }
+// }
+
+ final int invocationOffset = context.getInvocationOffset();
+ final ICompilationUnit compilationUnit = javaContext.getCompilationUnit();
+ final Annotation annotation = JdtUtils.resolveAnnotationAt(invocationOffset,
compilationUnit);
+ if(annotation != null &&
annotation.getFullyQualifiedName().equals(PATH_PARAM.qualifiedName)) {
+ final IJaxrsResourceMethod resourceMethod =
metamodel.getElement(annotation.getJavaParent(),
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 ISourceRange range = annotation.getSourceRange();
- if (annotation.getName().equals(PATH_PARAM.qualifiedName) && range !=
null
- && context.getInvocationOffset() >= range.getOffset()
- && context.getInvocationOffset() < (range.getOffset() +
range.getLength())) {
- // completion proposal on @PathParam method
- // annotation
- return internalComputePathParamProposals(javaContext, annotation,
resourceMethod);
- }
-
- }
- }
- }
+ return internalComputePathParamProposals(javaContext, resourceMethod);
}
+
} catch (Exception e) {
Logger.error("Failed to compute completion proposal", e);
}
@@ -127,8 +137,8 @@
* @throws org.eclipse.jface.text.BadLocationException
*/
private List<ICompletionProposal> internalComputePathParamProposals(
- final JavaContentAssistInvocationContext javaContext, final Annotation
pathParamAnnotation,
- final IJaxrsResourceMethod resourceMethod) throws CoreException, BadLocationException
{
+ final JavaContentAssistInvocationContext javaContext, final IJaxrsResourceMethod
resourceMethod)
+ throws CoreException, BadLocationException {
final List<ICompletionProposal> completionProposals = new
ArrayList<ICompletionProposal>();
final ITypedRegion region = getRegion(javaContext);
String matchValue = javaContext.getDocument().get(region.getOffset(),
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsValidatorConfigurationBlock.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsValidatorConfigurationBlock.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsValidatorConfigurationBlock.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -60,7 +60,6 @@
return WRONG_BUILDER_ORDER_KEY;
}
- @SuppressWarnings("restriction")
public JaxrsValidatorConfigurationBlock(IStatusChangeListener context,
IProject project, IWorkbenchPreferenceContainer container) {
super(context, project, getKeys(), container);
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/AddRetentionAnnotationMarkerResolution.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/AddRetentionAnnotationMarkerResolution.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/AddRetentionAnnotationMarkerResolution.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.ui.quickfix;
+
+
+import java.lang.annotation.RetentionPolicy;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.refactoring.CompilationUnitChange;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.jboss.tools.common.refactoring.BaseMarkerResolution;
+import org.jboss.tools.common.refactoring.MarkerResolutionUtils;
+import org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname;
+import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
+
+/**
+ * @author Xavier Coulon
+ *
+ */
+public class AddRetentionAnnotationMarkerResolution extends BaseMarkerResolution {
+
+ private final IType type;
+
+ public AddRetentionAnnotationMarkerResolution(IType type){
+ super(type.getCompilationUnit());
+ this.type = type;
+ label =
NLS.bind(JaxrsQuickFixMessages.ADD_RETENTION_ANNOTATION_MARKER_RESOLUTION_TITLE,
type.getElementName());
+ init();
+ }
+
+ @Override
+ protected CompilationUnitChange getChange(ICompilationUnit compilationUnit){
+ CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+ MultiTextEdit edit = new MultiTextEdit();
+ change.setEdit(edit);
+ try{
+ MarkerResolutionUtils.addImport(EnumJaxrsClassname.RETENTION.qualifiedName,
compilationUnit, edit);
+ MarkerResolutionUtils.addImport(RetentionPolicy.class.getName(), compilationUnit,
edit);
+ MarkerResolutionUtils.addAnnotation(EnumJaxrsClassname.RETENTION.simpleName,
compilationUnit, type, "(RetentionPolicy.RUNTIME)", edit);
+ } catch (JavaModelException e) {
+ Logger.error("Failed to add @Retention annotation on type " +
type.getFullyQualifiedName(), e);
+ }
+ return change;
+ }
+
+ @Override
+ public Image getImage() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/AddRetentionAnnotationMarkerResolution.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/AddTargetAnnotationMarkerResolution.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/AddTargetAnnotationMarkerResolution.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/AddTargetAnnotationMarkerResolution.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -48,7 +48,7 @@
try{
MarkerResolutionUtils.addImport(EnumJaxrsClassname.TARGET.qualifiedName,
compilationUnit, edit);
MarkerResolutionUtils.addImport(ElementType.class.getName(), compilationUnit, edit);
- MarkerResolutionUtils.addAnnotation(EnumJaxrsClassname.TARGET.annotationName,
compilationUnit, type, "(ElementType.METHOD)", edit);
+ MarkerResolutionUtils.addAnnotation(EnumJaxrsClassname.TARGET.simpleName,
compilationUnit, type, "(ElementType.METHOD)", edit);
} catch (JavaModelException e) {
Logger.error("Failed to add @Target annotation on type " +
type.getFullyQualifiedName(), e);
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/JaxrsMarkerResolutionGenerator.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/JaxrsMarkerResolutionGenerator.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/JaxrsMarkerResolutionGenerator.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -1,4 +1,4 @@
-package org.jboss.tools.ws.jaxrs.ui.quickfix;
+ package org.jboss.tools.ws.jaxrs.ui.quickfix;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
@@ -35,13 +35,19 @@
private IMarkerResolution[] getMarkerResolutions(final IMarker marker) {
try {
final int quickfixId = getQuickFixID(marker);
- switch (quickfixId) {
- case JaxrsValidationQuickFixes.HTTP_METHOD_MISSING_TARGET_ANNOTATION_ID:
- final ICompilationUnit compilationUnit =
JdtUtils.getCompilationUnit(marker.getResource());
- final IType type = (IType) JdtUtils.getElementAt(compilationUnit,
- marker.getAttribute(IMarker.CHAR_START, 0), IJavaElement.TYPE);
- if (type != null) {
+ final ICompilationUnit compilationUnit =
JdtUtils.getCompilationUnit(marker.getResource());
+ final IType type = (IType) JdtUtils.getElementAt(compilationUnit,
+ marker.getAttribute(IMarker.CHAR_START, 0), IJavaElement.TYPE);
+ if (type != null) {
+ switch (quickfixId) {
+ case JaxrsValidationQuickFixes.HTTP_METHOD_MISSING_TARGET_ANNOTATION_ID:
return new IMarkerResolution[] { new AddTargetAnnotationMarkerResolution(type) };
+ case JaxrsValidationQuickFixes.HTTP_METHOD_MISSING_RETENTION_ANNOTATION_ID:
+ return new IMarkerResolution[] { new AddRetentionAnnotationMarkerResolution(type)
};
+ case JaxrsValidationQuickFixes.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE_ID:
+ return new IMarkerResolution[] { new
UpdateTargetAnnotationValueMarkerResolution(type) };
+ case JaxrsValidationQuickFixes.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE_ID:
+ return new IMarkerResolution[] { new
UpdateRetentionAnnotationValueMarkerResolution(type) };
}
}
} catch (CoreException e) {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/JaxrsQuickFixMessages.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/JaxrsQuickFixMessages.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/JaxrsQuickFixMessages.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -22,6 +22,12 @@
public static String ADD_TARGET_ANNOTATION_MARKER_RESOLUTION_TITLE;
+ public static String ADD_RETENTION_ANNOTATION_MARKER_RESOLUTION_TITLE;
+
+ public static String UPDATE_TARGET_ANNOTATION_VALUE_MARKER_RESOLUTION_TITLE;
+
+ public static String UPDATE_RETENTION_ANNOTATION_VALUE_MARKER_RESOLUTION_TITLE;
+
static {
NLS.initializeMessages(BUNDLE_NAME, JaxrsQuickFixMessages.class);
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/JaxrsQuickFixMessages.properties
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/JaxrsQuickFixMessages.properties 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/JaxrsQuickFixMessages.properties 2012-10-12
09:10:19 UTC (rev 44469)
@@ -9,4 +9,7 @@
### Red Hat, Inc. - initial API and implementation
##################################################################################
-ADD_TARGET_ANNOTATION_MARKER_RESOLUTION_TITLE=Add @Target annotation on type {0}
\ No newline at end of file
+ADD_TARGET_ANNOTATION_MARKER_RESOLUTION_TITLE=Add @Target annotation on type {0}
+ADD_RETENTION_ANNOTATION_MARKER_RESOLUTION_TITLE=Add @Retention annotation on type {0}
+UPDATE_TARGET_ANNOTATION_VALUE_MARKER_RESOLUTION_TITLE=Set @Target annotation value to
'ElementType.METHOD' on type {0}
+UPDATE_RETENTION_ANNOTATION_VALUE_MARKER_RESOLUTION_TITLE=Set @Retention annotation value
to 'RetentionPolicy.RUNTIME' on type {0}
\ No newline at end of file
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/UpdateRetentionAnnotationValueMarkerResolution.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/UpdateRetentionAnnotationValueMarkerResolution.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/UpdateRetentionAnnotationValueMarkerResolution.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.ui.quickfix;
+
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.refactoring.CompilationUnitChange;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.jboss.tools.common.refactoring.BaseMarkerResolution;
+import org.jboss.tools.common.refactoring.MarkerResolutionUtils;
+import org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname;
+import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
+
+/**
+ * @author Xavier Coulon
+ *
+ */
+public class UpdateRetentionAnnotationValueMarkerResolution extends BaseMarkerResolution
{
+
+ private final IType type;
+
+ public UpdateRetentionAnnotationValueMarkerResolution(IType type){
+ super(type.getCompilationUnit());
+ this.type = type;
+ label =
NLS.bind(JaxrsQuickFixMessages.UPDATE_RETENTION_ANNOTATION_VALUE_MARKER_RESOLUTION_TITLE,
type.getElementName());
+ init();
+ }
+
+ @Override
+ protected CompilationUnitChange getChange(ICompilationUnit compilationUnit){
+ CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+ MultiTextEdit edit = new MultiTextEdit();
+ change.setEdit(edit);
+ try{
+ MarkerResolutionUtils.updateAnnotation(EnumJaxrsClassname.RETENTION.simpleName,
compilationUnit, type, "(ElementType.METHOD)", edit);
+ } catch (JavaModelException e) {
+ Logger.error("Failed to add @Retention annotation on type " +
type.getFullyQualifiedName(), e);
+ }
+ return change;
+ }
+
+ @Override
+ public Image getImage() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/UpdateRetentionAnnotationValueMarkerResolution.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/UpdateTargetAnnotationValueMarkerResolution.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/UpdateTargetAnnotationValueMarkerResolution.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/UpdateTargetAnnotationValueMarkerResolution.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.ui.quickfix;
+
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.refactoring.CompilationUnitChange;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.jboss.tools.common.refactoring.BaseMarkerResolution;
+import org.jboss.tools.common.refactoring.MarkerResolutionUtils;
+import org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname;
+import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
+
+/**
+ * @author Xavier Coulon
+ *
+ */
+public class UpdateTargetAnnotationValueMarkerResolution extends BaseMarkerResolution {
+
+ private final IType type;
+
+ public UpdateTargetAnnotationValueMarkerResolution(IType type){
+ super(type.getCompilationUnit());
+ this.type = type;
+ label = NLS.bind(JaxrsQuickFixMessages.ADD_TARGET_ANNOTATION_MARKER_RESOLUTION_TITLE,
type.getElementName());
+ init();
+ }
+
+ @Override
+ protected CompilationUnitChange getChange(ICompilationUnit compilationUnit){
+ CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+ MultiTextEdit edit = new MultiTextEdit();
+ change.setEdit(edit);
+ try{
+ MarkerResolutionUtils.updateAnnotation(EnumJaxrsClassname.TARGET.simpleName,
compilationUnit, type, "(ElementType.METHOD)", edit);
+ } catch (JavaModelException e) {
+ Logger.error("Failed to add @Target annotation on type " +
type.getFullyQualifiedName(), e);
+ }
+ return change;
+ }
+
+ @Override
+ public Image getImage() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/quickfix/UpdateTargetAnnotationValueMarkerResolution.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/BarResource.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/BarResource.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/BarResource.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -56,7 +56,7 @@
@PUT
@Path("{param2}")
public Response update3(@Context HttpServletRequest requestContext,
- @PathParam("param1") String param2,
+ @PathParam("param1") String param1,
@PathParam("param2") String param2,
String bar, String foo) throws Exception {
return null;
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/CustomerResource.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/CustomerResource.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/CustomerResource.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -24,7 +24,7 @@
import org.jboss.tools.ws.jaxrs.sample.domain.Customer;
@Encoded
-(a)Path(CustomerResource.URI_BASE)
+(a)Path(value=CustomerResource.URI_BASE) // leave as-is: this form is required by a test
@Consumes(MediaType.APPLICATION_XML)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@SuppressWarnings("foo") // keep this for tests
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -56,6 +56,7 @@
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.ILocalVariable;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IOpenable;
@@ -444,6 +445,29 @@
return null;
}
+ public static ILocalVariable getLocalVariable(IMethod method, String variableName)
throws JavaModelException {
+ for (ILocalVariable param : method.getParameters()) {
+ if (param.getElementName().equals(variableName)) {
+ return param;
+ }
+ }
+ Assert.fail("Failed to locate method parameter named '" + variableName +
"'");
+ return null;
+ }
+
+
+
+ public static IField getField(IType type, String fieldName) throws JavaModelException {
+ for (IField field : type.getFields()) {
+ if (field.getElementName().equals(fieldName)) {
+ return field;
+ }
+ }
+ Assert.fail("Failed to locate method named '" + fieldName +
"'");
+ return null;
+ }
+
+
public static IAnnotation addMethodAnnotation(IMethod method, String annotationStmt,
boolean useWorkingCopy)
throws JavaModelException {
ICompilationUnit compilationUnit = method.getCompilationUnit();
@@ -837,7 +861,7 @@
return found;
}
- public static Annotation getAnnotation(final IMember member, final String
annotationName)
+ public static Annotation resolveAnnotation(final IMember member, final String
annotationName)
throws JavaModelException {
if (annotationName == null) {
return null;
@@ -851,7 +875,7 @@
Map<String, List<String>> elements = new HashMap<String,
List<String>>();
elements.put("value", Arrays.asList(values));
- annotation.update(new Annotation(annotation.getJavaAnnotation(), annotation.getName(),
elements, null));
+ annotation.update(new Annotation(annotation.getJavaAnnotation(),
annotation.getFullyQualifiedName(), elements));
return annotation;
}
@@ -969,4 +993,5 @@
}
}
+
}
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-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessorTestCase.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -12,19 +12,22 @@
import static org.eclipse.jdt.core.IJavaElementDelta.ADDED;
import static org.eclipse.jdt.core.IJavaElementDelta.CHANGED;
+import static org.eclipse.jdt.core.IJavaElementDelta.F_CHILDREN;
import static org.eclipse.jdt.core.IJavaElementDelta.REMOVED;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.everyItem;
+import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
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.WorkbenchUtils.getMethod;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getType;
+import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.resolveAnnotation;
import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.IJavaElementDeltaFlag.F_SIGNATURE;
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_ELEMENT_KIND;
+import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.F_FINE_GRAINED;
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_METHOD_PARAMETERS;
import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.F_METHOD_RETURN_TYPE;
@@ -71,6 +74,7 @@
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.hamcrest.Matchers;
@@ -78,6 +82,7 @@
import org.jboss.tools.ws.jaxrs.core.JBossJaxrsCorePlugin;
import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBaseElement;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsElementFactory;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsHttpMethod;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsJavaApplication;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
@@ -85,6 +90,7 @@
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResourceField;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResourceMethod;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
+import org.jboss.tools.ws.jaxrs.core.jdt.CompilationUnitsRepository;
import org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname;
import org.jboss.tools.ws.jaxrs.core.jdt.JavaMethodParameter;
import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
@@ -116,6 +122,7 @@
metamodel = spy(JaxrsMetamodel.create(javaProject));
// replace the normal metamodel instance with the one spied by Mockito
javaProject.getProject().setSessionProperty(JaxrsMetamodel.METAMODEL_QUALIFIED_NAME,
metamodel);
+ CompilationUnitsRepository.getInstance().clear();
}
/**
@@ -123,10 +130,13 @@
* @throws CoreException
* @throws JavaModelException
*/
- private JaxrsHttpMethod createHttpMethod(EnumJaxrsClassname httpMethodElement) throws
CoreException, JavaModelException {
- final IType httpMethodType = JdtUtils.resolveType(httpMethodElement.qualifiedName,
javaProject, progressMonitor);
- final Annotation httpMethodAnnotation = getAnnotation(httpMethodType,
HTTP_METHOD.qualifiedName);
- final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(httpMethodType,
metamodel).httpMethod(httpMethodAnnotation).build();
+ private JaxrsHttpMethod createHttpMethod(EnumJaxrsClassname httpMethodElement) throws
CoreException,
+ JavaModelException {
+ final IType httpMethodType = JdtUtils
+ .resolveType(httpMethodElement.qualifiedName, javaProject, progressMonitor);
+ final Annotation httpMethodAnnotation = resolveAnnotation(httpMethodType,
HTTP_METHOD.qualifiedName);
+ final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(httpMethodType,
metamodel).httpMethod(
+ httpMethodAnnotation).build();
return httpMethod;
}
@@ -137,12 +147,13 @@
private Annotation createAnnotation(IAnnotation annotation, String name, String value)
{
Map<String, List<String>> values = new HashMap<String,
List<String>>();
values.put("value", Arrays.asList(value));
- return new Annotation(annotation, name, values, null);
+ return new Annotation(annotation, name, values);
}
private List<JaxrsElementDelta> processEvent(JavaElementDelta event,
IProgressMonitor progressmonitor) {
- final List<JaxrsMetamodelDelta> affectedMetamodels =
processor.processAffectedJavaElements(Arrays.asList(event), progressmonitor);
- if(affectedMetamodels.isEmpty()) {
+ final List<JaxrsMetamodelDelta> affectedMetamodels =
processor.processAffectedJavaElements(
+ Arrays.asList(event), progressmonitor);
+ if (affectedMetamodels.isEmpty()) {
return Collections.emptyList();
}
return affectedMetamodels.get(0).getAffectedElements();
@@ -157,10 +168,8 @@
return createEvent(element, deltaKind, NO_FLAG);
}
- private static JavaElementDelta createEvent(IMember element, int deltaKind, int flags)
- throws JavaModelException {
- return new JavaElementDelta(element, deltaKind, ANY_EVENT_TYPE,
- JdtUtils.parse(element, progressMonitor), flags);
+ private static JavaElementDelta createEvent(IMember element, int deltaKind, int flags)
throws JavaModelException {
+ return new JavaElementDelta(element, deltaKind, ANY_EVENT_TYPE, JdtUtils.parse(element,
progressMonitor), flags);
}
private static JavaElementDelta createEvent(ICompilationUnit element, int deltaKind)
@@ -169,6 +178,12 @@
JdtUtils.parse(element, progressMonitor), NO_FLAG);
}
+ private static JavaElementDelta createEvent(ICompilationUnit element, int deltaKind, int
flags)
+ throws JavaModelException {
+ return new JavaElementDelta(element, deltaKind, ANY_EVENT_TYPE,
+ JdtUtils.parse(element, progressMonitor), flags);
+ }
+
private static JavaElementDelta createEvent(IPackageFragmentRoot element, int
deltaKind)
throws JavaModelException {
return new JavaElementDelta(element, deltaKind, ANY_EVENT_TYPE, null, NO_FLAG);
@@ -255,7 +270,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, APPLICATION_PATH.qualifiedName);
// operation
final JavaElementDelta event = createEvent(annotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -273,10 +288,10 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation appPathAnnotation = getAnnotation(type,
APPLICATION_PATH.qualifiedName);
+ final Annotation appPathAnnotation = resolveAnnotation(type,
APPLICATION_PATH.qualifiedName);
final JaxrsJavaApplication application = new JaxrsJavaApplication(type,
appPathAnnotation, true, metamodel);
metamodel.add(application);
- final Annotation suppressWarningAnnotation = getAnnotation(type,
SuppressWarnings.class.getName());
+ final Annotation suppressWarningAnnotation = resolveAnnotation(type,
SuppressWarnings.class.getName());
// operation
final JavaElementDelta event = createEvent(suppressWarningAnnotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -310,7 +325,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation appPathAnnotation = getAnnotation(type,
APPLICATION_PATH.qualifiedName);
+ final Annotation appPathAnnotation = resolveAnnotation(type,
APPLICATION_PATH.qualifiedName);
final JaxrsJavaApplication application = new JaxrsJavaApplication(type,
appPathAnnotation, true, metamodel);
metamodel.add(application);
// operation
@@ -326,10 +341,10 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation appPathAnnotation = getAnnotation(type,
APPLICATION_PATH.qualifiedName);
+ final Annotation appPathAnnotation = resolveAnnotation(type,
APPLICATION_PATH.qualifiedName);
final JaxrsJavaApplication application = new JaxrsJavaApplication(type,
appPathAnnotation, true, metamodel);
metamodel.add(application);
- final Annotation suppressWarningsAnnotation = getAnnotation(type,
SuppressWarnings.class.getName());
+ final Annotation suppressWarningsAnnotation = resolveAnnotation(type,
SuppressWarnings.class.getName());
// operation
final JavaElementDelta event = createEvent(suppressWarningsAnnotation, CHANGED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -343,7 +358,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation appPathAnnotation = getAnnotation(type,
APPLICATION_PATH.qualifiedName);
+ final Annotation appPathAnnotation = resolveAnnotation(type,
APPLICATION_PATH.qualifiedName);
final JaxrsJavaApplication application = new JaxrsJavaApplication(type,
appPathAnnotation, true, metamodel);
metamodel.add(application);
// operation
@@ -362,7 +377,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation appPathAnnotation = getAnnotation(type,
APPLICATION_PATH.qualifiedName);
+ final Annotation appPathAnnotation = resolveAnnotation(type,
APPLICATION_PATH.qualifiedName);
final JaxrsJavaApplication application = new JaxrsJavaApplication(type,
appPathAnnotation, true, metamodel);
metamodel.add(application);
// operation
@@ -381,7 +396,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation appPathAnnotation = getAnnotation(type,
APPLICATION_PATH.qualifiedName);
+ final Annotation appPathAnnotation = resolveAnnotation(type,
APPLICATION_PATH.qualifiedName);
final JaxrsJavaApplication application = new JaxrsJavaApplication(type,
appPathAnnotation, true, metamodel);
metamodel.add(application);
// operation
@@ -401,7 +416,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation appPathAnnotation = getAnnotation(type,
APPLICATION_PATH.qualifiedName);
+ final Annotation appPathAnnotation = resolveAnnotation(type,
APPLICATION_PATH.qualifiedName);
final JaxrsJavaApplication application = new JaxrsJavaApplication(type,
appPathAnnotation, false, metamodel);
metamodel.add(application);
// operation
@@ -414,7 +429,7 @@
assertThat(impacts.get(0).getElement(), is(notNullValue()));
assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
}
-
+
@Test
public void shouldRemoveApplicationWhenRemovingHierarchyAndAnnotationAlreadyMissing()
throws CoreException {
// pre-conditions
@@ -433,17 +448,17 @@
assertThat(impacts.get(0).getElement(), is(notNullValue()));
assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
}
-
+
@Test
public void shouldDoNothingWhenRemovingUnrelatedAnnotationOnApplication() throws
CoreException {
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation appPathAnnotation = getAnnotation(type,
APPLICATION_PATH.qualifiedName);
+ final Annotation appPathAnnotation = resolveAnnotation(type,
APPLICATION_PATH.qualifiedName);
final JaxrsJavaApplication application = new JaxrsJavaApplication(type,
appPathAnnotation, true, metamodel);
metamodel.add(application);
// operation
- final JavaElementDelta event = createEvent(getAnnotation(type,
SuppressWarnings.class.getName()), REMOVED);
+ final JavaElementDelta event = createEvent(resolveAnnotation(type,
SuppressWarnings.class.getName()), REMOVED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
// verifications
assertThat(impacts.size(), equalTo(0));
@@ -455,7 +470,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation appPathAnnotation = getAnnotation(type,
APPLICATION_PATH.qualifiedName);
+ final Annotation appPathAnnotation = resolveAnnotation(type,
APPLICATION_PATH.qualifiedName);
final JaxrsJavaApplication application = new JaxrsJavaApplication(type,
appPathAnnotation, true, metamodel);
metamodel.add(application);
final IPackageFragmentRoot sourceFolder =
WorkbenchUtils.getPackageFragmentRoot(javaProject, "src/main/java",
@@ -470,7 +485,7 @@
assertThat(impacts.get(0).getDeltaKind(), equalTo(REMOVED));
assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
}
-
+
@Test
public void shouldAddHttpMethodWhenAddingSourceCompilationUnit() throws CoreException {
// pre-conditions
@@ -501,7 +516,7 @@
assertThat(impacts.get(0).getElement().getElementCategory(),
equalTo(EnumElementCategory.HTTP_METHOD));
assertThat(impacts.get(0).getDeltaKind(), equalTo(ADDED));
assertThat(((JaxrsHttpMethod) impacts.get(0).getElement()).getHttpVerb(),
equalTo("FOO"));
- //verify(metamodel, times(1)).add(any(HTTP_METHOD.qualifiedName));
+ // verify(metamodel, times(1)).add(any(HTTP_METHOD.qualifiedName));
assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
}
@@ -510,7 +525,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
// operation
final JavaElementDelta event = createEvent(annotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -528,9 +543,10 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(getAnnotation(type, HTTP_METHOD.qualifiedName)).build();
+ final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(
+ resolveAnnotation(type, HTTP_METHOD.qualifiedName)).build();
metamodel.add(httpMethod);
- final Annotation annotation = getAnnotation(type, Target.class.getName());
+ final Annotation annotation = resolveAnnotation(type, Target.class.getName());
// operation
final JavaElementDelta event = createEvent(annotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -564,7 +580,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(annotation).build();
metamodel.add(httpMethod);
// operation
@@ -580,10 +596,11 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final Annotation httpMethodAnnotation = getAnnotation(type,
HTTP_METHOD.qualifiedName);
- final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(httpMethodAnnotation).build();
+ final Annotation httpMethodAnnotation = resolveAnnotation(type,
HTTP_METHOD.qualifiedName);
+ final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type, metamodel)
+ .httpMethod(httpMethodAnnotation).build();
metamodel.add(httpMethod);
- final Annotation targetAnnotation = getAnnotation(type, Target.class.getName());
+ final Annotation targetAnnotation = resolveAnnotation(type, Target.class.getName());
// operation
final JavaElementDelta event = createEvent(targetAnnotation, CHANGED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -598,7 +615,7 @@
// JaxrsMetamodel metamodel = new JaxrsMetamodel(javaProject);
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(annotation).build();
metamodel.add(httpMethod);
// operation
@@ -617,7 +634,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(annotation).build();
metamodel.add(httpMethod);
// operation
@@ -636,7 +653,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(annotation).build();
metamodel.add(httpMethod);
// operation
@@ -655,10 +672,11 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(getAnnotation(type, HTTP_METHOD.qualifiedName)).build();
+ final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(
+ resolveAnnotation(type, HTTP_METHOD.qualifiedName)).build();
metamodel.add(httpMethod);
// operation
- final JavaElementDelta event = createEvent(getAnnotation(type, Target.class.getName()),
REMOVED);
+ final JavaElementDelta event = createEvent(resolveAnnotation(type,
Target.class.getName()), REMOVED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
// verifications
assertThat(impacts.size(), equalTo(0));
@@ -670,7 +688,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(annotation).build();
metamodel.add(httpMethod);
final IPackageFragmentRoot sourceFolder =
WorkbenchUtils.getPackageFragmentRoot(javaProject, "src/main/java",
@@ -693,7 +711,7 @@
"lib/jaxrs-api-2.0.1.GA.jar", progressMonitor);
// let's suppose that this jar only contains 1 HTTP Methods ;-)
final IType type = JdtUtils.resolveType("javax.ws.rs.GET", javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(annotation).build();
metamodel.add(httpMethod);
// operation
@@ -787,7 +805,7 @@
metamodel.add(createHttpMethod(DELETE));
// operation
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation annotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, PATH.qualifiedName);
final JavaElementDelta event = createEvent(annotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
// verifications
@@ -796,8 +814,7 @@
final JaxrsResource resource = (JaxrsResource) impacts.get(0).getElement();
assertThat(resource.getPathTemplate(), equalTo("/customers"));
assertThat(resource.getConsumedMediaTypes(),
equalTo(Arrays.asList("application/xml")));
- assertThat(resource.getProducedMediaTypes(),
- equalTo(Arrays.asList("application/xml", "application/json")));
+ assertThat(resource.getProducedMediaTypes(),
equalTo(Arrays.asList("application/xml", "application/json")));
// includes HttpMethods, Resource, ResourceMethods and ResourceFields
assertThat(metamodel.getElements(javaProject).size(), equalTo(11));
}
@@ -806,12 +823,12 @@
public void shouldBecomeRootResourceWhenAddingPathAnnotation() throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation consumesAnnotation = getAnnotation(type, CONSUMES.qualifiedName);
- final Annotation producesAnnotation = getAnnotation(type, PRODUCES.qualifiedName);
+ final Annotation consumesAnnotation = resolveAnnotation(type, CONSUMES.qualifiedName);
+ final Annotation producesAnnotation = resolveAnnotation(type, PRODUCES.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).consumes(consumesAnnotation)
.produces(producesAnnotation).build();
metamodel.add(resource);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
// operation
final JavaElementDelta event = createEvent(pathAnnotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -827,7 +844,7 @@
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.FooResource", javaProject);
// operation
- final Annotation annotation = getAnnotation(type, CONSUMES.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, CONSUMES.qualifiedName);
final JavaElementDelta event = createEvent(annotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
// verifications
@@ -858,8 +875,8 @@
public void shouldUpdateResourceWhenAddingConsumesAnnotation() throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation annotation = getAnnotation(type, CONSUMES.qualifiedName);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, CONSUMES.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// operation
@@ -876,7 +893,7 @@
public void shouldUpdateResourceWhenChangingConsumesAnnotationValue() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final Annotation consumesAnnotation = changeAnnotation(type, CONSUMES.qualifiedName,
"application/foo");
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
.consumes(consumesAnnotation).build();
@@ -895,8 +912,8 @@
public void shouldUpdateResourceWhenRemovingConsumesAnnotation() throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
- final Annotation consumesAnnotation = getAnnotation(type, CONSUMES.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
+ final Annotation consumesAnnotation = resolveAnnotation(type, CONSUMES.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
.consumes(consumesAnnotation).build();
metamodel.add(resource);
@@ -914,10 +931,10 @@
public void shouldUpdateResourceWhenAddingProducesAnnotation() throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
- final Annotation producesAnnotation = getAnnotation(type, PRODUCES.qualifiedName);
+ final Annotation producesAnnotation = resolveAnnotation(type, PRODUCES.qualifiedName);
// operation
final JavaElementDelta event = createEvent(producesAnnotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -933,7 +950,7 @@
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation annotation = changeAnnotation(type, PRODUCES.qualifiedName,
"application/foo");
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
.produces(annotation).build();
metamodel.add(resource);
@@ -951,8 +968,8 @@
public void shouldUpdateResourceWhenRemovingProducesAnnotation() throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation annotation = getAnnotation(type, PRODUCES.qualifiedName);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, PRODUCES.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
.produces(annotation).build();
metamodel.add(resource);
@@ -970,10 +987,10 @@
public void shouldAddResourceFieldWhenAddingPathParamAnnotationOnField() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
- final Annotation annotation = getAnnotation(type.getField("productType"),
PATH_PARAM.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type.getField("productType"),
PATH_PARAM.qualifiedName);
// operation
final JavaElementDelta event = createEvent(annotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -1001,10 +1018,10 @@
public void shouldAddResourceFieldWhenAddingQueryParamAnnotationOnField() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
- final Annotation annotation = getAnnotation(type.getField("foo"),
QUERY_PARAM.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type.getField("foo"),
QUERY_PARAM.qualifiedName);
// operation
final JavaElementDelta event = createEvent(annotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -1018,10 +1035,10 @@
public void shouldAddResourceFieldWhenAddingMatrixParamAnnotationOnField() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
- final Annotation annotation = getAnnotation(type.getField("bar"),
MATRIX_PARAM.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type.getField("bar"),
MATRIX_PARAM.qualifiedName);
// operation
final JavaElementDelta event = createEvent(annotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -1035,7 +1052,7 @@
public void shouldAddResourceFieldWhenAddingFieldAnnotatedWithPathParam() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("productType");
@@ -1052,7 +1069,7 @@
public void shouldAddResourceFieldWhenAddingFieldAnnotatedWithQueryParam() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("foo");
@@ -1069,7 +1086,7 @@
public void shouldAddResourceFieldWhenAddingFieldAnnotatedWithMatrixParam() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("bar");
@@ -1086,7 +1103,7 @@
public void shouldDoNothingWhenAddingFieldWithAnyAnnotation() throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("entityManager");
@@ -1102,7 +1119,7 @@
public void shouldDoNothingWhenAddingUnrelatedAnnotationOnField() throws CoreException
{
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("entityManager");
@@ -1118,7 +1135,7 @@
public void shouldUpdateResourceFieldWhenChangingPathParamAnnotationValueOnField()
throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("productType");
@@ -1138,7 +1155,7 @@
public void shouldUpdateResourceFieldWhenChangingQueryParamAnnotationValueOnField()
throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("foo");
@@ -1158,7 +1175,7 @@
public void shouldUpdateResourceFieldWhenChangingMatrixParamAnnotationValueOnField()
throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("bar");
@@ -1178,7 +1195,7 @@
public void shouldDoNothingWhenChangingUnrelatedResourceFieldAnnotationValue() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("bar");
@@ -1197,11 +1214,11 @@
public void shouldRemoveResourceFieldWhenRemovingPathParamAnnotatedOnField() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("productType");
- final Annotation annotation = getAnnotation(field, PATH_PARAM.qualifiedName);
+ final Annotation annotation = resolveAnnotation(field, PATH_PARAM.qualifiedName);
final JaxrsResourceField resourceField = new JaxrsResourceField(field, annotation,
resource, metamodel);
metamodel.add(resourceField);
// operation
@@ -1217,11 +1234,11 @@
public void shouldRemoveResourceFieldWhenRemovingQueryParamAnnotationOnField() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("foo");
- final Annotation annotation = getAnnotation(field, QUERY_PARAM.qualifiedName);
+ final Annotation annotation = resolveAnnotation(field, QUERY_PARAM.qualifiedName);
final JaxrsResourceField resourceField = new JaxrsResourceField(field, annotation,
resource, metamodel);
metamodel.add(resourceField);
// operation
@@ -1237,11 +1254,11 @@
public void shouldRemoveResourceFieldWhenRemovingMatrixParamAnnotationOnField() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("bar");
- final Annotation annotation = getAnnotation(field, MATRIX_PARAM.qualifiedName);
+ final Annotation annotation = resolveAnnotation(field, MATRIX_PARAM.qualifiedName);
final JaxrsResourceField resourceField = new JaxrsResourceField(field, annotation,
resource, metamodel);
metamodel.add(resourceField);
// operation
@@ -1257,11 +1274,11 @@
public void shouldRemoveResourceFieldWhenRemovingFieldAnnotatedWithQueryParam() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
IField field = type.getField("foo");
- final Annotation annotation = getAnnotation(field, QUERY_PARAM.qualifiedName);
+ final Annotation annotation = resolveAnnotation(field, QUERY_PARAM.qualifiedName);
final JaxrsResourceField resourceField = new JaxrsResourceField(field, annotation,
resource, metamodel);
metamodel.add(resourceField);
// operation
@@ -1277,11 +1294,11 @@
public void shouldRemoveResourceFieldWhenRemovingFieldAnnotatedWithPathParam() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("productType");
- final Annotation annotation = getAnnotation(field, PATH_PARAM.qualifiedName);
+ final Annotation annotation = resolveAnnotation(field, PATH_PARAM.qualifiedName);
final JaxrsResourceField resourceField = new JaxrsResourceField(field, annotation,
resource, metamodel);
metamodel.add(resourceField);
// operation
@@ -1297,11 +1314,11 @@
public void shouldRemoveResourceFieldWhenRemovingFieldAnnotatedWithMatrixParam() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("bar");
- final Annotation annotation = getAnnotation(field, MATRIX_PARAM.qualifiedName);
+ final Annotation annotation = resolveAnnotation(field, MATRIX_PARAM.qualifiedName);
final JaxrsResourceField resourceField = new JaxrsResourceField(field, annotation,
resource, metamodel);
metamodel.add(resourceField);
// operation
@@ -1317,7 +1334,7 @@
public void shouldDoNothingWhenRemovingUnrelatedAnnotationOnField() throws CoreException
{
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IField field = type.getField("entityManager");
@@ -1349,10 +1366,10 @@
public void shouldDoNothingWhenChangingUnrelatedResourceAnnotationValue() throws
CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
- final Annotation annotation = getAnnotation(type, CONSUMES.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, CONSUMES.qualifiedName);
// operation
final JavaElementDelta event = createEvent(annotation, CHANGED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -1399,7 +1416,7 @@
public void shouldRemoveResourceWhenRemovingAnnotation() throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation annotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(annotation).build();
metamodel.add(resource);
for (JaxrsBaseElement resourceMethod : resource.getMethods().values()) {
@@ -1422,12 +1439,12 @@
metamodel.add(createHttpMethod(POST));
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "createCustomer");
- final Annotation annotation = getAnnotation(method, POST.qualifiedName);
+ final Annotation annotation = resolveAnnotation(method, POST.qualifiedName);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(annotation).build();
metamodel.add(resourceMethod);
@@ -1448,12 +1465,12 @@
metamodel.add(httpMethod);
// JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "createCustomer");
- final Annotation httpMethodAnnotation = getAnnotation(method, POST.qualifiedName);
+ final Annotation httpMethodAnnotation = resolveAnnotation(method, POST.qualifiedName);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(httpMethodAnnotation).build();
metamodel.add(resourceMethod);
@@ -1474,8 +1491,7 @@
final JaxrsResource resource = new JaxrsResource.Builder(type, metamodel).build();
metamodel.add(resource);
// in case it would be removed
- final Annotation annotation = getAnnotation(type,
- ENCODED.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, ENCODED.qualifiedName);
// operation
final JavaElementDelta event = createEvent(annotation, REMOVED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -1490,7 +1506,7 @@
final IPackageFragmentRoot sourceFolder =
WorkbenchUtils.getPackageFragmentRoot(javaProject, "src/main/java",
progressMonitor);
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation annotation = getAnnotation(type, CONSUMES.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, CONSUMES.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(annotation).build();
metamodel.add(resource);
// operation
@@ -1515,11 +1531,11 @@
metamodel.add(createHttpMethod(POST));
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IMethod method = getMethod(type, "createCustomer");
- final Annotation annotation = getAnnotation(method, POST.qualifiedName);
+ final Annotation annotation = resolveAnnotation(method, POST.qualifiedName);
// operation
final JavaElementDelta event = createEvent(annotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -1536,7 +1552,7 @@
metamodel.add(createHttpMethod(POST));
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IMethod method = getMethod(type, "createCustomer");
@@ -1554,11 +1570,11 @@
// pre-conditions
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
final IMethod method = getMethod(type, "getProductResourceLocator");
- final Annotation annotation = getAnnotation(method, PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(method, PATH.qualifiedName);
// operation
final JavaElementDelta event = createEvent(annotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -1576,12 +1592,12 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "createCustomer");
- final Annotation annotation = getAnnotation(method, POST.qualifiedName);
+ final Annotation annotation = resolveAnnotation(method, POST.qualifiedName);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(annotation).build();
metamodel.add(resourceMethod);
@@ -1602,15 +1618,15 @@
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(
- getAnnotation(type, PATH.qualifiedName)).build();
+ resolveAnnotation(type, PATH.qualifiedName)).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "getCustomer");
- final Annotation httpAnnotation = getAnnotation(method, GET.qualifiedName);
+ final Annotation httpAnnotation = resolveAnnotation(method, GET.qualifiedName);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(httpAnnotation).build();
metamodel.add(resourceMethod);
- final Annotation pathAnnotation = getAnnotation(method, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(method, PATH.qualifiedName);
// operation
final JavaElementDelta event = createEvent(pathAnnotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
@@ -1630,12 +1646,12 @@
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(
- getAnnotation(type, PATH.qualifiedName)).build();
+ resolveAnnotation(type, PATH.qualifiedName)).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "getCustomer");
- final Annotation httpAnnotation = getAnnotation(method, GET.qualifiedName);
- final Annotation pathAnnotation = getAnnotation(method, PATH.qualifiedName);
+ final Annotation httpAnnotation = resolveAnnotation(method, GET.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(method, PATH.qualifiedName);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(httpAnnotation).pathTemplate(pathAnnotation).build();
metamodel.add(resourceMethod);
@@ -1658,12 +1674,12 @@
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(
- getAnnotation(type, PATH.qualifiedName)).build();
+ resolveAnnotation(type, PATH.qualifiedName)).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "getCustomer");
- final Annotation pathAnnotation = getAnnotation(method, PATH.qualifiedName);
- final Annotation httpAnnotation = getAnnotation(method, GET.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(method, PATH.qualifiedName);
+ final Annotation httpAnnotation = resolveAnnotation(method, GET.qualifiedName);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(httpAnnotation).pathTemplate(pathAnnotation).build();
metamodel.add(resourceMethod);
@@ -1683,11 +1699,11 @@
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(
- getAnnotation(type, PATH.qualifiedName)).build();
+ resolveAnnotation(type, PATH.qualifiedName)).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "getProductResourceLocator");
- final Annotation annotation = getAnnotation(method, PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(method, PATH.qualifiedName);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.pathTemplate(annotation).build();
metamodel.add(resourceMethod);
@@ -1709,12 +1725,12 @@
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(
- getAnnotation(type, PATH.qualifiedName)).build();
+ resolveAnnotation(type, PATH.qualifiedName)).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "getCustomer");
final Annotation pathAnnotation = changeAnnotation(method, PATH.qualifiedName,
"/foo");
- final Annotation httpAnnotation = getAnnotation(method, GET.qualifiedName);
+ final Annotation httpAnnotation = resolveAnnotation(method, GET.qualifiedName);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(httpAnnotation).pathTemplate(pathAnnotation).build();
metamodel.add(resourceMethod);
@@ -1736,13 +1752,13 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "createCustomer");
- final Annotation consumesAnnotation = getAnnotation(method, CONSUMES.qualifiedName);
- final Annotation httpAnnotation = getAnnotation(method, POST.qualifiedName);
+ final Annotation consumesAnnotation = resolveAnnotation(method,
CONSUMES.qualifiedName);
+ final Annotation httpAnnotation = resolveAnnotation(method, POST.qualifiedName);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(httpAnnotation).build();
metamodel.add(resourceMethod);
@@ -1764,13 +1780,13 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "createCustomer");
final Annotation consumesAnnotation = changeAnnotation(method, CONSUMES.qualifiedName,
"application/foo");
- final Annotation httpAnnotation = getAnnotation(method, POST.qualifiedName);
+ final Annotation httpAnnotation = resolveAnnotation(method, POST.qualifiedName);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(httpAnnotation).consumes(consumesAnnotation).build();
metamodel.add(resourceMethod);
@@ -1792,13 +1808,13 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "createCustomer");
- final Annotation httpAnnotation = getAnnotation(method, POST.qualifiedName);
- final Annotation consumesAnnotation = getAnnotation(method, CONSUMES.qualifiedName);
+ final Annotation httpAnnotation = resolveAnnotation(method, POST.qualifiedName);
+ final Annotation consumesAnnotation = resolveAnnotation(method,
CONSUMES.qualifiedName);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(httpAnnotation).consumes(consumesAnnotation).build();
metamodel.add(resourceMethod);
@@ -1820,13 +1836,13 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "getCustomerAsVCard");
- final Annotation producesAnnotation = getAnnotation(method, PRODUCES.qualifiedName);
- final Annotation httpAnnotation = getAnnotation(method, GET.qualifiedName);
+ final Annotation producesAnnotation = resolveAnnotation(method,
PRODUCES.qualifiedName);
+ final Annotation httpAnnotation = resolveAnnotation(method, GET.qualifiedName);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(httpAnnotation).build();
metamodel.add(resourceMethod);
@@ -1848,12 +1864,12 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "getCustomerAsVCard");
- final Annotation httpAnnotation = getAnnotation(method, GET.qualifiedName);
+ final Annotation httpAnnotation = resolveAnnotation(method, GET.qualifiedName);
final Annotation producesAnnotation = changeAnnotation(method, PRODUCES.qualifiedName,
"application/foo");
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(httpAnnotation).produces(producesAnnotation).build();
@@ -1876,13 +1892,13 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "getCustomerAsVCard");
- final Annotation httpAnnotation = getAnnotation(method, GET.qualifiedName);
- final Annotation producesAnnotation = getAnnotation(method, PRODUCES.qualifiedName);
+ final Annotation httpAnnotation = resolveAnnotation(method, GET.qualifiedName);
+ final Annotation producesAnnotation = resolveAnnotation(method,
PRODUCES.qualifiedName);
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(httpAnnotation).produces(producesAnnotation).build();
metamodel.add(resourceMethod);
@@ -1910,16 +1926,17 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "getCustomer");
- final JavaMethodParameter pathParameter = new JavaMethodParameter("id",
Integer.class.getName(), null, null);
+ final JavaMethodParameter pathParameter = new JavaMethodParameter("id",
Integer.class.getName(),
+ new ArrayList<Annotation>());
final JavaMethodParameter contextParameter = new
JavaMethodParameter("uriInfo", URI_INFO.qualifiedName,
- Arrays.asList(createAnnotation(CONTEXT.qualifiedName, null)), null);
+ Arrays.asList(createAnnotation(CONTEXT.qualifiedName, null)));
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method, GET.qualifiedName))
+ .httpMethod(resolveAnnotation(method, GET.qualifiedName))
.returnType(getType(RESPONSE.qualifiedName,
javaProject)).methodParameter(pathParameter)
.methodParameter(contextParameter).build();
metamodel.add(resourceMethod);
@@ -1942,17 +1959,17 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "getCustomer");
final JavaMethodParameter pathParameter = new JavaMethodParameter("id",
Integer.class.getName(),
- Arrays.asList(createAnnotation(PATH_PARAM.qualifiedName, "foo!")), null);
+ Arrays.asList(createAnnotation(PATH_PARAM.qualifiedName, "foo!")));
final JavaMethodParameter contextParameter = new
JavaMethodParameter("uriInfo", URI_INFO.qualifiedName,
- Arrays.asList(createAnnotation(CONTEXT.qualifiedName, null)), null);
+ Arrays.asList(createAnnotation(CONTEXT.qualifiedName, null)));
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method, GET.qualifiedName))
+ .httpMethod(resolveAnnotation(method, GET.qualifiedName))
.returnType(getType(RESPONSE.qualifiedName,
javaProject)).methodParameter(pathParameter)
.methodParameter(contextParameter).build();
metamodel.add(resourceMethod);
@@ -1975,18 +1992,18 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
- // JAX-RS Resource Method
+ // JAX-RS Resource Method with an extra @PathParam annotation on the 'update'
parameter.
final IMethod method = getMethod(type, "updateCustomer");
final JavaMethodParameter pathParameter = new JavaMethodParameter("id",
Integer.class.getName(),
- Arrays.asList(createAnnotation(PATH_PARAM.qualifiedName, "id")), null);
+ Arrays.asList(createAnnotation(PATH_PARAM.qualifiedName, "id")));
final JavaMethodParameter customerParameter = new
JavaMethodParameter("update",
"org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
Arrays.asList(createAnnotation(
- PATH_PARAM.qualifiedName, "foo")), null);
+ PATH_PARAM.qualifiedName, "foo")));
final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method,
PUT.qualifiedName)).returnType(getType("void", javaProject))
+ .httpMethod(resolveAnnotation(method,
PUT.qualifiedName)).returnType(getType("void", javaProject))
.methodParameter(pathParameter).methodParameter(customerParameter).build();
metamodel.add(resourceMethod);
// operation
@@ -2008,18 +2025,19 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// 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(QUERY_PARAM.qualifiedName, "start")),
null);
+ Arrays.asList(createAnnotation(QUERY_PARAM.qualifiedName, "start")));
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", URI_INFO.qualifiedName,
- Arrays.asList(createAnnotation(CONTEXT.qualifiedName, null)), null);
+ Arrays.asList(createAnnotation(CONTEXT.qualifiedName, null)));
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method,
GET.qualifiedName)).returnType(getType("java.util.List", javaProject))
- .methodParameter(startParameter).methodParameter(uriInfoParameter).build();
+ .httpMethod(resolveAnnotation(method, GET.qualifiedName))
+ .returnType(getType("java.util.List",
javaProject)).methodParameter(startParameter)
+ .methodParameter(uriInfoParameter).build();
metamodel.add(jaxrsMethod);
// operation
final JavaElementDelta event = createEvent(method, CHANGED, F_SIGNATURE);
@@ -2041,15 +2059,15 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// 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(PATH_PARAM.qualifiedName, null)), null);
+ Arrays.asList(createAnnotation(PATH_PARAM.qualifiedName, null)));
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .pathTemplate(getAnnotation(method,
PATH.qualifiedName)).methodParameter(pathParameter)
+ .pathTemplate(resolveAnnotation(method,
PATH.qualifiedName)).methodParameter(pathParameter)
.returnType(getType("java.lang.Object", javaProject)).build();
metamodel.add(jaxrsMethod);
// operation
@@ -2072,21 +2090,21 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// 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(QUERY_PARAM.qualifiedName, "start")),
null);
+ Arrays.asList(createAnnotation(QUERY_PARAM.qualifiedName, "start")));
final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int",
- Arrays.asList(createAnnotation(DEFAULT_VALUE.qualifiedName, "2")), null);
+ Arrays.asList(createAnnotation(DEFAULT_VALUE.qualifiedName, "2")));
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", URI_INFO.qualifiedName,
- Arrays.asList(createAnnotation(CONTEXT.qualifiedName, null)), null);
+ Arrays.asList(createAnnotation(CONTEXT.qualifiedName, null)));
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method,
GET.qualifiedName)).returnType(getType("java.util.List", javaProject))
- .methodParameter(startParameter).methodParameter(sizeParameter).methodParameter(uriInfoParameter)
- .build();
+ .httpMethod(resolveAnnotation(method, GET.qualifiedName))
+ .returnType(getType("java.util.List",
javaProject)).methodParameter(startParameter)
+ .methodParameter(sizeParameter).methodParameter(uriInfoParameter).build();
metamodel.add(jaxrsMethod);
// operation
final JavaElementDelta event = createEvent(method, CHANGED, F_SIGNATURE);
@@ -2107,22 +2125,23 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method (QueryParam value is different: "length" vs
// "size" on second param)
final IMethod method = getMethod(type, "getCustomers");
final JavaMethodParameter startParameter = new JavaMethodParameter("start",
"int",
- Arrays.asList(createAnnotation(QUERY_PARAM.qualifiedName, "start")),
null);
+ Arrays.asList(createAnnotation(QUERY_PARAM.qualifiedName, "start")));
final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(
- createAnnotation(QUERY_PARAM.qualifiedName, "length"),
createAnnotation(DEFAULT_VALUE.qualifiedName, "2")), null);
+ createAnnotation(QUERY_PARAM.qualifiedName, "length"),
+ createAnnotation(DEFAULT_VALUE.qualifiedName, "2")));
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", URI_INFO.qualifiedName,
- Arrays.asList(createAnnotation(CONTEXT.qualifiedName, null)), null);
+ Arrays.asList(createAnnotation(CONTEXT.qualifiedName, null)));
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method,
GET.qualifiedName)).returnType(getType("java.util.List", javaProject))
- .methodParameter(startParameter).methodParameter(sizeParameter).methodParameter(uriInfoParameter)
- .build();
+ .httpMethod(resolveAnnotation(method, GET.qualifiedName))
+ .returnType(getType("java.util.List",
javaProject)).methodParameter(startParameter)
+ .methodParameter(sizeParameter).methodParameter(uriInfoParameter).build();
metamodel.add(jaxrsMethod);
// operation
final JavaElementDelta event = createEvent(method, CHANGED, F_SIGNATURE);
@@ -2143,21 +2162,23 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// 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(QUERY_PARAM.qualifiedName, "start")),
null);
- final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(
- createAnnotation(QUERY_PARAM.qualifiedName, "size"),
createAnnotation(DEFAULT_VALUE.qualifiedName, "2")), null);
+ Arrays.asList(createAnnotation(QUERY_PARAM.qualifiedName, "start")));
+ final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int",
+ Arrays.asList(createAnnotation(QUERY_PARAM.qualifiedName, "size"),
+ createAnnotation(DEFAULT_VALUE.qualifiedName, "2")));
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", URI_INFO.qualifiedName,
- Arrays.asList(createAnnotation(QUERY_PARAM.qualifiedName, "foo"),
createAnnotation(CONTEXT.qualifiedName, null)), null);
+ Arrays.asList(createAnnotation(QUERY_PARAM.qualifiedName, "foo"),
+ createAnnotation(CONTEXT.qualifiedName, null)));
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method,
GET.qualifiedName)).returnType(getType("java.util.List", javaProject))
- .methodParameter(startParameter).methodParameter(sizeParameter).methodParameter(uriInfoParameter)
- .build();
+ .httpMethod(resolveAnnotation(method, GET.qualifiedName))
+ .returnType(getType("java.util.List",
javaProject)).methodParameter(startParameter)
+ .methodParameter(sizeParameter).methodParameter(uriInfoParameter).build();
metamodel.add(jaxrsMethod);
// operation
final JavaElementDelta event = createEvent(method, CHANGED, F_SIGNATURE);
@@ -2178,18 +2199,19 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method (MATRIX_PARAM.qualifiedName 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(PATH_PARAM.qualifiedName, "id")), null);
+ Arrays.asList(createAnnotation(PATH_PARAM.qualifiedName, "id")));
final JavaMethodParameter sizeParameter = new JavaMethodParameter("color",
String.class.getName(),
- new ArrayList<Annotation>(), null);
+ new ArrayList<Annotation>());
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method,
GET.qualifiedName)).returnType(getType("java.lang.Object", javaProject))
- .methodParameter(startParameter).methodParameter(sizeParameter).build();
+ .httpMethod(resolveAnnotation(method, GET.qualifiedName))
+ .returnType(getType("java.lang.Object",
javaProject)).methodParameter(startParameter)
+ .methodParameter(sizeParameter).build();
metamodel.add(jaxrsMethod);
// operation
final JavaElementDelta event = createEvent(method, CHANGED, F_SIGNATURE);
@@ -2210,18 +2232,19 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method (MATRIX_PARAM.qualifiedName 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(PATH_PARAM.qualifiedName, "id")), null);
+ Arrays.asList(createAnnotation(PATH_PARAM.qualifiedName, "id")));
final JavaMethodParameter sizeParameter = new JavaMethodParameter("color",
String.class.getName(),
- Arrays.asList(createAnnotation(MATRIX_PARAM.qualifiedName, "foo")), null);
+ Arrays.asList(createAnnotation(MATRIX_PARAM.qualifiedName, "foo")));
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method,
GET.qualifiedName)).returnType(getType("java.lang.Object", javaProject))
- .methodParameter(startParameter).methodParameter(sizeParameter).build();
+ .httpMethod(resolveAnnotation(method, GET.qualifiedName))
+ .returnType(getType("java.lang.Object",
javaProject)).methodParameter(startParameter)
+ .methodParameter(sizeParameter).build();
metamodel.add(jaxrsMethod);
// operation
final JavaElementDelta event = createEvent(method, CHANGED, F_SIGNATURE);
@@ -2242,15 +2265,15 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method (an extra MATRIX_PARAM.qualifiedName annotation on
'id' param)
final IMethod method = getMethod(type, "getProduct");
final JavaMethodParameter pathParameter = new JavaMethodParameter("id",
Integer.class.getName(), Arrays.asList(
- createAnnotation(MATRIX_PARAM.qualifiedName, "foo"),
createAnnotation(PATH_PARAM.qualifiedName, "id")), null);
+ createAnnotation(MATRIX_PARAM.qualifiedName, "foo"),
createAnnotation(PATH_PARAM.qualifiedName, "id")));
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method, GET.qualifiedName))
+ .httpMethod(resolveAnnotation(method, GET.qualifiedName))
.returnType(getType("org.jboss.tools.ws.jaxrs.sample.domain.Book",
javaProject))
.methodParameter(pathParameter).build();
metamodel.add(jaxrsMethod);
@@ -2273,20 +2296,21 @@
metamodel.add(httpMethod);
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method (declared return type is
// 'javax.ws.rs.Response')
final IMethod method = getMethod(type, "getCustomers");
final JavaMethodParameter startParameter = new JavaMethodParameter("start",
"int",
- Arrays.asList(createAnnotation(QUERY_PARAM.qualifiedName, "start")),
null);
- final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(
- createAnnotation(QUERY_PARAM.qualifiedName, "size"),
createAnnotation(DEFAULT_VALUE.qualifiedName, "2")), null);
+ Arrays.asList(createAnnotation(QUERY_PARAM.qualifiedName, "start")));
+ final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int",
+ Arrays.asList(createAnnotation(QUERY_PARAM.qualifiedName, "size"),
+ createAnnotation(DEFAULT_VALUE.qualifiedName, "2")));
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", URI_INFO.qualifiedName,
- Arrays.asList(createAnnotation(CONTEXT.qualifiedName, null)), null);
+ Arrays.asList(createAnnotation(CONTEXT.qualifiedName, null)));
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method, GET.qualifiedName))
+ .httpMethod(resolveAnnotation(method, GET.qualifiedName))
.returnType(getType(RESPONSE.qualifiedName,
javaProject)).methodParameter(startParameter)
.methodParameter(sizeParameter).methodParameter(uriInfoParameter).build();
metamodel.add(jaxrsMethod);
@@ -2313,16 +2337,18 @@
// pre-conditions
// Parent JAX-RS Resource
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// 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(QUERY_PARAM.qualifiedName, "start")),
null);
+ Arrays.asList(createAnnotation(QUERY_PARAM.qualifiedName, "start")));
final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(
- createAnnotation(QUERY_PARAM.qualifiedName, "length"),
createAnnotation(DEFAULT_VALUE.qualifiedName, "2")), null);
- final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", URI_INFO.qualifiedName, null, null);
+ createAnnotation(QUERY_PARAM.qualifiedName, "length"),
+ createAnnotation(DEFAULT_VALUE.qualifiedName, "2")));
+ final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", URI_INFO.qualifiedName,
+ new ArrayList<Annotation>());
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.methodParameter(startParameter).methodParameter(sizeParameter).methodParameter(uriInfoParameter)
.build();
@@ -2351,7 +2377,7 @@
public void shouldDoNothingWhenAddingBasicJavaMethod() throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method (an extra annotation on 'start' param)
@@ -2367,7 +2393,7 @@
public void shouldDoNothingWhenChangingBasicJavaMethod() throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method (an extra annotation on 'start' param)
@@ -2383,7 +2409,7 @@
public void shouldDoNothingWhenRemovingBasicJavaMethod() throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation pathAnnotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method (an extra annotation on 'start' param)
@@ -2412,5 +2438,247 @@
public void shouldUpdateResourceMethodWhenRemovingThrowsException() throws CoreException
{
fail("Not implemented yet - postponed along with support for providers");
}
-
+
+ /**
+ * Test in relation with
https://issues.jboss.org/browse/JBIDE-12806
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void shouldUpdateTypeAnnotationLocationAfterCodeChangeAbove() throws
CoreException {
+ // pre-condition: using the CustomerResource type
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, progressMonitor);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
+ // this test needs a complete Resource, built by the Factory
+ final JaxrsResource customerResource = new JaxrsElementFactory().createResource(type,
+ JdtUtils.parse(type, null), metamodel);
+ metamodel.add(customerResource);
+ final ISourceRange beforeChangeSourceRange = JdtUtils.resolveMemberPairValueRange(
+ pathAnnotation.getJavaAnnotation(), pathAnnotation.getFullyQualifiedName(),
"value");
+ final int length = beforeChangeSourceRange.getLength();
+ final int offset = beforeChangeSourceRange.getOffset();
+ // operation: removing @Encoded *before* the CustomerResource type
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type, "@Encoded", "",
true);
+ CompilationUnitsRepository.getInstance().mergeAST(type.getCompilationUnit(),
+ JdtUtils.parse(type.getCompilationUnit(), null), true);
+ // verifications
+ final ISourceRange afterChangeSourceRange = JdtUtils.resolveMemberPairValueRange(
+ pathAnnotation.getJavaAnnotation(), pathAnnotation.getFullyQualifiedName(),
"value");
+ assertThat(afterChangeSourceRange.getOffset(), lessThan(offset));
+ assertThat(afterChangeSourceRange.getLength(), equalTo(length));
+ }
+
+ /**
+ * Test in relation with
https://issues.jboss.org/browse/JBIDE-12806
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void shouldUpdateMethodAnnotationLocationAfterCodeChangeAbove() throws
CoreException {
+ // pre-condition: using the CustomerResource type
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, progressMonitor);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
+ final JaxrsResource customerResource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
+ .build();
+ metamodel.add(customerResource);
+ final IMethod method = getMethod(type, "createCustomer");
+ final Annotation postAnnotation = resolveAnnotation(method, POST.qualifiedName);
+ final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
customerResource, metamodel)
+ .httpMethod(postAnnotation).build();
+ metamodel.add(resourceMethod);
+ final ISourceRange beforeChangeSourceRange =
postAnnotation.getJavaAnnotation().getSourceRange();
+ final int length = beforeChangeSourceRange.getLength();
+ final int offset = beforeChangeSourceRange.getOffset();
+ // operation: removing @Encoded *before* the createCustomer() method
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type, "@Encoded", "",
false);
+ CompilationUnitsRepository.getInstance().mergeAST(type.getCompilationUnit(),
+ JdtUtils.parse(type.getCompilationUnit(), null), true);
+ final JavaElementDelta event = createEvent(type.getCompilationUnit(), CHANGED,
F_CHILDREN+F_FINE_GRAINED);
+ processEvent(event, progressMonitor);
+ // verifications
+ final ISourceRange afterChangeSourceRange =
postAnnotation.getJavaAnnotation().getSourceRange();
+ assertThat(afterChangeSourceRange.getOffset(), lessThan(offset));
+ assertThat(afterChangeSourceRange.getLength(), equalTo(length));
+ }
+
+ /**
+ * Test in relation with
https://issues.jboss.org/browse/JBIDE-12806
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void shouldUpdateMethodParameterAnnotationLocationAfterCodeChangeAbove() throws
CoreException {
+ // pre-condition: using the CustomerResource type
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, progressMonitor);
+ final JaxrsResource customerResource = new JaxrsElementFactory().createResource(type,
+ JdtUtils.parse(type.getCompilationUnit(), null), metamodel);
+ metamodel.add(customerResource);
+ final IMethod javaMethod = getMethod(type, "getCustomer");
+ final JaxrsResourceMethod resourceMethod =
customerResource.getMethods().get(javaMethod.getHandleIdentifier());
+ final Annotation pathParamAnnotation =
resourceMethod.getJavaMethodParameters().get(0).getAnnotations()
+ .get(PATH_PARAM.qualifiedName);
+ final ISourceRange beforeChangeSourceRange = JdtUtils.resolveMemberPairValueRange(
+ pathParamAnnotation.getJavaAnnotation(), pathParamAnnotation.getFullyQualifiedName(),
"value");
+ final int beforeLength = beforeChangeSourceRange.getLength();
+ final int beforeOffset = beforeChangeSourceRange.getOffset();
+ // operation: removing @Encoded *before* the getCustomer() method
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type, "@Encoded", "",
true);
+ CompilationUnitsRepository.getInstance().mergeAST(type.getCompilationUnit(),
+ JdtUtils.parse(type.getCompilationUnit(), null), true);
+ final JavaElementDelta event = createEvent(type.getCompilationUnit(), CHANGED,
F_CHILDREN+F_FINE_GRAINED);
+ processEvent(event, progressMonitor);
+ // verifications
+ final ISourceRange afterChangeSourceRange = JdtUtils.resolveMemberPairValueRange(
+ pathParamAnnotation.getJavaAnnotation(), pathParamAnnotation.getFullyQualifiedName(),
"value");
+ final int afterLength = afterChangeSourceRange.getLength();
+ final int afterOffset = afterChangeSourceRange.getOffset();
+ assertThat(afterOffset, lessThan(beforeOffset));
+ assertThat(afterLength, equalTo(beforeLength));
+ }
+
+ /**
+ * Test in relation with
https://issues.jboss.org/browse/JBIDE-12806
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void
shouldUpdateMethodParameterAnnotationLocationAfterPreviousMethodParamRemoved() throws
CoreException {
+ // pre-condition: using the CustomerResource type
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, progressMonitor);
+ final JaxrsResource customerResource = new JaxrsElementFactory().createResource(type,
+ JdtUtils.parse(type.getCompilationUnit(), null), metamodel);
+ metamodel.add(customerResource);
+ IMethod javaMethod = getMethod(type, "getCustomer");
+ JaxrsResourceMethod resourceMethod =
customerResource.getMethods().get(javaMethod.getHandleIdentifier());
+ Annotation contextAnnotation =
resourceMethod.getJavaMethodParameters().get(1).getAnnotations()
+ .get(CONTEXT.qualifiedName);
+ final ISourceRange beforeChangeSourceRange =
contextAnnotation.getJavaAnnotation().getSourceRange();
+ final int beforeLength = beforeChangeSourceRange.getLength();
+ final int beforeOffset = beforeChangeSourceRange.getOffset();
+ // operation: removing "@PathParam("id") Integer id" parameter in
the getCustomer() method
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type, "@PathParam(\"id\")
Integer id, ", "", false);
+ CompilationUnitsRepository.getInstance().mergeAST(type.getCompilationUnit(),
+ JdtUtils.parse(type.getCompilationUnit(), null), true);
+ JavaElementDelta event = createEvent(javaMethod, REMOVED);
+ processEvent(event, progressMonitor);
+ javaMethod = getMethod(type, "getCustomer");
+ event = createEvent(javaMethod, ADDED);
+ processEvent(event, progressMonitor);
+ // verifications: java method has changed, so all references must be looked-up again
+ resourceMethod = customerResource.getMethods().get(javaMethod.getHandleIdentifier());
+ contextAnnotation =
resourceMethod.getJavaMethodParameters().get(0).getAnnotations().get(CONTEXT.qualifiedName);
+ final ISourceRange afterChangeSourceRange =
contextAnnotation.getJavaAnnotation().getSourceRange();
+ final int afterLength = afterChangeSourceRange.getLength();
+ final int afterOffset = afterChangeSourceRange.getOffset();
+ assertThat(afterOffset, lessThan(beforeOffset));
+ assertThat(afterLength, equalTo(beforeLength));
+ }
+
+ /**
+ * Test in relation with
https://issues.jboss.org/browse/JBIDE-12806
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void shouldNotUpdateTypeAnnotationLocationAfterCodeChangeBelow() throws
CoreException {
+ // pre-condition: using the CustomerResource type
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, progressMonitor);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
+ final JaxrsResource customerResource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
+ .build();
+ metamodel.add(customerResource);
+ final ISourceRange beforeChangeSourceRange = JdtUtils.resolveMemberPairValueRange(
+ pathAnnotation.getJavaAnnotation(), pathAnnotation.getFullyQualifiedName(),
"value");
+ final int length = beforeChangeSourceRange.getLength();
+ final int offset = beforeChangeSourceRange.getOffset();
+ final IMethod deleteMethod = getMethod(type, "deleteCustomer");
+ final Annotation deleteAnnotation = resolveAnnotation(deleteMethod,
"DELETE");
+ // operation: removing @DELETE *after* the CustomerResource type
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type, "@DELETE", "",
false);
+ CompilationUnitsRepository.getInstance().mergeAST(type.getCompilationUnit(),
+ JdtUtils.parse(type.getCompilationUnit(), null), true);
+ final JavaElementDelta event = createEvent(deleteAnnotation, REMOVED);
+ processEvent(event, progressMonitor);
+ // verifications
+ final ISourceRange afterChangeSourceRange = JdtUtils.resolveMemberPairValueRange(
+ pathAnnotation.getJavaAnnotation(), pathAnnotation.getFullyQualifiedName(),
"value");
+ assertThat(afterChangeSourceRange.getOffset(), equalTo(offset));
+ assertThat(afterChangeSourceRange.getLength(), equalTo(length));
+ }
+
+ /**
+ * Test in relation with
https://issues.jboss.org/browse/JBIDE-12806
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void shouldNotUpdateMethodAnnotationLocationAfterCodeChangeBelow() throws
CoreException {
+ // pre-condition: using the CustomerResource type
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, progressMonitor);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
+ final JaxrsResource customerResource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
+ .build();
+ metamodel.add(customerResource);
+ final IMethod method = getMethod(type, "createCustomer");
+ final Annotation postAnnotation = resolveAnnotation(method, POST.qualifiedName);
+ final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
customerResource, metamodel)
+ .httpMethod(postAnnotation).build();
+ metamodel.add(resourceMethod);
+ final ISourceRange beforeChangeSourceRange =
postAnnotation.getJavaAnnotation().getSourceRange();
+ final int length = beforeChangeSourceRange.getLength();
+ final int offset = beforeChangeSourceRange.getOffset();
+ final IMethod deleteMethod = getMethod(type, "deleteCustomer");
+ final Annotation deleteAnnotation = resolveAnnotation(deleteMethod,
"DELETE");
+ // operation: removing @DELETE *after* the CustomerResource type
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type, "@DELETE", "",
false);
+ CompilationUnitsRepository.getInstance().mergeAST(type.getCompilationUnit(),
+ JdtUtils.parse(type.getCompilationUnit(), null), true);
+ final JavaElementDelta event = createEvent(deleteAnnotation, REMOVED);
+ processEvent(event, progressMonitor);
+ // verifications
+ final ISourceRange afterChangeSourceRange =
postAnnotation.getJavaAnnotation().getSourceRange();
+ assertThat(afterChangeSourceRange.getOffset(), equalTo(offset));
+ assertThat(afterChangeSourceRange.getLength(), equalTo(length));
+ }
+
+ /**
+ * Test in relation with
https://issues.jboss.org/browse/JBIDE-12806
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void shouldNotUpdateMethodParameterAnnotationLocationAfterCodeChangeBelow()
throws CoreException {
+ // pre-condition: using the CustomerResource type
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, progressMonitor);
+ final JaxrsResource customerResource = new JaxrsElementFactory().createResource(type,
+ JdtUtils.parse(type.getCompilationUnit(), null), metamodel);
+ metamodel.add(customerResource);
+ final IMethod javaMethod = getMethod(type, "getCustomer");
+ final JaxrsResourceMethod resourceMethod =
customerResource.getMethods().get(javaMethod.getHandleIdentifier());
+ final Annotation pathParamAnnotation =
resourceMethod.getJavaMethodParameters().get(0).getAnnotations().get(PATH_PARAM.qualifiedName);
+ final ISourceRange beforeChangeSourceRange =
JdtUtils.resolveMemberPairValueRange(pathParamAnnotation.getJavaAnnotation(),
pathParamAnnotation.getFullyQualifiedName(), "value");
+ final int length = beforeChangeSourceRange.getLength();
+ final int offset = beforeChangeSourceRange.getOffset();
+ final IMethod deleteMethod = getMethod(type, "deleteCustomer");
+ final Annotation deleteAnnotation = resolveAnnotation(deleteMethod,
"DELETE");
+ // operation: removing @DELETE *after* the CustomerResource type
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type, "@DELETE", "",
false);
+ CompilationUnitsRepository.getInstance().mergeAST(type.getCompilationUnit(),
+ JdtUtils.parse(type.getCompilationUnit(), null), true);
+ final JavaElementDelta event = createEvent(deleteAnnotation, REMOVED);
+ processEvent(event, progressMonitor);
+ // verifications
+ final ISourceRange afterChangeSourceRange = JdtUtils.resolveMemberPairValueRange(
+ pathParamAnnotation.getJavaAnnotation(), pathParamAnnotation.getFullyQualifiedName(),
"value");
+ assertThat(afterChangeSourceRange.getOffset(), equalTo(offset));
+ assertThat(afterChangeSourceRange.getLength(), equalTo(length));
+ }
+
}
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScannerTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScannerTestCase.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScannerTestCase.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -506,7 +506,7 @@
IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject,
null);
// operation
- type = WorkbenchUtils.replaceFirstOccurrenceOfCode(type,
"(a)Path(CustomerResource.URI_BASE)", "@Path(\"/foo\")",
+ type = WorkbenchUtils.replaceFirstOccurrenceOfCode(type,
"(a)Path(value=CustomerResource.URI_BASE)",
"@Path(\"/foo\")",
WORKING_COPY);
IAnnotation annotation = type.getAnnotation("Path");
// verifications
@@ -519,7 +519,7 @@
IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject,
null);
// operation
- type = WorkbenchUtils.replaceFirstOccurrenceOfCode(type,
"(a)Path(CustomerResource.URI_BASE)", "@Path(\"/foo\")",
+ type = WorkbenchUtils.replaceFirstOccurrenceOfCode(type,
"(a)Path(value=CustomerResource.URI_BASE)",
"@Path(\"/foo\")",
PRIMARY_COPY);
// verifications
verifyEventNotification(type.getResource(), CHANGED, POST_CHANGE, CONTENT,
atLeastOnce());
@@ -532,7 +532,7 @@
null);
// operation
IAnnotation annotation = type.getAnnotation("Path");
- WorkbenchUtils.removeFirstOccurrenceOfCode(type,
"(a)Path(CustomerResource.URI_BASE)", WORKING_COPY);
+ WorkbenchUtils.removeFirstOccurrenceOfCode(type,
"(a)Path(value=CustomerResource.URI_BASE)", WORKING_COPY);
// verifications
verifyEventNotification(annotation, REMOVED, POST_RECONCILE, NO_FLAG, times(1));
}
@@ -543,7 +543,7 @@
IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject,
null);
// operation
- WorkbenchUtils.removeFirstOccurrenceOfCode(type,
"(a)Path(CustomerResource.URI_BASE)", PRIMARY_COPY);
+ WorkbenchUtils.removeFirstOccurrenceOfCode(type,
"(a)Path(value=CustomerResource.URI_BASE)", PRIMARY_COPY);
// verifications
verifyEventNotification(type.getResource(), CHANGED, POST_CHANGE, CONTENT,
atLeastOnce());
}
@@ -901,7 +901,7 @@
}
@Test
- public void shouldNotNotifyWhenMethodParameterNameChangedInWorkingCopy() throws
CoreException, InterruptedException {
+ public void shouldNotifyWhenMethodParameterNameChangedInWorkingCopy() throws
CoreException, InterruptedException {
// pre-condition
IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject,
null);
@@ -911,7 +911,7 @@
method = WorkbenchUtils
.replaceFirstOccurrenceOfCode(method, "Customer customer", "Customer
cust", WORKING_COPY);
// verifications
- verifyEventNotification(method, CHANGED, POST_RECONCILE, F_SIGNATURE, times(0));
+ verifyEventNotification(method, CHANGED, POST_RECONCILE, F_SIGNATURE, times(1));
}
@Test
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-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessorTestCase.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -17,7 +17,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isOneOf;
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.WorkbenchUtils.resolveAnnotation;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getMethod;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getType;
import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.F_ELEMENT_KIND;
@@ -35,6 +35,7 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map.Entry;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -84,7 +85,7 @@
private JaxrsJavaApplication createJavaApplication(String typeName) throws
CoreException, JavaModelException {
final IType applicationType = getType(typeName, javaProject);
- final Annotation appPathAnnotation = getAnnotation(applicationType,
APPLICATION_PATH.qualifiedName);
+ final Annotation appPathAnnotation = resolveAnnotation(applicationType,
APPLICATION_PATH.qualifiedName);
final JaxrsJavaApplication application = new JaxrsJavaApplication(applicationType,
appPathAnnotation, true, metamodel);
metamodel.add(application);
@@ -101,7 +102,7 @@
private JaxrsResource createResource(String typeName) throws CoreException,
JavaModelException {
final IType resourceType = getType(typeName, javaProject);
final JaxrsResource resource = new JaxrsResource.Builder(resourceType,
metamodel).pathTemplate(
- getAnnotation(resourceType, PATH.qualifiedName)).build();
+ resolveAnnotation(resourceType, PATH.qualifiedName)).build();
metamodel.add(resource);
return resource;
}
@@ -115,13 +116,14 @@
JdtUtils.parse(compilationUnit, progressMonitor));
final Builder builder = new JaxrsResourceMethod.Builder(javaMethod, (JaxrsResource)
parentResource, metamodel)
- .pathTemplate(getAnnotation(javaMethod,
PATH.qualifiedName)).returnType(methodSignature.getReturnedType());
+ .pathTemplate(resolveAnnotation(javaMethod,
PATH.qualifiedName)).returnType(methodSignature.getReturnedType());
if (httpMethodElement != null) {
- builder.httpMethod(getAnnotation(javaMethod, httpMethodElement.qualifiedName));
+ builder.httpMethod(resolveAnnotation(javaMethod, httpMethodElement.qualifiedName));
}
- for (JavaMethodParameter methodParam : methodSignature.getMethodParameters()) {
- builder.methodParameter(methodParam);
+ for (Entry<String, JavaMethodParameter> methodParameterEntry :
methodSignature.getMethodParameters().entrySet()) {
+ JavaMethodParameter parameter = methodParameterEntry.getValue();
+ builder.methodParameter(parameter);
}
final JaxrsResourceMethod resourceMethod = builder.build();
metamodel.add(resourceMethod);
@@ -130,7 +132,7 @@
private JaxrsHttpMethod createHttpMethod(String qualifiedName) throws
JavaModelException, CoreException {
final IType type = getType(qualifiedName, javaProject);
- final Annotation httpAnnotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation httpAnnotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(httpAnnotation).build();
metamodel.add(httpMethod);
return httpMethod;
@@ -163,11 +165,11 @@
// pre-conditions
final JaxrsHttpMethod httpMethod = JaxrsBuiltinHttpMethod.GET;
final JaxrsResource customerResource =
createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
- customerResource.addOrUpdateAnnotation(getAnnotation(customerResource.getJavaElement(),
CONSUMES.qualifiedName));
- customerResource.addOrUpdateAnnotation(getAnnotation(customerResource.getJavaElement(),
PRODUCES.qualifiedName));
+ customerResource.addOrUpdateAnnotation(resolveAnnotation(customerResource.getJavaElement(),
CONSUMES.qualifiedName));
+ customerResource.addOrUpdateAnnotation(resolveAnnotation(customerResource.getJavaElement(),
PRODUCES.qualifiedName));
final JaxrsResourceMethod customerResourceMethod =
createResourceMethod("getCustomerAsVCard", customerResource,
GET);
- customerResourceMethod.addOrUpdateAnnotation(getAnnotation(customerResourceMethod.getJavaElement(),
+ customerResourceMethod.addOrUpdateAnnotation(resolveAnnotation(customerResourceMethod.getJavaElement(),
PRODUCES.qualifiedName));
// operation
JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
@@ -288,7 +290,7 @@
null);
assertThat(customerSubresourceMethod.getElementKind(),
equalTo(EnumElementKind.SUBRESOURCE_LOCATOR));
// operation
- Annotation httpAnnotation = getAnnotation(customerSubresourceMethod.getJavaElement(),
GET.qualifiedName);
+ Annotation httpAnnotation =
resolveAnnotation(customerSubresourceMethod.getJavaElement(), GET.qualifiedName);
final int flags = customerSubresourceMethod.addOrUpdateAnnotation(httpAnnotation);
JaxrsElementDelta event = new JaxrsElementDelta(customerSubresourceMethod, CHANGED,
flags);
final List<JaxrsEndpointDelta> changes = processEvent(event, progressMonitor);
@@ -406,7 +408,7 @@
final JaxrsResource customerResource =
createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
final JaxrsResourceMethod customerResourceMethod =
createResourceMethod("getCustomer", customerResource,
GET);
- final Annotation annotation = getAnnotation(customerResourceMethod.getJavaElement(),
PATH.qualifiedName);
+ final Annotation annotation =
resolveAnnotation(customerResourceMethod.getJavaElement(), PATH.qualifiedName);
customerResourceMethod.removeAnnotation(annotation.getJavaAnnotation().getHandleIdentifier());
final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
assertThat(endpoint.getUriPathTemplate(), equalTo("/customers"));
@@ -610,7 +612,7 @@
final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
assertThat(endpoint.getUriPathTemplate(), equalTo("/customers/{id}"));
// operation
- final Annotation annotation = getAnnotation(customerResource.getJavaElement(),
PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(customerResource.getJavaElement(),
PATH.qualifiedName);
final int flags =
customerResource.removeAnnotation(annotation.getJavaAnnotation().getHandleIdentifier());
final JaxrsElementDelta event = new JaxrsElementDelta(customerResource, CHANGED,
flags);
final List<JaxrsEndpointDelta> changes = processEvent(event, progressMonitor);
@@ -678,7 +680,7 @@
final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
assertThat(endpoint.getUriPathTemplate(), equalTo("/customers/{id}"));
// operation
- final Annotation annotation = getAnnotation(customerResourceMethod.getJavaElement(),
PATH.qualifiedName);
+ final Annotation annotation =
resolveAnnotation(customerResourceMethod.getJavaElement(), PATH.qualifiedName);
final int flags =
customerResourceMethod.removeAnnotation(annotation.getJavaAnnotation().getHandleIdentifier());
final JaxrsElementDelta event = new JaxrsElementDelta(customerResourceMethod, CHANGED,
flags);
final List<JaxrsEndpointDelta> changes = processEvent(event, progressMonitor);
@@ -701,7 +703,7 @@
final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
assertThat(endpoint.getConsumedMediaTypes(), equalTo(Arrays.asList("*/*")));
// operation
- final int flags =
customerResource.addOrUpdateAnnotation(getAnnotation(customerResource.getJavaElement(),
+ final int flags =
customerResource.addOrUpdateAnnotation(resolveAnnotation(customerResource.getJavaElement(),
CONSUMES.qualifiedName));
final JaxrsElementDelta event = new JaxrsElementDelta(customerResource, CHANGED,
flags);
final List<JaxrsEndpointDelta> changes = processEvent(event, progressMonitor);
@@ -724,7 +726,7 @@
final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
assertThat(endpoint.getConsumedMediaTypes(), equalTo(Arrays.asList("*/*")));
// operation
- final int flags = customerResourceMethod.addOrUpdateAnnotation(getAnnotation(
+ final int flags = customerResourceMethod.addOrUpdateAnnotation(resolveAnnotation(
customerResourceMethod.getJavaElement(), CONSUMES.qualifiedName));
final JaxrsElementDelta event = new JaxrsElementDelta(customerResourceMethod, CHANGED,
flags);
final List<JaxrsEndpointDelta> changes = processEvent(event, progressMonitor);
@@ -750,7 +752,7 @@
final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
assertThat(endpoint.getConsumedMediaTypes(),
equalTo(Arrays.asList("application/foo")));
// operation
- int flags =
customerResourceMethod.addOrUpdateAnnotation(getAnnotation(customerResourceMethod.getJavaElement(),
+ int flags =
customerResourceMethod.addOrUpdateAnnotation(resolveAnnotation(customerResourceMethod.getJavaElement(),
CONSUMES.qualifiedName));
final JaxrsElementDelta event = new JaxrsElementDelta(customerResourceMethod, CHANGED,
flags);
final List<JaxrsEndpointDelta> changes = processEvent(event, progressMonitor);
@@ -775,7 +777,7 @@
final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
assertThat(endpoint.getConsumedMediaTypes(),
equalTo(Arrays.asList("application/foo")));
// operation
- int flags =
customerResource.addOrUpdateAnnotation(getAnnotation(customerResource.getJavaElement(),
+ int flags =
customerResource.addOrUpdateAnnotation(resolveAnnotation(customerResource.getJavaElement(),
CONSUMES.qualifiedName));
final JaxrsElementDelta event = new JaxrsElementDelta(customerResourceMethod, CHANGED,
flags);
final List<JaxrsEndpointDelta> changes = processEvent(event, progressMonitor);
@@ -872,7 +874,7 @@
final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
assertThat(endpoint.getProducedMediaTypes(), equalTo(Arrays.asList("*/*")));
// operation
- final int flags = customerResourceMethod.addOrUpdateAnnotation(getAnnotation(
+ final int flags = customerResourceMethod.addOrUpdateAnnotation(resolveAnnotation(
customerResourceMethod.getJavaElement(), PRODUCES.qualifiedName));
final JaxrsElementDelta event = new JaxrsElementDelta(customerResourceMethod, CHANGED,
flags);
final List<JaxrsEndpointDelta> changes = processEvent(event, progressMonitor);
@@ -923,7 +925,7 @@
final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
assertThat(endpoint.getProducedMediaTypes(),
equalTo(Arrays.asList("application/foo")));
// operation
- int flags =
customerResourceMethod.addOrUpdateAnnotation(getAnnotation(customerResourceMethod.getJavaElement(),
+ int flags =
customerResourceMethod.addOrUpdateAnnotation(resolveAnnotation(customerResourceMethod.getJavaElement(),
PRODUCES.qualifiedName));
final JaxrsElementDelta event = new JaxrsElementDelta(customerResourceMethod, CHANGED,
flags);
final List<JaxrsEndpointDelta> changes = processEvent(event, progressMonitor);
@@ -1018,7 +1020,7 @@
final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
assertThat(endpoint.getUriPathTemplate(), equalTo("/customers/{id}"));
// operation
- final Annotation annotation = getAnnotation(customerResource.getJavaElement(),
PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(customerResource.getJavaElement(),
PATH.qualifiedName);
final int flags =
customerResource.removeAnnotation(annotation.getJavaAnnotation().getHandleIdentifier());
final JaxrsElementDelta event = new JaxrsElementDelta(customerResource, CHANGED,
flags);
final List<JaxrsEndpointDelta> changes = processEvent(event, progressMonitor);
@@ -1210,7 +1212,7 @@
GET);
final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
// operation
- final Annotation annotation = getAnnotation(customerResourceMethod.getJavaElement(),
PATH.qualifiedName);
+ final Annotation annotation =
resolveAnnotation(customerResourceMethod.getJavaElement(), PATH.qualifiedName);
final int flags =
customerResourceMethod.removeAnnotation(annotation.getJavaAnnotation().getHandleIdentifier());
final JaxrsElementDelta event = new JaxrsElementDelta(customerResourceMethod, REMOVED,
flags);
final List<JaxrsEndpointDelta> changes = processEvent(event, progressMonitor);
@@ -1259,7 +1261,7 @@
final JaxrsResource gameResource =
createResource("org.jboss.tools.ws.jaxrs.sample.services.GameResource");
final JaxrsResourceMethod gameResourceMethod =
createResourceMethod("getProduct", gameResource, GET);
final JaxrsEndpoint gameEndpoint = createEndpoint(httpMethod,
productResourceLocatorMethod, gameResourceMethod);
- final Annotation productResourceLocatorPathAnnotation =
getAnnotation(productResourceLocator.getJavaElement(),
+ final Annotation productResourceLocatorPathAnnotation =
resolveAnnotation(productResourceLocator.getJavaElement(),
PATH.qualifiedName);
final int flags =
productResourceLocator.removeAnnotation(productResourceLocatorPathAnnotation
.getJavaAnnotation().getHandleIdentifier());
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessorTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessorTestCase.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessorTestCase.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -16,16 +16,21 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.everyItem;
+import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
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.WorkbenchUtils.resolveAnnotation;
+import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getMethod;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getType;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.APPLICATION_PATH;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.CONSUMES;
+import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.CONTEXT;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.DELETE;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.GET;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.HTTP_METHOD;
+import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.PATH;
+import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.PATH_PARAM;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.POST;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.PUT;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.RETENTION;
@@ -49,6 +54,7 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.hamcrest.Matchers;
@@ -109,7 +115,7 @@
* @throws JavaModelException
*/
private JaxrsJavaApplication createJavaApplication(IType type) throws JavaModelException
{
- final Annotation appPathAnnotation = getAnnotation(type,
APPLICATION_PATH.qualifiedName);
+ final Annotation appPathAnnotation = resolveAnnotation(type,
APPLICATION_PATH.qualifiedName);
return new JaxrsJavaApplication(type, appPathAnnotation, true, metamodel);
}
@@ -148,7 +154,7 @@
JavaModelException {
final IType httpMethodType = JdtUtils
.resolveType(httpMethodElement.qualifiedName, javaProject, progressMonitor);
- final Annotation httpMethodAnnotation = getAnnotation(httpMethodType,
HTTP_METHOD.qualifiedName);
+ final Annotation httpMethodAnnotation = resolveAnnotation(httpMethodType,
HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(httpMethodType,
metamodel).httpMethod(
httpMethodAnnotation).build();
@@ -156,9 +162,9 @@
}
private JaxrsHttpMethod createHttpMethod(IType type) throws JavaModelException {
- final Annotation httpMethodAnnotation = getAnnotation(type,
HTTP_METHOD.qualifiedName);
- final Annotation targetAnnotation = getAnnotation(type, TARGET.qualifiedName);
- final Annotation retentionAnnotation = getAnnotation(type, RETENTION.qualifiedName);
+ final Annotation httpMethodAnnotation = resolveAnnotation(type,
HTTP_METHOD.qualifiedName);
+ final Annotation targetAnnotation = resolveAnnotation(type, TARGET.qualifiedName);
+ final Annotation retentionAnnotation = resolveAnnotation(type,
RETENTION.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type, metamodel)
.httpMethod(httpMethodAnnotation).target(targetAnnotation).retention(retentionAnnotation).build();
return httpMethod;
@@ -297,7 +303,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, APPLICATION_PATH.qualifiedName);
// operation
final ResourceDelta event = createEvent(annotation.getJavaParent().getResource(),
CHANGED);
final List<JaxrsElementDelta> affectedElements = processResourceChanges(event,
progressMonitor);
@@ -334,7 +340,7 @@
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
metamodel.add(createJavaApplication(type));
- final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, APPLICATION_PATH.qualifiedName);
// operation
WorkbenchUtils.delete(annotation.getJavaAnnotation(), false);
final ResourceDelta event = createEvent(annotation.getJavaParent().getResource(),
CHANGED);
@@ -389,7 +395,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(annotation).build();
metamodel.add(httpMethod);
// operation
@@ -895,7 +901,7 @@
"lib/jaxrs-api-2.0.1.GA.jar", progressMonitor);
// let's suppose that this jar only contains 1 HTTP Methods ;-)
final IType type = JdtUtils.resolveType("javax.ws.rs.GET", javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(annotation).build();
metamodel.add(httpMethod);
// operation
@@ -910,7 +916,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
// operation
final ResourceDelta event = createEvent(annotation.getJavaParent().getResource(),
CHANGED);
final List<JaxrsElementDelta> affectedElements = processResourceChanges(event,
progressMonitor);
@@ -950,7 +956,7 @@
progressMonitor);
final JaxrsHttpMethod httpMethod = createHttpMethod(type);
metamodel.add(httpMethod);
- final Annotation annotation = getAnnotation(type, TARGET.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, TARGET.qualifiedName);
// operation
WorkbenchUtils.delete(annotation.getJavaAnnotation(), false);
final ResourceDelta event = createEvent(annotation.getJavaParent().getResource(),
CHANGED);
@@ -972,7 +978,7 @@
progressMonitor);
final JaxrsHttpMethod httpMethod = createHttpMethod(type);
metamodel.add(httpMethod);
- final Annotation annotation = getAnnotation(type, TARGET.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, TARGET.qualifiedName);
// operation
WorkbenchUtils.addTypeAnnotation(type, "@Deprecated", false);
final ResourceDelta event = createEvent(annotation.getJavaParent().getResource(),
CHANGED);
@@ -987,7 +993,7 @@
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
metamodel.add(createHttpMethod(type));
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
// operation
WorkbenchUtils.delete(annotation.getJavaAnnotation(), false);
final ResourceDelta event = createEvent(annotation.getJavaParent().getResource(),
CHANGED);
@@ -1007,7 +1013,7 @@
// JaxrsMetamodel metamodel = new JaxrsMetamodel(javaProject);
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(annotation).build();
metamodel.add(httpMethod);
// operation
@@ -1026,7 +1032,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(annotation).build();
metamodel.add(httpMethod);
// operation
@@ -1046,7 +1052,7 @@
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(type,
metamodel).httpMethod(annotation).build();
metamodel.add(httpMethod);
final IPackageFragmentRoot sourceFolder =
WorkbenchUtils.getPackageFragmentRoot(javaProject, "src/main/java",
@@ -1356,7 +1362,7 @@
final IPackageFragmentRoot sourceFolder =
WorkbenchUtils.getPackageFragmentRoot(javaProject, "src/main/java",
progressMonitor);
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation annotation = getAnnotation(type, CONSUMES.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, CONSUMES.qualifiedName);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(annotation).build();
metamodel.add(resource);
// operation
@@ -1410,4 +1416,227 @@
assertThat(metamodel.getElements(javaProject).size(), equalTo(4));
}
+ /**
+ * Test in relation with
https://issues.jboss.org/browse/JBIDE-12806
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void shouldUpdateTypeAnnotationLocationAfterCodeChangeAbove() throws
CoreException {
+ // pre-condition: using the CustomerResource type
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, progressMonitor);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
+ final JaxrsResource customerResource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
+ .build();
+ metamodel.add(customerResource);
+ final ISourceRange beforeChangeSourceRange = JdtUtils.resolveMemberPairValueRange(
+ pathAnnotation.getJavaAnnotation(), pathAnnotation.getFullyQualifiedName(),
"value");
+ final int length = beforeChangeSourceRange.getLength();
+ final int offset = beforeChangeSourceRange.getOffset();
+ // operation: removing @Encoded *before* the CustomerResource type
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type, "@Encoded", "",
false);
+ CompilationUnitsRepository.getInstance().mergeAST(type.getCompilationUnit(),
JdtUtils.parse(type.getCompilationUnit(), null), true);
+ final ResourceDelta event =
createEvent(customerResource.getJavaElement().getResource(), CHANGED);
+ processResourceChanges(event, progressMonitor);
+ // verifications
+ final ISourceRange afterChangeSourceRange = JdtUtils.resolveMemberPairValueRange(
+ pathAnnotation.getJavaAnnotation(), pathAnnotation.getFullyQualifiedName(),
"value");
+ assertThat(afterChangeSourceRange.getOffset(), lessThan(offset));
+ assertThat(afterChangeSourceRange.getLength(), equalTo(length));
+ }
+
+ /**
+ * Test in relation with
https://issues.jboss.org/browse/JBIDE-12806
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void shouldUpdateMethodAnnotationLocationAfterCodeChangeAbove() throws
CoreException {
+ // pre-condition: using the CustomerResource type
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, progressMonitor);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
+ final JaxrsResource customerResource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
+ .build();
+ metamodel.add(customerResource);
+ final IMethod method = getMethod(type, "createCustomer");
+ final Annotation postAnnotation = resolveAnnotation(method, POST.qualifiedName);
+ final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
customerResource, metamodel)
+ .httpMethod(postAnnotation).build();
+ metamodel.add(resourceMethod);
+ final ISourceRange beforeChangeSourceRange =
postAnnotation.getJavaAnnotation().getSourceRange();
+ final int length = beforeChangeSourceRange.getLength();
+ final int offset = beforeChangeSourceRange.getOffset();
+ // operation: removing @Encoded *before* the createCustomer() method
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type, "@Encoded", "",
false);
+ CompilationUnitsRepository.getInstance().mergeAST(type.getCompilationUnit(),
JdtUtils.parse(type.getCompilationUnit(), null), true);
+ final ResourceDelta event =
createEvent(customerResource.getJavaElement().getResource(), CHANGED);
+ processResourceChanges(event, progressMonitor);
+ // verifications
+ final ISourceRange afterChangeSourceRange =
postAnnotation.getJavaAnnotation().getSourceRange();
+ assertThat(afterChangeSourceRange.getOffset(), lessThan(offset));
+ assertThat(afterChangeSourceRange.getLength(), equalTo(length));
+ }
+
+ /**
+ * Test in relation with
https://issues.jboss.org/browse/JBIDE-12806
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void shouldUpdateMethodParameterAnnotationLocationAfterCodeChangeAbove() throws
CoreException {
+ // pre-condition: using the CustomerResource type
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, progressMonitor);
+ final JaxrsResource customerResource = new JaxrsElementFactory().createResource(type,
+ JdtUtils.parse(type.getCompilationUnit(), null), metamodel);
+ metamodel.add(customerResource);
+ final IMethod javaMethod = getMethod(type, "getCustomer");
+ final JaxrsResourceMethod resourceMethod =
customerResource.getMethods().get(javaMethod.getHandleIdentifier());
+ final Annotation pathParamAnnotation =
resourceMethod.getJavaMethodParameters().get(0).getAnnotations()
+ .get(PATH_PARAM.qualifiedName);
+ final ISourceRange beforeChangeSourceRange =
JdtUtils.resolveMemberPairValueRange(pathParamAnnotation.getJavaAnnotation(),
pathParamAnnotation.getFullyQualifiedName(), "value");
+ final int beforeLength = beforeChangeSourceRange.getLength();
+ final int beforeOffset = beforeChangeSourceRange.getOffset();
+ // operation: removing @Encoded *before* the getCustomer() method
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type, "@Encoded", "",
false);
+ CompilationUnitsRepository.getInstance().mergeAST(type.getCompilationUnit(),
JdtUtils.parse(type.getCompilationUnit(), null), true);
+ final ResourceDelta event =
createEvent(customerResource.getJavaElement().getResource(), CHANGED);
+ processResourceChanges(event, progressMonitor);
+ // verifications
+ final ISourceRange afterChangeSourceRange =
JdtUtils.resolveMemberPairValueRange(pathParamAnnotation.getJavaAnnotation(),
pathParamAnnotation.getFullyQualifiedName(), "value");
+ final int afterLength = afterChangeSourceRange.getLength();
+ final int afterOffset = afterChangeSourceRange.getOffset();
+ assertThat(afterOffset, lessThan(beforeOffset));
+ assertThat(afterLength, equalTo(beforeLength));
+ }
+
+ /**
+ * Test in relation with
https://issues.jboss.org/browse/JBIDE-12806
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void
shouldUpdateMethodParameterAnnotationLocationAfterPreviousMethodParamRemoved() throws
CoreException {
+ // pre-condition: using the CustomerResource type
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, progressMonitor);
+ final JaxrsResource customerResource = new JaxrsElementFactory().createResource(type,
+ JdtUtils.parse(type.getCompilationUnit(), null), metamodel);
+ metamodel.add(customerResource);
+ IMethod javaMethod = getMethod(type, "getCustomer");
+ JaxrsResourceMethod resourceMethod =
customerResource.getMethods().get(javaMethod.getHandleIdentifier());
+ Annotation contextAnnotation =
resourceMethod.getJavaMethodParameters().get(1).getAnnotations()
+ .get(CONTEXT.qualifiedName);
+ final ISourceRange beforeChangeSourceRange =
contextAnnotation.getJavaAnnotation().getSourceRange();
+ final int beforeLength = beforeChangeSourceRange.getLength();
+ final int beforeOffset = beforeChangeSourceRange.getOffset();
+ // operation: removing "@PathParam("id") Integer id" parameter in
the getCustomer() method
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type, "@PathParam(\"id\")
Integer id, ", "", false);
+ CompilationUnitsRepository.getInstance().mergeAST(type.getCompilationUnit(),
JdtUtils.parse(type.getCompilationUnit(), null), true);
+ final ResourceDelta event =
createEvent(customerResource.getJavaElement().getResource(), CHANGED);
+ processResourceChanges(event, progressMonitor);
+ // verifications: java method has changed, so all references must be looked-up again
+ javaMethod = getMethod(type, "getCustomer");
+ resourceMethod = customerResource.getMethods().get(javaMethod.getHandleIdentifier());
+ contextAnnotation =
resourceMethod.getJavaMethodParameters().get(0).getAnnotations().get(CONTEXT.qualifiedName);
+ final ISourceRange afterChangeSourceRange =
contextAnnotation.getJavaAnnotation().getSourceRange();
+ final int afterLength = afterChangeSourceRange.getLength();
+ final int afterOffset = afterChangeSourceRange.getOffset();
+ assertThat(afterOffset, lessThan(beforeOffset));
+ assertThat(afterLength, equalTo(beforeLength));
+ }
+
+ /**
+ * Test in relation with
https://issues.jboss.org/browse/JBIDE-12806
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void shouldNotUpdateTypeAnnotationLocationAfterCodeChangeBelow() throws
CoreException {
+ // pre-condition: using the CustomerResource type
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, progressMonitor);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
+ final JaxrsResource customerResource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
+ .build();
+ metamodel.add(customerResource);
+ final ISourceRange beforeChangeSourceRange =
JdtUtils.resolveMemberPairValueRange(pathAnnotation.getJavaAnnotation(),
pathAnnotation.getFullyQualifiedName(), "value");
+ final int length = beforeChangeSourceRange.getLength();
+ final int offset = beforeChangeSourceRange.getOffset();
+ // operation: removing @DELETE *after* the CustomerResource type
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type, "@DELETE", "",
false);
+ CompilationUnitsRepository.getInstance().mergeAST(type.getCompilationUnit(),
JdtUtils.parse(type.getCompilationUnit(), null), true);
+ final ResourceDelta event =
createEvent(customerResource.getJavaElement().getResource(), CHANGED);
+ processResourceChanges(event, progressMonitor);
+ // verifications
+ final ISourceRange afterChangeSourceRange =
JdtUtils.resolveMemberPairValueRange(pathAnnotation.getJavaAnnotation(),
pathAnnotation.getFullyQualifiedName(), "value");
+ assertThat(afterChangeSourceRange.getOffset(), equalTo(offset));
+ assertThat(afterChangeSourceRange.getLength(), equalTo(length));
+ }
+
+ /**
+ * Test in relation with
https://issues.jboss.org/browse/JBIDE-12806
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void shouldNotUpdateMethodAnnotationLocationAfterCodeChangeBelow() throws
CoreException {
+ // pre-condition: using the CustomerResource type
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, progressMonitor);
+ final Annotation pathAnnotation = resolveAnnotation(type, PATH.qualifiedName);
+ final JaxrsResource customerResource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
+ .build();
+ metamodel.add(customerResource);
+ final IMethod method = getMethod(type, "createCustomer");
+ final Annotation postAnnotation = resolveAnnotation(method, POST.qualifiedName);
+ final JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
customerResource, metamodel)
+ .httpMethod(postAnnotation).build();
+ metamodel.add(resourceMethod);
+ final ISourceRange beforeChangeSourceRange =
postAnnotation.getJavaAnnotation().getSourceRange();
+ final int length = beforeChangeSourceRange.getLength();
+ final int offset = beforeChangeSourceRange.getOffset();
+ // operation: removing @DELETE, after the createCustomer() method
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type, "@DELETE", "",
false);
+ CompilationUnitsRepository.getInstance().mergeAST(type.getCompilationUnit(),
JdtUtils.parse(type.getCompilationUnit(), null), true);
+ final ResourceDelta event =
createEvent(customerResource.getJavaElement().getResource(), CHANGED);
+ processResourceChanges(event, progressMonitor);
+ // verifications
+ final ISourceRange afterChangeSourceRange =
postAnnotation.getJavaAnnotation().getSourceRange();
+ assertThat(afterChangeSourceRange.getOffset(), equalTo(offset));
+ assertThat(afterChangeSourceRange.getLength(), equalTo(length));
+ }
+
+ /**
+ * Test in relation with
https://issues.jboss.org/browse/JBIDE-12806
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void shouldNotUpdateMethodParameterAnnotationLocationAfterCodeChangeBelow()
throws CoreException {
+ // pre-condition: using the CustomerResource type
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, progressMonitor);
+ final JaxrsResource customerResource = new JaxrsElementFactory().createResource(type,
+ JdtUtils.parse(type.getCompilationUnit(), null), metamodel);
+ metamodel.add(customerResource);
+ final IMethod javaMethod = getMethod(type, "getCustomer");
+ final JaxrsResourceMethod resourceMethod =
customerResource.getMethods().get(javaMethod.getHandleIdentifier());
+ final Annotation pathParamAnnotation =
resourceMethod.getJavaMethodParameters().get(0).getAnnotations()
+ .get(PATH_PARAM.qualifiedName);
+ final ISourceRange beforeChangeSourceRange =
JdtUtils.resolveMemberPairValueRange(pathParamAnnotation.getJavaAnnotation(),
pathParamAnnotation.getFullyQualifiedName(), "value");
+ final int length = beforeChangeSourceRange.getLength();
+ final int offset = beforeChangeSourceRange.getOffset();
+ // operation: removing @DELETE, *after* the getCustomer() method
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type, "@DELETE", "",
false);
+ CompilationUnitsRepository.getInstance().mergeAST(type.getCompilationUnit(),
JdtUtils.parse(type.getCompilationUnit(), null), true);
+ final ResourceDelta event =
createEvent(customerResource.getJavaElement().getResource(), CHANGED);
+ processResourceChanges(event, progressMonitor);
+ // verifications
+ final ISourceRange afterChangeSourceRange =
JdtUtils.resolveMemberPairValueRange(pathParamAnnotation.getJavaAnnotation(),
pathParamAnnotation.getFullyQualifiedName(), "value");
+ assertThat(afterChangeSourceRange.getOffset(), equalTo(offset));
+ assertThat(afterChangeSourceRange.getLength(), equalTo(length));
+ }
}
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactoryTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactoryTestCase.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactoryTestCase.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -13,7 +13,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.nullValue;
-import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getAnnotation;
+import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.resolveAnnotation;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getMethod;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getType;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.APPLICATION_PATH;
@@ -65,7 +65,7 @@
public void shouldCreateRootResourceFromPathAnnotation() throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final Annotation annotation = getAnnotation(type, PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, PATH.qualifiedName);
// operation
final JaxrsJavaElement<?> element =
factory.createElement(annotation.getJavaAnnotation(),
JdtUtils.parse(type, progressMonitor), metamodel);
@@ -100,7 +100,7 @@
public void shouldCreateHttpMethodFromAnnotation() throws CoreException {
// pre-conditions
final IType type = getType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject);
- final Annotation annotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
// operation
final JaxrsJavaElement<?> element =
factory.createElement(annotation.getJavaAnnotation(),
JdtUtils.parse(type, progressMonitor), metamodel);
@@ -124,12 +124,12 @@
public void shouldCreateMethodInRootResourceFromAnnotation() throws CoreException {
// pre-conditions
final IType httpType = getType(GET.qualifiedName, javaProject);
- final Annotation httpAnnotation = getAnnotation(httpType, HTTP_METHOD.qualifiedName);
+ final Annotation httpAnnotation = resolveAnnotation(httpType,
HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(httpType,
metamodel).httpMethod(httpAnnotation).build();
metamodel.add(httpMethod);
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final IMethod method = getMethod(type, "getCustomerAsVCard");
- final Annotation annotation = getAnnotation(method, PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(method, PATH.qualifiedName);
// operation
JaxrsResourceMethod element = factory.createResourceMethod(annotation,
JdtUtils.parse(method, progressMonitor), metamodel);
@@ -142,12 +142,12 @@
public void shouldCreateMethodInSubresourceFromAnnotation() throws CoreException {
// pre-conditions
final IType httpType = getType(GET.qualifiedName, javaProject);
- final Annotation httpAnnotation = getAnnotation(httpType, HTTP_METHOD.qualifiedName);
+ final Annotation httpAnnotation = resolveAnnotation(httpType,
HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(httpType,
metamodel).httpMethod(httpAnnotation).build();
metamodel.add(httpMethod);
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
final IMethod method = getMethod(type, "getProduct");
- final Annotation annotation = getAnnotation(method, PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(method, PATH.qualifiedName);
// operation
JaxrsResourceMethod element = factory.createResourceMethod(annotation,
JdtUtils.parse(method, progressMonitor), metamodel);
@@ -160,13 +160,13 @@
public void shouldCreateFieldFromAnnotation() throws CoreException {
// pre-conditions
final IType httpType = getType(GET.qualifiedName, javaProject);
- final Annotation httpAnnotation = getAnnotation(httpType, HTTP_METHOD.qualifiedName);
+ final Annotation httpAnnotation = resolveAnnotation(httpType,
HTTP_METHOD.qualifiedName);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod.Builder(httpType,
metamodel).httpMethod(httpAnnotation).build();
metamodel.add(httpMethod);
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
IField field = type.getField("foo");
- final Annotation annotation = getAnnotation(field, QUERY_PARAM.qualifiedName);
+ final Annotation annotation = resolveAnnotation(field, QUERY_PARAM.qualifiedName);
// operation
JaxrsResourceField element = factory.createField(annotation, JdtUtils.parse(field,
progressMonitor), metamodel);
// verifications
@@ -236,7 +236,7 @@
public void shouldCreateApplicationFromApplicationAnnotationAndApplicationSubclass()
throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject);
- final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, APPLICATION_PATH.qualifiedName);
// operation
final JaxrsJavaElement<?> element = factory.createApplication(annotation,
JdtUtils.parse(type, progressMonitor), metamodel);
@@ -251,7 +251,7 @@
public void shouldCreateApplicationFromApplicationSubclassOnly() throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject);
- final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, APPLICATION_PATH.qualifiedName);
WorkbenchUtils.delete(annotation.getJavaAnnotation(), false);
// operation
final JaxrsJavaElement<?> element = factory.createApplication(type,
@@ -271,7 +271,7 @@
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject);
final IType applicationType =
JdtUtils.resolveType(EnumJaxrsClassname.APPLICATION.qualifiedName, javaProject,
progressMonitor);
assertFalse(JdtUtils.isTypeOrSuperType(applicationType, type));
- final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ final Annotation annotation = resolveAnnotation(type, APPLICATION_PATH.qualifiedName);
// operation
final JaxrsJavaElement<?> element = factory.createApplication(annotation,
JdtUtils.parse(type, progressMonitor), metamodel);
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodelTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodelTestCase.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodelTestCase.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -16,9 +16,9 @@
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
-import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getAnnotation;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getMethod;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getType;
+import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.resolveAnnotation;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.HTTP_METHOD;
import static org.junit.Assert.assertThat;
@@ -67,7 +67,7 @@
public void shouldGetHttpMethodByAnnotation() throws CoreException {
IType javaType =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(javaType, HTTP_METHOD.qualifiedName);
+ final Annotation annotation = resolveAnnotation(javaType, HTTP_METHOD.qualifiedName);
assertThat((JaxrsHttpMethod) metamodel.getElement(annotation), notNullValue());
}
@@ -76,7 +76,7 @@
IType javaType =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
final Annotation annotation = JdtUtils.resolveAnnotation(javaType,
JdtUtils.parse(javaType, progressMonitor),
- SuppressWarnings.class);
+ SuppressWarnings.class.getName());
assertThat(metamodel.getElement(annotation), nullValue());
}
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-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorTestCase.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -12,7 +12,7 @@
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.WorkbenchUtils.resolveAnnotation;
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;
@@ -117,7 +117,7 @@
// preconditions
final IType fooType =
WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject);
final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType,
JaxrsHttpMethod.class);
- final Annotation targetAnnotation = getAnnotation(fooType, TARGET.qualifiedName);
+ final Annotation targetAnnotation = resolveAnnotation(fooType, TARGET.qualifiedName);
httpMethod.removeAnnotation(targetAnnotation);
deleteJaxrsMarkers(httpMethod);
// operation
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceValidatorTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceValidatorTestCase.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceValidatorTestCase.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -89,6 +89,9 @@
validatorManager, reporter);
// validation
final IMarker[] markers = findJaxrsMarkers(barResource);
+ for(IMarker marker : markers) {
+ LOGGER.debug("problem at line {}: {}",
marker.getAttribute(IMarker.LINE_NUMBER), marker.getAttribute(IMarker.MESSAGE));
+ }
assertThat(markers.length, equalTo(8));
final Map<String, JaxrsResourceMethod> resourceMethods =
barResource.getMethods();
for (Entry<String, JaxrsResourceMethod> entry : resourceMethods.entrySet()) {
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionUtilsTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionUtilsTestCase.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionUtilsTestCase.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -17,10 +17,13 @@
import static org.junit.Assert.assertThat;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import
org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtils.CollectionComparison;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtils.MapComparison;
import org.junit.Test;
@SuppressWarnings("serial")
@@ -28,123 +31,168 @@
@Test
public void shouldNotFindDifferencesInSameLists() {
+ // preconditions
List<String> control = Arrays.asList("a", "b",
"c");
List<String> test = Arrays.asList("a", "b", "c");
- assertThat(CollectionUtils.difference(control, test).size(), equalTo(0));
+ // operation
+ final List<String> difference = CollectionUtils.difference(control, test);
+ // verifications
+ assertThat(difference.size(), equalTo(0));
}
@Test
public void shouldFindDifferencesInListsOfSameSize() {
+ // preconditions
List<String> control = Arrays.asList("a", "b",
"d");
List<String> test = Arrays.asList("a", "b", "c");
+ // operation
List<String> diffs = (List<String>) CollectionUtils.difference(control,
test);
+ // verifications
assertThat(diffs.size(), equalTo(1));
assertThat(diffs.get(0), equalTo("d"));
}
@Test
public void shouldFindDifferencesInListsOfDifferentSizeWithMissingEntry() {
+ // preconditions
List<String> control = Arrays.asList("a", "b", "c",
"d");
List<String> test = Arrays.asList("a", "b", "c");
+ // operation
List<String> diffs = (List<String>) CollectionUtils.difference(control,
test);
+ // verifications
assertThat(diffs.size(), equalTo(1));
assertThat(diffs.get(0), equalTo("d"));
}
@Test
public void shouldNotFindDifferencesInListsOfDifferentSizeWithMissingEntry() {
+ // preconditions
List<String> control = Arrays.asList("a", "b",
"c");
List<String> test = Arrays.asList("a", "b", "c",
"d");
+ // operation
List<String> diffs = (List<String>) CollectionUtils.difference(control,
test);
+ // verifications
assertThat(diffs.size(), equalTo(0));
}
@Test
public void shouldFindDifferencesInListsOfDifferentSizeWithDifferentEntries() {
+ // preconditions
List<String> control = Arrays.asList("a", "b", "c",
"d");
List<String> test = Arrays.asList("a", "b", "c",
"e", "f");
+ // operation
List<String> diffs = (List<String>) CollectionUtils.difference(control,
test);
+ // verifications
assertThat(diffs.size(), equalTo(1));
assertThat(diffs.get(0), equalTo("d"));
}
@Test
public void shouldReturnNullWhenControlListToDifferentiateIsNull() {
+ // preconditions
List<String> control = null;
List<String> test = Arrays.asList("a", "b", "d",
"c");
+ // operation
List<String> diffs = (List<String>) CollectionUtils.difference(control,
test);
+ // verifications
assertNull(diffs);
}
@Test
public void shouldReturnControlWhenTestListToDifferentiateIsNull() {
+ // preconditions
List<String> control = Arrays.asList("a", "b",
"c");
List<String> test = null;
+ // operation
List<String> diffs = (List<String>) CollectionUtils.difference(control,
test);
+ // verifications
assertThat(diffs, equalTo(control));
}
@Test
public void shouldFindIntersectionsInSameLists() {
+ // preconditions
List<String> control = Arrays.asList("a", "b",
"c");
List<String> test = Arrays.asList("a", "b", "c");
- assertThat(CollectionUtils.intersection(control, test).size(), equalTo(3));
+ // operation
+ final Collection<String> intersection = CollectionUtils.intersection(control,
test);
+ // verifications
+ assertThat(intersection.size(), equalTo(3));
}
@Test
public void shouldFindIntersectionsInListsOfSameSize() {
+ // preconditions
List<String> control = Arrays.asList("a", "b",
"d");
List<String> test = Arrays.asList("a", "b", "c");
+ // operation
List<String> diffs = (List<String>) CollectionUtils.intersection(control,
test);
+ // verifications
assertThat(diffs.size(), equalTo(2));
assertThat(diffs, contains("a", "b"));
}
@Test
public void shouldFindIntersectionsInListsOfDifferentSizeWithMissingEntryInTest() {
+ // preconditions
List<String> control = Arrays.asList("a", "b", "c",
"d");
List<String> test = Arrays.asList("a", "b", "c");
+ // operation
List<String> diffs = (List<String>) CollectionUtils.intersection(control,
test);
+ // verifications
assertThat(diffs.size(), equalTo(3));
assertThat(diffs, contains("a", "b", "c"));
}
@Test
public void shouldFindIntersectionsInListsOfDifferentSizeWithMissingEntryInControl() {
+ // preconditions
List<String> control = Arrays.asList("a", "b",
"c");
List<String> test = Arrays.asList("a", "b", "c",
"d");
+ // operation
List<String> diffs = (List<String>) CollectionUtils.intersection(control,
test);
+ // verifications
assertThat(diffs.size(), equalTo(3));
assertThat(diffs, contains("a", "b", "c"));
}
@Test
public void shouldFindIntersectionsInListsOfDifferentSizeWithDifferentEntries() {
+ // preconditions
List<String> control = Arrays.asList("a", "b", "c",
"d");
List<String> test = Arrays.asList("a", "b", "c",
"e", "f");
+ // operation
List<String> diffs = (List<String>) CollectionUtils.intersection(control,
test);
+ // verifications
assertThat(diffs.size(), equalTo(3));
assertThat(diffs, contains("a", "b", "c"));
}
@Test
public void shouldReturnNullWhenControlListToIntersectIsNull() {
+ // preconditions
List<String> control = null;
List<String> test = Arrays.asList("a", "b", "d",
"c");
+ // operation
List<String> diffs = (List<String>) CollectionUtils.intersection(control,
test);
+ // verifications
assertNull(diffs);
}
@Test
public void shouldReturnControlWhenTestListToIntersectIsNull() {
+ // preconditions
List<String> control = Arrays.asList("a", "b",
"c");
List<String> test = null;
+ // operation
List<String> diffs = (List<String>) CollectionUtils.intersection(control,
test);
+ // verifications
assertThat(diffs, equalTo(control));
}
@Test
public void shouldNotFindDifferencesInSameMaps() {
+ // preconditions
Map<String, String> control = new HashMap<String, String>() {
{
put("a", "one");
@@ -159,11 +207,15 @@
put("c", "three");
}
};
- assertThat(CollectionUtils.difference(control, test).size(), equalTo(0));
+ // operation
+ final Map<String, String> difference = CollectionUtils.difference(control,
test);
+ // verifications
+ assertThat(difference.size(), equalTo(0));
}
@Test
public void shouldNotFindDifferencesInMapsOfSameSizeWithDifferentValues() {
+ // preconditions
Map<String, String> control = new HashMap<String, String>() {
{
put("a", "one");
@@ -178,12 +230,15 @@
put("c", "three");
}
};
+ // operation
Map<String, String> diffs = CollectionUtils.difference(control, test);
+ // verifications
assertThat(diffs.size(), equalTo(0));
}
@Test
public void shouldFindDifferencesInMapsOfSameSizeWithDifferentKeys() {
+ // preconditions
Map<String, String> control = new HashMap<String, String>() {
{
put("a", "one");
@@ -198,13 +253,16 @@
put("c", "three");
}
};
+ // operation
Map<String, String> diffs = CollectionUtils.difference(control, test);
+ // verifications
assertThat(diffs.size(), equalTo(1));
assertThat(diffs.get("d"), equalTo("four"));
}
@Test
public void shouldNotFindDifferencesInMapsOfDifferentSizeWithDifferentValues() {
+ // preconditions
Map<String, String> control = new HashMap<String, String>() {
{
put("a", "one");
@@ -221,12 +279,15 @@
put("d", "four");
}
};
+ // operation
Map<String, String> diffs = CollectionUtils.difference(control, test);
+ // verifications
assertThat(diffs.size(), equalTo(0));
}
@Test
public void shouldNotFindDifferencesInMapsOfDifferentSizeWithSameValues() {
+ // preconditions
Map<String, String> control = new HashMap<String, String>() {
{
put("a", "one");
@@ -243,12 +304,15 @@
put("d", "four");
}
};
+ // operation
Map<String, String> diffs = CollectionUtils.difference(control, test);
+ // verifications
assertThat(diffs.size(), equalTo(0));
}
@Test
public void shouldReturnNullWhenControlMapToDifferentiateIsNull() {
+ // preconditions
Map<String, String> control = null;
Map<String, String> test = new HashMap<String, String>() {
{
@@ -258,12 +322,15 @@
put("d", "four");
}
};
+ // operation
Map<String, String> diffs = CollectionUtils.difference(control, test);
+ // verifications
assertNull(diffs);
}
@Test
public void shouldReturnControlWhenTestMapToDifferentiateIsNull() {
+ // preconditions
Map<String, String> control = new HashMap<String, String>() {
{
put("a", "one");
@@ -273,12 +340,15 @@
}
};
Map<String, String> test = null;
+ // operation
Map<String, String> diffs = CollectionUtils.difference(control, test);
+ // verifications
assertThat(diffs, equalTo(control));
}
@Test
public void shouldNotFindIntersectionsInSameMaps() {
+ // preconditions
Map<String, String> control = new HashMap<String, String>() {
{
put("a", "one");
@@ -293,12 +363,15 @@
put("c", "three");
}
};
+ // operation
final Map<String, String> result = CollectionUtils.intersection(control, test);
+ // verifications
assertThat(result.size(), equalTo(3));
}
@Test
public void shouldNotFindIntersectionsInMapsOfSameSizeWithDifferentValues() {
+ // preconditions
Map<String, String> control = new HashMap<String, String>() {
{
put("a", "one");
@@ -313,13 +386,16 @@
put("c", "three");
}
};
+ // operation
Map<String, String> diffs = CollectionUtils.intersection(control, test);
+ // verifications
assertThat(diffs.size(), equalTo(3));
assertThat(diffs.get("a"), equalTo("one"));
}
@Test
public void shouldFindIntersectionsInMapsOfSameSizeWithDifferentKeys() {
+ // preconditions
Map<String, String> control = new HashMap<String, String>() {
{
put("a", "one");
@@ -334,13 +410,16 @@
put("c", "three");
}
};
+ // operation
Map<String, String> diffs = CollectionUtils.intersection(control, test);
+ // verifications
assertThat(diffs.size(), equalTo(2));
assertThat(diffs.keySet(), containsInAnyOrder("a", "b"));
}
@Test
public void shouldFindIntersectionsInMapsOfDifferentSizeWithDifferentValues() {
+ // preconditions
Map<String, String> control = new HashMap<String, String>() {
{
put("a", "one");
@@ -357,7 +436,9 @@
put("d", "four");
}
};
+ // operation
Map<String, String> diffs = CollectionUtils.intersection(control, test);
+ // verifications
assertThat(diffs.size(), equalTo(3));
assertThat(diffs.keySet(), containsInAnyOrder("a", "b",
"c"));
assertThat(diffs.get("a"), equalTo("one"));
@@ -365,6 +446,7 @@
@Test
public void shouldFindIntersectionsInMapsOfDifferentSizeWithSameValues() {
+ // preconditions
Map<String, String> control = new HashMap<String, String>() {
{
put("a", "one");
@@ -381,7 +463,9 @@
put("d", "four");
}
};
+ // operation
Map<String, String> diffs = CollectionUtils.intersection(control, test);
+ // verifications
assertThat(diffs.size(), equalTo(3));
assertThat(diffs.keySet(), containsInAnyOrder("a", "b",
"c"));
assertThat(diffs.get("a"), equalTo("one"));
@@ -389,6 +473,7 @@
@Test
public void shouldReturnNullWhenControlMapToIntersectIsNull() {
+ // preconditions
Map<String, String> control = null;
Map<String, String> test = new HashMap<String, String>() {
{
@@ -398,12 +483,15 @@
put("d", "four");
}
};
+ // operation
Map<String, String> diffs = CollectionUtils.intersection(control, test);
+ // verifications
assertNull(diffs);
}
@Test
public void shouldReturnControlWhenTestMapToIntersectIsNull() {
+ // preconditions
Map<String, String> control = new HashMap<String, String>() {
{
put("a", "one");
@@ -413,7 +501,49 @@
}
};
Map<String, String> test = null;
+ // operation
Map<String, String> diffs = CollectionUtils.intersection(control, test);
+ // verifications
assertThat(diffs, equalTo(control));
}
+
+ @Test
+ public void shouldCompareMaps() {
+ // preconditions
+ Map<String, String> control = new HashMap<String, String>() {
+ {
+ put("a", "one");
+ put("b", "2");
+ put("c", "three");
+
+ }
+ };
+ Map<String, String> test = new HashMap<String, String>() {
+ {
+ put("a", "one");
+ put("b", "two");
+ put("d", "four");
+ }
+ };
+ // operation
+ MapComparison<String, String> diffs = CollectionUtils.compare(control, test);
+ // verifications
+ assertThat(diffs.getAddedItems().keySet(), containsInAnyOrder("d"));
+ assertThat(diffs.getItemsInCommon().keySet(), containsInAnyOrder("a",
"b"));
+ assertThat(diffs.getItemsInCommon().get("b"), equalTo("2"));
+ assertThat(diffs.getRemovedItems().keySet(), containsInAnyOrder("c"));
+ }
+
+ @Test
+ public void shouldCompareLists() {
+ // preconditions
+ List<String> control = Arrays.asList("a", "b", "c",
"d");
+ List<String> test = Arrays.asList("a", "b", "c",
"e", "f");
+ // operation
+ CollectionComparison<String> diffs = CollectionUtils.compare(control, test);
+ // verifications
+ assertThat(diffs.getAddedItems(), containsInAnyOrder("e", "f"));
+ assertThat(diffs.getItemsInCommon(), containsInAnyOrder("a", "b",
"c"));
+ assertThat(diffs.getRemovedItems(), containsInAnyOrder("d"));
+ }
}
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/CompilationUnitsRepositoryTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/CompilationUnitsRepositoryTestCase.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/CompilationUnitsRepositoryTestCase.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -60,9 +60,8 @@
public void shouldGetASTByCompilationUnit() throws CoreException {
// pre-conditions
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
- final ICompilationUnit compilationUnit = type.getCompilationUnit();
// operation
- final CompilationUnit ast = repository.getAST(compilationUnit);
+ final CompilationUnit ast = repository.getAST(type.getCompilationUnit());
// verification
assertThat(ast, notNullValue());
}
@@ -84,7 +83,7 @@
final IMethod method = getMethod(type, "getCustomer");
final ICompilationUnit compilationUnit = type.getCompilationUnit();
// record the previous version
- repository.getAST(compilationUnit);
+ repository.getAST(type.getCompilationUnit());
// operation
WorkbenchUtils.replaceFirstOccurrenceOfCode(method, "@PathParam(\"id\")
Integer id",
"@PathParam(\"ide\") Integer id", true);
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtilsTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtilsTestCase.java 2012-10-12
09:02:27 UTC (rev 44468)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtilsTestCase.java 2012-10-12
09:10:19 UTC (rev 44469)
@@ -19,7 +19,7 @@
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
-import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getAnnotation;
+import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.resolveAnnotation;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.CONSUMES;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.ENCODED;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.GET;
@@ -27,7 +27,11 @@
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.PATH;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.PATH_PARAM;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.PRODUCES;
+import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.QUERY_PARAM;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.RESPONSE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import java.util.List;
@@ -43,6 +47,8 @@
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.ILocalVariable;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageFragmentRoot;
@@ -67,10 +73,18 @@
return JdtUtils.resolveType(typeName, javaProject, progressMonitor);
}
+ private IField getField(IType parentType, String fieldName) throws CoreException {
+ return WorkbenchUtils.getField(parentType, fieldName);
+ }
+
private IMethod getMethod(IType parentType, String methodName) throws JavaModelException
{
return WorkbenchUtils.getMethod(parentType, methodName);
}
+ private ILocalVariable getLocalVariable(IMethod method, String variableName) throws
JavaModelException {
+ return WorkbenchUtils.getLocalVariable(method, variableName);
+ }
+
@Test
public void shouldResolveTypeByQNameInSourceCode() throws CoreException {
// preconditions
@@ -98,8 +112,7 @@
// operation
final IType type = JdtUtils.resolveType("unknown.class", javaProject, new
NullProgressMonitor());
// verification
- Assert.assertNull("No Type expected",
- type);
+ Assert.assertNull("No Type expected", type);
}
@Test
@@ -175,7 +188,8 @@
IType type = JdtUtils.resolveType("javax.ws.rs.core.Application",
javaProject, new NullProgressMonitor());
Assert.assertNotNull("Type not found", type);
// operation
- final ITypeHierarchy hierarchy = JdtUtils.resolveTypeHierarchy(type,
type.getJavaProject(), true, new NullProgressMonitor());
+ final ITypeHierarchy hierarchy = JdtUtils.resolveTypeHierarchy(type,
type.getJavaProject(), true,
+ new NullProgressMonitor());
// verifications
Assert.assertNotNull("Type hierarchy not found", hierarchy);
Assert.assertEquals("Type hierarchy incomplete", 1,
hierarchy.getSubtypes(type).length);
@@ -195,7 +209,7 @@
Assert.assertNotNull("Type hierarchy not found", hierarchy);
Assert.assertEquals("Type hierarchy incomplete", 0,
hierarchy.getSubtypes(type).length);
}
-
+
@Test
public void shouldNotResolveTypeHierarchyOnRemovedClass() throws CoreException {
// preconditions
@@ -205,7 +219,8 @@
Assert.assertNotNull("Type not found", type);
// operation
type.delete(true, new NullProgressMonitor());
- final ITypeHierarchy hierarchy = JdtUtils.resolveTypeHierarchy(type,
type.getJavaProject(), false, new NullProgressMonitor());
+ final ITypeHierarchy hierarchy = JdtUtils.resolveTypeHierarchy(type,
type.getJavaProject(), false,
+ new NullProgressMonitor());
// verification
Assert.assertNull("No Type hierarchy expected", hierarchy);
}
@@ -220,8 +235,8 @@
IType matchSuperInterfaceType =
JdtUtils.resolveType("javax.ws.rs.ext.MessageBodyReader", javaProject,
progressMonitor);
Assert.assertNotNull("Interface Type not found", matchSuperInterfaceType);
- ITypeHierarchy parameterizedTypeHierarchy =
JdtUtils.resolveTypeHierarchy(parameterizedType, parameterizedType.getJavaProject(),
false,
- progressMonitor);
+ ITypeHierarchy parameterizedTypeHierarchy =
JdtUtils.resolveTypeHierarchy(parameterizedType,
+ parameterizedType.getJavaProject(), false, progressMonitor);
boolean removedReferencedLibrarySourceAttachment =
WorkbenchUtils.removeReferencedLibrarySourceAttachment(
javaProject, "resteasy-jaxb-provider-2.0.1.GA.jar", progressMonitor);
Assert.assertTrue("Source attachment was not removed (not found?)",
removedReferencedLibrarySourceAttachment);
@@ -244,8 +259,8 @@
javaProject, new NullProgressMonitor());
Assert.assertNotNull("Interface Type not found", matchGenericType);
// operation
- ITypeHierarchy parameterizedTypeHierarchy =
JdtUtils.resolveTypeHierarchy(parameterizedType, parameterizedType.getJavaProject(),
false,
- new NullProgressMonitor());
+ ITypeHierarchy parameterizedTypeHierarchy =
JdtUtils.resolveTypeHierarchy(parameterizedType,
+ parameterizedType.getJavaProject(), false, new NullProgressMonitor());
CompilationUnit compilationUnit = JdtUtils.parse(parameterizedType, null);
List<IType> resolvedTypeParameters =
JdtUtils.resolveTypeArguments(parameterizedType, compilationUnit,
matchGenericType, parameterizedTypeHierarchy, new NullProgressMonitor());
@@ -265,8 +280,8 @@
new NullProgressMonitor());
Assert.assertNotNull("Interface Type not found", matchGenericType);
CompilationUnit compilationUnit = JdtUtils.parse(parameterizedType, null);
- ITypeHierarchy parameterizedTypeHierarchy =
JdtUtils.resolveTypeHierarchy(parameterizedType, parameterizedType.getJavaProject(),
false,
- new NullProgressMonitor());
+ ITypeHierarchy parameterizedTypeHierarchy =
JdtUtils.resolveTypeHierarchy(parameterizedType,
+ parameterizedType.getJavaProject(), false, new NullProgressMonitor());
List<IType> resolvedTypeParameters =
JdtUtils.resolveTypeArguments(parameterizedType, compilationUnit,
matchGenericType, parameterizedTypeHierarchy, new NullProgressMonitor());
@@ -310,11 +325,11 @@
// verification
Assert.assertNotNull("Interface Type not found", matchSuperInterfaceType);
// operation
- ITypeHierarchy unrelatedTypeHierarchy = JdtUtils.resolveTypeHierarchy(unrelatedType,
unrelatedType.getJavaProject(), false,
- new NullProgressMonitor());
+ ITypeHierarchy unrelatedTypeHierarchy = JdtUtils.resolveTypeHierarchy(unrelatedType,
+ unrelatedType.getJavaProject(), false, new NullProgressMonitor());
CompilationUnit compilationUnit = JdtUtils.parse(parameterizedType, null);
- final List<IType> typeArgs = JdtUtils.resolveTypeArguments(parameterizedType,
compilationUnit, matchSuperInterfaceType,
- unrelatedTypeHierarchy, new NullProgressMonitor());
+ final List<IType> typeArgs = JdtUtils.resolveTypeArguments(parameterizedType,
compilationUnit,
+ matchSuperInterfaceType, unrelatedTypeHierarchy, new NullProgressMonitor());
// verification
Assert.assertNull(typeArgs);
}
@@ -422,10 +437,9 @@
Annotation javaAnnotation = JdtUtils.resolveAnnotation(type, JdtUtils.parse(type,
progressMonitor), "Path");
// verifications
assertThat(javaAnnotation.getJavaAnnotation(), notNullValue());
- assertThat(javaAnnotation.getName(), equalTo(PATH.qualifiedName));
+ assertThat(javaAnnotation.getFullyQualifiedName(), equalTo(PATH.qualifiedName));
assertThat(javaAnnotation.getJavaAnnotationElements().size(), equalTo(1));
assertThat(javaAnnotation.getJavaAnnotationElements().get("value").get(0),
equalTo("/customers"));
- assertThat(javaAnnotation.getSourceRange(), notNullValue());
}
@Test
@@ -441,9 +455,8 @@
// verifications
assertThat(javaAnnotations.size(), equalTo(4));
for (Entry<String, Annotation> entry : javaAnnotations.entrySet()) {
- assertThat(entry.getKey(), equalTo(entry.getValue().getName()));
+ assertThat(entry.getKey(), equalTo(entry.getValue().getFullyQualifiedName()));
assertThat(entry.getValue().getJavaAnnotation(), notNullValue());
- assertThat(entry.getValue().getSourceRange(), notNullValue());
}
}
@@ -459,7 +472,7 @@
Annotation javaAnnotation = JdtUtils.resolveAnnotation(annotation, JdtUtils.parse(type,
progressMonitor));
// verifications
assertThat(javaAnnotation.getJavaAnnotation(), equalTo(annotation));
- assertThat(javaAnnotation.getName(), equalTo(PATH.qualifiedName));
+ assertThat(javaAnnotation.getFullyQualifiedName(), equalTo(PATH.qualifiedName));
assertThat(javaAnnotation.getJavaAnnotationElements().size(), equalTo(1));
assertThat(javaAnnotation.getJavaAnnotationElements().get("value").get(0),
equalTo("/customers"));
}
@@ -471,9 +484,9 @@
progressMonitor);
Assert.assertNotNull("Type not found", type);
// operation
- Annotation javaAnnotation = getAnnotation(type, HTTP_METHOD.qualifiedName);
+ Annotation annotation = resolveAnnotation(type, HTTP_METHOD.qualifiedName);
// verifications
- assertThat(javaAnnotation, nullValue());
+ assertThat(annotation, nullValue());
}
@Test
@@ -486,7 +499,7 @@
HTTP_METHOD.qualifiedName);
// verifications
assertThat(javaAnnotation.getJavaAnnotation(), notNullValue());
- assertThat(javaAnnotation.getName(), equalTo(HTTP_METHOD.qualifiedName));
+ assertThat(javaAnnotation.getFullyQualifiedName(),
equalTo(HTTP_METHOD.qualifiedName));
assertThat(javaAnnotation.getJavaAnnotationElements().size(), equalTo(1));
assertThat(javaAnnotation.getJavaAnnotationElements().get("value").get(0),
equalTo("GET"));
}
@@ -504,7 +517,7 @@
Annotation javaAnnotation = javaAnnotations.get(HTTP_METHOD.qualifiedName);
assertThat(javaAnnotation, notNullValue());
assertThat(javaAnnotation.getJavaAnnotation(), notNullValue());
- assertThat(javaAnnotation.getName(), equalTo(HTTP_METHOD.qualifiedName));
+ assertThat(javaAnnotation.getFullyQualifiedName(),
equalTo(HTTP_METHOD.qualifiedName));
assertThat(javaAnnotation.getJavaAnnotationElements().size(), equalTo(1));
assertThat(javaAnnotation.getJavaAnnotationElements().get("value").get(0),
equalTo("GET"));
}
@@ -520,7 +533,7 @@
Annotation annotation = JdtUtils.resolveAnnotation(javaAnnotation, JdtUtils.parse(type,
progressMonitor));
// verifications
assertThat(annotation.getJavaAnnotation(), equalTo(javaAnnotation));
- assertThat(annotation.getName(), equalTo(HTTP_METHOD.qualifiedName));
+ assertThat(annotation.getFullyQualifiedName(), equalTo(HTTP_METHOD.qualifiedName));
assertThat(annotation.getJavaAnnotationElements().size(), equalTo(1));
assertThat(annotation.getJavaAnnotationElements().get("value").get(0),
equalTo("GET"));
}
@@ -533,7 +546,7 @@
IAnnotation javaAnnotation = type.getAnnotation(PATH.qualifiedName);
Assert.assertFalse("Annotation not expected", javaAnnotation.exists());
// operation
- Annotation annotation = getAnnotation(type, PATH.qualifiedName);
+ Annotation annotation = resolveAnnotation(type, PATH.qualifiedName);
// verifications
assertThat(annotation, nullValue());
}
@@ -547,6 +560,17 @@
JdtUtils.parse(type, progressMonitor));
// verification
Assert.assertEquals(7, methodSignatures.size());
+ for (JavaMethodSignature methodSignature : methodSignatures) {
+ for (Entry<String, JavaMethodParameter> methodParameterEntry :
methodSignature.getMethodParameters()
+ .entrySet()) {
+ for (Entry<String, Annotation> annotationEntry :
methodParameterEntry.getValue().getAnnotations()
+ .entrySet()) {
+ assertNotNull(
+ "JavaAnnotation for " + methodParameterEntry.getKey() + "." +
annotationEntry.getKey()
+ + " is null", annotationEntry.getValue().getJavaAnnotation());
+ }
+ }
+ }
}
@Test
@@ -554,17 +578,25 @@
// pre-condition
final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
IMethod method = WorkbenchUtils.getMethod(type, "getCustomer");
- method = WorkbenchUtils.replaceFirstOccurrenceOfCode(method,
"@PathParam(\"id\") Integer id", "@PathParam() Integer id",
- false);
+ method = WorkbenchUtils.replaceFirstOccurrenceOfCode(method,
"@PathParam(\"id\") Integer id",
+ "@PathParam() Integer id", false);
// operation
final JavaMethodSignature methodSignature = JdtUtils.resolveMethodSignature(method,
JdtUtils.parse(type, progressMonitor));
// verification
- Assert.assertNotNull(methodSignature);
- Assert.assertEquals(2, methodSignature.getMethodParameters().size());
- Assert.assertNull(methodSignature.getMethodParameters().get(0).getAnnotation(PATH_PARAM.qualifiedName).getValue("value"));
+ assertNotNull(methodSignature);
+ assertEquals(2, methodSignature.getMethodParameters().size());
+ for (Entry<String, JavaMethodParameter> methodParameterEntry :
methodSignature.getMethodParameters().entrySet()) {
+ for (Entry<String, Annotation> annotationEntry :
methodParameterEntry.getValue().getAnnotations()
+ .entrySet()) {
+ assertNotNull("JavaAnnotation for " + methodParameterEntry.getKey() +
"." + annotationEntry.getKey()
+ + " is null", annotationEntry.getValue().getJavaAnnotation());
+ }
+ }
+ assertNull(methodSignature.getMethodParameters().get("id").getAnnotation(PATH_PARAM.qualifiedName)
+ .getValue("value"));
}
-
+
@Test
public void shouldResolveJavaMethodSignaturesForParameterizedType() throws CoreException
{
// preconditions
@@ -575,7 +607,7 @@
// verification
Assert.assertEquals(1, methodSignatures.size());
}
-
+
@Test
public void shouldResolveJavaMethodSignature() throws CoreException {
// preconditions
@@ -588,13 +620,11 @@
assertThat(methodSignature, notNullValue());
assertThat(methodSignature.getJavaMethod(), notNullValue());
assertThat(methodSignature.getMethodParameters().size(), equalTo(3));
- final ISourceRange sourceRange = method.getSourceRange();
- for (JavaMethodParameter parameter : methodSignature.getMethodParameters()) {
+ for (Entry<String, JavaMethodParameter> parameterEntry :
methodSignature.getMethodParameters().entrySet()) {
+ JavaMethodParameter parameter = parameterEntry.getValue();
assertThat(parameter.getAnnotations().size(), isOneOf(1, 2));
- for (Annotation annotation : parameter.getAnnotations()) {
- assertThat(annotation.getSourceRange().getOffset(),
greaterThan(sourceRange.getOffset()));
- assertThat(annotation.getSourceRange().getOffset(),
- lessThan(sourceRange.getOffset() + sourceRange.getLength()));
+ for (Annotation annotation : parameter.getAnnotations().values()) {
+ assertThat(annotation.getJavaAnnotation(), notNullValue());
}
}
assertThat(methodSignature.getReturnedType().getFullyQualifiedName(),
endsWith(".List"));
@@ -605,7 +635,10 @@
// preconditions
final IType bookType =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource");
final IType objectType = getType(Object.class.getName());
- assertThat(JdtUtils.isTypeOrSuperType(objectType, bookType), is(true));
+ // operation
+ final boolean typeOrSuperType = JdtUtils.isTypeOrSuperType(objectType, bookType);
+ // verification
+ assertThat(typeOrSuperType, is(true));
}
@Test
@@ -613,7 +646,10 @@
// preconditions
final IType subType =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource");
final IType superType =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource");
- assertThat(JdtUtils.isTypeOrSuperType(superType, subType), is(true));
+ // operation
+ final boolean typeOrSuperType = JdtUtils.isTypeOrSuperType(superType, subType);
+ // verification
+ assertThat(typeOrSuperType, is(true));
}
@Test
@@ -621,7 +657,280 @@
// preconditions
final IType bookType =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource");
final IType objectType = getType(RESPONSE.qualifiedName);
- assertThat(JdtUtils.isTypeOrSuperType(objectType, bookType), is(false));
+ // operation
+ final boolean typeOrSuperType = JdtUtils.isTypeOrSuperType(objectType, bookType);
+ // verification
+ assertThat(typeOrSuperType, is(false));
}
+ @Test
+ public void shouldRetrieveTypeAnnotationFromNameLocation() throws CoreException {
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final Annotation annotation = resolveAnnotation(customerType, PATH.qualifiedName);
+ final int offset = annotation.getJavaAnnotation().getNameRange().getOffset();
+ // operation
+ final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset,
customerType.getCompilationUnit());
+ // verification
+ assertThat(foundAnnotation, notNullValue());
+ assertThat(foundAnnotation.getJavaAnnotation(), notNullValue());
+ }
+
+ @Test
+ public void shouldRetrieveTypeAnnotationFromMemberPairLocation() throws CoreException {
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final Annotation annotation = resolveAnnotation(customerType, PATH.qualifiedName);
+ final int offset = annotation.getJavaAnnotation().getSourceRange().getOffset() +
PATH.qualifiedName.length()
+ + 3;
+ // operation
+ final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset,
customerType.getCompilationUnit());
+ // verification
+ assertThat(foundAnnotation, notNullValue());
+ assertThat(foundAnnotation.getJavaAnnotation(), notNullValue());
+ }
+
+ @Test
+ public void shouldRetrieveAnnotationTypeAnnotationFromNameLocation() throws
CoreException {
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.FOO");
+ final Annotation annotation = resolveAnnotation(customerType,
HTTP_METHOD.qualifiedName);
+ final int offset = annotation.getJavaAnnotation().getNameRange().getOffset();
+ // operation
+ final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset,
customerType.getCompilationUnit());
+ // verification
+ assertThat(foundAnnotation, notNullValue());
+ assertThat(foundAnnotation.getJavaAnnotation(), notNullValue());
+ }
+
+ @Test
+ public void shouldRetrieveAnnotationTypeAnnotationFromMemberPairLocation() throws
CoreException {
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.FOO");
+ final Annotation annotation = resolveAnnotation(customerType,
HTTP_METHOD.qualifiedName);
+ final int offset = annotation.getJavaAnnotation().getSourceRange().getOffset()
+ + HTTP_METHOD.qualifiedName.length() + 3;
+ // operation
+ final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset,
customerType.getCompilationUnit());
+ // verification
+ assertThat(foundAnnotation, notNullValue());
+ assertThat(foundAnnotation.getJavaAnnotation(), notNullValue());
+ }
+
+ @Test
+ public void shouldRetrieveMethodAnnotationFromNameLocation() throws CoreException {
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IMethod method = getMethod(customerType, "createCustomer");
+ final Annotation annotation = resolveAnnotation(method, CONSUMES.qualifiedName);
+ final int offset = annotation.getJavaAnnotation().getNameRange().getOffset();
+ // operation
+ final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset,
customerType.getCompilationUnit());
+ // verification
+ assertThat(foundAnnotation, notNullValue());
+ assertThat(foundAnnotation.getJavaAnnotation(), notNullValue());
+ }
+
+ @Test
+ public void shouldRetrieveMethodAnnotationFromMemberPairLocation() throws CoreException
{
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IMethod method = getMethod(customerType, "createCustomer");
+ final Annotation annotation = resolveAnnotation(method, CONSUMES.qualifiedName);
+ final int offset = annotation.getJavaAnnotation().getSourceRange().getOffset()
+ + CONSUMES.qualifiedName.length() + 3;
+ // operation
+ final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset,
method.getCompilationUnit());
+ // verification
+ assertThat(foundAnnotation, notNullValue());
+ assertThat(foundAnnotation.getJavaAnnotation(), notNullValue());
+ }
+
+ @Test
+ public void shouldRetrieveLocalVariableAnnotationFromNameLocation() throws CoreException
{
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IMethod method = getMethod(customerType, "getCustomer");
+ final ILocalVariable localVariable = getLocalVariable(method, "id");
+ final int offset = localVariable.getAnnotations()[0].getNameRange().getOffset();
+ // operation
+ final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset,
method.getCompilationUnit());
+ // verification
+ assertThat(foundAnnotation, notNullValue());
+ assertThat(foundAnnotation.getJavaAnnotation(), nullValue());
+ }
+
+ @Test
+ public void shouldRetrieveLocalVariableAnnotationFromMemberPairLocation() throws
CoreException {
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IMethod method = getMethod(customerType, "getCustomer");
+ final ILocalVariable localVariable = getLocalVariable(method, "id");
+ final int offset = localVariable.getAnnotations()[0].getNameRange().getOffset()
+ + PATH_PARAM.simpleName.length() + 3;
+ // operation
+ final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset,
customerType.getCompilationUnit());
+ // verification
+ assertThat(foundAnnotation, notNullValue());
+ // iannotation retrieved from this method is null and does not need to be evaluated
anyway.
+ assertThat(foundAnnotation.getJavaAnnotation(), nullValue());
+ }
+
+ @Test
+ public void shouldRetrieveFieldAnnotationFromNameLocation() throws CoreException {
+ // preconditions
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IField field = getField(type, "foo");
+ final Annotation annotation = resolveAnnotation(field, QUERY_PARAM.qualifiedName);
+ final int offset = annotation.getJavaAnnotation().getNameRange().getOffset();
+ // operation
+ final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset,
type.getCompilationUnit());
+ // verification
+ assertThat(foundAnnotation, notNullValue());
+ assertThat(foundAnnotation.getJavaAnnotation(), notNullValue());
+ }
+
+ @Test
+ public void shouldRetrieveFieldAnnotationFromMemberPairLocation() throws CoreException
{
+ // preconditions
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IField field = getField(type, "foo");
+ final Annotation annotation = resolveAnnotation(field, QUERY_PARAM.qualifiedName);
+ final int offset = annotation.getJavaAnnotation().getSourceRange().getOffset() +
CONSUMES.simpleName.length()
+ + 3;
+ // operation
+ final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset,
type.getCompilationUnit());
+ // verification
+ assertThat(foundAnnotation, notNullValue());
+ assertThat(foundAnnotation.getJavaAnnotation(), notNullValue());
+ }
+
+ @Test
+ public void shouldNotRetrieveAnnotationFromTypeNameLocation() throws CoreException {
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final int offset = customerType.getNameRange().getOffset();
+ // operation
+ final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset,
customerType.getCompilationUnit());
+ // verification
+ assertThat(foundAnnotation, nullValue());
+ }
+
+ @Test
+ public void shouldNotRetrieveAnnotationFromMethodNameLocation() throws CoreException {
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IMethod method = getMethod(customerType, "getCustomer");
+ final int offset = method.getNameRange().getOffset();
+ // operation
+ final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset,
customerType.getCompilationUnit());
+ // verification
+ assertThat(foundAnnotation, nullValue());
+ }
+
+ @Test
+ public void shouldNotRetrieveAnnotationFromMethodBodyLocation() throws CoreException {
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IMethod method = getMethod(customerType, "getCustomer");
+ final int offset = method.getSourceRange().getOffset() +
method.getSourceRange().getLength() - 2;
+ // operation
+ final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset,
customerType.getCompilationUnit());
+ // verification
+ assertThat(foundAnnotation, nullValue());
+ }
+
+ @Test
+ public void shouldNotRetrieveAnnotationFromFieldNameLocation() throws CoreException {
+ // preconditions
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IField field = getField(type, "foo");
+ final int offset = field.getSourceRange().getOffset();
+ // operation
+ final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset,
type.getCompilationUnit());
+ // verification
+ assertThat(foundAnnotation, nullValue());
+ }
+
+ @Test
+ public void shouldRetrieveTypeAnnotationMemberValuePairSourceRange() throws
CoreException {
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final Annotation annotation = resolveAnnotation(customerType, PATH.qualifiedName);
+ // operation
+ final ISourceRange range =
JdtUtils.resolveMemberPairValueRange(annotation.getJavaAnnotation(),
+ annotation.getFullyQualifiedName(), "value");
+ // verification
+ assertThat(range, notNullValue());
+ final ISourceRange annotationRange = annotation.getJavaAnnotation().getSourceRange();
+ assertThat(range.getOffset(), greaterThan(annotationRange.getOffset()));
+ assertThat(range.getOffset(), lessThan(annotationRange.getOffset() +
annotationRange.getLength()));
+
+ }
+
+ @Test
+ public void shouldRetrieveTypeSingleMemberAnnotationMemberValuePairSourceRange() throws
CoreException {
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final Annotation annotation = resolveAnnotation(customerType, CONSUMES.qualifiedName);
+ // operation
+ final ISourceRange range =
JdtUtils.resolveMemberPairValueRange(annotation.getJavaAnnotation(),
+ annotation.getFullyQualifiedName(), "value");
+ // verification
+ assertThat(range, notNullValue());
+ final ISourceRange annotationRange = annotation.getJavaAnnotation().getSourceRange();
+ assertThat(range.getOffset(), greaterThan(annotationRange.getOffset()));
+ assertThat(range.getOffset(), lessThan(annotationRange.getOffset() +
annotationRange.getLength()));
+
+ }
+
+ @Test
+ public void shouldRetrieveMethodAnnotationMemberValuePairSourceRange() throws
CoreException {
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IMethod method = getMethod(customerType, "getCustomer");
+ final Annotation annotation = resolveAnnotation(method, PATH.qualifiedName);
+ // operation
+ final ISourceRange range =
JdtUtils.resolveMemberPairValueRange(annotation.getJavaAnnotation(),
+ annotation.getFullyQualifiedName(), "value");
+ // verification
+ assertThat(range, notNullValue());
+ final ISourceRange annotationRange = annotation.getJavaAnnotation().getSourceRange();
+ assertThat(range.getOffset(), greaterThan(annotationRange.getOffset()));
+ assertThat(range.getOffset(), lessThan(annotationRange.getOffset() +
annotationRange.getLength()));
+ }
+
+ @Test
+ public void shouldRetrieveFieldAnnotationMemberValuePairSourceRange() throws
CoreException {
+ // preconditions
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IField field = getField(type, "foo");
+ final Annotation annotation = resolveAnnotation(field, QUERY_PARAM.qualifiedName);
+ // operation
+ final ISourceRange range =
JdtUtils.resolveMemberPairValueRange(annotation.getJavaAnnotation(),
+ annotation.getFullyQualifiedName(), "value");
+ // verification
+ assertThat(range, notNullValue());
+ final ISourceRange annotationRange = annotation.getJavaAnnotation().getSourceRange();
+ assertThat(range.getOffset(), greaterThan(annotationRange.getOffset()));
+ assertThat(range.getOffset(), lessThan(annotationRange.getOffset() +
annotationRange.getLength()));
+ }
+
+ @Test
+ public void shouldRetrieveLocalVariableAnnotationMemberValuePairSourceRange() throws
CoreException {
+ // preconditions
+ final IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IMethod method = getMethod(customerType, "getCustomer");
+ final ILocalVariable localVariable = getLocalVariable(method, "id");
+ final IAnnotation annotation = localVariable.getAnnotations()[0];
+ // operation
+ final ISourceRange range = JdtUtils.resolveMemberPairValueRange(annotation,
PATH_PARAM.qualifiedName,
+ "value");
+ // verification
+ assertThat(range, notNullValue());
+ final ISourceRange annotationRange = annotation.getSourceRange();
+ assertThat(range.getOffset(), greaterThan(annotationRange.getOffset()));
+ assertThat(range.getOffset(), lessThan(annotationRange.getOffset() +
annotationRange.getLength()));
+ }
+
}