Author: xcoulon
Date: 2011-11-22 08:26:39 -0500 (Tue, 22 Nov 2011)
New Revision: 36531
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java
Removed:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionFilterUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/MemberAnnotationBindingVisitor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/MemberAnnotationBindingsVisitor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/MethodBindingVisitor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignatureVisitor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/AbstractBuildDelegateTestCase.java
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/jdt/Annotation.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/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/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/JaxrsElementChangedProcessorTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuildJobTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtilsTestCase.java
Log:
Moved content assist/validation into the core plugin - using the metamodel
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 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -334,4 +334,37 @@
return false;
}
+ @Override
+ public List<String> getPathParamValueProposals() {
+ List<String> proposals = new ArrayList<String>();
+ final Annotation methodPathAnnotation = getPathAnnotation();
+ if(methodPathAnnotation != null) {
+ final String value = methodPathAnnotation.getValue("value");
+ proposals.addAll(extractParamsFromUriTemplateFragment(value));
+ }
+ final Annotation typePathAnnotation = getParentResource().getPathAnnotation();
+ if(typePathAnnotation != null) {
+ final String value = typePathAnnotation.getValue("value");
+ proposals.addAll(extractParamsFromUriTemplateFragment(value));
+ }
+ return proposals;
+ }
+
+ /**
+ * Extracts all the character sequences inside of curly braces ('{' and
'}') and returns them as a list of strings
+ * @param value the given value
+ * @return the list of character sequences, or an empty list
+ */
+ private static List<String> extractParamsFromUriTemplateFragment(String value) {
+ List<String> params = new ArrayList<String>();
+ int beginIndex = -1;
+ while ((beginIndex = value.indexOf("{", beginIndex + 1)) != -1) {
+ int semicolonIndex = value.indexOf(":", beginIndex);
+ int closingCurlyBraketIndex = value.indexOf("}", beginIndex);
+ int endIndex = semicolonIndex != -1 ? semicolonIndex : closingCurlyBraketIndex;
+ params.add(value.substring(beginIndex + 1, endIndex).trim());
+ }
+ return params;
+ }
+
}
Deleted:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionFilterUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionFilterUtils.java 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionFilterUtils.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -1,5 +0,0 @@
-package org.jboss.tools.ws.jaxrs.core.internal.utils;
-
-public class CollectionFilterUtils {
-
-}
Deleted:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/MemberAnnotationBindingVisitor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/MemberAnnotationBindingVisitor.java 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/MemberAnnotationBindingVisitor.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -1,5 +0,0 @@
-package org.jboss.tools.ws.jaxrs.core.internal.utils;
-
-public class MemberAnnotationBindingVisitor {
-
-}
Deleted:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/MemberAnnotationBindingsVisitor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/MemberAnnotationBindingsVisitor.java 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/MemberAnnotationBindingsVisitor.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -1,5 +0,0 @@
-package org.jboss.tools.ws.jaxrs.core.internal.utils;
-
-public class MemberAnnotationBindingsVisitor {
-
-}
Deleted:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/MethodBindingVisitor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/MethodBindingVisitor.java 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/MethodBindingVisitor.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -1,5 +0,0 @@
-package org.jboss.tools.ws.jaxrs.core.internal.utils;
-
-public class MethodBindingVisitor {
-
-}
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 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -32,45 +32,6 @@
this.region = region;
}
- /** convenient constructor: no typed region specified
- *
- * @param annotation
- * @param name
- * @param annotationElements */
- public Annotation(IAnnotation annotation, String name, Map<String,
List<String>> annotationElements) {
- this.javaAnnotation = annotation;
- this.javaAnnotationName = name;
- this.javaAnnotationElements = new HashMap<String,
List<String>>(annotationElements);
- this.region = null;
- }
-
- /** Convenient constructor : only one element named "value", whose value is
- * given in parameter
- *
- * @param annotation
- * @param name */
- public Annotation(IAnnotation annotation, String name) {
- this.javaAnnotation = annotation;
- this.javaAnnotationName = name;
- this.javaAnnotationElements = new HashMap<String, List<String>>();
- this.region = null;
- }
-
- /** Convenient constructor : no element provided
- *
- * @param annotation
- * @param name
- * @param singleElementValue */
- public Annotation(IAnnotation annotation, String name, String singleElementValue) {
- this.javaAnnotation = annotation;
- this.javaAnnotationName = name;
- this.javaAnnotationElements = new HashMap<String, List<String>>();
- if (singleElementValue != null) {
- this.javaAnnotationElements.put("value",
Arrays.asList(singleElementValue));
- }
- this.region = null;
- }
-
public boolean update(Annotation annotation) {
assert annotation != null;
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 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaAnnotationsVisitor.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -28,6 +28,8 @@
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TypedRegion;
/** A visitor for a single annotation on a java member (can be a method or a
* type).
@@ -45,7 +47,7 @@
private final List<String> annotationNames = new ArrayList<String>();
/** the bindings for the matching annotation. */
- private final List<IAnnotationBinding> annotationBindings = new
ArrayList<IAnnotationBinding>();
+ private final List<Annotation> annotations = new ArrayList<Annotation>();
/** Full Constructor to resolve a single annotation from its fully qualified
* name.
@@ -140,12 +142,18 @@
private void visitExtendedModifiers(final List<?> modifiers) {
for (Object modifier : modifiers) {
if (modifier instanceof org.eclipse.jdt.core.dom.Annotation) {
- IAnnotationBinding binding = ((org.eclipse.jdt.core.dom.Annotation) modifier)
+ 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();
- final String qualifiedName = binding.getAnnotationType().getQualifiedName();
- final String name = binding.getAnnotationType().getName();
+ final String qualifiedName =
annotationBinding.getAnnotationType().getQualifiedName();
+ final String name = annotationBinding.getAnnotationType().getName();
if (annotationNames.contains(qualifiedName) || annotationNames.contains(name)) {
- annotationBindings.add(binding);
+ final String annotationName =
annotationBinding.getAnnotationType().getQualifiedName();
+ final Map<String, List<String>> annotationElements =
resolveAnnotationElements(annotationBinding);
+ final TypedRegion typedRegion = new TypedRegion(annotation.getStartPosition(),
+ annotation.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
+ final IAnnotation javaAnnotation = (IAnnotation)
annotationBinding.getJavaElement();
+ annotations.add(new Annotation(javaAnnotation, annotationName, annotationElements,
typedRegion));
}
}
}
@@ -161,15 +169,10 @@
* in case of underlying exception */
public final Annotation getResolvedAnnotation() throws JavaModelException {
assert annotationNames.size() == 1;
- if (annotationBindings.size() == 0) {
+ if (annotations.size() == 0) {
return null;
}
- final IAnnotationBinding annotationBinding = annotationBindings.get(0);
- final IAnnotation annotation = (IAnnotation) annotationBinding.getJavaElement();
- final String annotationName =
annotationBinding.getAnnotationType().getQualifiedName();
- final Map<String, List<String>> annotationElements =
resolveAnnotationElements(annotationBinding);
- final Annotation resolvedJavaAnnotation = new Annotation(annotation, annotationName,
annotationElements);
- return resolvedJavaAnnotation;
+ return annotations.get(0);
}
/** Returns the Annotation elements matching the annotations name given in
@@ -184,11 +187,8 @@
* in case of underlying exception */
public final Map<String, Annotation> getResolvedAnnotations() throws
JavaModelException {
final Map<String, Annotation> resolvedJavaAnnotations = new HashMap<String,
Annotation>();
- for (IAnnotationBinding annotationBinding : annotationBindings) {
- final IAnnotation annotation = (IAnnotation) annotationBinding.getJavaElement();
- final String annotationName =
annotationBinding.getAnnotationType().getQualifiedName();
- final Map<String, List<String>> annotationElements =
resolveAnnotationElements(annotationBinding);
- resolvedJavaAnnotations.put(annotationName, new Annotation(annotation, annotationName,
annotationElements));
+ for (Annotation annotation: annotations) {
+ resolvedJavaAnnotations.put(annotation.getName(), annotation);
}
return resolvedJavaAnnotations;
}
Deleted:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignatureVisitor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignatureVisitor.java 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignatureVisitor.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -1,142 +0,0 @@
-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.ICompilationUnit;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-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.ITypeBinding;
-import org.eclipse.jdt.core.dom.IVariableBinding;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
-import org.eclipse.jface.text.TypedRegion;
-import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
-
-public class JavaMethodSignatureVisitor extends ASTVisitor {
-
- private final ICompilationUnit compilationUnit;
-
- private final IMethod method;
-
- private JavaMethodSignature methodSignature = null;
-
- public JavaMethodSignatureVisitor(IMethod method) {
- this.compilationUnit = method.getCompilationUnit();
- this.method = method;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse
- * .jdt.core.dom.MethodDeclaration)
- */
- @Override
- public boolean visit(MethodDeclaration declaration) {
- try {
- IMethod method = (IMethod)
compilationUnit.getElementAt(declaration.getStartPosition());
- if (!this.method.getHandleIdentifier().equals(method.getHandleIdentifier())) {
- return true;
- }
-
- final IMethodBinding methodBinding = declaration.resolveBinding();
- // sometimes, the binding cannot be resolved
- if (methodBinding == null) {
- Logger.warn("Could not resolve bindings form method " +
method.getElementName());
- } else {
- final IType returnedType = methodBinding.getReturnType() != null ? (IType)
methodBinding
- .getReturnType().getJavaElement() : null;
- final ITypeBinding[] parameterTypeBindings = methodBinding.getParameterTypes();
- List<JavaMethodParameter> methodParameters = new
ArrayList<JavaMethodParameter>();
- @SuppressWarnings("unchecked")
- List<SingleVariableDeclaration> parameters = declaration.parameters();
- for (SingleVariableDeclaration parameter : parameters) {
- 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 TypedRegion typedRegion = new TypedRegion(annotation.getStartPosition(),
- annotation.getLength(), parameter.getType().toString());
- paramAnnotations.add(new org.jboss.tools.ws.jaxrs.core.jdt.Annotation(null,
annotationName,
- annotationElements, typedRegion));
- }
- }
- methodParameters.add(new JavaMethodParameter(paramName, paramTypeName,
paramAnnotations));
- }
- /*
- * for (int i = 0; i < parameterTypeBindings.length; i++) {
- * final ITypeBinding parameterTypeBinding =
- * parameterTypeBindings[i];
- * final String paramTypeName =
- * parameterTypeBinding.getQualifiedName();
- * final List<Annotation> paramAnnotations = new
- * ArrayList<Annotation>();
- * final IAnnotationBinding[] parameterAnnotationBindings =
- * methodBinding.getParameterAnnotations(i);
- * for (IAnnotationBinding parameterAnnotationBinding :
- * parameterAnnotationBindings) {
- * parameterAnnotationBinding.getAnnotationType().getJavaElement(
- * );
- * final String annotationName =
- * parameterAnnotationBinding.getAnnotationType
- * ().getBinaryName();
- * final Map<String, List<String>> annotationElements =
- * resolveAnnotationElements(parameterAnnotationBinding);
- * final TypedRegion typedRegion = new
- * TypedRegion(annotation.getStartPosition(),
- * annotation.getLength(), param.getType().toString());
- *
- * paramAnnotations.add(new Annotation(null, annotationName,
- * annotationElements));
- * }
- * methodParameters.add(new JavaMethodParameter(paramName,
- * paramTypeName, paramAnnotations));
- * }
- */
- // TODO : add support for thrown exceptions
- this.methodSignature = new JavaMethodSignature(method, returnedType,
methodParameters);
- }
- } catch (JavaModelException e) {
- Logger.error("Failed to analyse compilation unit methods", e);
- }
- return true;
- }
-
- 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() 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() {
- return methodSignature;
- }
-}
\ No newline at end of file
Deleted:
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 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -1,96 +0,0 @@
-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.ICompilationUnit;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.dom.ASTVisitor;
-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.ITypeBinding;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
-import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
-
-public class JavaMethodSignaturesVisitor extends ASTVisitor {
-
- private final ICompilationUnit compilationUnit;
-
- private final List<JavaMethodSignature> methodSignatures = new
ArrayList<JavaMethodSignature>();
-
- public JavaMethodSignaturesVisitor(ICompilationUnit compilationUnit2) {
- this.compilationUnit = compilationUnit2;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse
- * .jdt.core.dom.MethodDeclaration)
- */
- @Override
- public boolean visit(MethodDeclaration declaration) {
- try {
- IMethod method = (IMethod)
compilationUnit.getElementAt(declaration.getStartPosition());
- final IMethodBinding methodBinding = declaration.resolveBinding();
- // sometimes, the binding cannot be resolved
- if (methodBinding == null) {
- Logger.warn("Could not resolve bindings form method " +
method.getElementName());
- } else {
- final IType returnedType = methodBinding.getReturnType() != null ? (IType)
methodBinding
- .getReturnType().getJavaElement() : null;
- final ITypeBinding[] parameterTypeBindings = methodBinding.getParameterTypes();
- List<JavaMethodParameter> methodParameters = new
ArrayList<JavaMethodParameter>();
- @SuppressWarnings("unchecked")
- List<SingleVariableDeclaration> parameters = declaration.parameters();
- for (int i = 0; i < parameterTypeBindings.length; i++) {
- final ITypeBinding parameterTypeBinding = parameterTypeBindings[i];
- final String paramTypeName = parameterTypeBinding.getQualifiedName();
- final String paramName = parameters.get(i).getName().getFullyQualifiedName();
- final List<Annotation> paramAnnotations = new ArrayList<Annotation>();
- final IAnnotationBinding[] parameterAnnotationBindings =
methodBinding.getParameterAnnotations(i);
- for (IAnnotationBinding parameterAnnotationBinding : parameterAnnotationBindings) {
- final String annotationName =
parameterAnnotationBinding.getAnnotationType().getBinaryName();
- // ((IType)parameterAnnotationBinding.getAnnotationType().getJavaElement()).getF
- final Map<String, List<String>> annotationElements =
resolveAnnotationElements(parameterAnnotationBinding);
- // method parameters are not eligible java elements...
- paramAnnotations.add(new Annotation(null, annotationName, annotationElements));
- }
- methodParameters.add(new JavaMethodParameter(paramName, paramTypeName,
paramAnnotations));
- }
- // TODO : add support for thrown exceptions
- methodSignatures.add(new JavaMethodSignature(method, returnedType,
methodParameters));
- }
- } catch (JavaModelException e) {
- Logger.error("Failed to analyse compilation unit methods", e);
- }
- return true;
- }
-
- 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() 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 List<JavaMethodSignature> getMethodSignatures() {
- return methodSignatures;
- }
-}
\ No newline at end of file
Copied:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java
(from rev 36520,
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignatureVisitor.java)
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -0,0 +1,138 @@
+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.ICompilationUnit;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+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.ITypeBinding;
+import org.eclipse.jdt.core.dom.IVariableBinding;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TypedRegion;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
+
+public class JavaMethodSignaturesVisitor extends ASTVisitor {
+
+ private final ICompilationUnit compilationUnit;
+
+ private final IMethod method;
+
+ private final List<JavaMethodSignature> methodSignatures = new
ArrayList<JavaMethodSignature>();
+
+ /**
+ * Constructor to use when you need all Java Method signatures in the given
+ * compilation unit
+ *
+ * @param method
+ */
+ public JavaMethodSignaturesVisitor(ICompilationUnit compilationUnit) {
+ this.compilationUnit = compilationUnit;
+ this.method = null;
+ }
+
+ /**
+ * Constructor to use when you only need a single Java Method signature
+ *
+ * @param method
+ */
+ public JavaMethodSignaturesVisitor(IMethod method) {
+ this.compilationUnit = method.getCompilationUnit();
+ this.method = method;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse
+ * .jdt.core.dom.MethodDeclaration)
+ */
+ @Override
+ public boolean visit(MethodDeclaration declaration) {
+ try {
+ IMethod method = (IMethod)
compilationUnit.getElementAt(declaration.getStartPosition());
+ if (this.method != null &&
!this.method.getHandleIdentifier().equals(method.getHandleIdentifier())) {
+ return true;
+ }
+
+ final IMethodBinding methodBinding = declaration.resolveBinding();
+ // sometimes, the binding cannot be resolved
+ if (methodBinding == null) {
+ Logger.warn("Could not resolve bindings form method " +
method.getElementName());
+ } else {
+ final IType returnedType = methodBinding.getReturnType() != null ? (IType)
methodBinding
+ .getReturnType().getJavaElement() : null;
+ List<JavaMethodParameter> methodParameters = new
ArrayList<JavaMethodParameter>();
+ @SuppressWarnings("unchecked")
+ List<SingleVariableDeclaration> parameters = declaration.parameters();
+ for (SingleVariableDeclaration parameter : parameters) {
+ 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 TypedRegion typedRegion = new TypedRegion(annotation.getStartPosition(),
+ annotation.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
+ paramAnnotations.add(new org.jboss.tools.ws.jaxrs.core.jdt.Annotation(null,
annotationName,
+ annotationElements, typedRegion));
+ }
+ }
+ methodParameters.add(new JavaMethodParameter(paramName, paramTypeName,
paramAnnotations));
+ }
+
+ // TODO : add support for thrown exceptions
+ this.methodSignatures.add(new JavaMethodSignature(method, returnedType,
methodParameters));
+ }
+ } catch (JavaModelException e) {
+ Logger.error("Failed to analyse compilation unit methods", e);
+ }
+ return true;
+ }
+
+ 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() 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) {
+ return null;
+ }
+ return this.methodSignatures.get(0);
+
+ }
+
+ /** @return the methodDeclarations */
+ public List<JavaMethodSignature> getMethodSignatures() {
+ return this.methodSignatures;
+ }
+}
\ No newline at end of file
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 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -247,8 +247,8 @@
if (member.isBinary()) {
IAnnotatable javaElement = (IAnnotatable) member;
final IAnnotation annotation = javaElement.getAnnotation(annotationName);
- if (annotation.exists()) {
- return new Annotation(annotation, annotation.getElementName(),
resolveAnnotationElements(annotation));
+ if (annotation != null && annotation.exists()) {
+ return new Annotation(annotation, annotation.getElementName(),
resolveAnnotationElements(annotation), null);
}
return null;
}
@@ -291,7 +291,7 @@
final IAnnotation annotation = javaElement.getAnnotation(annotationName);
if (annotation.exists()) {
annotations.put(annotationName, new Annotation(annotation,
annotation.getElementName(),
- resolveAnnotationElements(annotation)));
+ resolveAnnotationElements(annotation), null));
}
}
return annotations;
@@ -754,7 +754,7 @@
}
public static JavaMethodSignature resolveMethodSignature(IMethod method, CompilationUnit
ast) {
- JavaMethodSignatureVisitor methodsVisitor = new JavaMethodSignatureVisitor(method);
+ JavaMethodSignaturesVisitor methodsVisitor = new JavaMethodSignaturesVisitor(method);
ast.accept(methodsVisitor);
return methodsVisitor.getMethodSignature();
}
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 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsResourceMethod.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -42,5 +42,12 @@
abstract List<String> getProducedMediaTypes();
List<JavaMethodParameter> getJavaMethodParameters();
+
+ /**
+ * Determines the proposals for the PathParam annotated method parameters of the
underlying Java Method.
+ * This list is based on the @Path annotation found on the Java Method and on the parent
Java Type.
+ * @return
+ */
+ List<String> getPathParamValueProposals();
}
\ 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 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/PathParamAnnotationValueCompletionProposalComputer.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -22,8 +22,6 @@
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.text.IJavaPartitions;
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
@@ -46,10 +44,12 @@
import org.jboss.tools.ws.jaxrs.ui.JBossJaxrsUIPlugin;
import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
-/** Computes proposals for <code>java.ws.rs.PathParam</code> annotation
values in
+/**
+ * Computes proposals for <code>java.ws.rs.PathParam</code> annotation values
in
* the compilation unit context.
*
- * @author xcoulon */
+ * @author xcoulon
+ */
public class PathParamAnnotationValueCompletionProposalComputer implements
IJavaCompletionProposalComputer {
/** Icon for completion proposals. */
@@ -101,7 +101,8 @@
return Collections.emptyList();
}
- /** Computes the valid proposals for the <code>javax.ws.rs.PathParam</code>
+ /**
+ * Computes the valid proposals for the <code>javax.ws.rs.PathParam</code>
* annotation value. The proposals are based on:
* <ul>
* <li>The values of the <code>javax.ws.rs.Path</code> annotations,
both at
@@ -120,64 +121,46 @@
* @throws CoreException
* in case of underlying exception
* @throws BadLocationException
- * @throws org.eclipse.jface.text.BadLocationException */
+ * @throws org.eclipse.jface.text.BadLocationException
+ */
private List<ICompletionProposal> internalComputePathParamProposals(
final JavaContentAssistInvocationContext javaContext, final Annotation
pathParamAnnotation,
final IJaxrsResourceMethod resourceMethod) throws CoreException, BadLocationException
{
- ITypedRegion region = getRegion(javaContext);
+ final List<ICompletionProposal> completionProposals = new
ArrayList<ICompletionProposal>();
+ final ITypedRegion region = getRegion(javaContext);
String matchValue = javaContext.getDocument().get(region.getOffset(),
javaContext.getInvocationOffset() - region.getOffset());
- // int cursorPosition = javaContext.getInvocationOffset();
- List<ICompletionProposal> completionProposals = new
ArrayList<ICompletionProposal>();
- // compute proposals from @Path annotations on the method
- completionProposals.addAll(generateCompletionProposal(resourceMethod.getPathAnnotation(),
region, matchValue));
- // compute proposals from @Path annotations on the type
- completionProposals.addAll(generateCompletionProposal(resourceMethod.getParentResource().getPathAnnotation(),
- region, matchValue));
- return completionProposals;
- }
+ if(matchValue.charAt(0) == '\"') {
+ matchValue = matchValue.substring(1);
+ }
+ List<String> proposals = resourceMethod.getPathParamValueProposals();
+ for (String proposal : proposals) {
+ if (proposal.startsWith(matchValue)) {
+ completionProposals.add(generateCompletionProposal(resourceMethod.getJavaElement(),
region, proposal));
- private List<ICompletionProposal> generateCompletionProposal(Annotation
annotation, ITypedRegion region,
- String matchValue) throws CoreException {
- final List<ICompletionProposal> completionProposals = new
ArrayList<ICompletionProposal>();
- if (annotation != null) {
- final String pathAnnotationValue = annotation.getValue("value");
- if (pathAnnotationValue != null && pathAnnotationValue.contains("{")
&& pathAnnotationValue.contains("}")) {
- List<String> uriParams =
extractParamsFromUriTemplateFragment(pathAnnotationValue);
- for (String uriParam : uriParams) {
- String replacementValue = "\"" + uriParam + "\"";
- if (replacementValue.startsWith(matchValue)) {
- String displayString = uriParam + " - JAX-RS Mapping";
- StyledString displayStyledString = new StyledString(displayString);
- displayStyledString.setStyle(uriParam.length(), displayString.length() -
uriParam.length(),
- StyledString.QUALIFIER_STYLER);
- completionProposals.add(new AnnotationCompletionProposal(replacementValue,
displayStyledString,
- region, icon, (IMember) annotation.getJavaParent()));
- }
- }
}
}
return completionProposals;
}
- private static List<String> extractParamsFromUriTemplateFragment(String fragment)
{
- List<String> params = new ArrayList<String>();
- int beginIndex = -1;
- while ((beginIndex = fragment.indexOf("{", beginIndex + 1)) != -1) {
- int semicolonIndex = fragment.indexOf(":", beginIndex);
- int closingCurlyBraketIndex = fragment.indexOf("}", beginIndex);
- int endIndex = semicolonIndex != -1 ? semicolonIndex : closingCurlyBraketIndex;
- params.add(fragment.substring(beginIndex + 1, endIndex).trim());
- }
- return params;
+ private ICompletionProposal generateCompletionProposal(IMember member, ITypedRegion
region, String proposalValue)
+ throws CoreException {
+ String replacementValue = "\"" + proposalValue + "\"";
+ String displayString = proposalValue + " - JAX-RS Mapping";
+ StyledString displayStyledString = new StyledString(displayString);
+ displayStyledString.setStyle(proposalValue.length(), displayString.length() -
proposalValue.length(),
+ StyledString.QUALIFIER_STYLER);
+ return new AnnotationCompletionProposal(replacementValue, displayStyledString, region,
icon, member);
}
- /** Resolves the typed region for the given java content assist invocation
+ /**
+ * Resolves the typed region for the given java content assist invocation
* context.
*
* @param javaContext
* the java content assist invocation context
- * @return the typed region */
+ * @return the typed region
+ */
private ITypedRegion getRegion(final JavaContentAssistInvocationContext javaContext) {
IDocument document = javaContext.getDocument();
IDocumentPartitioner documentPartitioner = ((IDocumentExtension3) document)
@@ -185,35 +168,6 @@
return documentPartitioner.getPartition(javaContext.getInvocationOffset());
}
- /** Returns the enclosing java type for the given java element.
- *
- * @param element
- * the element
- * @return the enclosing type, or null if the given element is neither a
- * method nor the type itself
- * @throws JavaModelException
- * in case of underlying exception */
- private IType getEnclosingType(final IJavaElement element) throws JavaModelException {
- if (element == null) {
- // no enclosing parent. For example, an annotation is set before the
- // method itself was written.
- return null;
- }
- switch (element.getElementType()) {
- case IJavaElement.TYPE:
- return (IType) element;
- case IJavaElement.METHOD:
- return (IType) element.getParent();
- case IJavaElement.FIELD:
- return null;
- default:
- break;
- }
- // Logger.error("Unexpected element type for " +
- // element.getElementName() + ": " + element.getElementType());
- return null;
- }
-
/** {@inheritDoc} */
@Override
public final List<IContextInformation> computeContextInformation(final
ContentAssistInvocationContext context,
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 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -22,8 +22,10 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
@@ -63,6 +65,8 @@
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.ui.internal.wizards.datatransfer.DataTransferMessages;
+import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
+import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.osgi.framework.Bundle;
@@ -813,4 +817,25 @@
return found;
}
+ public static Annotation getAnnotation(final IMember member, final Class<?>
annotationClass) throws JavaModelException {
+ if(annotationClass == null) {
+ return null;
+ }
+ return JdtUtils.resolveAnnotation(member, JdtUtils.parse(member, null),
annotationClass);
+ }
+
+ public static Annotation getAnnotation(final IMember member, final Class<?>
annotationClass, String... values)
+ throws JavaModelException {
+ Annotation annotation = JdtUtils.resolveAnnotation(member, JdtUtils.parse(member,
null),
+ annotationClass);
+ 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));
+ return annotation;
+ }
+
+ public static IType getType(String typeName, IJavaProject javaProject) throws
CoreException {
+ return JdtUtils.resolveType(typeName, javaProject, null);
+ }
+
}
Deleted:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/AbstractBuildDelegateTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/AbstractBuildDelegateTestCase.java 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/AbstractBuildDelegateTestCase.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Xavier Coulon - Initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder;
-
-import org.jboss.tools.ws.jaxrs.core.AbstractCommonTestCase;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class AbstractBuildDelegateTestCase extends AbstractCommonTestCase {
-
- protected static final Logger LOGGER =
LoggerFactory.getLogger(AbstractBuildDelegateTestCase.class);
-
-}
\ No newline at end of file
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 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessorTestCase.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -8,6 +8,9 @@
import static org.hamcrest.Matchers.everyItem;
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.internal.metamodel.builder.IJavaElementDeltaFlag.F_SIGNATURE;
import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementChangedEvent.F_CONSUMED_MEDIATYPES_VALUE;
import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementChangedEvent.F_ELEMENT_KIND;
@@ -49,6 +52,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IMember;
@@ -105,28 +109,20 @@
return httpMethod;
}
- private IType getType(String typeName) throws CoreException {
- return JdtUtils.resolveType(typeName, javaProject, progressMonitor);
+
+ private Annotation createAnnotation(IAnnotation annotation, String name) {
+ return createAnnotation(annotation, name, null);
}
- private IMethod getMethod(IType parentType, String methodName) throws JavaModelException
{
- return WorkbenchUtils.getMethod(parentType, methodName);
+ private Annotation createAnnotation(Class<?> clazz, String value) {
+ return createAnnotation(null, clazz.getName(), value);
}
-
- private Annotation getAnnotation(final IMember member, final Class<?>
annotationClass) throws JavaModelException {
- return JdtUtils.resolveAnnotation(member, JdtUtils.parse(member, progressMonitor),
annotationClass);
+
+ 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);
}
-
- private Annotation getAnnotation(final IMember member, final Class<?>
annotationClass, String... values)
- throws JavaModelException {
- Annotation annotation = JdtUtils.resolveAnnotation(member, JdtUtils.parse(member,
progressMonitor),
- annotationClass);
- 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));
- return annotation;
- }
-
private List<JaxrsElementChangedEvent> processEvent(JavaElementChangedEvent event,
IProgressMonitor progressmonitor) {
return delegate.processEvents(Arrays.asList(event), progressmonitor);
}
@@ -411,7 +407,7 @@
@Test
public void shouldAddResourceWhenAddingSourceCompilationUnit() throws CoreException {
// pre-conditions
- IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
// operation
final JavaElementChangedEvent event = createEvent(type.getCompilationUnit(), ADDED);
final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
@@ -426,7 +422,7 @@
// pre-conditions
final JaxrsHttpMethod httpMethod = createHttpMethod(GET.class);
metamodel.add(httpMethod);
- IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource");
+ IType type = getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource",
javaProject);
// operation
final JavaElementChangedEvent event = createEvent(type.getCompilationUnit(), ADDED);
final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
@@ -440,7 +436,7 @@
@Test
public void shouldAddSubresourceLocatorWhenAddingSourceCompilationUnit() throws
CoreException {
// pre-conditions
- IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
// operation
final JavaElementChangedEvent event = createEvent(type.getCompilationUnit(), ADDED);
final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
@@ -454,7 +450,7 @@
@Test
public void shouldAddResourceWhenAddingSourceType() throws CoreException {
// pre-conditions
- IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
// operation
final JavaElementChangedEvent event = createEvent(type, ADDED);
final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
@@ -470,7 +466,7 @@
@Test
public void shouldAddResourceWhenAddingPathAnnotation() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation annotation = getAnnotation(type, Path.class);
// operation
final JavaElementChangedEvent event = createEvent(annotation, ADDED);
@@ -491,7 +487,7 @@
@Test
public void shouldBecomeRootResourceWhenAddingPathAnnotation() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation annotation = getAnnotation(type, Path.class);
final IJaxrsResource resource = new JaxrsResource.Builder(type, metamodel).build();
metamodel.add(resource);
@@ -507,7 +503,7 @@
@Test
public void shouldNotAddResourceWhenAddingAnotherAnnotation() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation annotation = getAnnotation(type, Consumes.class);
// operation
final JavaElementChangedEvent event = createEvent(annotation, ADDED);
@@ -520,7 +516,7 @@
@Test
public void shouldUpdateResourceWhenChangingPathAnnotationValue() throws CoreException
{
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation annotation = getAnnotation(type, Path.class, "/bar");
final IJaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(annotation).build();
metamodel.add(resource);
@@ -537,7 +533,7 @@
@Test
public void shouldUpdateResourceWhenAddingConsumesAnnotation() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation annotation = getAnnotation(type, Consumes.class);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
@@ -554,7 +550,7 @@
@Test
public void shouldUpdateResourceWhenChangingConsumesAnnotationValue() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final Annotation consumesAnnotation = getAnnotation(type, Consumes.class,
"application/foo");
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
@@ -572,7 +568,7 @@
@Test
public void shouldUpdateResourceWhenRemovingConsumesAnnotation() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final Annotation consumesAnnotation = getAnnotation(type, Consumes.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
@@ -590,7 +586,7 @@
@Test
public void shouldUpdateResourceWhenAddingProducesAnnotation() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -607,7 +603,7 @@
@Test
public void shouldUpdateResourceWhenChangingProducesAnnotationValue() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation annotation = getAnnotation(type, Produces.class,
"application/foo");
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
@@ -625,7 +621,7 @@
@Test
public void shouldUpdateResourceWhenRemovingProducesAnnotation() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation annotation = getAnnotation(type, Produces.class);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation)
@@ -643,7 +639,7 @@
@Test
public void shouldAddResourceFieldWhenAddingPathParamAnnotationOnField() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -657,6 +653,7 @@
}
@Test
+ @Ignore
public void shouldAddResourceFieldWhenAddingImportPathParam() throws CoreException {
/*
* // pre-conditions final IType type =
@@ -676,7 +673,7 @@
@Test
public void shouldAddResourceFieldWhenAddingQueryParamAnnotationOnField() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -692,7 +689,7 @@
@Test
public void shouldAddResourceFieldWhenAddingMatrixParamAnnotationOnField() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -708,7 +705,7 @@
@Test
public void shouldAddResourceFieldWhenAddingFieldAnnotatedWithPathParam() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -724,7 +721,7 @@
@Test
public void shouldAddResourceFieldWhenAddingFieldAnnotatedWithQueryParam() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -740,7 +737,7 @@
@Test
public void shouldAddResourceFieldWhenAddingFieldAnnotatedWithMatrixParam() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -756,7 +753,7 @@
@Test
public void shouldDoNothingWhenAddingFieldWithAnyAnnotation() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -771,7 +768,7 @@
@Test
public void shouldDoNothingWhenAddingAnotherAnnotationOnField() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -786,7 +783,7 @@
@Test
public void shouldUpdateResourceFieldWhenChangingPathParamAnnotationValueOnField()
throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -805,7 +802,7 @@
@Test
public void shouldUpdateResourceFieldWhenChangingQueryParamAnnotationValueOnField()
throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -824,7 +821,7 @@
@Test
public void shouldUpdateResourceFieldWhenChangingMatrixParamAnnotationValueOnField()
throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -843,7 +840,7 @@
@Test
public void shouldDoNothingWhenChangingAnotherAnnotationValueOnField() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -861,7 +858,7 @@
@Test
public void shouldRemoveResourceFieldWhenRemovingPathParamAnnotatedOnField() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -880,7 +877,7 @@
@Test
public void shouldRemoveResourceFieldWhenRemovingQueryParamAnnotationOnField() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -899,7 +896,7 @@
@Test
public void shouldRemoveResourceFieldWhenRemovingMatrixParamAnnotationOnField() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -918,7 +915,7 @@
@Test
public void shouldRemoveResourceFieldWhenRemovingFieldAnnotatedWithQueryParam() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -937,7 +934,7 @@
@Test
public void shouldRemoveResourceFieldWhenRemovingFieldAnnotatedWithPathParam() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -957,7 +954,7 @@
@Test
public void shouldRemoveResourceFieldWhenRemovingFieldAnnotatedWithMatrixParam() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -976,7 +973,7 @@
@Test
public void shouldDoNothingWhenRemovingAnotherAnnotationOnField() throws CoreException
{
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -991,7 +988,7 @@
@Test
public void shouldDoNothingWhenAnnotationValueRemainsSameOnResource() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation annotation = JdtUtils.resolveAnnotation(type, JdtUtils.parse(type,
progressMonitor),
Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(annotation).build();
@@ -1006,7 +1003,7 @@
@Test
public void shouldDoNothingResourceWhenChangingAnotherAnnotationValue() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1021,7 +1018,7 @@
@Test
public void shouldRemoveResourceWhenRemovingCompilationUnit() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final IJaxrsResource resource = new JaxrsResource.Builder(type, metamodel).build();
metamodel.add(resource);
// operation
@@ -1037,7 +1034,7 @@
@Test
public void shouldRemoveResourceWhenRemovingSourceType() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final IJaxrsResource resource = new JaxrsResource.Builder(type, metamodel).build();
metamodel.add(resource);
// operation
@@ -1053,7 +1050,7 @@
@Test
public void shouldRemoveResourceWhenRemovingAnnotation() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation annotation = getAnnotation(type, Path.class);
final IJaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(annotation).build();
metamodel.add(resource);
@@ -1076,7 +1073,7 @@
final JaxrsHttpMethod httpMethod = createHttpMethod(POST.class);
metamodel.add(httpMethod);
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1101,7 +1098,7 @@
final JaxrsHttpMethod httpMethod = createHttpMethod(POST.class);
metamodel.add(httpMethod);
// JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1123,7 +1120,7 @@
@Test
public void shouldDoNothingWhenRemovingAnotherAnnotationOnResource() throws
CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final IJaxrsResource resource = new JaxrsResource.Builder(type, metamodel).build();
metamodel.add(resource);
// in case it would be removed
@@ -1141,7 +1138,7 @@
// pre-conditions
final IPackageFragmentRoot sourceFolder =
WorkbenchUtils.getPackageFragmentRoot(javaProject, "src/main/java",
progressMonitor);
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation annotation = getAnnotation(type, Consumes.class);
final IJaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(annotation).build();
metamodel.add(resource);
@@ -1165,7 +1162,7 @@
// JAX-RS HttpMethod
metamodel.add(createHttpMethod(POST.class));
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1185,7 +1182,7 @@
// JAX-RS HttpMethod
metamodel.add(createHttpMethod(POST.class));
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1202,7 +1199,7 @@
public void shouldAddSubresourceLocatorWhenAddingPathAnnotation() throws CoreException
{
// pre-conditions
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1223,7 +1220,7 @@
final JaxrsHttpMethod httpMethod = createHttpMethod(POST.class);
metamodel.add(httpMethod);
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1247,7 +1244,7 @@
final JaxrsHttpMethod httpMethod = createHttpMethod(GET.class);
metamodel.add(httpMethod);
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ 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.class)).build();
metamodel.add(resource);
@@ -1274,7 +1271,7 @@
final JaxrsHttpMethod httpMethod = createHttpMethod(GET.class);
metamodel.add(httpMethod);
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ 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.class)).build();
metamodel.add(resource);
@@ -1301,7 +1298,7 @@
final JaxrsHttpMethod httpMethod = createHttpMethod(GET.class);
metamodel.add(httpMethod);
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ 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.class)).build();
metamodel.add(resource);
@@ -1325,7 +1322,7 @@
public void shouldRemoveSubresourceLocatorWhenRemovingPathAnnotation() throws
CoreException {
// pre-conditions
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ 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.class)).build();
metamodel.add(resource);
@@ -1350,7 +1347,7 @@
final JaxrsHttpMethod httpMethod = createHttpMethod(GET.class);
metamodel.add(httpMethod);
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ 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.class)).build();
metamodel.add(resource);
@@ -1377,7 +1374,7 @@
final JaxrsHttpMethod httpMethod = createHttpMethod(POST.class);
metamodel.add(httpMethod);
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1404,7 +1401,7 @@
final JaxrsHttpMethod httpMethod = createHttpMethod(POST.class);
metamodel.add(httpMethod);
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1431,7 +1428,7 @@
final JaxrsHttpMethod httpMethod = createHttpMethod(POST.class);
metamodel.add(httpMethod);
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1458,7 +1455,7 @@
final JaxrsHttpMethod httpMethod = createHttpMethod(POST.class);
metamodel.add(httpMethod);
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1485,7 +1482,7 @@
final JaxrsHttpMethod httpMethod = createHttpMethod(POST.class);
metamodel.add(httpMethod);
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1512,7 +1509,7 @@
final JaxrsHttpMethod httpMethod = createHttpMethod(GET.class);
metamodel.add(httpMethod);
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1542,7 +1539,7 @@
// the method signature is changed
// pre-conditions
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1550,9 +1547,9 @@
final IMethod method = getMethod(type, "getCustomer");
final JavaMethodParameter pathParameter = new JavaMethodParameter("id",
Integer.class.getName(), null);
final JavaMethodParameter contextParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(),
- Arrays.asList(new Annotation(null, Context.class.getName())));
+ Arrays.asList(createAnnotation(Context.class, null)));
final IJaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method,
GET.class)).returnType(getType(Response.class.getName()))
+ .httpMethod(getAnnotation(method,
GET.class)).returnType(getType(Response.class.getName(), javaProject))
.methodParameter(pathParameter).methodParameter(contextParameter).build();
metamodel.add(resourceMethod);
// operation
@@ -1570,18 +1567,18 @@
// the method signature is changed
// pre-conditions
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
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(new Annotation(null, PathParam.class.getName(), "foo!")));
+ Arrays.asList(createAnnotation(PathParam.class, "foo!")));
final JavaMethodParameter contextParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(),
- Arrays.asList(new Annotation(null, Context.class.getName())));
+ Arrays.asList(createAnnotation(Context.class, null)));
final IJaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method,
GET.class)).returnType(getType(Response.class.getName()))
+ .httpMethod(getAnnotation(method,
GET.class)).returnType(getType(Response.class.getName(), javaProject))
.methodParameter(pathParameter).methodParameter(contextParameter).build();
metamodel.add(resourceMethod);
// operation
@@ -1598,19 +1595,19 @@
// the method signature is changed
// pre-conditions
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method
final IMethod method = getMethod(type, "updateCustomer");
final JavaMethodParameter pathParameter = new JavaMethodParameter("id",
Integer.class.getName(),
- Arrays.asList(new Annotation(null, PathParam.class.getName(), "id")));
+ Arrays.asList(createAnnotation(PathParam.class, "id")));
final JavaMethodParameter customerParameter = new
JavaMethodParameter("update",
- "org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
Arrays.asList(new Annotation(null,
- PathParam.class.getName(), "foo")));
+ "org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
Arrays.asList(createAnnotation(
+ PathParam.class, "foo")));
final IJaxrsResourceMethod resourceMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method, PUT.class)).returnType(getType("void"))
+ .httpMethod(getAnnotation(method, PUT.class)).returnType(getType("void",
javaProject))
.methodParameter(pathParameter).methodParameter(customerParameter).build();
metamodel.add(resourceMethod);
// operation
@@ -1627,18 +1624,18 @@
// the method signature is changed
// pre-conditions
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
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(new Annotation(null, QueryParam.class.getName(), "start")));
+ Arrays.asList(createAnnotation(QueryParam.class, "start")));
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(),
- Arrays.asList(new Annotation(null, Context.class.getName())));
+ Arrays.asList(createAnnotation(Context.class, null)));
final IJaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.util.List"))
+ .httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.util.List", javaProject))
.methodParameter(startParameter).methodParameter(uriInfoParameter).build();
metamodel.add(jaxrsMethod);
// operation
@@ -1655,20 +1652,20 @@
// the method signature is changed
// pre-conditions
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
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(new Annotation(null, QueryParam.class.getName(), "start")));
- final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(new Annotation(
- null, DefaultValue.class.getName(), "2")));
+ Arrays.asList(createAnnotation(QueryParam.class, "start")));
+ final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(createAnnotation(
+ DefaultValue.class, "2")));
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(),
- Arrays.asList(new Annotation(null, Context.class.getName())));
+ Arrays.asList(createAnnotation(Context.class, null)));
final IJaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.util.List"))
+ .httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.util.List", javaProject))
.methodParameter(startParameter).methodParameter(sizeParameter).methodParameter(uriInfoParameter)
.build();
metamodel.add(jaxrsMethod);
@@ -1686,7 +1683,7 @@
// the method signature is changed
// pre-conditions
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1694,13 +1691,13 @@
// "size" on second param)
final IMethod method = getMethod(type, "getCustomers");
final JavaMethodParameter startParameter = new JavaMethodParameter("start",
"int",
- Arrays.asList(new Annotation(null, QueryParam.class.getName(), "start")));
- final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(new Annotation(
- null, QueryParam.class.getName(), "length"), new Annotation(null,
DefaultValue.class.getName(), "2")));
+ Arrays.asList(createAnnotation(QueryParam.class, "start")));
+ final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(createAnnotation(
+ QueryParam.class, "length"), createAnnotation(DefaultValue.class,
"2")));
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(),
- Arrays.asList(new Annotation(null, Context.class.getName())));
+ Arrays.asList(createAnnotation(Context.class, null)));
final IJaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.util.List"))
+ .httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.util.List", javaProject))
.methodParameter(startParameter).methodParameter(sizeParameter).methodParameter(uriInfoParameter)
.build();
metamodel.add(jaxrsMethod);
@@ -1718,21 +1715,21 @@
// the method signature is changed
// pre-conditions
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
// JAX-RS Resource Method (an extra annotation on 'start' param)
final IMethod method = getMethod(type, "getCustomers");
final JavaMethodParameter startParameter = new JavaMethodParameter("start",
"int", Arrays.asList(
- new Annotation(null, QueryParam.class.getName(), "start"),
- new Annotation(null, DefaultValue.class.getName(), "0")));
- final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(new Annotation(
- null, QueryParam.class.getName(), "size"), new Annotation(null,
DefaultValue.class.getName(), "2")));
+ createAnnotation(QueryParam.class, "start"),
+ createAnnotation(DefaultValue.class, "0")));
+ final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(createAnnotation(
+ QueryParam.class, "size"), createAnnotation(DefaultValue.class,
"2")));
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(),
- Arrays.asList(new Annotation(null, Context.class.getName())));
+ Arrays.asList(createAnnotation(Context.class, null)));
final IJaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.util.List"))
+ .httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.util.List", javaProject))
.methodParameter(startParameter).methodParameter(sizeParameter).methodParameter(uriInfoParameter)
.build();
metamodel.add(jaxrsMethod);
@@ -1768,7 +1765,7 @@
// the method signature is changed
// pre-conditions
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1776,13 +1773,13 @@
// 'javax.ws.rs.Response')
final IMethod method = getMethod(type, "getCustomers");
final JavaMethodParameter startParameter = new JavaMethodParameter("start",
"int",
- Arrays.asList(new Annotation(null, QueryParam.class.getName(), "start")));
- final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(new Annotation(
- null, QueryParam.class.getName(), "size"), new Annotation(null,
DefaultValue.class.getName(), "2")));
+ Arrays.asList(createAnnotation(QueryParam.class, "start")));
+ final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(createAnnotation(
+ QueryParam.class, "size"), createAnnotation(DefaultValue.class,
"2")));
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(),
- Arrays.asList(new Annotation(null, Context.class.getName())));
+ Arrays.asList(createAnnotation(Context.class, null)));
final IJaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
- .httpMethod(getAnnotation(method,
GET.class)).returnType(getType(Response.class.getName()))
+ .httpMethod(getAnnotation(method,
GET.class)).returnType(getType(Response.class.getName(), javaProject))
.methodParameter(startParameter).methodParameter(sizeParameter).methodParameter(uriInfoParameter)
.build();
metamodel.add(jaxrsMethod);
@@ -1792,7 +1789,8 @@
// verifications
assertThat(impacts.size(), equalTo(1));
assertThat(impacts.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(impacts.get(0).getFlags(), equalTo(F_METHOD_RETURN_TYPE));
+ // annotations were not provided but are retrieved...
+ assertThat(impacts.get(0).getFlags(), equalTo(F_METHOD_RETURN_TYPE +
F_METHOD_PARAMETERS));
}
@Test
@@ -1806,16 +1804,16 @@
// the method signature is changed
// pre-conditions
// Parent JAX-RS Resource
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
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(new Annotation(null, QueryParam.class.getName(), "start")));
- final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(new Annotation(
- null, QueryParam.class.getName(), "length"), new Annotation(null,
DefaultValue.class.getName(), "2")));
+ Arrays.asList(createAnnotation(QueryParam.class, "start")));
+ final JavaMethodParameter sizeParameter = new JavaMethodParameter("size",
"int", Arrays.asList(createAnnotation(
+ QueryParam.class, "length"), createAnnotation(DefaultValue.class,
"2")));
final JavaMethodParameter uriInfoParameter = new
JavaMethodParameter("uriInfo", UriInfo.class.getName(), null);
final IJaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.methodParameter(startParameter).methodParameter(sizeParameter).methodParameter(uriInfoParameter)
@@ -1843,7 +1841,7 @@
@Test
public void shouldDoNothingWhenAddingBasicJavaMethod() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1859,7 +1857,7 @@
@Test
public void shouldDoNothingWhenChangingBasicJavaMethod() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
@@ -1875,7 +1873,7 @@
@Test
public void shouldDoNothingWhenRemovingBasicJavaMethod() throws CoreException {
// pre-conditions
- final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final IType type =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
final Annotation pathAnnotation = getAnnotation(type, Path.class);
final JaxrsResource resource = new JaxrsResource.Builder(type,
metamodel).pathTemplate(pathAnnotation).build();
metamodel.add(resource);
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedProcessorTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedProcessorTestCase.java 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedProcessorTestCase.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -54,6 +54,8 @@
import org.junit.Ignore;
import org.junit.Test;
+import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.*;
+
public class JaxrsElementChangedProcessorTestCase extends AbstractCommonTestCase {
private JaxrsMetamodel metamodel;
@@ -68,7 +70,7 @@
}
private JaxrsResource createResource(String typeName) throws CoreException,
JavaModelException {
- final IType resourceType = getType(typeName);
+ final IType resourceType = getType(typeName, javaProject);
final JaxrsResource customerResource = new JaxrsResource.Builder(resourceType,
metamodel).pathTemplate(
getAnnotation(resourceType, Path.class)).build();
metamodel.add(customerResource);
@@ -95,7 +97,7 @@
}
private JaxrsHttpMethod createHttpMethod(Class<?> annotationClass) throws
JavaModelException, CoreException {
- final IType type = getType(annotationClass.getName());
+ final IType type = getType(annotationClass.getName(), javaProject);
final Annotation httpAnnotation = getAnnotation(type, HttpMethod.class);
final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod(type, httpAnnotation,
metamodel);
metamodel.add(httpMethod);
@@ -109,31 +111,7 @@
return endpoint;
}
- private IType getType(String typeName) throws CoreException {
- return JdtUtils.resolveType(typeName, javaProject, progressMonitor);
- }
-
- private IMethod getMethod(IType parentType, String methodName) throws JavaModelException
{
- return WorkbenchUtils.getMethod(parentType, methodName);
- }
-
- private Annotation getAnnotation(final IMember member, final Class<?>
annotationClass) throws JavaModelException {
- if (annotationClass == null) {
- return null;
- }
- return JdtUtils.resolveAnnotation(member, JdtUtils.parse(member, progressMonitor),
annotationClass);
- }
-
- private Annotation getAnnotation(final IMember member, final Class<?>
annotationClass, String... values)
- throws JavaModelException {
- Annotation annotation = JdtUtils.resolveAnnotation(member, JdtUtils.parse(member,
progressMonitor),
- annotationClass);
- 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));
- return annotation;
- }
-
+
@Test
public void shouldConstructSimpleEndpoint() throws JavaModelException, CoreException {
// pre-conditions
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuildJobTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuildJobTestCase.java 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuildJobTestCase.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -11,8 +11,15 @@
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.emptyIterable;
+import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
+import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getMethod;
+import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getType;
import static org.junit.Assert.assertThat;
import java.util.HashSet;
@@ -20,12 +27,13 @@
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
-import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsEndpoint;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResource;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
import org.junit.Assert;
import org.junit.Test;
@@ -45,76 +53,16 @@
}
}
- /** @Test
- * @Ignore
- * public void shouldAssertProviders() throws CoreException {
- * // FIXME : check no abstract class is registered
- * Assert.assertEquals(2,
- * metamodel.getProviders(EnumKind.CONSUMER).size());
- * for (IJaxrsProvider p :
- * metamodel.getProviders(EnumKind.CONSUMER)) {
- * Assert.assertNotNull("Missing provided type",
- * p.getProvidedKinds().containsKey(EnumKind.CONSUMER));
- * /
- * Assert.assertNotNull("Missing mime-type: " +
- * p.getJavaType().getFullyQualifiedName(),
- * p.getMediaTypes(EnumKind.CONSUMER));
- * /
- * Assert.assertFalse("Provider type shouldn't be abstract: " +
- * p.getJavaElement().getFullyQualifiedName(),
- * JdtUtils.isAbstractType(p.getJavaElement()));
- * }
- *
- * Assert.assertEquals(3,
- * metamodel.getProviders(EnumKind.PRODUCER).size());
- * for (IJaxrsProvider p :
- * metamodel.getProviders(EnumKind.PRODUCER)) {
- * Assert.assertNotNull("Missing provided type",
- * p.getProvidedKinds().containsKey(EnumKind.PRODUCER));
- * /
- * Assert.assertNotNull("Missing mime-type: " +
- * p.getJavaType().getFullyQualifiedName(),
- * p.getMediaTypes(EnumKind.PRODUCER));
- * /
- * Assert.assertFalse("Provider type shouldn't be abstract: " +
- * p.getJavaElement().getFullyQualifiedName(),
- * JdtUtils.isAbstractType(p.getJavaElement()));
- * }
- *
- * Assert.assertEquals(3,
- * metamodel.getProviders(EnumKind.EXCEPTION_MAPPER).size());
- * for (IJaxrsProvider p :
- * metamodel.getProviders(EnumKind.EXCEPTION_MAPPER)) {
- * Assert.assertNotNull("Missing provided type",
- * p.getProvidedKinds().containsKey(EnumKind.EXCEPTION_MAPPER));
- * Assert.assertNull("Unexpected mime-type: " +
- * p.getJavaElement().getFullyQualifiedName(),
- * p.getMediaTypeCapabilities(EnumKind.EXCEPTION_MAPPER));
- * Assert.assertFalse("Provider type shouldn't be abstract: " +
- * p.getJavaElement().getFullyQualifiedName(),
- * JdtUtils.isAbstractType(p.getJavaElement()));
- * }
- * } */
-
@Test
public void shouldAssertResourcesAndMethods() throws CoreException {
// for now, the result excludes the (binary) AsynchronousDispatcher, and
// hence, its (sub)resources
- // FIXME : should this include the subresource locator (method) ???
Assert.assertEquals(5, metamodel.getAllResources().size());
for (IJaxrsResource jaxrsResource : metamodel.getAllResources()) {
assertThat(jaxrsResource.getJavaElement(), notNullValue());
assertThat(jaxrsResource.getKind(), notNullValue());
assertThat(jaxrsResource.getAllMethods().size(), greaterThan(0));
}
- /*
- * for (IJaxrsResource resource : metamodel.getAllResources()) {
- * Assert.assertNotNull("JavaType not found",
- * resource.getJavaElement());
- * Assert.assertEquals("Wrong kind", EnumKind.ROOT_RESOURCE,
- * resource.getKind());
- * }
- */
}
@Test
@@ -132,24 +80,50 @@
Assert.assertFalse("No consumed media types",
endpoint.getConsumedMediaTypes().isEmpty());
Assert.assertFalse("No produced media types",
endpoint.getProducedMediaTypes().isEmpty());
}
- /*
- * List<Route> uriMappings = new
- * ArrayList<Route>(resolveUriMappings.keySet());
- * Collections.sort(uriMappings); Assert.assertEquals("Wrong result",
- * "/customers?start={int}&size={int}", uriMappings.get(0)
- * .getFullUriPathTemplate()); Assert.assertEquals("Wrong result",
- * "GET", uriMappings.get(0).getHTTPMethod().getHttpVerb());
- * Assert.assertEquals("Wrong result", "/products/{type}/{id}",
- * uriMappings.get(9).getFullUriPathTemplate());
- */
}
@Test
- public void shouldFullyAssertCustomerResource() throws CoreException {
- IJaxrsResource customerResource = (IJaxrsResource)
metamodel.getElement(JdtUtils.resolveType(
- "org.jboss.tools.ws.jaxrs.sample.services.CustomerResource", javaProject,
new NullProgressMonitor()));
- Assert.assertNotNull("CustomerResource not found", customerResource);
+ public void shouldRetrieveCustomerResource() throws CoreException {
+ IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
+ final IJaxrsResource customerResource = (IJaxrsResource)
metamodel.getElement(customerType);
+ Assert.assertNotNull("CustomerResource not found", customerType);
Assert.assertEquals("Wrong number of resource resourceMethods", 6,
customerResource.getResourceMethods().size());
}
+ @Test
+ public void shouldRetrieveCustomerResourceMethodProposals() throws CoreException {
+ IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
+ IMethod customerMethod = getMethod(customerType, "getCustomers");
+ final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod)
metamodel.getElement(customerMethod);
+ Assert.assertThat(customerResourceMethod, notNullValue());
+ Assert.assertThat(customerResourceMethod.getPathParamValueProposals().size(),
equalTo(0));
+ }
+
+ @Test
+ public void shouldRetrieveCustomerSubresourceMethodProposals() throws CoreException {
+ IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
+ IMethod customerMethod = getMethod(customerType, "getCustomer");
+ final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod)
metamodel.getElement(customerMethod);
+ Assert.assertThat(customerResourceMethod, notNullValue());
+ Assert.assertThat(customerResourceMethod.getPathParamValueProposals(),
containsInAnyOrder("id"));
+ }
+
+ @Test
+ public void shouldRetrieveBookResourceMethodProposals() throws CoreException {
+ IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
+ IMethod customerMethod = getMethod(customerType, "getAllProducts");
+ final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod)
metamodel.getElement(customerMethod);
+ Assert.assertThat(customerResourceMethod, notNullValue());
+ Assert.assertThat(customerResourceMethod.getPathParamValueProposals().size(),
equalTo(0));
+ }
+
+ @Test
+ public void shouldRetrieveBooksubresourceMethodProposals() throws CoreException {
+ IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
+ IMethod customerMethod = getMethod(customerType, "getProduct");
+ final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod)
metamodel.getElement(customerMethod);
+ Assert.assertThat(customerResourceMethod, notNullValue());
+ Assert.assertThat(customerResourceMethod.getPathParamValueProposals(),
containsInAnyOrder("id"));
+ }
+
}
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 2011-11-22
12:30:55 UTC (rev 36530)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtilsTestCase.java 2011-11-22
13:26:39 UTC (rev 36531)
@@ -655,6 +655,7 @@
assertThat(javaAnnotation.getName(), equalTo(Path.class.getName()));
assertThat(javaAnnotation.getJavaAnnotationElements().size(), equalTo(1));
assertThat(javaAnnotation.getJavaAnnotationElements().get("value").get(0),
equalTo("/customers"));
+ assertThat(javaAnnotation.getRegion(), notNullValue());
}
@Test
@@ -670,8 +671,9 @@
// verifications
assertThat(javaAnnotations.size(), equalTo(4));
for (Entry<String, Annotation> entry : javaAnnotations.entrySet()) {
+ assertThat(entry.getKey(), equalTo(entry.getValue().getName()));
assertThat(entry.getValue().getJavaAnnotation(), notNullValue());
- assertThat(entry.getKey(), equalTo(entry.getValue().getName()));
+ assertThat(entry.getValue().getRegion(), notNullValue());
}
}