Skip to content
Browse files

JBIDE-16422 - Fixing sonar issues in RS (not WS) code

Fixing 'critical' issues plus a bunch of 'major' ones
Added more unit tests for edge cases (null args in method calls)
  • Loading branch information...
1 parent 9544ba6 commit 74560f26d1e7c67bdead35a905820ac6759a8ffd @xcoulon xcoulon committed Feb 6, 2014
Showing with 541 additions and 368 deletions.
  1. +14 −11 ....core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/{DeltaFlags.java → Flags.java}
  2. +9 −4 ...core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedBuildJob.java
  3. +1 −1 ...xrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaFilter.java
  4. +8 −8 ...rg/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedProcessorDelegate.java
  5. +18 −29 ...rs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedBuildJob.java
  6. +14 −16 ...ools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsEndpoint.java
  7. +3 −3 ...ls.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsHttpMethod.java
  8. +3 −3 ....jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaApplication.java
  9. +3 −3 ...s.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaElement.java
  10. +90 −64 ...ols.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java
  11. +5 −4 ...ools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsProvider.java
  12. +80 −70 ...ools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java
  13. +2 −2 ...ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceField.java
  14. +11 −10 ...s.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java
  15. +8 −6 ...org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorDelegate.java
  16. +6 −0 ...ore/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMarkerResolutionIds.java
  17. +57 −25 .../org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorDelegate.java
  18. +0 −2 ...c/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsProviderValidatorDelegate.java
  19. +6 −6 ...jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceMethodValidatorDelegate.java
  20. +7 −4 ...core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationMessages.java
  21. +5 −9 plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java
  22. +0 −9 plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/EnumJaxrsClassname.java
  23. +15 −1 plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java
  24. +0 −13 ....tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/domain/IJaxrsResourceMethod.java
  25. +6 −6 ...oss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/domain/JaxrsElementDelta.java
  26. +2 −0 plugins/org.jboss.tools.ws.wise.ui/.classpath
  27. +43 −42 ...rg/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessingTestCase.java
  28. +10 −9 ...c/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessingTestCase.java
  29. +5 −4 ....core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsEndpointTestCase.java
  30. +27 −1 ...core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodelTestCase.java
  31. +41 −3 ...ss/tools/ws/jaxrs/core/internal/metamodel/indexation/JaxrsElementsIndexationDelegateTestCase.java
  32. +42 −0 ...oss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/HamcrestExtras.java
View
25 ...nternal/metamodel/builder/DeltaFlags.java → ...ore/internal/metamodel/builder/Flags.java
@@ -22,14 +22,14 @@
*
*
*/
-public class DeltaFlags {
+public class Flags {
int flags;
/**
* Default constructor. Starting with <code>flags=0</code>.
*/
- public DeltaFlags() {
+ public Flags() {
this.flags = 0;
}
@@ -38,7 +38,7 @@ public DeltaFlags() {
*
* @param flags
*/
- public DeltaFlags(final int flags) {
+ public Flags(final int flags) {
this.flags = flags;
}
@@ -71,7 +71,7 @@ public void addFlags(final int otherFlags) {
* @param otherFlags
* the flags to add.
*/
- public void addFlags(final DeltaFlags otherFlags) {
+ public void addFlags(final Flags otherFlags) {
if (otherFlags != null) {
addFlags(otherFlags.getValue());
}
@@ -89,14 +89,17 @@ public boolean hasValue() {
}
/**
- * Returns
- * <code>true<code> if the internal flags have been set to the given value
- * , false otherwise.
- *
- * @return true or false.
+ * @return {@code true} if the internal flags have been set to at least one
+ * of the given values , {@code false} otherwise.
+ * @param values the values to check
*/
- public boolean hasValue(int flag) {
- return (this.flags & flag) > 0;
+ public boolean hasValue(int... values) {
+ for(int value : values) {
+ if((this.flags & value) > 0) {
+ return true;
+ }
+ }
+ return false;
}
@Override
View
13 .../org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedBuildJob.java
@@ -24,6 +24,7 @@
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
+import org.jboss.tools.ws.jaxrs.core.JBossJaxrsCorePlugin;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
import org.jboss.tools.ws.jaxrs.core.metamodel.domain.JaxrsMetamodelLocator;
@@ -86,11 +87,15 @@ protected IStatus run(final IProgressMonitor progressMonitor) {
}
}
}
- } catch (Throwable e) {
- if(element != null) {
- return Logger.error("Failed to build or refresh the JAX-RS metamodel while processing " + element.getElementName() + " in project " + element.getAncestor(IJavaElement.JAVA_PROJECT).getElementName(), e);
+ } catch (Exception e) {
+ if (element != null) {
+ return new Status(IStatus.ERROR, JBossJaxrsCorePlugin.PLUGIN_ID,
+ "Failed to build or refresh the JAX-RS metamodel while processing " + element.getElementName()
+ + " in project " + element.getAncestor(IJavaElement.JAVA_PROJECT).getElementName(), e);
} else {
- return Logger.error("Failed to build or refresh the JAX-RS metamodel while processing a change in the Java Model", e);
+ return new Status(IStatus.ERROR, JBossJaxrsCorePlugin.PLUGIN_ID,
+ "Failed to build or refresh the JAX-RS metamodel while processing a change in the Java Model",
+ e);
}
} finally {
progressMonitor.done();
View
2 .../src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaFilter.java
@@ -21,7 +21,7 @@
import static org.eclipse.jdt.core.IJavaElement.TYPE;
import static org.eclipse.jdt.core.IJavaElementDelta.ADDED;
import static org.eclipse.jdt.core.IJavaElementDelta.CHANGED;
-import static org.eclipse.jdt.core.IJavaElementDelta.*;
+import static org.eclipse.jdt.core.IJavaElementDelta.F_ADDED_TO_CLASSPATH;
import static org.eclipse.jdt.core.IJavaElementDelta.F_AST_AFFECTED;
import static org.eclipse.jdt.core.IJavaElementDelta.F_CONTENT;
import static org.eclipse.jdt.core.IJavaElementDelta.F_FINE_GRAINED;
View
16 .../tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedProcessorDelegate.java
@@ -40,7 +40,7 @@
public static void processEvent(final JaxrsElementDelta event) throws CoreException {
final IJaxrsElement element = event.getElement();
final EnumElementCategory elementKind = element.getElementKind().getCategory();
- final int flags = event.getFlags();
+ final Flags flags = event.getFlags();
switch (event.getDeltaKind()) {
case ADDED:
switch (elementKind) {
@@ -161,7 +161,7 @@ private static void processSubresourceMethodAddition(final JaxrsResourceMethod r
JaxrsEndpointFactory.createEndpointsFromSubresourceMethod(resourceMethod);
}
- private static void processChange(final IJaxrsApplication application, int flags) {
+ private static void processChange(final IJaxrsApplication application, final Flags flags) {
final JaxrsMetamodel metamodel = (JaxrsMetamodel) application.getMetamodel();
if (application.equals(metamodel.getApplication())) {
for (Iterator<IJaxrsEndpoint> iterator = metamodel.getAllEndpoints().iterator(); iterator.hasNext();) {
@@ -174,16 +174,16 @@ private static void processChange(final IJaxrsApplication application, int flags
}
}
- private static void processChange(final JaxrsHttpMethod httpMethod, int flags) {
+ private static void processChange(final JaxrsHttpMethod httpMethod, final Flags flags) {
final List<JaxrsEndpoint> endpoints = ((JaxrsMetamodel) httpMethod.getMetamodel()).findEndpoints(httpMethod);
for (JaxrsEndpoint endpoint : endpoints) {
endpoint.update(httpMethod);
}
}
- private static void processChange(final JaxrsResource resource, int flags) throws CoreException {
+ private static void processChange(final JaxrsResource resource, final Flags flags) throws CoreException {
// no structural change in the resource: refresh its methods
- if ((flags & F_ELEMENT_KIND) == 0) {
+ if (!flags.hasValue(F_ELEMENT_KIND)) {
for (JaxrsResourceMethod resourceMethod : resource.getMethods().values()) {
processChange(resourceMethod, flags);
}
@@ -198,15 +198,15 @@ private static void processChange(final JaxrsResource resource, int flags) throw
}
}
- private static void processChange(final JaxrsResourceMethod changedResourceMethod, int flags) throws CoreException {
+ private static void processChange(final JaxrsResourceMethod changedResourceMethod, final Flags flags) throws CoreException {
final JaxrsMetamodel metamodel = changedResourceMethod.getMetamodel();
- if ((flags & F_ELEMENT_KIND) > 0) {
+ if (flags.hasValue(F_ELEMENT_KIND)) {
// remove endpoints using this resoureMethod:
metamodel.removeEndpoints(changedResourceMethod);
// create endpoints using this resourceMethod:
processAddition(changedResourceMethod);
} else if (changedResourceMethod.getElementKind() == EnumElementKind.SUBRESOURCE_LOCATOR
- && (flags & F_METHOD_RETURN_TYPE) > 0) {
+ && flags.hasValue(F_METHOD_RETURN_TYPE)) {
// remove endpoints using this resoureMethod:
metamodel.removeEndpoints(changedResourceMethod);
// create endpoints using this resourceMethod:
View
47 ...src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedBuildJob.java
@@ -50,6 +50,7 @@ public ResourceChangedBuildJob(final IProject project, final IResourceChangeEven
@Override
protected IStatus run(final IProgressMonitor progressMonitor) {
final long startTime = new Date().getTime();
+ JaxrsMetamodel metamodel = null;
try {
progressMonitor.beginTask("Building JAX-RS Metamodel", 3 * SCALE);
Logger.debug("Building JAX-RS Metamodel after resource changed...");
@@ -61,42 +62,30 @@ protected IStatus run(final IProgressMonitor progressMonitor) {
}
// compute changes on the JAX-RS Application(s), HttpMethods, Resources, etc.
final IJavaProject javaProject = JavaCore.create(project);
- JaxrsMetamodel metamodel = JaxrsMetamodelLocator.get(javaProject);
- try {
- if (metamodel == null) {
- metamodel = JaxrsMetamodelLocator.get(javaProject, true);
- if(metamodel != null) {
- metamodel.processProject(progressMonitor);
- }
- } else if (event.getBuildKind() == IncrementalProjectBuilder.FULL_BUILD
- || event.getBuildKind() == IncrementalProjectBuilder.CLEAN_BUILD) {
- metamodel.processProject(progressMonitor);
- } else {
- metamodel.processAffectedResources(affectedResources, progressMonitor);
- }
- } catch(CoreException e) {
- final IStatus status = Logger.error("Failed to (re)build the JAX-RS metamodel for projet " + project.getName(), e);
+ metamodel = JaxrsMetamodelLocator.get(javaProject);
+ if (metamodel == null) {
+ metamodel = JaxrsMetamodelLocator.get(javaProject, true);
if(metamodel != null) {
- metamodel.setBuildStatus(status);
+ metamodel.processProject(progressMonitor);
}
- return status;
+ } else if (event.getBuildKind() == IncrementalProjectBuilder.FULL_BUILD
+ || event.getBuildKind() == IncrementalProjectBuilder.CLEAN_BUILD) {
+ metamodel.processProject(progressMonitor);
+ } else {
+ metamodel.processAffectedResources(affectedResources, progressMonitor);
}
return Status.OK_STATUS;
- } catch (Throwable e) {
- return Logger.error("Failed to (re)build the JAX-RS metamodel for projet " + project.getName(), e);
+ } catch (Exception e) {
+ final IStatus status = Logger.error("Failed to (re)build the JAX-RS metamodel for projet " + project.getName(), e);
+ if(metamodel != null) {
+ metamodel.setBuildStatus(status);
+ }
+ return status;
} finally {
long endTime = new Date().getTime();
if (Logger.isDebugEnabled()) {
- Logger.debug("JAX-RS Metamodel for project '{}' built in {} ms.", project.getName(), (endTime - startTime));
- try {
- final JaxrsMetamodel metamodel = JaxrsMetamodelLocator.get(project);
- if(metamodel != null && Logger.isDebugEnabled()) {
- Logger.debug(metamodel.getStatus());
- }
- } catch (Throwable e) {
- // debug level here since the purpose was to display a debug message
- Logger.debug("Error occurred: {}", e);
- }
+ Logger.debug("JAX-RS Metamodel for project '{}' built in {} ms, ended with status {}.", project
+ .getName(), (endTime - startTime), (metamodel != null ? metamodel.getStatus() : "unknown"));
}
progressMonitor.done();
}
View
30 ...jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsEndpoint.java
@@ -33,6 +33,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.Flags;
import org.jboss.tools.ws.jaxrs.core.internal.utils.ObjectUtils;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.jdt.JavaMethodParameter;
@@ -193,27 +194,24 @@ public boolean remove(final IJaxrsApplication application) {
*
* @throws CoreException
*/
- public void update(final int flags) throws CoreException {
+ public void update(final Flags flags) throws CoreException {
boolean changed = false;
- if ((flags & F_HTTP_METHOD_ANNOTATION) > 0) {
+ if (flags.hasValue(F_HTTP_METHOD_ANNOTATION)) {
changed = changed || refreshHttpMethod();
}
- if ((flags & F_PATH_ANNOTATION) > 0 || (flags & F_QUERY_PARAM_ANNOTATION) > 0
- || (flags & F_MATRIX_PARAM_ANNOTATION) > 0 || (flags & F_DEFAULT_VALUE_ANNOTATION) > 0
- || (flags & F_METHOD_PARAMETERS) > 0) {
+ if (flags.hasValue(F_PATH_ANNOTATION, F_QUERY_PARAM_ANNOTATION, F_MATRIX_PARAM_ANNOTATION,
+ F_DEFAULT_VALUE_ANNOTATION, F_METHOD_PARAMETERS)) {
changed = changed || refreshUriPathTemplate();
}
// look for mediatype capabilities at the method level, then fall back
// at the type level, then "any" otherwise
- if ((flags & F_CONSUMES_ANNOTATION) > 0 || (flags & F_PRODUCES_ANNOTATION) > 0) {
- if ((flags & F_CONSUMES_ANNOTATION) > 0) {
- changed = changed || refreshConsumedMediaTypes();
- }
- if ((flags & F_PRODUCES_ANNOTATION) > 0) {
- changed = changed || refreshProducedMediaTypes();
- }
+ if (flags.hasValue(F_CONSUMES_ANNOTATION)) {
+ changed = changed || refreshConsumedMediaTypes();
+ }
+ if (flags.hasValue(F_PRODUCES_ANNOTATION)) {
+ changed = changed || refreshProducedMediaTypes();
}
if (changed) {
metamodel.update(this);
@@ -314,8 +312,8 @@ private void refreshUriTemplateMatrixParams(final StringBuilder uriPathTemplateB
.getJavaMethodParametersAnnotatedWith(MATRIX_PARAM.qualifiedName);
for (JavaMethodParameter matrixParameter : matrixParameters) {
final Annotation matrixParamAnnotation = matrixParameter.getAnnotation(MATRIX_PARAM.qualifiedName);
- if (matrixParamAnnotation.getValue("value") != null) {
- uriPathTemplateBuilder.append(";").append(matrixParamAnnotation.getValue("value")).append("={")
+ if (matrixParamAnnotation.getValue() != null) {
+ uriPathTemplateBuilder.append(";").append(matrixParamAnnotation.getValue()).append("={")
.append(matrixParameter.getTypeName()).append("}");
}
}
@@ -330,14 +328,14 @@ private void refreshUriTemplateQueryParams(final StringBuilder uriPathTemplateBu
for (Iterator<JavaMethodParameter> iterator = queryParameters.iterator(); iterator.hasNext();) {
JavaMethodParameter queryParam = iterator.next();
final Annotation queryParamAnnotation = queryParam.getAnnotation(QUERY_PARAM.qualifiedName);
- final String paramName = queryParamAnnotation.getValue("value");
+ final String paramName = queryParamAnnotation.getValue();
if (paramName != null) {
final String paramType = queryParam.getTypeName();
uriPathTemplateBuilder.append(paramName).append("={");
uriPathTemplateBuilder.append(paramName).append(":").append(paramType);
final Annotation defaultValueAnnotation = queryParam.getAnnotation(DEFAULT_VALUE.qualifiedName);
if (defaultValueAnnotation != null) {
- uriPathTemplateBuilder.append('=').append(defaultValueAnnotation.getValue("value"));
+ uriPathTemplateBuilder.append('=').append(defaultValueAnnotation.getValue());
}
uriPathTemplateBuilder.append('}');
// prepare for next query param item if there is more to
View
6 ...xrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsHttpMethod.java
@@ -28,7 +28,7 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.DeltaFlags;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.Flags;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
import org.jboss.tools.ws.jaxrs.core.metamodel.domain.EnumElementKind;
@@ -230,7 +230,7 @@ public boolean isMarkedForRemoval() {
public String getHttpVerb() {
final Annotation httpVerbAnnotation = getHttpMethodAnnotation();
if (httpVerbAnnotation != null) {
- return httpVerbAnnotation.getValue("value");
+ return httpVerbAnnotation.getValue();
}
return null;
}
@@ -303,7 +303,7 @@ public void update(final IJavaElement element, final CompilationUnit ast) throws
if (transientHttpMethod == null) {
remove();
} else {
- final DeltaFlags flags = updateAnnotations(transientHttpMethod.getAnnotations());
+ final Flags flags = updateAnnotations(transientHttpMethod.getAnnotations());
if (isMarkedForRemoval()) {
remove();
}
View
6 ...ore/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaApplication.java
@@ -24,7 +24,7 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.DeltaFlags;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.Flags;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname;
@@ -238,7 +238,7 @@ public String getApplicationPath() {
}
final Annotation applicationPathAnnotation = getApplicationPathAnnotation();
if (applicationPathAnnotation != null) {
- return applicationPathAnnotation.getValue("value");
+ return applicationPathAnnotation.getValue();
}
return null;
}
@@ -273,7 +273,7 @@ public void update(final IJavaElement javaElement, final CompilationUnit ast) th
if (transientApplication == null) {
remove();
} else {
- final DeltaFlags updateAnnotationsFlag = updateAnnotations(transientApplication.getAnnotations());
+ final Flags updateAnnotationsFlag = updateAnnotations(transientApplication.getAnnotations());
final JaxrsElementDelta delta = new JaxrsElementDelta(this, CHANGED, updateAnnotationsFlag);
if (this.isJaxrsCoreApplicationSubclass() != transientApplication.isJaxrsCoreApplicationSubclass()) {
this.isApplicationSubclass = transientApplication.isJaxrsCoreApplicationSubclass();
View
6 ...rs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaElement.java
@@ -53,7 +53,7 @@
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.DeltaFlags;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.Flags;
import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtils;
import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtils.MapComparison;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
@@ -257,8 +257,8 @@ private int internalUpdateAnnotation(final Annotation annotation) {
return F_NONE;
}
- DeltaFlags updateAnnotations(final Map<String, Annotation> otherAnnotations) {
- final DeltaFlags flags = new DeltaFlags();
+ Flags updateAnnotations(final Map<String, Annotation> otherAnnotations) {
+ final Flags flags = new Flags();
final MapComparison<String, Annotation> annotationsComparison = CollectionUtils.compare(this.annotations, otherAnnotations);
// added annotations (ie: found in 'otherAnnotation' but not
// this.annotations)
View
154 ...axrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java
@@ -132,10 +132,10 @@
private final JaxrsElementsIndexationDelegate indexationService;
/** The Listeners for JAX-RS Element changes. */
- final Set<IJaxrsElementChangedListener> elementChangedListeners = new HashSet<IJaxrsElementChangedListener>();
+ private final Set<IJaxrsElementChangedListener> elementChangedListeners = new HashSet<IJaxrsElementChangedListener>();
/** The Listeners for JAX-RS Endpoint changes. */
- final Set<IJaxrsEndpointChangedListener> endpointChangedListeners = new HashSet<IJaxrsEndpointChangedListener>();
+ private final Set<IJaxrsEndpointChangedListener> endpointChangedListeners = new HashSet<IJaxrsEndpointChangedListener>();
/** A boolean marker that indicates if the metamodel is being initialized (ie, first/full build).*/
private boolean initializing=true;
@@ -565,7 +565,7 @@ public void processProject(final IProgressMonitor progressMonitor) throws CoreEx
processResourceChange(new ResourceDelta(getProject(), ADDED, 0), progressMonitor);
if (WtpUtils.hasWebDeploymentDescriptor(getProject())) {
processWebDeploymentDescriptorChange(
- new ResourceDelta(WtpUtils.getWebDeploymentDescriptor(getProject()), ADDED, 0), progressMonitor);
+ new ResourceDelta(WtpUtils.getWebDeploymentDescriptor(getProject()), ADDED, 0));
}
progressMonitor.worked(1);
} catch (CoreException e) {
@@ -624,48 +624,62 @@ private void processResourceChange(final ResourceDelta event, final IProgressMon
return;
}
final IJavaElement javaElement = JavaCore.create(resource);
- final int deltaKind = event.getDeltaKind();
- if (javaElement != null &&
// ignore changes on binary files (added/removed/changed jars to improve
// builder performances)
- !(javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT && ((IPackageFragmentRoot) javaElement)
- .isArchive())) {
- final List<JaxrsJavaElement<?>> matchingElements = findElements(javaElement);
- switch (deltaKind) {
- case ADDED:
- JaxrsElementFactory.createElements(javaElement, JdtUtils.parse(javaElement, progressMonitor), this,
- progressMonitor);
- break;
+ if (javaElement != null && !JdtUtils.isArchive(javaElement)) {
+ processJavaElement(javaElement, event.getDeltaKind(), progressMonitor);
+ } else if (WtpUtils.isWebDeploymentDescriptor(resource)) {
+ processWebDeploymentDescriptorChange(new ResourceDelta(resource, event.getDeltaKind(), 0));
+ }
- case CHANGED:
- final CompilationUnit ast = JdtUtils.parse(javaElement, progressMonitor);
- if (matchingElements.isEmpty()) {
- JaxrsElementFactory.createElements(javaElement, ast, this, progressMonitor);
- } else {
- for (JaxrsJavaElement<?> element : matchingElements) {
- // only working on JAX-RS elements bound to IType, not
- // IFields nor IMethods
- // those elements will internally update their own
- // children elements based on IMethods and IFields
- if (element.getJavaElement().getElementType() == IJavaElement.TYPE) {
- element.update(javaElement, ast);
- }
- }
- }
- break;
- case REMOVED:
+ }
+
+ /**
+ * Process the givne {@link IJavaElement} to see if it can be a JAX-RS element
+ * @param javaElement
+ * @param deltaKind
+ * @param progressMonitor
+ * @throws CoreException
+ * @throws JavaModelException
+ */
+ private void processJavaElement(final IJavaElement javaElement, final int deltaKind,
+ final IProgressMonitor progressMonitor) throws CoreException, JavaModelException {
+ final List<JaxrsJavaElement<?>> matchingElements = findElements(javaElement);
+ switch (deltaKind) {
+ case ADDED:
+ JaxrsElementFactory.createElements(javaElement, JdtUtils.parse(javaElement, progressMonitor), this,
+ progressMonitor);
+ break;
+ case CHANGED:
+ final CompilationUnit ast = JdtUtils.parse(javaElement, progressMonitor);
+ if (matchingElements.isEmpty()) {
+ JaxrsElementFactory.createElements(javaElement, ast, this, progressMonitor);
+ } else {
for (JaxrsJavaElement<?> element : matchingElements) {
- element.remove();
+ // only working on JAX-RS elements bound to IType, not
+ // IFields nor IMethods
+ // those elements will internally update their own
+ // children elements based on IMethods and IFields
+ if (element.getJavaElement().getElementType() == IJavaElement.TYPE) {
+ element.update(javaElement, ast);
+ }
}
- break;
}
- } else if (WtpUtils.isWebDeploymentDescriptor(resource)) {
- processWebDeploymentDescriptorChange(new ResourceDelta(resource, deltaKind, 0), progressMonitor);
+ break;
+ case REMOVED:
+ for (JaxrsJavaElement<?> element : matchingElements) {
+ element.remove();
+ }
+ break;
}
-
}
- private void processWebDeploymentDescriptorChange(final ResourceDelta delta, final IProgressMonitor progressMonitor)
+ /**
+ * Process change in the 'web.xml' deployment descriptor
+ * @param delta
+ * @throws CoreException
+ */
+ private void processWebDeploymentDescriptorChange(final ResourceDelta delta)
throws CoreException {
final IResource webxmlResource = delta.getResource();
final JaxrsWebxmlApplication webxmlElement = (JaxrsWebxmlApplication) findElement(webxmlResource);
@@ -1048,14 +1062,17 @@ private IJaxrsStatus findElementByIdentifier(final IJaxrsElement element) {
}
/**
- * Finds and returns a {@link Set} of {@link IResource}s that have the given problemType as an {@link IMarker} attached
- * to them.
+ * Finds and returns a {@link List} of {@link IResource}s that have the given problemType as an {@link IMarker} attached
+ * to them, or empty list if none was found.
* @param problemType the problem type to look for
* @return the resources having the given problem type.
* @throws CoreException
* @throws NumberFormatException
*/
public List<IResource> findResourcesWithProblemOfType(final String problemType) {
+ if(problemType == null) {
+ return Collections.emptyList();
+ }
try {
readWriteLock.readLock().lock();
final Term categoryTerm = new Term(FIELD_TYPE, IMarker.class.getSimpleName());
@@ -1072,11 +1089,11 @@ private IJaxrsStatus findElementByIdentifier(final IJaxrsElement element) {
*/
@Override
public IJaxrsElement findElement(final IJavaElement javaElement) {
+ if (javaElement == null) {
+ return null;
+ }
try {
readWriteLock.readLock().lock();
- if (javaElement == null) {
- return null;
- }
return searchJaxrsElement(LuceneDocumentFactory.getIdentifierTerm(javaElement));
} finally {
readWriteLock.readLock().unlock();
@@ -1091,6 +1108,9 @@ public IJaxrsElement findElement(final IJavaElement javaElement) {
*/
public boolean containsElement(JaxrsBaseElement element) {
try {
+ if(element == null) {
+ return false;
+ }
readWriteLock.readLock().lock();
return this.elements.containsKey(element.getIdentifier());
} finally {
@@ -1154,10 +1174,10 @@ public final IJaxrsApplication getApplication() {
*/
public final IJaxrsApplication getApplication(final IResource resource) {
try {
- readWriteLock.readLock().lock();
if (resource == null) {
return null;
}
+ readWriteLock.readLock().lock();
final Term resourceTerm = new Term(FIELD_RESOURCE_PATH, resource.getFullPath().toPortableString());
final Term categoryTerm = new Term(FIELD_TYPE, EnumElementCategory.APPLICATION.toString());
return searchJaxrsElement(resourceTerm, categoryTerm);
@@ -1186,6 +1206,9 @@ public final IJaxrsApplication getApplication(final IResource resource) {
* none was found.
*/
public final JaxrsJavaApplication findJavaApplicationByTypeName(final String typeName) {
+ if(typeName == null) {
+ return null;
+ }
try {
readWriteLock.readLock().lock();
final Term classNameTerm = new Term(FIELD_JAVA_CLASS_NAME, typeName);
@@ -1238,6 +1261,9 @@ public final JaxrsWebxmlApplication findWebxmlApplication() {
* if none was found.
*/
public final JaxrsWebxmlApplication findWebxmlApplicationByClassName(final String className) {
+ if(className == null) {
+ return null;
+ }
try {
readWriteLock.readLock().lock();
final Term classNameTerm = new Term(FIELD_JAVA_CLASS_NAME, className);
@@ -1275,11 +1301,11 @@ public final JaxrsWebxmlApplication findWebxmlApplicationByClassName(final Strin
* @throws CoreException
*/
public JaxrsHttpMethod findHttpMethodByTypeName(final String typeName) throws CoreException {
+ if (typeName == null) {
+ return null;
+ }
try {
readWriteLock.readLock().lock();
- if (typeName == null) {
- return null;
- }
final Term categoryTerm = new Term(FIELD_TYPE, EnumElementCategory.HTTP_METHOD.toString());
final Term typeTerm = new Term(FIELD_JAVA_CLASS_NAME, typeName);
return searchJaxrsElement(categoryTerm, typeTerm);
@@ -1296,11 +1322,11 @@ public JaxrsHttpMethod findHttpMethodByTypeName(final String typeName) throws Co
* @return the JAX-RS Provider or null if not found
*/
public IJaxrsProvider findProvider(final IType providerType) {
+ if (providerType == null) {
+ return null;
+ }
try {
readWriteLock.readLock().lock();
- if (providerType == null) {
- return null;
- }
final Term projectTerm = new Term(FIELD_JAVA_PROJECT_IDENTIFIER, getJavaProject().getHandleIdentifier());
final Term categoryTerm = new Term(FIELD_TYPE, EnumElementCategory.PROVIDER.toString());
final Term typeTerm = new Term(FIELD_JAVA_CLASS_NAME, providerType.getFullyQualifiedName());
@@ -1318,11 +1344,11 @@ public IJaxrsProvider findProvider(final IType providerType) {
* @return the JAX-RS Resource or null if not found
*/
public JaxrsResource findResource(IType resourceType) {
+ if (resourceType == null) {
+ return null;
+ }
try {
readWriteLock.readLock().lock();
- if (resourceType == null) {
- return null;
- }
final Term projectTerm = new Term(FIELD_JAVA_PROJECT_IDENTIFIER, getJavaProject().getHandleIdentifier());
final Term categoryTerm = new Term(FIELD_TYPE, EnumElementCategory.RESOURCE.toString());
final Term typeTerm = new Term(FIELD_JAVA_CLASS_NAME, resourceType.getFullyQualifiedName());
@@ -1337,14 +1363,14 @@ public JaxrsResource findResource(IType resourceType) {
*
* @param returnedType
* : the returned type of the JAX-RS Resource Methods
- * @return the JAX-RS Resource or null if not found
+ * @return the JAX-RS Resource or empty list if not found
*/
public List<IJaxrsResourceMethod> findResourceMethodsByReturnedType(final IType returnedType) {
+ if (returnedType == null) {
+ return Collections.emptyList();
+ }
try {
readWriteLock.readLock().lock();
- if (returnedType == null) {
- return null;
- }
final Term projectTerm = new Term(FIELD_JAVA_PROJECT_IDENTIFIER, getJavaProject().getHandleIdentifier());
final Term categoryTerm = new Term(FIELD_TYPE, EnumElementCategory.RESOURCE_METHOD.toString());
final Term typeTerm = new Term(FIELD_RETURNED_TYPE_NAME, returnedType.getFullyQualifiedName());
@@ -1370,11 +1396,11 @@ public JaxrsResource findResource(IType resourceType) {
* @return the JAX-RS Providers or empty list if no match
*/
public List<JaxrsProvider> findProviders(final EnumElementKind providerKind, final String providedClassName) {
+ if (providerKind == null || providedClassName == null) {
+ return Collections.emptyList();
+ }
try {
readWriteLock.readLock().lock();
- if (providerKind == null || providedClassName == null) {
- return null;
- }
final Term projectTerm = new Term(FIELD_JAVA_PROJECT_IDENTIFIER, getJavaProject().getHandleIdentifier());
final Term categoryTerm = new Term(FIELD_TYPE, EnumElementCategory.PROVIDER.toString());
final Term providerKindTerm = new Term(FIELD_PROVIDER_KIND + providerKind.toString(), providedClassName);
@@ -1391,14 +1417,14 @@ public JaxrsResource findResource(IType resourceType) {
* @param resourceMethod
* the resource method used by the searched Endpoints
* @return a collection containing zero or more matches, or
- * <code>null</code> if the input was <code>null</null>.
+ * empty list if the input was {@code null}.
*/
public List<JaxrsEndpoint> findEndpoints(final IJaxrsElement element) {
+ if (element == null) {
+ return Collections.emptyList();
+ }
try {
readWriteLock.readLock().lock();
- if (element == null) {
- return null;
- }
final Term projectTerm = new Term(FIELD_JAVA_PROJECT_IDENTIFIER, getJavaProject().getHandleIdentifier());
final Term categoryTerm = new Term(FIELD_TYPE, EnumElementCategory.ENDPOINT.toString());
final Term jaxrsElementTerm = new Term(FIELD_JAXRS_ELEMENT, element.getIdentifier());
@@ -1476,8 +1502,8 @@ public JaxrsEndpoint getEndpoint(String identifier) {
public void removeEndpoints(final IJaxrsElement removedElement) {
try {
readWriteLock.writeLock().lock();
- final List<JaxrsEndpoint> endpoints = findEndpoints(removedElement);
- for (JaxrsEndpoint endpoint : endpoints) {
+ final List<JaxrsEndpoint> elementEndpoints = findEndpoints(removedElement);
+ for (JaxrsEndpoint endpoint : elementEndpoints) {
endpoint.remove();
}
} finally {
View
9 ...jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsProvider.java
@@ -12,6 +12,7 @@
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
import static org.eclipse.jdt.core.IJavaElementDelta.CHANGED;
+import static org.jboss.tools.ws.jaxrs.core.jdt.Annotation.VALUE;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.CONSUMES;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.ENCODED;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.PRODUCES;
@@ -36,7 +37,7 @@
import org.eclipse.jdt.core.ITypeHierarchy;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.DeltaFlags;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.Flags;
import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtils;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Pair;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
@@ -279,7 +280,7 @@ public Annotation getConsumesAnnotation() {
public List<String> getConsumedMediaTypes() {
final Annotation consumesAnnotation = getConsumesAnnotation();
if (consumesAnnotation != null) {
- return consumesAnnotation.getValues("value");
+ return consumesAnnotation.getValues(VALUE);
}
return Collections.emptyList();
}
@@ -292,7 +293,7 @@ public Annotation getProducesAnnotation() {
public List<String> getProducedMediaTypes() {
final Annotation producesAnnotation = getProducesAnnotation();
if (producesAnnotation != null) {
- return producesAnnotation.getValues("value");
+ return producesAnnotation.getValues(VALUE);
}
return Collections.emptyList();
}
@@ -313,7 +314,7 @@ public void update(final IJavaElement javaElement, final CompilationUnit ast) th
if (transientProvider == null) {
remove();
} else {
- final DeltaFlags updateAnnotationsFlags = updateAnnotations(transientProvider.getAnnotations());
+ final Flags updateAnnotationsFlags = updateAnnotations(transientProvider.getAnnotations());
final JaxrsElementDelta delta = new JaxrsElementDelta(this, CHANGED, updateAnnotationsFlags);
if (!this.getProvidedTypes().equals(transientProvider.getProvidedTypes())) {
this.getProvidedTypes().clear();
View
150 ...jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java
@@ -12,6 +12,7 @@
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
import static org.eclipse.jdt.core.IJavaElementDelta.CHANGED;
+import static org.jboss.tools.ws.jaxrs.core.jdt.Annotation.VALUE;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.CONSUMES;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.ENCODED;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.PATH;
@@ -25,7 +26,6 @@
import java.util.List;
import java.util.Map;
-import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
@@ -35,7 +35,7 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.DeltaFlags;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.Flags;
import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtils;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.jdt.JavaMethodSignature;
@@ -55,7 +55,7 @@
*
* @author xcoulon
*/
-public class JaxrsResource extends JaxrsJavaElement<IType> implements IJaxrsResource {
+public final class JaxrsResource extends JaxrsJavaElement<IType> implements IJaxrsResource {
private final Map<String, JaxrsResourceField> resourceFields = new HashMap<String, JaxrsResourceField>();
@@ -110,7 +110,7 @@ public static Builder from(final IJavaElement javaElement, final CompilationUnit
* @author xcoulon
*
*/
- public static class Builder {
+ public static final class Builder {
private final IType javaType;
private final CompilationUnit ast;
@@ -201,72 +201,84 @@ public void update(final IJavaElement javaElement, final CompilationUnit ast) th
final JaxrsResource transientResource = from(javaElement, ast, getMetamodel().findAllHttpMethods()).build();
if (transientResource == null) {
remove();
- } else {
- final DeltaFlags updateAnnotationsFlags = updateAnnotations(transientResource.getAnnotations());
- final JaxrsElementDelta delta = new JaxrsElementDelta(this, CHANGED, updateAnnotationsFlags);
- final List<IJaxrsResourceMethod> addedMethods = CollectionUtils.difference(
- transientResource.getAllMethods(), this.getAllMethods());
- for (IJaxrsResourceMethod addedMethod : addedMethods) {
- // create the Resource Method by attaching it to the metamodel
- // and this parent resource.
- JaxrsResourceMethod.from(addedMethod.getJavaElement(), ast, getMetamodel().findAllHttpMethods())
- .withMetamodel(getMetamodel()).withParentResource(this).build();
- }
- final Collection<IJaxrsResourceMethod> changedMethods = CollectionUtils.intersection(this.getAllMethods(),
- transientResource.getAllMethods());
- for (IJaxrsResourceMethod changedMethod : changedMethods) {
- ((JaxrsResourceMethod) changedMethod).update(transientResource.getMethods().get(
- changedMethod.getIdentifier()));
- }
- final List<IJaxrsResourceMethod> removedMethods = CollectionUtils.difference(this.getAllMethods(),
- transientResource.getAllMethods());
- for (IJaxrsResourceMethod removedMethod : removedMethods) {
- this.removeMethod(removedMethod);
- }
- final List<IJaxrsResourceField> addedFields = CollectionUtils.difference(transientResource.getAllFields(),
- this.getAllFields());
- for (IJaxrsResourceField addedField : addedFields) {
- // create the Resource Field by attaching it to the metamodel
- // and to this parent resource.
- JaxrsResourceField.from(addedField.getJavaElement(), ast).withMetamodel(getMetamodel())
- .withParentResource(this).build();
- }
- final Collection<IJaxrsResourceField> changedFields = CollectionUtils.intersection(this.getAllFields(),
- transientResource.getAllFields());
- for (IJaxrsResourceField changedField : changedFields) {
- ((JaxrsResourceField) changedField).update(transientResource.getFields().get(
- changedField.getIdentifier()));
- }
- final List<IJaxrsResourceField> removedFields = CollectionUtils.difference(this.getAllFields(),
- transientResource.getAllFields());
- for (IJaxrsResourceField removedField : removedFields) {
- this.removeField(removedField);
- }
-
- if (isMarkedForRemoval()) {
- remove();
- }
- // update indexes for this element.
- else if (hasMetamodel()) {
- getMetamodel().update(delta);
- }
+ return;
+ }
+ final Flags updateAnnotationsFlags = updateAnnotations(transientResource.getAnnotations());
+ final JaxrsElementDelta delta = new JaxrsElementDelta(this, CHANGED, updateAnnotationsFlags);
+ updateMethods(transientResource, ast);
+ updateFields(transientResource, ast);
+
+ if (isMarkedForRemoval()) {
+ remove();
+ }
+ // update indexes for this element.
+ else if (hasMetamodel()) {
+ getMetamodel().update(delta);
}
-
}
-
+
/**
- * Removes the JAX-RS {@link IMarker} and resets the problem level for this
- * {@link IJaxrsResource}, and at the same time, sets the problem level to
- * {@code zero} for all its {@link IJaxrsResourceField}s and
- * {@link IJaxrsResourceMethod}s children.
- *
+ * Updates the {@link IJaxrsResourceField}s of {@code this} from the ones provided by the given {@link JaxrsResource}
+ * @param transientResource the resource to analyze
+ * @param ast its associated AST.
* @throws CoreException
*/
- public void removeMarkers() throws CoreException {
- super.removeMarkers();
+ private void updateFields(final JaxrsResource transientResource, final CompilationUnit ast) throws CoreException {
+ final List<IJaxrsResourceField> allTransientInstanceFields = transientResource.getAllFields();
+ final List<IJaxrsResourceField> allCurrentFields = this.getAllFields();
+ final List<IJaxrsResourceField> addedFields = CollectionUtils.difference(allTransientInstanceFields,
+ allCurrentFields);
+ for (IJaxrsResourceField addedField : addedFields) {
+ // create the Resource Field by attaching it to the metamodel
+ // and to this parent resource.
+ JaxrsResourceField.from(addedField.getJavaElement(), ast).withMetamodel(getMetamodel())
+ .withParentResource(this).build();
+ }
+ final Collection<IJaxrsResourceField> changedFields = CollectionUtils.intersection(allCurrentFields,
+ allTransientInstanceFields);
+ for (IJaxrsResourceField changedField : changedFields) {
+ ((JaxrsResourceField) changedField).update(transientResource.getFields().get(
+ changedField.getIdentifier()));
+ }
+ final List<IJaxrsResourceField> removedFields = CollectionUtils.difference(allCurrentFields,
+ allTransientInstanceFields);
+ for (IJaxrsResourceField removedField : removedFields) {
+ this.removeField(removedField);
+ }
}
/**
+ * Updates the {@link IJaxrsResourceMethod}s of {@code this} from the ones provided by the given {@link JaxrsResource}
+ * @param transientResource the resource to analyze
+ * @param ast its associated AST.
+ * @throws CoreException
+ */
+ private void updateMethods(final JaxrsResource transientResource, final CompilationUnit ast)
+ throws CoreException {
+ final List<IJaxrsResourceMethod> allTransientInstanceMethods = transientResource.getAllMethods();
+ final List<IJaxrsResourceMethod> allCurrentMethods = this.getAllMethods();
+ final List<IJaxrsResourceMethod> addedMethods = CollectionUtils.difference(
+ allTransientInstanceMethods, allCurrentMethods);
+ for (IJaxrsResourceMethod addedMethod : addedMethods) {
+ // create the Resource Method by attaching it to the metamodel
+ // and this parent resource.
+ JaxrsResourceMethod.from(addedMethod.getJavaElement(), ast, getMetamodel().findAllHttpMethods())
+ .withMetamodel(getMetamodel()).withParentResource(this).build();
+ }
+ final Collection<IJaxrsResourceMethod> changedMethods = CollectionUtils.intersection(allCurrentMethods,
+ allTransientInstanceMethods);
+ for (IJaxrsResourceMethod changedMethod : changedMethods) {
+ ((JaxrsResourceMethod) changedMethod).update(transientResource.getMethods().get(
+ changedMethod.getIdentifier()));
+ }
+ final List<IJaxrsResourceMethod> removedMethods = CollectionUtils.difference(allCurrentMethods,
+ allTransientInstanceMethods);
+ for (IJaxrsResourceMethod removedMethod : removedMethods) {
+ this.removeMethod(removedMethod);
+ }
+ }
+
+ /**
* @return true if the current element has no <code>javax.ws.rs.Path</code>
* annotation AND no JAX-RS Resource Method nor JAX-RS Resource
* Field. <code>javax.ws.rs.Consumes</code>,
@@ -302,25 +314,24 @@ public String getPathTemplate() {
if (pathAnnotation == null) {
return null;
}
- return pathAnnotation.getValue("value");
+ return pathAnnotation.getValue();
}
@Override
public boolean hasPathTemplate() {
final Annotation pathAnnotation = getPathAnnotation();
- return pathAnnotation != null && pathAnnotation.getValue("value") != null;
+ return pathAnnotation != null && pathAnnotation.getValue() != null;
}
public Annotation getPathAnnotation() {
- final Annotation pathAnnotation = getAnnotation(PATH.qualifiedName);
- return pathAnnotation;
+ return getAnnotation(PATH.qualifiedName);
}
@Override
public List<String> getConsumedMediaTypes() {
final Annotation consumesAnnotation = getAnnotation(CONSUMES.qualifiedName);
if (consumesAnnotation != null) {
- return consumesAnnotation.getValues("value");
+ return consumesAnnotation.getValues(VALUE);
}
return Collections.emptyList();
}
@@ -329,14 +340,13 @@ public Annotation getPathAnnotation() {
public List<String> getProducedMediaTypes() {
final Annotation producesAnnotation = getAnnotation(PRODUCES.qualifiedName);
if (producesAnnotation != null) {
- return producesAnnotation.getValues("value");
+ return producesAnnotation.getValues(VALUE);
}
return Collections.emptyList();
}
public Annotation getProducesAnnotation() {
- final Annotation producesAnnotation = getAnnotation(PRODUCES.qualifiedName);
- return producesAnnotation;
+ return getAnnotation(PRODUCES.qualifiedName);
}
@Override
View
4 ....core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceField.java
@@ -30,7 +30,7 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.DeltaFlags;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.Flags;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
import org.jboss.tools.ws.jaxrs.core.metamodel.domain.EnumElementCategory;
@@ -153,7 +153,7 @@ void update(final JaxrsResourceField transientField) throws CoreException {
if (transientField == null) {
remove();
} else {
- final DeltaFlags upateAnnotationsFlags = updateAnnotations(transientField.getAnnotations());
+ final Flags upateAnnotationsFlags = updateAnnotations(transientField.getAnnotations());
final JaxrsElementDelta delta = new JaxrsElementDelta(this, CHANGED, upateAnnotationsFlags);
if (upateAnnotationsFlags.hasValue(F_ELEMENT_KIND) && isMarkedForRemoval()) {
remove();
View
21 ...core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java
@@ -12,6 +12,7 @@
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
import static org.eclipse.jdt.core.IJavaElementDelta.CHANGED;
+import static org.jboss.tools.ws.jaxrs.core.jdt.Annotation.VALUE;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.CONSUMES;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.ENCODED;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.PATH;
@@ -36,7 +37,7 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.DeltaFlags;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.Flags;
import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtils;
import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtils.CollectionComparison;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
@@ -224,7 +225,7 @@ public void update(final JaxrsResourceMethod transientMethod) throws CoreExcepti
if (transientMethod == null) {
remove();
} else {
- DeltaFlags flags = internalUpdate(transientMethod);
+ Flags flags = internalUpdate(transientMethod);
final JaxrsElementDelta delta = new JaxrsElementDelta(this, CHANGED, flags);
if (isMarkedForRemoval()) {
remove();
@@ -236,8 +237,8 @@ else if (hasMetamodel()) {
}
}
- DeltaFlags internalUpdate(final JaxrsResourceMethod transientMethod) throws CoreException {
- DeltaFlags flags = new DeltaFlags();
+ Flags internalUpdate(final JaxrsResourceMethod transientMethod) throws CoreException {
+ Flags flags = new Flags();
flags.addFlags(updateAnnotations(transientMethod.getAnnotations()));
// method parameters, including their own annotations
flags.addFlags(updateMethodParameters(transientMethod.getJavaMethodParameters()));
@@ -352,7 +353,7 @@ public Annotation getPathAnnotation() {
@Override
public boolean hasPathTemplate() {
final Annotation pathAnnotation = getPathAnnotation();
- return pathAnnotation != null && pathAnnotation.getValue("value") != null;
+ return pathAnnotation != null && pathAnnotation.getValue() != null;
}
@Override
@@ -361,7 +362,7 @@ public String getPathTemplate() {
if (pathAnnotation == null) {
return null;
}
- return pathAnnotation.getValue("value");
+ return pathAnnotation.getValue();
}
public Annotation getHttpMethodAnnotation() {
@@ -393,7 +394,7 @@ public Annotation getConsumesAnnotation() {
public List<String> getConsumedMediaTypes() {
final Annotation consumesAnnotation = getConsumesAnnotation();
if (consumesAnnotation != null) {
- return consumesAnnotation.getValues("value");
+ return consumesAnnotation.getValues(VALUE);
}
return Collections.emptyList();
}
@@ -406,7 +407,7 @@ public Annotation getProducesAnnotation() {
public List<String> getProducedMediaTypes() {
final Annotation producesAnnotation = getProducesAnnotation();
if (producesAnnotation != null) {
- return producesAnnotation.getValues("value");
+ return producesAnnotation.getValues(VALUE);
}
return Collections.emptyList();
}
@@ -492,8 +493,8 @@ public final String toString() {
private Map<String, Annotation> extractProposals(final Annotation pathAnnotation) {
final Map<String, Annotation> proposals = new HashMap<String, Annotation>();
- if (pathAnnotation != null && pathAnnotation.getValue("value") != null) {
- final String value = pathAnnotation.getValue("value");
+ if (pathAnnotation != null && pathAnnotation.getValue() != null) {
+ final String value = pathAnnotation.getValue();
List<String> params = extractParamsFromUriTemplateFragment(value);
for (String param : params) {
proposals.put(param, pathAnnotation);
View
14 ...s/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorDelegate.java
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
+import static org.jboss.tools.ws.jaxrs.core.jdt.Annotation.VALUE;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.RetentionPolicy;
@@ -60,15 +62,15 @@ private void validateHttpMethodAnnotation(final JaxrsHttpMethod httpMethod) thro
final Annotation httpMethodAnnotation = httpMethod.getHttpMethodAnnotation();
// if annotation is null, the resource is not a JaxrsHttpMethod anymore.
if (httpMethodAnnotation != null) {
- final String httpValue = httpMethodAnnotation.getValue("value");
+ final String httpValue = httpMethodAnnotation.getValue();
if (httpValue == null) {
final ISourceRange range = httpMethodAnnotation.getJavaAnnotation().getNameRange();
markerManager.addMarker(httpMethod,
range, JaxrsValidationMessages.HTTP_METHOD_INVALID_HTTP_METHOD_ANNOTATION_VALUE, new String[0],
JaxrsPreferences.HTTP_METHOD_INVALID_HTTP_METHOD_ANNOTATION_VALUE);
} else if (httpValue.isEmpty()) {
final ISourceRange range = JdtUtils.resolveMemberPairValueRange(
- httpMethodAnnotation.getJavaAnnotation(), "value");
+ httpMethodAnnotation.getJavaAnnotation(), VALUE);
markerManager.addMarker(httpMethod,
range, JaxrsValidationMessages.HTTP_METHOD_INVALID_HTTP_METHOD_ANNOTATION_VALUE, new String[0],
JaxrsPreferences.HTTP_METHOD_INVALID_HTTP_METHOD_ANNOTATION_VALUE);
@@ -90,15 +92,15 @@ private void validateTargetAnnotation(final JaxrsHttpMethod httpMethod) throws C
range, JaxrsValidationMessages.HTTP_METHOD_MISSING_TARGET_ANNOTATION, new String[0], JaxrsPreferences.HTTP_METHOD_MISSING_TARGET_ANNOTATION,
JaxrsMarkerResolutionIds.HTTP_METHOD_MISSING_TARGET_ANNOTATION_QUICKFIX_ID);
} else {
- final String annotationValue = targetAnnotation.getValue("value");
+ final String annotationValue = targetAnnotation.getValue();
if (annotationValue == null) {
final ISourceRange range = targetAnnotation.getJavaAnnotation().getNameRange();
markerManager.addMarker(httpMethod,
range, JaxrsValidationMessages.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE, new String[0], JaxrsPreferences.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE,
JaxrsMarkerResolutionIds.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE_QUICKFIX_ID);
} else if (!annotationValue.equals(ElementType.METHOD.name())) {
final ISourceRange range = JdtUtils.resolveMemberPairValueRange(targetAnnotation.getJavaAnnotation(),
- "value");
+ VALUE);
markerManager.addMarker(httpMethod,
range, JaxrsValidationMessages.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE, new String[0], JaxrsPreferences.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE,
JaxrsMarkerResolutionIds.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE_QUICKFIX_ID);
@@ -121,15 +123,15 @@ private void validateRetentionAnnotation(final JaxrsHttpMethod httpMethod) throw
range, JaxrsValidationMessages.HTTP_METHOD_MISSING_RETENTION_ANNOTATION, new String[0], JaxrsPreferences.HTTP_METHOD_MISSING_RETENTION_ANNOTATION,
JaxrsMarkerResolutionIds.HTTP_METHOD_MISSING_RETENTION_ANNOTATION_QUICKFIX_ID);
} else {
- final String annotationValue = retentionAnnotation.getValue("value");
+ final String annotationValue = retentionAnnotation.getValue();
if (annotationValue == null) {
final ISourceRange range = retentionAnnotation.getJavaAnnotation().getNameRange();
markerManager.addMarker(httpMethod,
range, JaxrsValidationMessages.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE, new String[0],
JaxrsPreferences.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE, JaxrsMarkerResolutionIds.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE_QUICKFIX_ID);
} else if (!annotationValue.equals(RetentionPolicy.RUNTIME.name())) {
final ISourceRange range = JdtUtils.resolveMemberPairValueRange(
- retentionAnnotation.getJavaAnnotation(), "value");
+ retentionAnnotation.getJavaAnnotation(), VALUE);
markerManager.addMarker(httpMethod,
range, JaxrsValidationMessages.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE, new String[0],
JaxrsPreferences.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE, JaxrsMarkerResolutionIds.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE_QUICKFIX_ID);
View
6 ...org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMarkerResolutionIds.java
@@ -20,4 +20,10 @@
/** QuickFix for invalid <code>javax.ws.rs.core.Application</code> subclass hierarchy .*/
public static final int JAVA_APPLICATION_INVALID_TYPE_HIERARCHY_QUICKFIX_ID = 6;
+ /**
+ * Private constructor for the utility class.
+ */
+ private JaxrsMarkerResolutionIds() {
+ super();
+ }
}
View
82 ...ss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorDelegate.java
@@ -17,6 +17,7 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBaseElement;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsJavaApplication;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
@@ -40,6 +41,12 @@ public JaxrsMetamodelValidatorDelegate(final IMarkerManager markerManager) {
this.markerManager = markerManager;
}
+ /**
+ * Validates the given {@link JaxrsMetamodel}.
+ *
+ * @param metamodel the metamodel to validate
+ * @throws CoreException
+ */
void validate(JaxrsMetamodel metamodel) throws CoreException {
Logger.debug("Validating element {}", metamodel);
final IProject project = metamodel.getProject();
@@ -52,39 +59,64 @@ void validate(JaxrsMetamodel metamodel) throws CoreException {
JaxrsValidationMessages.APPLICATION_NO_OCCURRENCE_FOUND, new String[0], JaxrsPreferences.APPLICATION_NO_OCCURRENCE_FOUND);
} else if (javaApplications.size() >= 2 || (javaApplications.size() >= 1 && webxmlApplications.size() >= 1)) {
for(JaxrsJavaApplication javaApplication: javaApplications) {
- // remove previous marker of type APPLICATION_TOO_MANY_OCCURRENCES
- removeMarkers(javaApplication, JaxrsPreferences.APPLICATION_TOO_MANY_OCCURRENCES);
- if(javaApplication.isOverriden()) {
- continue;
- }
- final ISourceRange javaNameRange = javaApplication.getJavaElement().getNameRange();
- addTooManyOccurrencesMarker(javaApplication, javaNameRange);
+ validateApplication(javaApplication);
}
for(IJaxrsApplication webxmlapplication: webxmlApplications) {
- final JaxrsWebxmlApplication webxmlApplication = (JaxrsWebxmlApplication) webxmlapplication;
- // remove previous marker of type APPLICATION_TOO_MANY_OCCURRENCES
- removeMarkers(webxmlapplication, JaxrsPreferences.APPLICATION_TOO_MANY_OCCURRENCES);
- if((webxmlApplication.isOverride() && javaApplications.size() >= 2)
- || (!webxmlApplication.isOverride() && javaApplications.size() >= 1)) {
- final ISourceRange webxmlNameRange = WtpUtils.getApplicationPathLocation(webxmlApplication.getResource(),
- webxmlApplication.getJavaClassName());
- if (webxmlNameRange == null) {
- Logger.warn("Cannot add a problem marker: unable to locate '" + webxmlApplication.getJavaClassName()
- + "' in resource '" + webxmlApplication.getResource().getFullPath().toString() + "'. ");
- } else {
- addTooManyOccurrencesMarker(webxmlApplication, webxmlNameRange);
- if(webxmlApplication.isOverride()) {
- final JaxrsJavaApplication javaApplication = webxmlApplication.getOverridenJaxrsJavaApplication();
- final ISourceRange javaNameRange = javaApplication.getJavaElement().getNameRange();
- addTooManyOccurrencesMarker(javaApplication, javaNameRange);
- }
- }
+ validateWebxmlApplication(webxmlapplication, javaApplications);
+ }
+ }
+ }
+
+ /**
+ * Validate the given {@link JaxrsWebxmlApplication} against the existing list of {@link JaxrsJavaApplication} of the metamodel.
+ *
+ * @param webxmlapplication
+ * @param javaApplications
+ * @throws CoreException
+ * @throws JavaModelException
+ */
+ private void validateWebxmlApplication(final IJaxrsApplication webxmlapplication,
+ final List<JaxrsJavaApplication> javaApplications) throws CoreException, JavaModelException {
+ final JaxrsWebxmlApplication webxmlApplication = (JaxrsWebxmlApplication) webxmlapplication;
+ // remove previous marker of type APPLICATION_TOO_MANY_OCCURRENCES
+ removeMarkers(webxmlapplication, JaxrsPreferences.APPLICATION_TOO_MANY_OCCURRENCES);
+ if((webxmlApplication.isOverride() && javaApplications.size() >= 2)
+ || (!webxmlApplication.isOverride() && javaApplications.size() >= 1)) {
+ final ISourceRange webxmlNameRange = WtpUtils.getApplicationPathLocation(webxmlApplication.getResource(),
+ webxmlApplication.getJavaClassName());
+ if (webxmlNameRange == null) {
+ Logger.warn("Cannot add a problem marker: unable to locate '" + webxmlApplication.getJavaClassName()
+ + "' in resource '" + webxmlApplication.getResource().getFullPath().toString() + "'. ");
+ } else {
+ addTooManyOccurrencesMarker(webxmlApplication, webxmlNameRange);
+ if(webxmlApplication.isOverride()) {
+ final JaxrsJavaApplication javaApplication = webxmlApplication.getOverridenJaxrsJavaApplication();
+ final ISourceRange javaNameRange = javaApplication.getJavaElement().getNameRange();
+ addTooManyOccurrencesMarker(javaApplication, javaNameRange);
}
}
}
}
/**
+ * Validates the given {@link JaxrsJavaApplication}
+ *
+ * @param javaApplication
+ * @throws CoreException
+ * @throws JavaModelException
+ */
+ private void validateApplication(JaxrsJavaApplication javaApplication) throws CoreException,
+ JavaModelException {
+ // remove previous marker of type APPLICATION_TOO_MANY_OCCURRENCES
+ removeMarkers(javaApplication, JaxrsPreferences.APPLICATION_TOO_MANY_OCCURRENCES);
+ if(javaApplication.isOverriden()) {
+ return;
+ }
+ final ISourceRange javaNameRange = javaApplication.getJavaElement().getNameRange();
+ addTooManyOccurrencesMarker(javaApplication, javaNameRange);
+ }
+
+ /**
* Removes all {@link IMarker} whose {@link JaxrsMetamodelValidator#JAXRS_PROBLEM_TYPE} attribute is equal to the given problemType argument.
* @param application the {@link IJaxrsApplication}
* @param problemType the problem type attribute value of the marker to remove.
View
2 ...oss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsProviderValidatorDelegate.java
@@ -136,8 +136,6 @@ private static boolean isValidConstructor(final IMethod method) throws JavaModel
}
// only accepting constructors with parameters annotated with
// @javax.ws.rs.core.Context
- //final JavaMethodSignature methodSignature = JdtUtils.resolveMethodSignature(method,
- // JdtUtils.parse(method, new NullProgressMonitor()));
final JavaMethodSignature methodSignature = CompilationUnitsRepository.getInstance().getMethodSignature(method);
if(methodSignature != null) {
for (JavaMethodParameter parameter : methodSignature.getMethodParameters()) {
View
12 ...ols/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceMethodValidatorDelegate.java
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
+import static org.jboss.tools.ws.jaxrs.core.jdt.Annotation.VALUE;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.CONTEXT;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.PATH_PARAM;
@@ -25,7 +26,6 @@
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.ISourceRange;
-import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.SourceRange;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResource;
@@ -181,19 +181,19 @@ private void validateNoUnboundPathParamAnnotationValues(final JaxrsResourceMetho
for (JavaMethodParameter parameter : resourceMethod.getJavaMethodParameters()) {
final Annotation pathParamAnnotation = parameter.getAnnotation(PATH_PARAM.qualifiedName);
if (pathParamAnnotation != null) {
- final String pathParamValue = pathParamAnnotation.getValue("value");
+ final String pathParamValue = pathParamAnnotation.getValue();
if (pathParamValue != null) {
if (!alphaNumPattern.matcher(pathParamValue).matches()) {
final ISourceRange range = JdtUtils.resolveMemberPairValueRange(
- pathParamAnnotation.getJavaAnnotation(), "value");
+ pathParamAnnotation.getJavaAnnotation(), VALUE);
markerManager.addMarker(
resourceMethod,
range,
JaxrsValidationMessages.RESOURCE_METHOD_INVALID_PATHPARAM_ANNOTATION_VALUE, new String[] { pathParamValue },
JaxrsPreferences.RESOURCE_METHOD_INVALID_PATHPARAM_ANNOTATION_VALUE);
} else if (!pathParamValueProposals.keySet().contains(pathParamValue)) {
final ISourceRange range = JdtUtils.resolveMemberPairValueRange(
- pathParamAnnotation.getJavaAnnotation(), "value");
+ pathParamAnnotation.getJavaAnnotation(), VALUE);
markerManager.addMarker(
resourceMethod,
range,
@@ -224,13 +224,13 @@ private ISourceRange resolveAnnotationParamSourceRange(final Annotation pathTemp
// refine source range for path parameter in the value (including
// whitespaces between starting curly bracket and param name)
final ISourceRange valueRange = JdtUtils.resolveMemberPairValueRange(
- pathTemplateParameterAnnotation.getJavaAnnotation(), "value");
+ pathTemplateParameterAnnotation.getJavaAnnotation(), VALUE);
final String annotationValue = pathTemplateParameterAnnotation.getValue();
final Pattern p = Pattern.compile("\\{\\s*" + Pattern.quote(pathTemplateParameter));
final Matcher matcher = p.matcher(annotationValue);
if (matcher.find()) {
final int start = matcher.start();
- final int end = annotationValue.indexOf("}", start);
+ final int end = annotationValue.indexOf('}', start);
return new SourceRange(valueRange.getOffset() + start + 1, end - start + 1);
}
return valueRange;
View
11 .../org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationMessages.java
@@ -21,7 +21,6 @@
private static final String BUNDLE_NAME = JaxrsValidationMessages.class.getName(); //$NON-NLS-1$
-
public static String SEARCHING_RESOURCES;
public static String VALIDATING_RESOURCE;
public static String VALIDATING_PROJECT;
@@ -51,10 +50,14 @@
public static String PROVIDER_DUPLICATE_MESSAGE_BODY_WRITER;
public static String PROVIDER_DUPLICATE_EXCEPTION_MAPPER;
-
-
-
static {
NLS.initializeMessages(BUNDLE_NAME, JaxrsValidationMessages.class);
}
+
+ /**
+ * Private constructor for the utility class.
+ */
+ private JaxrsValidationMessages() {
+ super();
+ }
}
View
14 plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java
@@ -33,6 +33,9 @@
*/
@SuppressWarnings("restriction")
public class Annotation {
+
+ /** Default name of the attribute when it is alone in the annotation. */
+ public static final String VALUE = "value";
/**
* Underlying java annotation, which may change in the case of method
@@ -75,7 +78,7 @@ public Annotation(final IAnnotation annotation, final String annotationName,
* @throws JavaModelException
*/
public Annotation(final IAnnotation annotation, final String annotationName, final String annotationValue) {
- this(annotation, annotationName, CollectionUtils.toMap("value", Arrays.asList(annotationValue)));
+ this(annotation, annotationName, CollectionUtils.toMap(VALUE, Arrays.asList(annotationValue)));
}
/**
@@ -134,14 +137,7 @@ public String getFullyQualifiedName() {
/** @return the default value */
public String getValue() {
- final List<String> values = javaAnnotationElements.get("value");
- if (values != null) {
- assert !(values.size() > 1);
- if (values.size() == 1) {
- return values.get(0);
- }
- }
- return null;
+ return getValue(VALUE);
}
/** @return the value */
View
9 ...g.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/EnumJaxrsClassname.java
@@ -95,13 +95,4 @@ private EnumJaxrsClassname(final String qualifiedName, final String simpleName)
this.simpleName = simpleName;
}
- /**
- * Compares the enum element's {@link qualifiedName} attribute with the given value.
- * @param qualifiedName
- * @return true or false
- */
- public boolean equals(final String qualifiedName) {
- return this.qualifiedName.equals(qualifiedName);
- }
-
}
View
16 plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java
@@ -34,6 +34,7 @@
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeHierarchy;
@@ -117,6 +118,19 @@ public static ICompilationUnit getCompilationUnit(final IJavaElement element) {
}
/**
+ * @return {@code true} if the given {@link IJavaElement} is an Archive (ie,
+ * its type equals {@code IJavaElement#PACKAGE_FRAGMENT_ROOT} and
+ * call to {@code IPackageFragmentRoot#isArchive()} return true. Otherwise,
+ * returns false.
+ * @param javaElement
+ * the {@link IJavaElement} to analyze.
+ */
+ public static boolean isArchive(final IJavaElement javaElement) {
+ return (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT && ((IPackageFragmentRoot) javaElement)
+ .isArchive());
+ }
+
+ /**
* Checks whether the given type is abstract or not.
*
* @param type
@@ -637,7 +651,7 @@ private static Annotation toAnnotation(final IAnnotationBinding annotationBindin
// org.eclipse.jdt.core.dom.DefaultValuePairBinding.<init>(DefaultValuePairBinding.java:31)
// at
// org.eclipse.jdt.core.dom.AnnotationBinding.getAllMemberValuePairs(AnnotationBinding.java:98)
- } catch (Throwable e) {
+ } catch (RuntimeException e) {
// silently ignore
}
return annotationElements;
View
13 ...s.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/domain/IJaxrsResourceMethod.java
@@ -21,19 +21,6 @@
abstract IMethod getJavaElement();
- /**
- * Sets the severity level for the given resource method. If the resource
- * method already has problem with higher severity, the given one is
- * ignored. On the other side, if the given problem severity is higher than
- * the current one, it is kept.
- *
- * @param level the severity level.
- *
- * @see {@link IMarker} for severity levels and values.
- */
- @Deprecated
- abstract void setProblemLevel(final int level);
-
abstract String getPathTemplate();
abstract String getHttpMethodClassName();
View
12 ...s.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/domain/JaxrsElementDelta.java
@@ -20,7 +20,7 @@
import java.util.List;
import org.eclipse.jdt.core.IJavaElementDelta;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.DeltaFlags;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.Flags;
import org.jboss.tools.ws.jaxrs.core.internal.utils.ConstantUtils;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
@@ -76,7 +76,7 @@
private final int deltaKind;
- private DeltaFlags flags;
+ private Flags flags;
/**
* Full constructor.
@@ -98,7 +98,7 @@ public JaxrsElementDelta(final IJaxrsElement element, final int deltaKind) {
public JaxrsElementDelta(final IJaxrsElement element, final int deltaKind, final int flags) {
this.element = element;
this.deltaKind = deltaKind;
- this.flags = new DeltaFlags(flags);
+ this.flags = new Flags(flags);
if (this.deltaKind == CHANGED && !this.flags.hasValue()) {
Logger.debug("*** No flag to describe the change ?!? ***");
}
@@ -111,7 +111,7 @@ public JaxrsElementDelta(final IJaxrsElement element, final int deltaKind, final
* @param deltaKind
* @param flags
*/
- public JaxrsElementDelta(final IJaxrsElement element, final int deltaKind, final DeltaFlags flags) {
+ public JaxrsElementDelta(final IJaxrsElement element, final int deltaKind, final Flags flags) {
this.element = element;
this.deltaKind = deltaKind;
this.flags = flags;
@@ -144,8 +144,8 @@ public int getDeltaKind() {
}
/** @return the flags */
- public int getFlags() {
- return flags.getValue();
+ public Flags getFlags() {
+ return flags;
}
/**
View
2 plugins/org.jboss.tools.ws.wise.ui/.classpath
@@ -60,6 +60,8 @@
<classpathentry exported="true" kind="lib" path="lib/xmlschema-core-2.0.3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xpp3_min-1.1.3.4.O.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xstream-1.2.2.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/jaxb-impl-2.2.5.1.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/jaxb-xjc-2.2.5.1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/wise-core-2.0.2.Final.jar"/>
<classpathentry exported="true" kind="lib" path="lib/wise-core-cxf-2.0.2.Final.jar"/>
<classpathentry kind="output" path="target/classes"/>
View
85 .../tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessingTestCase.java
@@ -21,6 +21,7 @@
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getAnnotation;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getAnnotations;
import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.IJavaElementDeltaFlag.F_SIGNATURE;
+import static org.jboss.tools.ws.jaxrs.core.internal.utils.HamcrestExtras.flagMatches;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.APPLICATION_PATH;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.CONSUMES;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.CONTEXT;
@@ -459,7 +460,7 @@ public void shouldDoNothingWhenAddingUnrelatedAnnotationOnHttpMethod() throws Co
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_TARGET_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_TARGET_ANNOTATION));
// one call, during pre-conditions
// 6 Built-in HTTP Methods + 1 custom one
assertThat(metamodel.findElements(javaProject).size(), equalTo(7));
@@ -698,7 +699,7 @@ public void shouldBecomeRootResourceWhenAddingPathAnnotation() throws CoreExcept
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_ELEMENT_KIND + F_PATH_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_ELEMENT_KIND + F_PATH_ANNOTATION));
}
@Test
@@ -728,7 +729,7 @@ public void shouldUpdateResourceWhenChangingPathAnnotationValue() throws CoreExc
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_PATH_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_PATH_ANNOTATION));
assertThat((JaxrsResource) elementChanges.get(0).getElement(), equalTo(resource));
// 6 built-in HTTP Methods + 1 Resource + 6 Resource Methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
@@ -746,7 +747,7 @@ public void shouldUpdateResourceWhenAddingConsumesAnnotation() throws CoreExcept
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_CONSUMES_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_CONSUMES_ANNOTATION));
// 6 built-in HTTP Methods + 1 Resource + 6 Resource Methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -764,7 +765,7 @@ public void shouldUpdateResourceWhenChangingConsumesAnnotationValue() throws Cor
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_CONSUMES_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_CONSUMES_ANNOTATION));
// 6 built-in HTTP Methods + 1 Resource + 6 Resource Methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -779,7 +780,7 @@ public void shouldUpdateResourceWhenRemovingConsumesAnnotation() throws CoreExce
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_CONSUMES_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_CONSUMES_ANNOTATION));
// 6 built-in HTTP Methods + 1 Resource + 6 Resource Methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -796,7 +797,7 @@ public void shouldUpdateResourceWhenAddingProducesAnnotation() throws CoreExcept
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_PRODUCES_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_PRODUCES_ANNOTATION));
// 6 built-in HTTP Methods + 1 Resource + 6 Resource Methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -814,7 +815,7 @@ public void shouldUpdateResourceWhenChangingProducesAnnotationValue() throws Cor
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_PRODUCES_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_PRODUCES_ANNOTATION));
// 6 built-in HTTP Methods + 1 Resource + 6 Resource Methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -829,7 +830,7 @@ public void shouldUpdateResourceWhenRemovingProducesAnnotation() throws CoreExce
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_PRODUCES_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_PRODUCES_ANNOTATION));
// 6 built-in HTTP Methods + 1 Resource + 6 Resource Methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -1241,7 +1242,7 @@ public void shouldBecomeSubresourceWhenRemovingPathAnnotation() throws CoreExcep
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_ELEMENT_KIND + F_PATH_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_ELEMENT_KIND + F_PATH_ANNOTATION));
// 6 built-in HTTP Methods + 1 resource + 6 methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -1359,7 +1360,7 @@ public void shouldConvertIntoSubresourceMethodWhenAddingPathAnnotation() throws
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_PATH_ANNOTATION + F_ELEMENT_KIND));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_PATH_ANNOTATION + F_ELEMENT_KIND));
// 6 built-in HTTP Methods + 1 resource + 5 methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -1375,7 +1376,7 @@ public void shouldConvertIntoResourceMethodWhenRemovingPathAnnotation() throws C
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_PATH_ANNOTATION + F_ELEMENT_KIND));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_PATH_ANNOTATION + F_ELEMENT_KIND));
// 6 built-in HTTP Methods + 1 resource + 5 methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -1391,7 +1392,7 @@ public void shouldConvertIntoSubresourceLocatorWhenRemovingHttpMethodAnnotation(
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_HTTP_METHOD_ANNOTATION + F_ELEMENT_KIND));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_HTTP_METHOD_ANNOTATION + F_ELEMENT_KIND));
// 6 built-in HTTP Methods + 1 resource + 5 methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -1424,7 +1425,7 @@ public void shouldUpdateSubresourceMethodWhenChangingPathAnnotationValue() throw
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_PATH_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_PATH_ANNOTATION));
// 6 built-in HTTP Methods + 1 resource + 6 methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -1442,7 +1443,7 @@ public void shouldUpdateResourceMethodWhenAddingConsumesAnnotation() throws Core
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_CONSUMES_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_CONSUMES_ANNOTATION));
// 6 built-in HTTP Methods + 1 resource + 6 methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -1460,7 +1461,7 @@ public void shouldUpdateResourceMethodWhenChangingConsumesAnnotationValue() thro
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_CONSUMES_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_CONSUMES_ANNOTATION));
// 6 built-in HTTP Methods + 1 resource + 6 methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -1476,7 +1477,7 @@ public void shouldUpdateResourceMethodMethodWhenRemovingConsumesAnnotation() thr
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_CONSUMES_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_CONSUMES_ANNOTATION));
// 6 built-in HTTP Methods + 1 resource + 6 methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -1494,7 +1495,7 @@ public void shouldUpdateResourceMethodWhenAddingProducesAnnotation() throws Core
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_PRODUCES_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_PRODUCES_ANNOTATION));
// 6 built-in HTTP Methods + 1 resource + 6 methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}
@@ -1512,7 +1513,7 @@ public void shouldUpdateResourceMethodWhenChangingProducesAnnotationValue() thro
// verifications
assertThat(elementChanges.size(), equalTo(1));
assertThat(elementChanges.get(0).getDeltaKind(), equalTo(CHANGED));
- assertThat(elementChanges.get(0).getFlags(), equalTo(F_PRODUCES_ANNOTATION));
+ assertThat(elementChanges.get(0).getFlags(), flagMatches(F_PRODUCES_ANNOTATION));
// 6 built-in HTTP Methods + 1 resource + 6 methods
assertThat(metamodel.findElements(javaProject).size(), equalTo(13));
}