[jbosstools-commits] JBoss Tools SVN: r31416 - in trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core: src/org/jboss/tools/ws/jaxrs/core/internal/builder and 2 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Sun May 22 12:04:56 EDT 2011


Author: xcoulon
Date: 2011-05-22 12:04:56 -0400 (Sun, 22 May 2011)
New Revision: 31416

Added:
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/ResourceMethodAnnotatedParameter.java
Removed:
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodAnnotatedParameter.java
Modified:
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/lib/jaxrs-api.jar
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JAXRSAnnotationsScanner.java
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElement.java
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethod.java
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethods.java
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Provider.java
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResolvedUriMapping.java
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resource.java
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethod.java
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/UriMapping.java
   trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java
Log:
Refactoring pieces of the metamodel classes and JdtUtils API + Fixing incomplete jaxrs-api jar

Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/lib/jaxrs-api.jar
===================================================================
(Binary files differ)

Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JAXRSAnnotationsScanner.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JAXRSAnnotationsScanner.java	2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JAXRSAnnotationsScanner.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -28,7 +28,6 @@
 import org.eclipse.jdt.core.IMethod;
 import org.eclipse.jdt.core.IType;
 import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.IAnnotationBinding;
 import org.eclipse.jdt.core.search.IJavaSearchConstants;
 import org.eclipse.jdt.core.search.IJavaSearchScope;
 import org.eclipse.jdt.core.search.SearchEngine;
@@ -123,7 +122,7 @@
 	public static List<IType> findHTTPMethodTypes(final IJavaElement scope, final IProgressMonitor progressMonitor)
 			throws CoreException {
 		IJavaSearchScope searchScope = null;
-		if(scope instanceof IJavaProject) {
+		if (scope instanceof IJavaProject) {
 			IJavaProject javaProject = (IJavaProject) scope;
 			searchScope = SearchEngine.createJavaSearchScope(javaProject.getPackageFragmentRoots());
 		} else {
@@ -243,14 +242,11 @@
 	 */
 	public static List<String> resolveMediaTypeCapabilities(final IMember annotatedMember,
 			final CompilationUnit compilationUnit, final Class<?> annotationClass) throws CoreException {
-		IAnnotationBinding annotationBinding = JdtUtils.resolveAnnotationBinding(annotatedMember, compilationUnit,
-				annotationClass);
-		Object capabilities = JdtUtils.resolveAnnotationAttributeValue(annotationBinding, "value");
+		Object capabilities = JdtUtils.resolveAnnotationAttributeValue(annotatedMember, compilationUnit,
+				annotationClass, "value");
 		return asList(capabilities);
 	}
 
-	
-
 	/**
 	 * Converts the type signature to a human-readable literal.
 	 * 

Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElement.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElement.java	2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElement.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -29,6 +29,8 @@
 
 	/** The functional type of the JAX-RS Element. */
 	public enum EnumType {
+		/** An application */
+		APPLICATION,
 		/** A root resource. */
 		ROOT_RESOURCE,
 		/** A subresource. */
@@ -61,7 +63,7 @@
 	}
 
 	/** The current instance state. */
-	private EnumState state = EnumState.UNKNOWN;
+	EnumState state = EnumState.UNKNOWN;
 
 	/** The associated metamodel. */
 	private final Metamodel metamodel;
@@ -79,9 +81,10 @@
 	 *            the associated metamodel
 	 * @param element
 	 *            the underlying java element
+	 * @throws InvalidModelElementException
 	 */
-	public BaseElement(final Metamodel model, final T element) {
-		this.metamodel = model;
+	public BaseElement(final T element, final Metamodel metamodel) {
+		this.metamodel = metamodel;
 		this.javaElement = element;
 	}
 
@@ -93,7 +96,8 @@
 	}
 
 	/**
-	 * @param javaElement the javaElement to set
+	 * @param javaElement
+	 *            the javaElement to set
 	 */
 	public void setJavaElement(T javaElement) {
 		this.javaElement = javaElement;
@@ -124,31 +128,20 @@
 
 	/**
 	 * Returns the CompilationUnit (AST3/DOM) of the given java element.
-	 * @param element the java element
-	 * @param progressMonitor the progress monitor
+	 * 
+	 * @param element
+	 *            the java element
+	 * @param progressMonitor
+	 *            the progress monitor
 	 * @return the compilation unit or null
-	 * @throws JavaModelException in case of underlying exception
+	 * @throws JavaModelException
+	 *             in case of underlying exception
 	 */
-	final CompilationUnit getCompilationUnit(final T element, final IProgressMonitor progressMonitor)
-			throws JavaModelException {
-		return JdtUtils.parse(element, progressMonitor);
+	final CompilationUnit getCompilationUnit(final IProgressMonitor progressMonitor) throws JavaModelException {
+		return JdtUtils.parse(javaElement, progressMonitor);
 	}
 
 	/**
-	 * @return the state
-	 */
-	public final EnumState getState() {
-		return state;
-	}
-
-	/**
-	 * @param s the state to set
-	 */
-	public final void setState(final EnumState s) {
-		this.state = s;
-	}
-
-	/**
 	 * @return the metamodel
 	 */
 	public final Metamodel getMetamodel() {

Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java	                        (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -0,0 +1,138 @@
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
+
+public abstract class BaseElementContainer<T extends BaseElement<?>> implements Iterable<Entry<String, T>> {
+
+	/** the elements of the container. */
+	final Map<String, T> elements = new HashMap<String, T>();
+
+	/** the enclosing metamodel. */
+	final Metamodel metamodel;
+
+	/**
+	 * Full constructor.
+	 * 
+	 * @param m
+	 *            the enclosing metamodel
+	 */
+	public BaseElementContainer(final Metamodel m) {
+		this.metamodel = m;
+	}
+
+	/**
+	 * Adding elements from the given scope.
+	 * 
+	 */
+	public abstract void addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor) throws CoreException;
+
+	/**
+	 * Remove an element from the container given its underlying (eclipse)
+	 * resource
+	 * 
+	 * @param removedResource
+	 * @param progressMonitor
+	 */
+	public final void removeElement(final IResource removedResource, final IProgressMonitor progressMonitor) {
+		for (Iterator<T> iterator = elements.values().iterator(); iterator.hasNext();) {
+			T element = iterator.next();
+			if (removedResource.equals(element.getJavaElement().getResource())) {
+				iterator.remove();
+				return;
+			}
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#contains(org
+	 * .eclipse.jdt.core.IType)
+	 */
+	public final boolean contains(final IType type) {
+		return elements.containsKey(type.getFullyQualifiedName());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#getByType(org
+	 * .eclipse.jdt.core.IType)
+	 */
+	public final T getByType(final IType type) {
+		return elements.get(type.getFullyQualifiedName());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#getByTypeName
+	 * (java.lang.String)
+	 */
+	public final T getByTypeName(final String typeName) {
+		return elements.get(typeName);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#getAll()
+	 */
+	public final List<T> getAll() {
+		return Collections.unmodifiableList(new ArrayList<T>(elements.values()));
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#getTypeNames()
+	 */
+	public final Set<String> getTypeNames() {
+		return elements.keySet();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#size()
+	 */
+	public final int size() {
+		return elements.size();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#iterator()
+	 */
+	@Override
+	public final Iterator<Entry<String, T>> iterator() {
+		return elements.entrySet().iterator();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#reset()
+	 */
+	public void reset() {
+		this.elements.clear();
+	}
+}


Property changes on: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethod.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethod.java	2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethod.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -17,7 +17,6 @@
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jdt.core.IType;
 import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.IAnnotationBinding;
 import org.eclipse.jdt.internal.core.BinaryType;
 import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
 
@@ -97,27 +96,51 @@
 	}
 
 	/**
-	 * Full constructor.
+	 * Internal 'HTTPMethod' element builder.
 	 * 
-	 * @param javaType
-	 *            the underlying java type
-	 * @param metamodel
-	 *            the associated parent metamodel
-	 * @param progressMonitor
-	 *            the progress monitor
-	 * @throws CoreException
-	 *             in case of underlying exception
-	 * @throws InvalidModelElementException
-	 *             in case of underlying exception
+	 * @author xcoulon
+	 * 
 	 */
-	public HTTPMethod(final IType javaType, final Metamodel metamodel, final IProgressMonitor progressMonitor)
-			throws CoreException, InvalidModelElementException {
-		super(metamodel, javaType);
-		// this.state = EnumState.CREATING;
-		merge(javaType, progressMonitor);
-		// this.state = EnumState.CREATED;
+	public static class Builder {
+
+		private final Metamodel metamodel;
+		private final IType javaType;
+
+		/**
+		 * Mandatory attributes of the enclosing 'HTTPMethod' element.
+		 * 
+		 * @param javaType
+		 * @param metamodel
+		 */
+		public Builder(final IType javaType, final Metamodel metamodel) {
+			this.javaType = javaType;
+			this.metamodel = metamodel;
+		}
+
+		/**
+		 * Builds and returns the elements. Internally calls the merge() method.
+		 * 
+		 * @param progressMonitor
+		 * @return
+		 * @throws InvalidModelElementException
+		 * @throws CoreException
+		 */
+		public HTTPMethod build(IProgressMonitor progressMonitor) throws InvalidModelElementException, CoreException {
+			HTTPMethod httpMethod = new HTTPMethod(this);
+			httpMethod.merge(javaType, progressMonitor);
+			return httpMethod;
+		}
 	}
 
+	/**
+	 * Full constructor using the inner 'Builder' static class.
+	 * 
+	 * @param builder
+	 */
+	private HTTPMethod(Builder builder) {
+		super(builder.javaType, builder.metamodel);
+	}
+
 	@Override
 	public final void merge(final IType javaType, final IProgressMonitor progressMonitor)
 			throws InvalidModelElementException, CoreException {
@@ -132,19 +155,11 @@
 		if (!JdtUtils.isTopLevelType(javaType)) {
 			throw new InvalidModelElementException("Type is not a top-level type");
 		}
-		CompilationUnit compilationUnit = getCompilationUnit(javaType, progressMonitor);
-		/*
-		 * if (state == EnumState.CREATED) { Set<IProblem> problems =
-		 * JdtUtils.resolveErrors(javaType, compilationUnit); if (problems !=
-		 * null && problems.size() > 0) { //metamodel.reportErrors(javaType,
-		 * problems); return; } }
-		 */
-		IAnnotationBinding annotationBinding = JdtUtils.resolveAnnotationBinding(getJavaElement(), compilationUnit,
-				HttpMethod.class);
-		if (annotationBinding == null) {
+		CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
+		this.httpVerb = (String) JdtUtils.resolveAnnotationAttributeValue(getJavaElement(), compilationUnit,
+				HttpMethod.class, "value");
+		if (this.httpVerb == null) {
 			throw new InvalidModelElementException("Annotation binding not found : missing 'import' statement ?");
-		} else {
-			this.httpVerb = (String) JdtUtils.resolveAnnotationAttributeValue(annotationBinding, "value");
 		}
 
 	}

Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethods.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethods.java	2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethods.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -11,16 +11,9 @@
 
 package org.jboss.tools.ws.jaxrs.core.metamodel;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Set;
 
-import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jdt.core.IJavaElement;
@@ -34,34 +27,27 @@
  * @author xcoulon
  * 
  */
-public class HTTPMethods implements Iterable<Entry<String, HTTPMethod>> {
+public class HTTPMethods extends BaseElementContainer<HTTPMethod> {
 
 	/**
-	 * The available HTTP Methods including the 5 standard ones (@GET, @POST,
-	 * etc.) and the application custom extensions (for WebDAV operations
-	 * support, etc.): annotations annotated with <code>@HTTPMethod</code>. The resourceMethods are
-	 * indexed by their associated java type fully qualified name.
-	 */
-	private final Map<String, HTTPMethod> httpMethods = new HashMap<String, HTTPMethod>();
-
-	/** the enclosing metamodel. */
-	private final Metamodel metamodel;
-
-	/**
 	 * Full constructor.
-	 * @param m the enclosing metamodel
+	 * 
+	 * @param m
+	 *            the enclosing metamodel
 	 */
 	public HTTPMethods(final Metamodel m) {
-		this.metamodel = m;
+		super(m);
 	}
 
-	/**
-	 * Registers all discovered HTTP Methods in the given scope.
+	/*
+	 * (non-Javadoc)
 	 * 
-	 * @param scope the scope from which HTTPMethods should be added
-	 * @param progressMonitor the progress monitor
-	 * @throws CoreException in case of underlying exception
+	 * @see
+	 * org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#addFrom(org
+	 * .eclipse.jdt.core.IJavaElement,
+	 * org.eclipse.core.runtime.IProgressMonitor)
 	 */
+	@Override
 	public final void addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor) throws CoreException {
 		try {
 			progressMonitor.beginTask("HTTP Methods registration", 2);
@@ -73,8 +59,8 @@
 			for (IType httpMethodType : httpMethodTypes) {
 				try {
 					// FIXME : must retrieve java errors somewhere around here
-					this.httpMethods.put(httpMethodType.getFullyQualifiedName(), new HTTPMethod(httpMethodType,
-							metamodel, progressMonitor));
+					elements.put(httpMethodType.getFullyQualifiedName(), new HTTPMethod.Builder(httpMethodType,
+							metamodel).build(progressMonitor));
 				} catch (InvalidModelElementException e) {
 					Logger.warn("Type '" + httpMethodType.getFullyQualifiedName()
 							+ "' is not a valid JAX-RS HTTP ResourceMethod: " + e.getMessage());
@@ -87,68 +73,14 @@
 	}
 
 	/**
-	 * Removes the JAX-RS HTTPMethod associated with the given removed resource.
-	 * @param removedResource the removed/deleted underlying resource
-	 * @param progressMonitor the progress monitor
-	 */
-	public final void removeElement(final IResource removedResource, final IProgressMonitor progressMonitor) {
-		for (Iterator<HTTPMethod> iterator = httpMethods.values().iterator(); iterator.hasNext();) {
-			HTTPMethod element = iterator.next();
-			if (removedResource.equals(element.getJavaElement().getResource())) {
-				iterator.remove();
-				return;
-			}
-		}
-	}
-
-	/**
-	 * Returns true if an HTTPMethod is based on the given java type.
-	 * @param type the underlying java type
-	 * @return true of false ;-)
-	 */
-	public final boolean contains(final IType type) {
-		return httpMethods.containsKey(type.getFullyQualifiedName());
-	}
-
-	/**
-	 * Returns the HTTPMethod based on the given java type.
-	 * @param type the underlying java type
-	 * @return the matching HTTPMethod
-	 */
-	public final HTTPMethod getByType(final IType type) {
-		return httpMethods.get(type.getFullyQualifiedName());
-	}
-
-	/**
-	 * Returns the HTTPMethod based on the given java type.
-	 * @param typeName the underlying java type fully qualified name
-	 * @return the matching HTTPMethod
-	 */
-	public final HTTPMethod getByTypeName(final String typeName) {
-		return httpMethods.get(typeName);
-	}
-
-	/**
-	 * @return the httpMethods
-	 */
-	public final List<HTTPMethod> getAll() {
-		return Collections.unmodifiableList(new ArrayList<HTTPMethod>(httpMethods.values()));
-	}
-
-	/**
-	 * @return the list of HTTPMethod types
-	 */
-	public final Set<String> getTypeNames() {
-		return httpMethods.keySet();
-	}
-
-	/**
 	 * Returns the HTTPMethod matching the given HTTP verb.
-	 * @param httpVerb the HTTP verb
+	 * 
+	 * @param httpVerb
+	 *            the HTTP verb
 	 * @return the httpMethod bound to the given HTTP Verb
 	 */
 	public final HTTPMethod getByVerb(final String httpVerb) {
-		for (Entry<String, HTTPMethod> entry : httpMethods.entrySet()) {
+		for (Entry<String, HTTPMethod> entry : elements.entrySet()) {
 			HTTPMethod httpMethod = entry.getValue();
 			if (httpMethod.getHttpVerb() != null && httpMethod.getHttpVerb().equals(httpVerb)) {
 				return httpMethod;
@@ -157,23 +89,4 @@
 		return null;
 	}
 
-	/**
-	 * @return the number of HTTP Methods in the metamodel.
-	 */
-	public final Object size() {
-		return httpMethods.size();
-	}
-
-	@Override
-	public final Iterator<Entry<String, HTTPMethod>> iterator() {
-		return httpMethods.entrySet().iterator();
-	}
-
-	/**
-	 * Resets the HTTPMethods list
-	 */
-	public void reset() {
-		this.httpMethods.clear();
-	}
-
 }

Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java	2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -64,7 +64,7 @@
 	 * annotations (@Path, etc.) and custom annotations (HTTP Methods).
 	 * 
 	 */
-	private List<String> jaxrsAnnotationNames = new ArrayList<String>();
+	private final List<String> jaxrsAnnotationNames = new ArrayList<String>();
 
 	/**
 	 * All the resources (both rootresources and subresources) available in the
@@ -208,6 +208,7 @@
 	public final void addElements(final IJavaElement scope, final IProgressMonitor progressMonitor)
 			throws CoreException {
 		try {
+
 			progressMonitor.beginTask("Computing JAX-RS metamodel", TOTAL_STEPS);
 			httpMethods.addFrom(scope, progressMonitor);
 			progressMonitor.worked(1);
@@ -278,7 +279,7 @@
 	private BaseElement<IMethod> findElement(final IMethod method) throws JavaModelException {
 		Resource resource = resources.getByType((IType) (method.getParent()));
 		if (resource != null) {
-			return resource.getByJavaMethod((IMethod) method);
+			return resource.getByJavaMethod(method);
 		}
 		return null;
 	}
@@ -427,7 +428,7 @@
 		this.httpMethods.reset();
 		this.providers.reset();
 		this.resources.reset();
-		
+
 	}
 
 }

Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Provider.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Provider.java	2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Provider.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -56,20 +56,55 @@
 	private final Providers container;
 
 	/**
-	 * @param javaType
-	 * @throws CoreException
-	 * @throws InvalidModelElementException
+	 * Internal 'Provider' element builder.
+	 * 
+	 * @author xcoulon
+	 * 
 	 */
-	public Provider(final IType javaType, final Metamodel metamodel, final Providers container,
-			final IProgressMonitor progressMonitor) throws CoreException, InvalidModelElementException {
-		super(metamodel, javaType);
-		this.container = container;
-		setState(EnumState.CREATING);
-		merge(javaType, progressMonitor);
-		setState(EnumState.CREATED);
+	public static class Builder {
+
+		private final Metamodel metamodel;
+		private final IType javaType;
+		private final Providers container;
+
+		/**
+		 * Mandatory attributes of the enclosing 'Provider' element.
+		 * 
+		 * @param javaType
+		 * @param metamodel
+		 */
+		public Builder(final IType javaType, final Metamodel metamodel, final Providers container) {
+			this.javaType = javaType;
+			this.metamodel = metamodel;
+			this.container = container;
+		}
+
+		/**
+		 * Builds and returns the elements. Internally calls the merge() method.
+		 * 
+		 * @param progressMonitor
+		 * @return
+		 * @throws InvalidModelElementException
+		 * @throws CoreException
+		 */
+		public Provider build(IProgressMonitor progressMonitor) throws InvalidModelElementException, CoreException {
+			Provider provider = new Provider(this);
+			provider.merge(javaType, progressMonitor);
+			return provider;
+		}
 	}
 
 	/**
+	 * Full constructor using the inner 'Builder' static class.
+	 * 
+	 * @param builder
+	 */
+	private Provider(Builder builder) {
+		super(builder.javaType, builder.metamodel);
+		this.container = builder.container;
+	}
+
+	/**
 	 * @param javaType
 	 * @throws InvalidModelElementException
 	 * @throws CoreException
@@ -80,13 +115,11 @@
 		if (!JdtUtils.isTopLevelType(javaType)) {
 			throw new InvalidModelElementException("Type is not a top-level type");
 		}
-		CompilationUnit compilationUnit = getCompilationUnit(javaType, progressMonitor);
-		if (getState() == EnumState.CREATED) {
-			Set<IProblem> problems = JdtUtils.resolveErrors(javaType, compilationUnit);
-			if (problems != null && problems.size() > 0) {
-				// metamodel.reportErrors(javaType, problems);
-				return;
-			}
+		CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
+		Set<IProblem> problems = JdtUtils.resolveErrors(javaType, compilationUnit);
+		if (problems != null && problems.size() > 0) {
+			// metamodel.reportErrors(javaType, problems);
+			return;
 		}
 		IAnnotationBinding annotationBinding = JdtUtils.resolveAnnotationBinding(javaType, compilationUnit,
 				javax.ws.rs.ext.Provider.class);

Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java	2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -14,19 +14,15 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
-import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.jdt.core.IJavaElement;
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
 import org.jboss.tools.ws.jaxrs.core.internal.builder.JAXRSAnnotationsScanner;
 import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
 import org.jboss.tools.ws.jaxrs.core.metamodel.Provider.EnumProviderKind;
@@ -38,23 +34,20 @@
  * @author xcoulon
  * 
  */
-public class Providers {
+public class Providers extends BaseElementContainer<Provider> {
 
-	/**
-	 * The available providers (classes which implement MessageBodyWriter<T>,
-	 * MessageBodyReader<T> or ExceptionMapper<T>), , indexed by their
-	 * associated java type fully qualified name
-	 */
-	private final Map<String, Provider> providers = new HashMap<String, Provider>();
-
 	/** The interfaces that a provider can implement, indexed by kind */
-	private Map<EnumProviderKind, IType> providerInterfaces;
+	private final Map<EnumProviderKind, IType> providerInterfaces;
 
-	private final Metamodel metamodel;
-
+	/**
+	 * Full constructor
+	 * 
+	 * @param javaProject
+	 * @param metamodel
+	 * @throws CoreException
+	 */
 	public Providers(final IJavaProject javaProject, final Metamodel metamodel) throws CoreException {
-		super();
-		this.metamodel = metamodel;
+		super(metamodel);
 		providerInterfaces = new HashMap<EnumProviderKind, IType>();
 		providerInterfaces.put(EnumProviderKind.CONSUMER,
 				JdtUtils.resolveType("javax.ws.rs.ext.MessageBodyReader", javaProject.getJavaProject(), null));
@@ -90,14 +83,14 @@
 	 * implement the interface(s). (Yep, this is the hardest part of the thing,
 	 * but it provides added-value to the end-developper...)
 	 * 
-	 * @param errors
+	 * @param scope
+	 *            the scope from which elements should be added
 	 * 
-	 * @param javaElement
 	 * @param progressMonitor
 	 * @throws CoreException
-	 * @throws JavaModelException
 	 */
-	public final void addFrom(final IJavaElement scope, final SubProgressMonitor progressMonitor) throws CoreException {
+	@Override
+	public final void addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor) throws CoreException {
 		progressMonitor.beginTask("Adding providers", 1);
 		try {
 			// FIXME : add support for javax.ws.rs.ext.ContextResolver(s) (most
@@ -109,8 +102,8 @@
 			// exists. Throw an exception in constructor ?
 			for (IType providerType : providerTypes) {
 				try {
-					providers.put(providerType.getFullyQualifiedName(), new Provider(providerType, metamodel, this,
-							progressMonitor));
+					elements.put(providerType.getFullyQualifiedName(), new Provider.Builder(providerType, metamodel,
+							this).build(progressMonitor));
 				} catch (InvalidModelElementException e) {
 					Logger.warn("Type '" + providerType.getFullyQualifiedName() + "' is not a valid JAX-RS Provider : "
 							+ e.getMessage());
@@ -120,24 +113,9 @@
 		} finally {
 			progressMonitor.done();
 		}
-
 	}
 
-	public final boolean contains(final IType providerType) {
-		return providers.containsKey(providerType.getFullyQualifiedName());
-	}
-
 	/**
-	 * Return the provider implemented by the given type, or null if not found.
-	 * 
-	 * @param peType
-	 * @return a provider, or null
-	 */
-	public final Provider getByType(final IType javaType) {
-		return providers.get(javaType.getFullyQualifiedName());
-	}
-
-	/**
 	 * Return the provider for the given parameterized type, or null if not
 	 * found.
 	 * 
@@ -147,7 +125,7 @@
 	 * @return a provider, or null
 	 */
 	public final Provider getFor(final String type) {
-		for (Entry<String, Provider> providerEntry : providers.entrySet()) {
+		for (Entry<String, Provider> providerEntry : elements.entrySet()) {
 			Provider p = providerEntry.getValue();
 			for (Entry<EnumProviderKind, IType> kindEntry : p.getProvidedKinds().entrySet()) {
 				if (type.equals(kindEntry.getValue().getFullyQualifiedName())) {
@@ -168,7 +146,7 @@
 	 * @return a provider, or null
 	 */
 	public final Provider getFor(final IType providedType) {
-		for (Entry<String, Provider> providerEntry : providers.entrySet()) {
+		for (Entry<String, Provider> providerEntry : elements.entrySet()) {
 			Provider p = providerEntry.getValue();
 			for (Entry<EnumProviderKind, IType> kindEntry : p.getProvidedKinds().entrySet()) {
 				if (providedType.equals(kindEntry.getValue())) {
@@ -208,7 +186,7 @@
 
 	private List<Provider> filterProvidersByKind(final EnumProviderKind providerKind) {
 		List<Provider> matches = new ArrayList<Provider>();
-		for (Entry<String, Provider> entry : providers.entrySet()) {
+		for (Entry<String, Provider> entry : elements.entrySet()) {
 			Provider p = entry.getValue();
 			if (p.getProvidedKinds().containsKey(providerKind)) {
 				matches.add(p);
@@ -216,34 +194,4 @@
 		}
 		return Collections.unmodifiableList(matches);
 	}
-
-	/**
-	 * @return the all the providers, no matter which role they have (reader,
-	 *         writer, exception mapper)
-	 */
-	public final List<Provider> getAll() {
-		return Collections.unmodifiableList(new ArrayList<Provider>(providers.values()));
-	}
-
-	public final void removeElement(final IResource removedResource, final IProgressMonitor progressMonitor) {
-		for (Iterator<Provider> iterator = providers.values().iterator(); iterator.hasNext();) {
-			Provider element = iterator.next();
-			if (removedResource.equals(element.getJavaElement().getResource())) {
-				iterator.remove();
-				return;
-			}
-		}
-	}
-
-	public final Object size() {
-		return providers.size();
-	}
-
-	/**
-	 * Resets the HTTPMethods list
-	 */
-	public void reset() {
-		this.providers.clear();
-	}
-
 }

Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResolvedUriMapping.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResolvedUriMapping.java	2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResolvedUriMapping.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -14,6 +14,8 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.jboss.tools.ws.jaxrs.core.utils.ResourceMethodAnnotatedParameter;
+
 public class ResolvedUriMapping implements Comparable<ResolvedUriMapping> {
 
 	private HTTPMethod httpMethod = null;

Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resource.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resource.java	2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resource.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -31,7 +31,6 @@
 import org.eclipse.jdt.core.JavaModelException;
 import org.eclipse.jdt.core.compiler.IProblem;
 import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.IAnnotationBinding;
 import org.jboss.tools.ws.jaxrs.core.internal.builder.JAXRSAnnotationsScanner;
 import org.jboss.tools.ws.jaxrs.core.internal.builder.JaxrsMetamodelBuilder;
 import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionFilterUtil;
@@ -79,23 +78,51 @@
 	final Map<String, ResourceMethod> resourceMethods = new HashMap<String, ResourceMethod>();
 
 	/**
-	 * Full constructor
+	 * Internal 'Resource' element builder.
 	 * 
-	 * @param javaType
-	 * @param metamodel
-	 * @param compilationUnit
-	 * @param mediaTypeCapabilities
-	 * @throws CoreException
-	 * @throws InvalidModelElementException
+	 * @author xcoulon
+	 * 
 	 */
-	public Resource(final IType javaType, final Metamodel metamodel, final IProgressMonitor progressMonitor)
-			throws CoreException, InvalidModelElementException {
-		super(metamodel, javaType);
-		setState(EnumState.CREATING);
-		merge(javaType, progressMonitor);
-		setState(EnumState.CREATED);
+	public static class Builder {
+
+		private final Metamodel metamodel;
+		private final IType javaType;
+
+		/**
+		 * Mandatory attributes of the enclosing 'HTTPMethod' element.
+		 * 
+		 * @param javaType
+		 * @param metamodel
+		 */
+		public Builder(final IType javaType, final Metamodel metamodel) {
+			this.javaType = javaType;
+			this.metamodel = metamodel;
+		}
+
+		/**
+		 * Builds and returns the elements. Internally calls the merge() method.
+		 * 
+		 * @param progressMonitor
+		 * @return
+		 * @throws InvalidModelElementException
+		 * @throws CoreException
+		 */
+		public Resource build(IProgressMonitor progressMonitor) throws InvalidModelElementException, CoreException {
+			Resource resource = new Resource(this);
+			resource.merge(javaType, progressMonitor);
+			return resource;
+		}
 	}
 
+	/**
+	 * Full constructor using the inner 'Builder' static class.
+	 * 
+	 * @param builder
+	 */
+	private Resource(Builder builder) {
+		super(builder.javaType, builder.metamodel);
+	}
+
 	public final boolean isRootResource() {
 		return isRootResource;
 	}
@@ -114,25 +141,22 @@
 		if (!JdtUtils.isTopLevelType(javaType)) {
 			throw new InvalidModelElementException("Type is not a top-level type");
 		}
-		CompilationUnit compilationUnit = getCompilationUnit(javaType, progressMonitor);
+		CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
 		// TODO : base64.decode()
-		if (getState() == EnumState.CREATED) {
-			Set<IProblem> problems = JdtUtils.resolveErrors(javaType, compilationUnit);
-			if (problems != null && problems.size() > 0) {
-				// metamodel.reportErrors(javaType, problems);
-				return;
-			}
+		// if (state == EnumState.CREATED) {
+		Set<IProblem> problems = JdtUtils.resolveErrors(javaType, compilationUnit);
+		if (problems != null && problems.size() > 0) {
+			return;
 		}
+		// }
 
 		// String serviceURI = container.getMetamodel().getServiceURI();
-		IAnnotationBinding pathAnnotationBinding = JdtUtils.resolveAnnotationBinding(javaType, compilationUnit,
-				Path.class);
-		if (pathAnnotationBinding != null) {
+		this.uriPathTemplate = (String) JdtUtils.resolveAnnotationAttributeValue(javaType, compilationUnit, Path.class,
+				"value");
+		if (uriPathTemplate != null) {
 			isRootResource = true;
-			this.uriPathTemplate = (String) JdtUtils.resolveAnnotationAttributeValue(pathAnnotationBinding, "value");
 		} else {
 			isRootResource = false;
-			this.uriPathTemplate = null;
 		}
 
 		mediaTypeCapabilities.setConsumedMimeTypes(JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(javaType,
@@ -184,8 +208,8 @@
 					resourceMethod.merge(javaMethod, progressMonitor);
 					Logger.debug("Updated " + resourceMethod.toString());
 				} else {
-					ResourceMethod resourceMethod = new ResourceMethod(javaMethod, this, getMetamodel(),
-							progressMonitor);
+					ResourceMethod resourceMethod = new ResourceMethod.Builder(javaMethod, this, getMetamodel())
+							.build(progressMonitor);
 					resourceMethods.put(key, resourceMethod);
 					Logger.debug("Added " + resourceMethod.toString());
 				}
@@ -262,8 +286,8 @@
 		return CollectionFilterUtil.filterElementsByKind(resourceMethods.values(), EnumType.SUBRESOURCE_LOCATOR);
 	}
 
-	public final ResourceMethod getByURIMapping(final HTTPMethod httpMethod, final String uriPathTemplateFragment, final String consumes,
-			final String produces) {
+	public final ResourceMethod getByURIMapping(final HTTPMethod httpMethod, final String uriPathTemplateFragment,
+			final String consumes, final String produces) {
 		for (ResourceMethod resourceMethod : resourceMethods.values()) {
 			if (resourceMethod.getUriMapping().matches(httpMethod, uriPathTemplateFragment, consumes, produces)) {
 				return resourceMethod;

Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethod.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethod.java	2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethod.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -42,39 +42,75 @@
 	private IType returnType = null;
 
 	/**
-	 * Constructor
+	 * Internal 'Resource' element builder.
 	 * 
-	 * @param javaMethod
-	 * @param metamodel
-	 * @param problems
-	 * @throws CoreException
-	 * @throws InvalidModelElementException
+	 * @author xcoulon
+	 * 
 	 */
-	public ResourceMethod(final IMethod javaMethod, final Resource parentResource, final Metamodel metamodel,
-			final IProgressMonitor progressMonitor) throws InvalidModelElementException, CoreException {
-		super(metamodel, javaMethod);
-		this.parentResource = parentResource;
-		setState(EnumState.CREATING);
-		merge(javaMethod, progressMonitor);
-		setState(EnumState.CREATED);
+	public static class Builder {
+
+		private final Metamodel metamodel;
+		private final IMethod javaMethod;
+		private final Resource parentResource;
+
+		/**
+		 * Mandatory attributes of the enclosing 'ResourceMethod' element.
+		 * 
+		 * @param javaMethod
+		 * @param metamodel
+		 * @param parentResource
+		 */
+		public Builder(final IMethod javaMethod, final Resource parentResource, final Metamodel metamodel) {
+			this.javaMethod = javaMethod;
+			this.metamodel = metamodel;
+			this.parentResource = parentResource;
+		}
+
+		/**
+		 * Builds and returns the elements. Internally calls the merge() method.
+		 * 
+		 * @param progressMonitor
+		 * @return
+		 * @throws InvalidModelElementException
+		 * @throws CoreException
+		 */
+		public ResourceMethod build(IProgressMonitor progressMonitor) throws InvalidModelElementException,
+				CoreException {
+			ResourceMethod resourceMethod = new ResourceMethod(this);
+			resourceMethod.merge(javaMethod, progressMonitor);
+			return resourceMethod;
+		}
 	}
 
+	/**
+	 * Full constructor using the inner 'Builder' static class.
+	 * 
+	 * @param builder
+	 */
+	public ResourceMethod(final Builder builder) throws InvalidModelElementException, CoreException {
+		super(builder.javaMethod, builder.metamodel);
+		this.parentResource = builder.parentResource;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
 	@Override
 	public final void merge(final IMethod javaMethod, final IProgressMonitor progressMonitor)
 			throws InvalidModelElementException, CoreException {
-		CompilationUnit compilationUnit = getCompilationUnit(javaMethod, progressMonitor);
-		if (getState() == EnumState.CREATED) {
+		CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
+		if (state == EnumState.CREATED) {
 			Set<IProblem> problems = JdtUtils.resolveErrors(javaMethod, compilationUnit);
 			if (problems != null && problems.size() > 0) {
-				// metamodel.reportErrors(javaType, problems);
+				// metamodel.reportErrors(javaMethod, problems);
 				return;
 			}
 		}
 		IMethodBinding methodBinding = JdtUtils.resolveMethodBinding(javaMethod, compilationUnit);
 		if (uriMapping == null) {
-			this.uriMapping = new UriMapping(javaMethod, compilationUnit, getMetamodel());
+			this.uriMapping = new UriMapping.Builder(javaMethod, getMetamodel()).build(compilationUnit);
 		} else {
-			this.uriMapping.merge(javaMethod, compilationUnit);
+			this.uriMapping.merge(compilationUnit);
 		}
 		HTTPMethod httpMethod = uriMapping.getHTTPMethod();
 		String uriPathTemplateFragment = uriMapping.getUriPathTemplateFragment();
@@ -104,6 +140,7 @@
 		getUriMapping().validate();
 	}
 
+	@Override
 	public final BaseElement.EnumType getKind() {
 		return kind;
 	}

Deleted: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodAnnotatedParameter.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodAnnotatedParameter.java	2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodAnnotatedParameter.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -1,112 +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.metamodel;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-
-public class ResourceMethodAnnotatedParameter implements Validable, Comparable<ResourceMethodAnnotatedParameter> {
-
-	private final String parameterType;
-	
-	private final String annotationType;
-
-	private final String annotationValue;
-	
-	private final int charStart;
-	
-	private final int charEnd;
-	
-	private final int lineNumber;
-	
-
-	/**
-	 * Full constructor
-	 * @param parent
-	 * @param parameterName
-	 * @param parameterType
-	 * @param annotationType
-	 * @param annotationValue
-	 * @param charStart
-	 * @param charEnd
-	 * @param lineNumber
-	 */
-	public ResourceMethodAnnotatedParameter(String parameterType,
-			String annotationType, String annotationValue, int charStart, int charEnd, int lineNumber) {
-		super();
-		this.parameterType = parameterType;
-		this.annotationType = annotationType;
-		this.annotationValue = annotationValue;
-		this.charStart = charStart;
-		this.charEnd = charEnd;
-		this.lineNumber = lineNumber;
-	}
-
-	@Override
-	public void validate(IProgressMonitor progressMonitor) throws CoreException {
-		// TODO Auto-generated method stub
-	}
-
-	/**
-	 * @return the parameterType
-	 */
-	public String getParameterType() {
-		return parameterType;
-	}
-
-	/**
-	 * @return the annotationType
-	 */
-	public String getAnnotationType() {
-		return annotationType;
-	}
-
-	/**
-	 * @return the annotationValue
-	 */
-	public String getAnnotationValue() {
-		return annotationValue;
-	}
-
-	/**
-	 * @return the charStart
-	 */
-	public int getCharStart() {
-		return charStart;
-	}
-
-	/**
-	 * @return the charEnd
-	 */
-	public int getCharEnd() {
-		return charEnd;
-	}
-
-	/**
-	 * @return the lineNumber
-	 */
-	public int getLineNumber() {
-		return lineNumber;
-	}
-
-	/**
-	 * Compares method parameters by their textual location
-	 * {@inheritDoc}
-	 * @param otherParam
-	 * @return
-	 */
-	@Override
-	public int compareTo(ResourceMethodAnnotatedParameter otherParam) {
-		return getCharStart() - otherParam.getCharStart(); 
-	}
-	
-}

Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java	2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -11,10 +11,7 @@
 
 package org.jboss.tools.ws.jaxrs.core.metamodel;
 
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -23,7 +20,6 @@
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.jdt.core.IJavaElement;
 import org.eclipse.jdt.core.IType;
 import org.eclipse.jdt.core.ITypeHierarchy;
@@ -33,24 +29,44 @@
 import org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement.EnumType;
 import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
 
-public class Resources {
+public class Resources extends BaseElementContainer<Resource> {
 
-	private final Map<String, Resource> resources = new HashMap<String, Resource>();
-
-	private final Metamodel metamodel;
-
+	/**
+	 * Full constructor
+	 * 
+	 * @param metamodel
+	 */
 	public Resources(final Metamodel metamodel) {
-		this.metamodel = metamodel;
+		super(metamodel);
 	}
 
+	// FIXME deal with interfaces/implementations
+	@Override
+	public final void addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor) throws CoreException {
+		progressMonitor.beginTask("Adding resources and resourceMethods", 1);
+		HTTPMethods httpMethods = metamodel.getHttpMethods();
+		List<IType> javaTypes = JAXRSAnnotationsScanner.findResources(scope, httpMethods.getTypeNames(),
+				progressMonitor);
+		for (IType javaType : javaTypes) {
+			try {
+				elements.put(javaType.getFullyQualifiedName(),
+						new Resource.Builder(javaType, metamodel).build(progressMonitor));
+			} catch (InvalidModelElementException e) {
+				Logger.warn("Type '" + javaType.getFullyQualifiedName() + "' is not a valid JAX-RS Resource: "
+						+ e.getMessage());
+			}
+		}
+	}
+
 	/**
 	 * Resolve the URI Mappings in the model, given all root resources,
-	 * subresources , resource resourceMethods , subresource resourceMethods and subresource
-	 * locators
+	 * subresources , resource resourceMethods , subresource resourceMethods and
+	 * subresource locators
 	 * 
 	 * @throws CoreException
 	 */
-	public final Map<ResolvedUriMapping, Stack<ResourceMethod>> resolveUriMappings(final IProgressMonitor progressMonitor) throws CoreException {
+	public final Map<ResolvedUriMapping, Stack<ResourceMethod>> resolveUriMappings(
+			final IProgressMonitor progressMonitor) throws CoreException {
 		Map<ResolvedUriMapping, Stack<ResourceMethod>> uriMappings = new HashMap<ResolvedUriMapping, Stack<ResourceMethod>>();
 		for (Resource resource : getRootResources()) {
 			resolveResourcesUriMappings(resource, "/*", uriMappings, new Stack<ResourceMethod>(), progressMonitor);
@@ -68,12 +84,14 @@
 	private void resolveResourcesUriMappings(final Resource resource, final String uriTemplateFragment,
 			final Map<ResolvedUriMapping, Stack<ResourceMethod>> uriMappings, final Stack<ResourceMethod> methodsStack,
 			final IProgressMonitor progressMonitor) throws CoreException {
-		// resource resourceMethods and subresources resourceMethods are treated the same way
+		// resource resourceMethods and subresources resourceMethods are treated
+		// the same way
 		for (ResourceMethod resourceMethod : resource.getAllMethods()) {
 			String uriPathTemplate = resolveURIPathTemplate(uriTemplateFragment, resource, resourceMethod);
 			MediaTypeCapabilities mediaTypeCapabilities = resolveMediaTypeCapabilities(resource, resourceMethod);
 			UriMapping resourceUriMapping = resourceMethod.getUriMapping();
-			ResolvedUriMapping uriMapping = new ResolvedUriMapping(resourceUriMapping.getHTTPMethod(), uriPathTemplate, resourceUriMapping.getQueryParams(), mediaTypeCapabilities);
+			ResolvedUriMapping uriMapping = new ResolvedUriMapping(resourceUriMapping.getHTTPMethod(), uriPathTemplate,
+					resourceUriMapping.getQueryParams(), mediaTypeCapabilities);
 			@SuppressWarnings("unchecked")
 			Stack<ResourceMethod> stack = (Stack<ResourceMethod>) methodsStack.clone();
 			stack.add(resourceMethod);
@@ -84,7 +102,7 @@
 		for (ResourceMethod resourceMethod : resource.getSubresourceLocators()) {
 			String uriPathTemplate = resolveURIPathTemplate(uriTemplateFragment, resource, resourceMethod);
 			IType returnType = resourceMethod.getReturnType();
-			if(returnType == null) {
+			if (returnType == null) {
 				continue;
 			}
 			ITypeHierarchy subresourceTypeHierarchy = JdtUtils.resolveTypeHierarchy(returnType, false, progressMonitor);
@@ -101,7 +119,8 @@
 	}
 
 	// FIXME : include method parameters if annotated with @QueryParam
-	private static final String resolveURIPathTemplate(final String uriTemplateFragment, final Resource resource, final ResourceMethod resourceMethod) {
+	private static final String resolveURIPathTemplate(final String uriTemplateFragment, final Resource resource,
+			final ResourceMethod resourceMethod) {
 		StringBuffer uriTemplateBuffer = new StringBuffer(uriTemplateFragment);
 		String resourceUriPathTemplate = resource.getUriPathTemplate();
 		String methodUriPathTemplate = resourceMethod.getUriMapping().getUriPathTemplateFragment();
@@ -114,7 +133,8 @@
 		return uriTemplateBuffer.toString().replaceAll("/\\*", "/").replaceAll("///", "/").replaceAll("//", "/");
 	}
 
-	private static final MediaTypeCapabilities resolveMediaTypeCapabilities(final Resource resource, final ResourceMethod resourceMethod) {
+	private static final MediaTypeCapabilities resolveMediaTypeCapabilities(final Resource resource,
+			final ResourceMethod resourceMethod) {
 		MediaTypeCapabilities resourceMediaTypeCapabilities = resource.getMediaTypeCapabilities();
 		MediaTypeCapabilities methodMediaTypeCapabilities = resourceMethod.getUriMapping().getMediaTypeCapabilities();
 		MediaTypeCapabilities mediaTypeCapabilities = new MediaTypeCapabilities();
@@ -137,62 +157,19 @@
 		return mediaTypeCapabilities;
 	}
 
-	// FIXME deal with interfaces/implementations
-	public final void addFrom(final IJavaElement scope, final SubProgressMonitor progressMonitor) throws CoreException {
-		progressMonitor.beginTask("Adding resources and resourceMethods", 1);
-		HTTPMethods httpMethods = metamodel.getHttpMethods();
-		List<IType> javaTypes = JAXRSAnnotationsScanner.findResources(scope, httpMethods.getTypeNames(),
-				progressMonitor);
-		for (IType javaType : javaTypes) {
-			try {
-				resources.put(javaType.getFullyQualifiedName(), new Resource(javaType, metamodel, progressMonitor));
-			} catch (InvalidModelElementException e) {
-				Logger.warn("Type '" + javaType.getFullyQualifiedName() + "' is not a valid JAX-RS Resource: "
-						+ e.getMessage());
-			}
-		}
-	}
-
-	public final void removeElement(final IResource removedResource, final IProgressMonitor progressMonitor) {
-		for (Iterator<Resource> iterator = resources.values().iterator(); iterator.hasNext();) {
-			Resource r = iterator.next();
-			if (removedResource.equals(r.getJavaElement().getResource())) {
-				iterator.remove();
-			}
-		}
-	}
-
-	public final Resource getByType(final IType type) {
-		if(type == null) {
-			return null;
-		}
-		return resources.get(type.getFullyQualifiedName());
-	}
-	
 	public Resource getByResource(IResource resource) {
-		if(resource == null) {
+		if (resource == null) {
 			return null;
 		}
-		for(Entry<String, Resource> entry : resources.entrySet()) {
+		for (Entry<String, Resource> entry : elements.entrySet()) {
 			Resource r = entry.getValue();
-			if(resource.equals(r.getJavaElement().getResource())) {
+			if (resource.equals(r.getJavaElement().getResource())) {
 				return r;
 			}
 		}
 		return null;
 	}
 
-	public final boolean contains(final IType type) {
-		if(type == null) {
-			return false;
-		}
-		return resources.containsKey(type.getFullyQualifiedName());
-	}
-
-	public final Resource getByTypeName(final String fullyQualifiedName) {
-		return resources.get(fullyQualifiedName);
-	}
-
 	/**
 	 * Returns the Root resource for the given Path
 	 * 
@@ -200,7 +177,7 @@
 	 * @return
 	 */
 	public final Resource getByPath(final String path) {
-		for (Entry<String, Resource> entry : resources.entrySet()) {
+		for (Entry<String, Resource> entry : elements.entrySet()) {
 			Resource resource = entry.getValue();
 			if (resource.isRootResource() && resource.getUriPathTemplate().endsWith(path)) {
 				return resource;
@@ -210,24 +187,12 @@
 		return null;
 	}
 
-	public final List<Resource> getAll() {
-		return Collections.unmodifiableList(new ArrayList<Resource>(resources.values()));
-	}
-
 	public final List<Resource> getRootResources() {
-		return CollectionFilterUtil.filterElementsByKind(resources.values(), EnumType.ROOT_RESOURCE);
+		return CollectionFilterUtil.filterElementsByKind(elements.values(), EnumType.ROOT_RESOURCE);
 	}
 
 	public final List<Resource> getSubresources() {
-		return CollectionFilterUtil.filterElementsByKind(resources.values(), EnumType.SUBRESOURCE);
+		return CollectionFilterUtil.filterElementsByKind(elements.values(), EnumType.SUBRESOURCE);
 	}
 
-	/**
-	 * Resets the HTTPMethods list
-	 */
-	public void reset() {
-		this.resources.clear();
-	}
-
-
 }

Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/UriMapping.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/UriMapping.java	2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/UriMapping.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -12,10 +12,7 @@
 package org.jboss.tools.ws.jaxrs.core.metamodel;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.Path;
@@ -29,13 +26,12 @@
 import org.eclipse.jdt.core.JavaModelException;
 import org.eclipse.jdt.core.dom.CompilationUnit;
 import org.eclipse.jdt.core.dom.IAnnotationBinding;
-import org.eclipse.jdt.core.dom.IMemberValuePairBinding;
-import org.eclipse.jface.text.ITypedRegion;
 import org.eclipse.osgi.util.NLS;
 import org.jboss.tools.ws.jaxrs.core.internal.builder.JAXRSAnnotationsScanner;
 import org.jboss.tools.ws.jaxrs.core.internal.builder.JaxrsMetamodelBuilder;
 import org.jboss.tools.ws.jaxrs.core.internal.utils.ValidationMessages;
 import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
+import org.jboss.tools.ws.jaxrs.core.utils.ResourceMethodAnnotatedParameter;
 
 public class UriMapping {
 
@@ -55,46 +51,83 @@
 
 	private final Metamodel metamodel;
 
-	public UriMapping(final IMethod javaMethod, final CompilationUnit compilationUnit, final Metamodel metamodel)
-			throws CoreException {
-		this.javaMethod = javaMethod;
-		this.metamodel = metamodel;
-		merge(javaMethod, compilationUnit);
+	/**
+	 * Internal 'Resource' element builder.
+	 * 
+	 * @author xcoulon
+	 * 
+	 */
+	public static class Builder {
+
+		private final IMethod javaMethod;
+		private final Metamodel metamodel;
+
+		/**
+		 * Mandatory attributes of the enclosing 'ResourceMethod' element.
+		 * 
+		 * @param javaMethod
+		 * @param metamodel
+		 * @param parentResource
+		 */
+		public Builder(final IMethod javaMethod, final Metamodel metamodel) {
+			this.javaMethod = javaMethod;
+			this.metamodel = metamodel;
+		}
+
+		/**
+		 * Builds and returns the elements. Internally calls the merge() method.
+		 * 
+		 * @param progressMonitor
+		 * @return
+		 * @throws InvalidModelElementException
+		 * @throws CoreException
+		 */
+		public UriMapping build(final CompilationUnit compilationUnit) throws InvalidModelElementException,
+				CoreException {
+			UriMapping resourceMethod = new UriMapping(this);
+			resourceMethod.merge(compilationUnit);
+			return resourceMethod;
+		}
 	}
 
 	/**
+	 * Full constructor using the inner 'Builder' static class.
+	 * 
+	 * @param builder
+	 */
+	private UriMapping(Builder builder) {
+		this.javaMethod = builder.javaMethod;
+		this.metamodel = builder.metamodel;
+	}
+
+	/**
 	 * @param javaMethod
 	 * @param compilationUnit
 	 * @throws JavaModelException
 	 * @throws CoreException
 	 */
-	protected void merge(IMethod javaMethod, CompilationUnit compilationUnit) throws JavaModelException, CoreException {
-		IAnnotationBinding pathAnnotationBinding = JdtUtils.resolveAnnotationBinding(javaMethod, compilationUnit,
-				Path.class);
-		IAnnotationBinding httpMethodAnnotationBinding = null;
+	public void merge(CompilationUnit compilationUnit) throws JavaModelException, CoreException {
+		HTTPMethod httpMethod = null;
 		for (String httpMethodName : metamodel.getHttpMethods().getTypeNames()) {
-			httpMethodAnnotationBinding = JdtUtils
-					.resolveAnnotationBinding(javaMethod, compilationUnit, httpMethodName);
+			IAnnotationBinding httpMethodAnnotationBinding = JdtUtils.resolveAnnotationBinding(javaMethod,
+					compilationUnit, httpMethodName);
 			if (httpMethodAnnotationBinding != null) {
+				// String qualifiedName =
+				// JdtUtils.resolveAnnotationFullyQualifiedName(httpMethodAnnotationBinding);
+				// httpMethod =
+				// metamodel.getHttpMethods().getByTypeName(qualifiedName);
+				httpMethod = metamodel.getHttpMethods().getByTypeName(httpMethodName);
 				// stop iterating
 				break;
 			}
 		}
 		// resource method
-		HTTPMethod httpMethod = null;
-		String uriPathTemplateFragment = null;
-		if (httpMethodAnnotationBinding != null) {
-			String qualifiedName = JdtUtils.resolveAnnotationFullyQualifiedName(httpMethodAnnotationBinding);
-			httpMethod = metamodel.getHttpMethods().getByTypeName(qualifiedName);
-		}
-		if (pathAnnotationBinding != null) {
-			uriPathTemplateFragment = (String) JdtUtils.resolveAnnotationAttributeValue(pathAnnotationBinding, "value");
-		}
-
-		List<ResourceMethodAnnotatedParameter> pathParams = resolveParameters(javaMethod, compilationUnit,
-				PathParam.class);
-		List<ResourceMethodAnnotatedParameter> queryParams = resolveParameters(javaMethod, compilationUnit,
-				QueryParam.class);
+		String uriPathTemplateFragment = (String) JdtUtils.resolveAnnotationAttributeValue(javaMethod, compilationUnit,
+				Path.class, "value");
+		List<ResourceMethodAnnotatedParameter> pathParams = JdtUtils.resolveMethodParameters(javaMethod,
+				compilationUnit, PathParam.class);
+		List<ResourceMethodAnnotatedParameter> queryParams = JdtUtils.resolveMethodParameters(javaMethod,
+				compilationUnit, QueryParam.class);
 		setHTTPMethod(httpMethod);
 		setUriPathTemplateFragment(uriPathTemplateFragment);
 		setPathParams(pathParams);
@@ -105,57 +138,14 @@
 		setMediaTypeCapabilities(mediaTypeCapabilities);
 	}
 
-	private List<ResourceMethodAnnotatedParameter> resolveParameters(IMethod javaMethod,
-			CompilationUnit compilationUnit, Class<?> annotationType) throws JavaModelException {
-		List<ResourceMethodAnnotatedParameter> parameters = new ArrayList<ResourceMethodAnnotatedParameter>();
-		Map<IAnnotationBinding, ITypedRegion> bindings = JdtUtils.resolveMethodParamBindings(javaMethod,
-				compilationUnit, annotationType);
-		for (Entry<IAnnotationBinding, ITypedRegion> entry : bindings.entrySet()) {
-			IAnnotationBinding binding = entry.getKey();
-			ITypedRegion region = entry.getValue();
-			IMemberValuePairBinding[] allMemberValuePairs = binding.getAllMemberValuePairs();
-			IMemberValuePairBinding memberValuePair = allMemberValuePairs[0];
-			String annotationValue = (String) memberValuePair.getValue();
-			int lineNumber = compilationUnit.getLineNumber(region.getOffset());
-			parameters.add(new ResourceMethodAnnotatedParameter(region.getType(), annotationType.getName(),
-					annotationValue, region.getOffset(), region.getOffset() + region.getLength(), lineNumber));
-		}
-		Collections.sort(parameters);
-		return parameters;
-	}
-
 	/**
-	 * Convenient constructor
-	 * 
-	 * @param httpMethod
-	 *            optional http method
-	 * @param consumes
-	 *            optional single consumed media type
-	 * @param produces
-	 *            optional single produced media type
-	 * @param uriPathTemplateFragment
-	 *            optional URI path template fragment public UriMapping(final
-	 *            HTTPMethod httpMethod, final String uriPathTemplateFragment,
-	 *            final String consumes, final String produces, final Metamodel
-	 *            metamodel) { super(); this.metamodel = metamodel;
-	 *            this.httpMethod = httpMethod; List<String> producedMimeTypes =
-	 *            new ArrayList<String>(); if (produces != null) {
-	 *            producedMimeTypes.add(produces); } List<String>
-	 *            consumedMimeTypes = new ArrayList<String>(); if (consumes !=
-	 *            null) { consumedMimeTypes.add(consumes); }
-	 *            setMediaTypeCapabilities(new
-	 *            MediaTypeCapabilities(consumedMimeTypes, producedMimeTypes));
-	 *            setUriPathTemplateFragment(uriPathTemplateFragment);
-	 *            setQueryParams(new HashMap<String, String>()); }
-	 */
-
-	/**
 	 * Validates the URI Mapping by checking that all
 	 * <code>javax.ws.rs.PathParam</code> annotation values match a parameter in
 	 * the URI Path Template fragment defined by the value of the
 	 * <code>java.ws.rs.Path</code> annotation value.
-	 * @throws CoreException 
 	 * 
+	 * @throws CoreException
+	 * 
 	 */
 	public void validate() throws CoreException {
 		if (uriPathTemplateFragment != null) {

Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java	2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -17,6 +17,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 
 import org.eclipse.core.resources.IResource;
@@ -226,7 +227,7 @@
 				ITypeBinding[] typeArgBindings = typeBinding.getTypeArguments();
 				arguments = new ArrayList<IType>(typeArgBindings.length);
 				for (ITypeBinding typeArgBinding : typeArgBindings) {
-					Logger.debug("Resolving Java Element for type argument '" + typeArgBinding.getName() +"'");
+					Logger.debug("Resolving Java Element for type argument '" + typeArgBinding.getName() + "'");
 					IJavaElement javaElement = typeArgBinding.getJavaElement();
 					if (javaElement.getElementType() == IJavaElement.TYPE && javaElement.exists()) {
 						arguments.add((IType) javaElement);
@@ -330,7 +331,6 @@
 	 * @throws JavaModelException
 	 *             in case of underlying exception
 	 */
-	// TODO : merge with JdtUtils ?
 	public static Map<IAnnotationBinding, ITypedRegion> resolveMethodParamBindings(final IMethod javaMethod,
 			CompilationUnit compilationUnit, final Class<?> annotationTypeFilter) throws JavaModelException {
 		MemberAnnotationBindingsVisitor visitor = new MemberAnnotationBindingsVisitor(javaMethod,
@@ -386,7 +386,9 @@
 	 * @throws CoreException
 	 *             the underlying CoreException thrown by the manipulated JDT
 	 *             APIs
+	 * 
 	 */
+	@Deprecated
 	public static Object resolveAnnotationAttributeValue(final IAnnotationBinding annotationBinding,
 			final String attributeName) throws CoreException {
 		if (annotationBinding != null) {
@@ -400,6 +402,36 @@
 	}
 
 	/**
+	 * Returns the value set for the given attribute from the given annotation
+	 * binding.
+	 * 
+	 * @param annotationBinding
+	 *            the annotation binding
+	 * @param attributeName
+	 *            the attribute name to look up
+	 * @return
+	 * @return the value of the attribute, or null if the attribute is not
+	 *         defined. The value can also be an Array of objects if the
+	 *         attribute is multi-valued.
+	 * @throws CoreException
+	 *             the underlying CoreException thrown by the manipulated JDT
+	 *             APIs
+	 */
+	public static Object resolveAnnotationAttributeValue(final IMember member, final CompilationUnit compilationUnit,
+			final Class<?> annotationClass, final String attributeName) throws CoreException {
+		IAnnotationBinding annotationBinding = JdtUtils.resolveAnnotationBinding(member, compilationUnit,
+				annotationClass);
+		if (annotationBinding != null) {
+			for (IMemberValuePairBinding binding : annotationBinding.getAllMemberValuePairs()) {
+				if (binding.getName().equals(attributeName)) {
+					return binding.getValue();
+				}
+			}
+		}
+		return null;
+	}
+
+	/**
 	 * Resolves the fully qualified name of the annotation given its binding.
 	 * 
 	 * @param annotationBinding
@@ -491,4 +523,32 @@
 		return problems;
 	}
 
+	/**
+	 * Resolves the method parameters.
+	 * 
+	 * @param javaMethod
+	 * @param compilationUnit
+	 * @param annotationType
+	 * @return the method parameters
+	 * @throws JavaModelException
+	 */
+	public static List<ResourceMethodAnnotatedParameter> resolveMethodParameters(IMethod javaMethod,
+			CompilationUnit compilationUnit, Class<?> annotationType) throws JavaModelException {
+		List<ResourceMethodAnnotatedParameter> parameters = new ArrayList<ResourceMethodAnnotatedParameter>();
+		Map<IAnnotationBinding, ITypedRegion> bindings = JdtUtils.resolveMethodParamBindings(javaMethod,
+				compilationUnit, annotationType);
+		for (Entry<IAnnotationBinding, ITypedRegion> entry : bindings.entrySet()) {
+			IAnnotationBinding binding = entry.getKey();
+			ITypedRegion region = entry.getValue();
+			IMemberValuePairBinding[] allMemberValuePairs = binding.getAllMemberValuePairs();
+			IMemberValuePairBinding memberValuePair = allMemberValuePairs[0];
+			String annotationValue = (String) memberValuePair.getValue();
+			int lineNumber = compilationUnit.getLineNumber(region.getOffset());
+			parameters.add(new ResourceMethodAnnotatedParameter(region.getType(), annotationType.getName(),
+					annotationValue, region.getOffset(), region.getOffset() + region.getLength(), lineNumber));
+		}
+		Collections.sort(parameters);
+		return parameters;
+	}
+
 }

Copied: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/ResourceMethodAnnotatedParameter.java (from rev 31413, trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodAnnotatedParameter.java)
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/ResourceMethodAnnotatedParameter.java	                        (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/ResourceMethodAnnotatedParameter.java	2011-05-22 16:04:56 UTC (rev 31416)
@@ -0,0 +1,113 @@
+/******************************************************************************* 
+ * 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.utils;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.jboss.tools.ws.jaxrs.core.metamodel.Validable;
+
+public class ResourceMethodAnnotatedParameter implements Validable, Comparable<ResourceMethodAnnotatedParameter> {
+
+	private final String parameterType;
+	
+	private final String annotationType;
+
+	private final String annotationValue;
+	
+	private final int charStart;
+	
+	private final int charEnd;
+	
+	private final int lineNumber;
+	
+
+	/**
+	 * Full constructor
+	 * @param parent
+	 * @param parameterName
+	 * @param parameterType
+	 * @param annotationType
+	 * @param annotationValue
+	 * @param charStart
+	 * @param charEnd
+	 * @param lineNumber
+	 */
+	public ResourceMethodAnnotatedParameter(String parameterType,
+			String annotationType, String annotationValue, int charStart, int charEnd, int lineNumber) {
+		super();
+		this.parameterType = parameterType;
+		this.annotationType = annotationType;
+		this.annotationValue = annotationValue;
+		this.charStart = charStart;
+		this.charEnd = charEnd;
+		this.lineNumber = lineNumber;
+	}
+
+	@Override
+	public void validate(IProgressMonitor progressMonitor) throws CoreException {
+		// TODO Auto-generated method stub
+	}
+
+	/**
+	 * @return the parameterType
+	 */
+	public String getParameterType() {
+		return parameterType;
+	}
+
+	/**
+	 * @return the annotationType
+	 */
+	public String getAnnotationType() {
+		return annotationType;
+	}
+
+	/**
+	 * @return the annotationValue
+	 */
+	public String getAnnotationValue() {
+		return annotationValue;
+	}
+
+	/**
+	 * @return the charStart
+	 */
+	public int getCharStart() {
+		return charStart;
+	}
+
+	/**
+	 * @return the charEnd
+	 */
+	public int getCharEnd() {
+		return charEnd;
+	}
+
+	/**
+	 * @return the lineNumber
+	 */
+	public int getLineNumber() {
+		return lineNumber;
+	}
+
+	/**
+	 * Compares method parameters by their textual location
+	 * {@inheritDoc}
+	 * @param otherParam
+	 * @return
+	 */
+	@Override
+	public int compareTo(ResourceMethodAnnotatedParameter otherParam) {
+		return getCharStart() - otherParam.getCharStart(); 
+	}
+	
+}



More information about the jbosstools-commits mailing list