Author: xcoulon
Date: 2011-11-22 16:07:06 -0500 (Tue, 22 Nov 2011)
New Revision: 36542
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidator.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJobTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java
Removed:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuilder.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/IMergeable.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuildJobTestCase.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/META-INF/MANIFEST.MF
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/plugin.xml
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/JBossJaxrsCorePlugin.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedListener.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJob.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElement.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsHttpMethod.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamBeanProperty.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamField.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsProvider.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsElement.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/PathParamValidationTestCase.java
Log:
Fixing
https://issues.jboss.org/browse/JBIDE-9829 (at least in the scope of a resource)
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/META-INF/MANIFEST.MF 2011-11-22
19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/META-INF/MANIFEST.MF 2011-11-22
21:07:06 UTC (rev 36542)
@@ -19,7 +19,8 @@
org.eclipse.ui.editors;bundle-version="3.7.0",
org.eclipse.core.commands;bundle-version="3.6.0",
org.eclipse.ui;bundle-version="3.7.0",
- org.eclipse.ltk.core.refactoring;bundle-version="3.5.200"
+ org.eclipse.ltk.core.refactoring;bundle-version="3.5.200",
+ org.eclipse.wst.validation;bundle-version="1.2.302";visibility:=reexport
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: javax.ws.rs,
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/plugin.xml
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/plugin.xml 2011-11-22 19:53:40 UTC (rev
36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/plugin.xml 2011-11-22 21:07:06 UTC (rev
36542)
@@ -10,7 +10,7 @@
hasNature="false"
isConfigurable="false">
<run
-
class="org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelFullBuilder">
+
class="org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuilder">
</run>
</builder>
</extension>
@@ -86,26 +86,24 @@
type="org.eclipse.core.resources.problemmarker">
</super>
</extension>
+ <extension
+ id="org.jboss.tools.ws.jaxrs.JaxrsMetamodelValidator"
+ name="JAX-RS Metamodel Validator"
+ point="org.eclipse.wst.validation.validatorV2">
+ <validator
+ build="true"
+
class="org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation.JaxrsMetamodelValidator"
+ manual="true"
+ markerId="org.jboss.tools.ws.jaxrs.metamodelMarker">
+ <include>
+ <rules>
+ <projectNature
+ id="org.jboss.tools.ws.jaxrs.nature">
+ </projectNature>
+ </rules>
+ </include>
+ </validator>
+ </extension>
-
- <!--extension
- point="org.eclipse.ui.propertyPages">
- <page
- adaptable="true"
- class="org.jboss.tools.ws.jaxrs.ui.Tapestry5SettingsPropertyPage"
- id="org.jboss.tools.ws.jaxrs.propertyPage"
- name="Tapestry5 Settings "
- objectClass="org.eclipse.core.resources.IProject">
- <enabledWhen>
- <adapt type="org.eclipse.core.resources.IProject">
- <test
- forcePluginActivation="true"
-
property="org.eclipse.wst.common.project.facet.core.projectFacet"
- value="org.jboss.tools.ws.jaxrs.projectFacet">
- </test>
- </adapt>
- </enabledWhen>
- </page>
- </extension-->
-
+
</plugin>
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/JBossJaxrsCorePlugin.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/JBossJaxrsCorePlugin.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/JBossJaxrsCorePlugin.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -36,20 +36,6 @@
public JBossJaxrsCorePlugin() {
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
- * )
- */
- @Override
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- registerListeners();
- }
-
/**
*
*/
@@ -72,6 +58,20 @@
super.stop(context);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ registerListeners();
+ }
+
/**
*
*/
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedListener.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedListener.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedListener.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -8,6 +8,7 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.IElementChangedListener;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
/** Listens to all change events (Java elements and resources) and triggers a new
* job for each change.<br>
@@ -37,7 +38,6 @@
Job job = new JaxrsMetamodelBuildJob(event);
job.schedule();
}
-
}
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -129,7 +129,8 @@
return Collections.emptyList();
}
- /** Process the addition of a Java Element (can be a JavaProject or a Java
+ /**
+ * Process the addition of a Java Element (can be a JavaProject or a Java
* Package Fragment root).
*
* @param scope
@@ -140,7 +141,8 @@
* the progress monitor
* @return a list of impacts (ie, JAX-RS elements that where created)
* @throws CoreException
- * in case of underlying exception */
+ * in case of underlying exception
+ */
private List<JaxrsElementChangedEvent> processAddition(final IJavaElement scope,
final JaxrsMetamodel metamodel,
final IProgressMonitor progressMonitor) throws CoreException {
final List<JaxrsElementChangedEvent> impacts = new
ArrayList<JaxrsElementChangedEvent>();
@@ -176,9 +178,11 @@
return impacts;
}
- /** @param type
+ /**
+ * @param type
* @param progressMonitor
- * @throws CoreException */
+ * @throws CoreException
+ */
private List<JaxrsElementChangedEvent> processAddition(final IType javaType, final
CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws
CoreException {
final List<JaxrsElementChangedEvent> impacts = new
ArrayList<JaxrsElementChangedEvent>();
@@ -210,9 +214,11 @@
return impacts;
}
- /** @param type
+ /**
+ * @param type
* @param progressMonitor
- * @throws CoreException */
+ * @throws CoreException
+ */
private List<JaxrsElementChangedEvent> processAddition(final IMethod javaMethod,
final CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws
CoreException {
final List<JaxrsElementChangedEvent> impacts = new
ArrayList<JaxrsElementChangedEvent>();
@@ -223,9 +229,11 @@
return impacts;
}
- /** @param javaAnnotation
+ /**
+ * @param javaAnnotation
* @param progressMonitor
- * @throws CoreException */
+ * @throws CoreException
+ */
private List<JaxrsElementChangedEvent> processAddition(final IAnnotation
javaAnnotation, final CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws
CoreException {
final List<JaxrsElementChangedEvent> impacts = new
ArrayList<JaxrsElementChangedEvent>();
@@ -247,27 +255,31 @@
return impacts;
}
- /** @param javaAnnotation
+ /**
+ * @param javaAnnotation
* @param progressMonitor
- * @throws CoreException */
+ * @throws CoreException
+ */
// FIXME : same code as method processAddition(annotation, etc..) ?!?
private List<JaxrsElementChangedEvent> processChange(final IAnnotation
javaAnnotation, final CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws
CoreException {
final List<JaxrsElementChangedEvent> impacts = new
ArrayList<JaxrsElementChangedEvent>();
Annotation annotation = JdtUtils.resolveAnnotation(javaAnnotation, ast);
- final IJaxrsElement<?> jaxrsElement = metamodel.getElement(annotation);
- if (jaxrsElement == null) {
- final List<IJaxrsElement<?>> elements =
factory.createElement(javaAnnotation, ast, metamodel);
- for (IJaxrsElement<?> element : elements) {
- if (element != null) {
- impacts.add(new JaxrsElementChangedEvent(element, ADDED));
+ if (annotation != null) {
+ final IJaxrsElement<?> jaxrsElement = metamodel.getElement(annotation);
+ if (jaxrsElement == null) {
+ final List<IJaxrsElement<?>> elements =
factory.createElement(javaAnnotation, ast, metamodel);
+ for (IJaxrsElement<?> element : elements) {
+ if (element != null) {
+ impacts.add(new JaxrsElementChangedEvent(element, ADDED));
+ }
}
+ } else {
+ final int flags = jaxrsElement.addOrUpdateAnnotation(annotation);
+ if (flags > 0) {
+ impacts.add(new JaxrsElementChangedEvent(jaxrsElement, CHANGED, flags));
+ }
}
- } else {
- final int flags = jaxrsElement.addOrUpdateAnnotation(annotation);
- if (flags > 0) {
- impacts.add(new JaxrsElementChangedEvent(jaxrsElement, CHANGED, flags));
- }
}
return impacts;
}
@@ -286,10 +298,12 @@
return impacts;
}
- /** @param element
+ /**
+ * @param element
* @param progressMonitor
* @return
- * @throws CoreException */
+ * @throws CoreException
+ */
private List<JaxrsElementChangedEvent> processRemoval(IPackageFragmentRoot
packageFragmentRoot,
final JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws CoreException
{
final List<JaxrsElementChangedEvent> impacts = new
ArrayList<JaxrsElementChangedEvent>();
@@ -301,11 +315,13 @@
return impacts;
}
- /** @param element
+ /**
+ * @param element
* @param ast
* @param progressMonitor
* @return
- * @throws CoreException */
+ * @throws CoreException
+ */
private List<JaxrsElementChangedEvent> processRemoval(ICompilationUnit
compilationUnit, CompilationUnit ast,
final JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws CoreException
{
final List<JaxrsElementChangedEvent> impacts = new
ArrayList<JaxrsElementChangedEvent>();
@@ -317,9 +333,11 @@
return impacts;
}
- /** @param javaType
+ /**
+ * @param javaType
* @param progressMonitor
- * @throws CoreException */
+ * @throws CoreException
+ */
private List<JaxrsElementChangedEvent> processRemoval(final IType javaType, final
CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws
CoreException {
final List<JaxrsElementChangedEvent> impacts = new
ArrayList<JaxrsElementChangedEvent>();
@@ -332,9 +350,11 @@
return impacts;
}
- /** @param javaAnnotation
+ /**
+ * @param javaAnnotation
* @param progressMonitor
- * @throws CoreException */
+ * @throws CoreException
+ */
private List<JaxrsElementChangedEvent> processRemoval(final IAnnotation
javaAnnotation, final CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws
CoreException {
final List<JaxrsElementChangedEvent> impacts = new
ArrayList<JaxrsElementChangedEvent>();
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJob.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJob.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJob.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -7,7 +7,6 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -34,21 +33,18 @@
private final IJavaProject javaProject;
- private final int kind;
-
private final Object event;
- public JaxrsMetamodelBuildJob(final IProject project) throws CoreException {
- super("Full JAX-RS Metamodel build for " + project.getName() +
"...");
+ public JaxrsMetamodelBuildJob(final IProject project, final boolean requiresReset)
throws CoreException {
+ super("JAX-RS Metamodel build for " + project.getName() + "...");
this.javaProject = JavaCore.create(project);
JavaElementDelta delta = new JavaElementDelta(javaProject);
delta.added();
this.event = new ElementChangedEvent(delta, ElementChangedEvent.POST_RECONCILE);
- this.kind = IncrementalProjectBuilder.FULL_BUILD;
final JaxrsMetamodel metamodel = JaxrsMetamodel.get(javaProject);
if (metamodel == null) {
JaxrsMetamodel.create(javaProject);
- } else {
+ } else if(requiresReset) {
metamodel.reset();
}
}
@@ -57,14 +53,12 @@
super("Incremental JAX-RS Metamodel build..."); //$NON-NLS-1$
this.event = event;
this.javaProject = JavaCore.create(event.getDelta().getResource().getProject());
- this.kind = IncrementalProjectBuilder.INCREMENTAL_BUILD;
}
public JaxrsMetamodelBuildJob(final ElementChangedEvent event) {
super("Incremental JAX-RS Metamodel build..."); //$NON-NLS-1$
this.javaProject = event.getDelta().getElement().getJavaProject();
this.event = event;
- this.kind = IncrementalProjectBuilder.INCREMENTAL_BUILD;
}
@Override
Copied:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java
(from rev 36520,
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuilder.java)
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -0,0 +1,160 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Coulon - Initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder;
+
+import java.lang.reflect.Field;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.QualifiedName;
+import org.jboss.tools.ws.jaxrs.core.JBossJaxrsCorePlugin;
+import org.jboss.tools.ws.jaxrs.core.configuration.ProjectNatureUtils;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
+
+/** The JAX-RS Metamodel builder. Invoked when a full build or an incremental
+ * build is triggered on a project on which the JAX-RS nature is installed.
+ *
+ * This builder is responsible of the creation and update of the JAX-RS
+ * Metamodel which is kept in the project's session properties.
+ *
+ * @author xcoulon */
+public class JaxrsMetamodelBuilder extends IncrementalProjectBuilder {
+
+ /** The number of steps to fully build the JAX-RS Metamodel. */
+ private static final int FULL_BUILD_STEPS = 100;
+
+ /** The standard 'Java type' marker type. */
+ public static final String JAVA_PROBLEM = "org.eclipse.jdt.core.problem";
+
+ /** The custom 'JAX-RS Problem' marker type. */
+ public static final String JAXRS_PROBLEM =
"org.jboss.tools.ws.jaxrs.metamodelMarker";
+
+ /** The Java element change listener name. */
+ public static final QualifiedName JAXRS_ELEMENT_CHANGE_LISTENER_NAME = new
QualifiedName(
+ JBossJaxrsCorePlugin.PLUGIN_ID, "jaxrsPostReconcileListener");
+
+ // TODO : add support for cancellation
+ // TODO : report build failed
+ /** {@inheritDoc} */
+ @Override
+ protected final IProject[] build(final int kind, @SuppressWarnings("rawtypes")
final Map args,
+ final IProgressMonitor monitor) throws CoreException {
+ IProject project = getProject();
+ if (!ProjectNatureUtils.isProjectNatureInstalled(project,
ProjectNatureUtils.JAXRS_NATURE_ID)) {
+ Logger.warn("Project '" + project.getName() + "' is not a
JAX-RS project.");
+ return null;
+ }
+ logBuild(kind, args, project);
+ switch (kind) {
+ case CLEAN_BUILD:
+ case FULL_BUILD:
+ build(project, true, monitor);
+ break;
+ case AUTO_BUILD:
+ case INCREMENTAL_BUILD:
+ //if (JaxrsMetamodel.get(getProject()) == null) {
+ build(getProject(), false, monitor);
+ //}
+ break;
+ default:
+ break;
+ }
+ return null;
+ }
+
+ /** Checks if the running operation was cancelled by the user, as reported by
+ * the progress monitor.
+ *
+ * @param monitor
+ * the progress monitor. */
+ // @see
http://www.eclipse.org/articles/Article-Builders/builders.html
+ protected final void checkCancel(final IProgressMonitor monitor) {
+ if (monitor.isCanceled()) {
+ forgetLastBuiltState(); // not always necessary
+ throw new OperationCanceledException();
+ }
+ }
+
+
+
+ /** Performs a full build of the project's JAX-RS Metamodel. This method has
+ * a public visibility so that it can be called from other components
+ *
+ * @param project
+ * the project
+ * @param monitor
+ * the progress monitor */
+ private void build(final IProject project, final boolean requiresReset, final
IProgressMonitor monitor) {
+ long startTime = new Date().getTime();
+ try {
+ monitor.beginTask("Building JAX-RS metamodel...", FULL_BUILD_STEPS);
+ JaxrsMetamodelBuildJob buildJob = new JaxrsMetamodelBuildJob(project, requiresReset);
+ buildJob.schedule();
+ // wait until the job is finished
+ buildJob.join();
+ } catch (InterruptedException e) {
+ Logger.error("Error while building the JAX-RS Metamodel for project " +
project.getName(), e);
+ } catch (CoreException e) {
+ Logger.error("Error while building the JAX-RS Metamodel for project " +
project.getName(), e);
+ } finally {
+ long endTime = new Date().getTime();
+ Logger.debug("JAX-RS Metamodel for project '" + project.getName() +
"' fully built in "
+ + (endTime - startTime) + "ms.");
+ monitor.done();
+ }
+ }
+
+ /** Trace the kind of build in the log.
+ *
+ * @param kind
+ * the build kind
+ * @param args
+ * @param project
+ * the project being built */
+ private void logBuild(final int kind, @SuppressWarnings("rawtypes") final Map
args, final IProject project) {
+ StringBuilder sb = new StringBuilder("'");
+ for (Field field : IncrementalProjectBuilder.class.getDeclaredFields()) {
+ String name = field.getName();
+ int value;
+ try {
+ value = field.getInt(this);
+ if (value == kind) {
+ sb.append(name.toLowerCase().replace('_', ' '));
+ }
+ } catch (IllegalArgumentException e) {
+ sb.append("*Unknow build*");
+ } catch (IllegalAccessException e) {
+ sb.append("*Unknow build*");
+ }
+ }
+ sb.append("' on project ").append(project.getName());
+ if (args != null && !args.isEmpty()) {
+ sb.append(" (");
+ for (Iterator<?> iterator = args.keySet().iterator(); iterator.hasNext();) {
+ Object key = iterator.next();
+ sb.append(key).append("=").append(args.get(key));
+ if (iterator.hasNext()) {
+ sb.append(", ");
+ }
+ }
+ sb.append(")");
+ }
+ Logger.debug(sb.toString());
+ }
+
+}
Deleted:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuilder.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuilder.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuilder.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -1,206 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Xavier Coulon - Initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder;
-
-import java.lang.reflect.Field;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.QualifiedName;
-import org.jboss.tools.ws.jaxrs.core.JBossJaxrsCorePlugin;
-import org.jboss.tools.ws.jaxrs.core.configuration.ProjectNatureUtils;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
-import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
-
-/** The JAX-RS Metamodel builder. Invoked when a full build or an incremental
- * build is triggered on a project on which the JAX-RS nature is installed.
- *
- * This builder is responsible of the creation and update of the JAX-RS
- * Metamodel which is kept in the project's session properties.
- *
- * @author xcoulon */
-public class JaxrsMetamodelFullBuilder extends IncrementalProjectBuilder {
-
- /** The number of steps to fully build the JAX-RS Metamodel. */
- private static final int FULL_BUILD_STEPS = 100;
-
- /** The standard 'Java type' marker type. */
- public static final String JAVA_PROBLEM = "org.eclipse.jdt.core.problem";
-
- /** The custom 'JAX-RS Problem' marker type. */
- public static final String JAXRS_PROBLEM =
"org.jboss.tools.ws.jaxrs.metamodelMarker";
-
- /** The Java element change listener name. */
- public static final QualifiedName JAXRS_ELEMENT_CHANGE_LISTENER_NAME = new
QualifiedName(
- JBossJaxrsCorePlugin.PLUGIN_ID, "jaxrsPostReconcileListener");
-
- // TODO : add support for cancellation
- // TODO : report build failed
- /** {@inheritDoc} */
- @Override
- protected final IProject[] build(final int kind, @SuppressWarnings("rawtypes")
final Map args,
- final IProgressMonitor monitor) throws CoreException {
- IProject project = getProject();
- if (!ProjectNatureUtils.isProjectNatureInstalled(project,
ProjectNatureUtils.JAXRS_NATURE_ID)) {
- Logger.warn("Project '" + project.getName() + "' is not a
JAX-RS project.");
- return null;
- }
- logBuild(kind, args, project);
- switch (kind) {
- case CLEAN_BUILD:
- case FULL_BUILD:
- fullBuild(project, monitor);
- break;
- case AUTO_BUILD:
- case INCREMENTAL_BUILD:
- if (JaxrsMetamodel.get(getProject()) == null) {
- fullBuild(getProject(), monitor);
- }
-
- /*
- * else { IResourceDelta delta = getDelta(project);
- * incrementalBuild(project, delta, monitor); }
- */
- break;
- default:
- break;
- }
- return null;
- }
-
- /** Checks if the running operation was cancelled by the user, as reported by
- * the progress monitor.
- *
- * @param monitor
- * the progress monitor. */
- // @see
http://www.eclipse.org/articles/Article-Builders/builders.html
- protected final void checkCancel(final IProgressMonitor monitor) {
- if (monitor.isCanceled()) {
- forgetLastBuiltState(); // not always necessary
- throw new OperationCanceledException();
- }
- }
-
- /** Performs and incremental build on the given project, using the given
- * delta.
- *
- * @param project
- * the project
- * @param delta
- * the resource delta
- * @param monitor
- * the progress monitor (optional)
- * @throws CoreException
- * in case of underlying exception */
- @SuppressWarnings("unused")
- private void incrementalBuild(final IProject project, final IResourceDelta delta, final
IProgressMonitor monitor)
- throws CoreException {
- if (delta == null) {
- return;
- }
- // delta.accept(this);
- }
-
- // @Override
- // public final boolean visit(final IResourceDelta delta) throws
- // CoreException {
- // IResource resource = delta.getResource();
- // if (resource.getType() == IResource.FILE &&
- // getProject().getFullPath().isPrefixOf(resource.getFullPath())
- // && resource.getFullPath().getFileExtension().equals("java")) {
- // JaxrsMetamodel jaxrsMetamodel =
- // JaxrsMetamodel.get(resource.getProject());
- // if (jaxrsMetamodel == null) {
- // Logger.warn("No Metamodel found for project " +
- // resource.getProject().getName());
- // return false;
- // }
- // logDelta(delta);
- // jaxrsMetamodel.applyDelta(delta, new NullProgressMonitor());
- // jaxrsMetamodel.validate(new NullProgressMonitor());
- // }
- // return true;
- // }
-
- /** Performs a full build of the project's JAX-RS Metamodel. This method has
- * a public visibility so that it can be called from other components
- *
- * @param project
- * the project
- * @param monitor
- * the progress monitor */
- private void fullBuild(final IProject project, final IProgressMonitor monitor) {
- long startTime = new Date().getTime();
- try {
- monitor.beginTask("Building JAX-RS metamodel...", FULL_BUILD_STEPS);
- JaxrsMetamodelBuildJob fullBuildJob = new JaxrsMetamodelBuildJob(project);
- fullBuildJob.schedule();
- // wait until the job is finished
- fullBuildJob.join();
- } catch (InterruptedException e) {
- Logger.error("Error while building the JAX-RS Metamodel for project " +
project.getName(), e);
- } catch (CoreException e) {
- Logger.error("Error while building the JAX-RS Metamodel for project " +
project.getName(), e);
- } finally {
- long endTime = new Date().getTime();
- Logger.debug("JAX-RS Metamodel for project '" + project.getName() +
"' fully built in "
- + (endTime - startTime) + "ms.");
- monitor.done();
- }
- }
-
- /** Trace the kind of build in the log.
- *
- * @param kind
- * the build kind
- * @param args
- * @param project
- * the project being built */
- private void logBuild(final int kind, @SuppressWarnings("rawtypes") final Map
args, final IProject project) {
- StringBuilder sb = new StringBuilder("'");
- for (Field field : IncrementalProjectBuilder.class.getDeclaredFields()) {
- String name = field.getName();
- int value;
- try {
- value = field.getInt(this);
- if (value == kind) {
- sb.append(name.toLowerCase().replace('_', ' '));
- }
- } catch (IllegalArgumentException e) {
- sb.append("*Unknow build*");
- } catch (IllegalAccessException e) {
- sb.append("*Unknow build*");
- }
- }
- sb.append("' on project ").append(project.getName());
- if (args != null && !args.isEmpty()) {
- sb.append(" (");
- for (Iterator<?> iterator = args.keySet().iterator(); iterator.hasNext();) {
- Object key = iterator.next();
- sb.append(key).append("=").append(args.get(key));
- if (iterator.hasNext()) {
- sb.append(", ");
- }
- }
- sb.append(")");
- }
- Logger.debug(sb.toString());
- }
-
-}
Deleted:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/IMergeable.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/IMergeable.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/IMergeable.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Xavier Coulon - Initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
-
-import java.util.Set;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.jboss.tools.ws.jaxrs.core.metamodel.InvalidModelElementException;
-
-public interface IMergeable<T> {
-
- /**
- * Merge of the current JAX-RS element with the java element given in
- * parameter.
- *
- * @param element
- * the java element that changed
- * @param progressMonitor
- * the progress monitor
- * @return a list of changes
- * @throws InvalidModelElementException
- * in case of underlying exception
- * @throws CoreException
- * in case of underlying exception
- */
- abstract Set<EnumElementChange> merge(T element, IProgressMonitor
progressMonitor)
- throws InvalidModelElementException, CoreException;
-
-}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -10,14 +10,17 @@
******************************************************************************/
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IType;
+import org.eclipse.wst.validation.ValidatorMessage;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsApplication;
-import org.jboss.tools.ws.jaxrs.core.metamodel.InvalidModelElementException;
/** The optional '@Application' annotation, used to designate the base context
* URI of the root resources.
@@ -83,14 +86,14 @@
*/
@Override
- public void validate(IProgressMonitor progressMonitor) throws CoreException {
- // TODO Auto-generated method stub
-
+ public EnumKind getKind() {
+ return EnumKind.APPLICATION;
}
@Override
- public EnumKind getKind() {
- return EnumKind.APPLICATION;
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ return messages;
}
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElement.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElement.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElement.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -38,6 +38,7 @@
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.JavaModelException;
@@ -47,7 +48,6 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
-import org.jboss.tools.ws.jaxrs.core.metamodel.InvalidModelElementException;
/** Base class for all elements in the JAX-RS Metamodel.
*
@@ -55,7 +55,7 @@
*
* @param <T>
* the underlying Java type managed by the JAX-RS ElementKind. */
-public abstract class JaxrsElement<T extends IMember> implements
IJaxrsElement<T>, IValidable {
+public abstract class JaxrsElement<T extends IMember> implements
IJaxrsElement<T> {
/** The associated metamodel. */
private final JaxrsMetamodel metamodel;
@@ -146,6 +146,10 @@
public List<Annotation> getAnnotations() {
return Collections.unmodifiableList(new
ArrayList<Annotation>(annotations.values()));
}
+
+ IResource getResource() {
+ return this.javaElement.getResource();
+ }
@Override
public int addOrUpdateAnnotation(final Annotation annotation) {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsHttpMethod.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsHttpMethod.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsHttpMethod.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -11,27 +11,36 @@
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.ws.rs.HttpMethod;
-import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.jdt.core.IType;
+import org.eclipse.wst.validation.ValidatorMessage;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuilder;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
-/** A request method designator is a runtime annotation that is annotated with
+/**
+ * A request method designator is a runtime annotation that is annotated with
* the @HttpMethod annotation. JAX-RS defines a set of request method
* designators for the common HTTP resourceMethods: @GET, @POST, @PUT, @DELETE,
*
* @HEAD. Users may define their own custom request method designators including
* alternate designators for the common HTTP resourceMethods.
*
- * @author xcoulon */
+ * @author xcoulon
+ */
public class JaxrsHttpMethod extends JaxrsElement<IType> implements
IJaxrsHttpMethod {
- /** A Simple sorter for HTTP Verbs: the preferred order is
- * GET/POST/PUT/DELETE/HEAD/OPTION. Other/custom Verbs come after. */
+ /**
+ * A Simple sorter for HTTP Verbs: the preferred order is
+ * GET/POST/PUT/DELETE/HEAD/OPTION. Other/custom Verbs come after.
+ */
private enum HttpVerbSortEnum {
/** GET Verb. */
GET(0),
@@ -51,10 +60,12 @@
/** the order rank. */
private int rank = 0;
- /** The constructor.
+ /**
+ * The constructor.
*
* @param r
- * the rank */
+ * the rank
+ */
HttpVerbSortEnum(final int r) {
this.rank = r;
}
@@ -64,12 +75,14 @@
return rank;
}
- /** Converter from literal to enum value. If no direct match, 'OTHER' is
+ /**
+ * Converter from literal to enum value. If no direct match, 'OTHER' is
* returned.
*
* @param verb
* the HTTP verb
- * @return the corresponding value in the enum. */
+ * @return the corresponding value in the enum.
+ */
static HttpVerbSortEnum from(final String verb) {
for (HttpVerbSortEnum e : HttpVerbSortEnum.values()) {
if (verb.equals(e.toString())) {
@@ -89,12 +102,28 @@
return EnumElementKind.HTTP_METHOD;
}
- /** {@inheritDoc} */
@Override
- public void validate(IProgressMonitor progressMonitor) {
-
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ final Annotation annotation = getHttpMethodAnnotation();
+ if(annotation == null) {
+
+ } else {
+ final String httpValue = annotation.getValue("value");
+ if(httpValue == null || httpValue.isEmpty()) {
+ final ValidatorMessage message = ValidatorMessage.create("HTTP Verb should not
be empty", getResource());
+ message.setAttribute(IMarker.MARKER, JaxrsMetamodelBuilder.JAXRS_PROBLEM);
+ message.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ message.setAttribute(IMarker.CHAR_START, annotation.getRegion().getOffset());
+ message.setAttribute(IMarker.CHAR_END, annotation.getRegion().getOffset() +
annotation.getRegion().getLength());
+ messages.add(message);
+ }
+ }
+ return messages;
}
+
+
/*
* (non-Javadoc)
*
@@ -111,9 +140,11 @@
return null;
}
- /** @param httpVerb
+ /**
+ * @param httpVerb
* the httpVerb to set
- * @return */
+ * @return
+ */
public boolean setHttpMethodAnnotation(final Annotation httpVerbAnnotation) {
return getHttpMethodAnnotation().update(httpVerbAnnotation);
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -24,6 +24,7 @@
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.QualifiedName;
@@ -47,14 +48,18 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResource;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
-/** Manages all the JAX-RS domain classes of the JAX-RS Metamodel. Not only a
+/**
+ * Manages all the JAX-RS domain classes of the JAX-RS Metamodel. Not only a
* POJO, but also provides business services.
*
- * @author xcoulon */
+ * @author xcoulon
+ */
public class JaxrsMetamodel implements IJaxrsMetamodel {
- /** The qualified name of the metamodel when stored in the project session
- * properties. */
+ /**
+ * The qualified name of the metamodel when stored in the project session
+ * properties.
+ */
public static final QualifiedName METAMODEL_QUALIFIED_NAME = new
QualifiedName(JBossJaxrsCorePlugin.PLUGIN_ID,
"metamodel");
@@ -64,17 +69,23 @@
/** The Service URI. Default is "/" */
private String serviceUri = "/";
- /** All the subclasses of <code>javax.ws.rs.core.Application</code>,
although
- * there should be only one. */
+ /**
+ * All the subclasses of <code>javax.ws.rs.core.Application</code>,
although
+ * there should be only one.
+ */
private final List<IJaxrsApplication> applications = new
ArrayList<IJaxrsApplication>();
- /** All the resources (both rootresources and subresources) available in the
- * service , indexed by their associated java type fully qualified name. */
+ /**
+ * All the resources (both rootresources and subresources) available in the
+ * service , indexed by their associated java type fully qualified name.
+ */
private final List<IJaxrsResource> resources = new
ArrayList<IJaxrsResource>();
- /** The available providers (classes which implement MessageBodyWriter<T>,
+ /**
+ * The available providers (classes which implement MessageBodyWriter<T>,
* MessageBodyReader<T> or ExceptionMapper<T>), , indexed by their
- * associated java type fully qualified name. */
+ * associated java type fully qualified name.
+ */
private final List<IJaxrsProvider> providers = new
ArrayList<IJaxrsProvider>();
/** The HTTP ResourceMethod elements container. */
@@ -86,12 +97,14 @@
/** the endpoints, built from the resource methods. */
private final List<IJaxrsEndpoint> endpoints = new
ArrayList<IJaxrsEndpoint>();
- /** Full constructor.
+ /**
+ * Full constructor.
*
* @param javaProject
* the enclosing java project
* @throws CoreException
- * in case of underlying exception */
+ * in case of underlying exception
+ */
private JaxrsMetamodel(final IJavaProject javaProject) throws CoreException {
this.javaProject = javaProject;
}
@@ -107,13 +120,15 @@
return javaProject;
}
- /** Accessor to the metamodel from the given project's session properties.
+ /**
+ * Accessor to the metamodel from the given project's session properties.
*
* @param javaProject
* the java project
* @return the metamodel or null if none was found
* @throws CoreException
- * in case of underlying exception */
+ * in case of underlying exception
+ */
public static JaxrsMetamodel create(final IJavaProject javaProject) throws CoreException
{
if (javaProject == null || javaProject.getProject() == null) {
return null;
@@ -124,13 +139,15 @@
return metamodel;
}
- /** Accessor to the metamodel from the given project's session properties.
+ /**
+ * Accessor to the metamodel from the given project's session properties.
*
* @param javaProject
* the java project
* @return the metamodel or null if none was found
* @throws CoreException
- * in case of underlying exception */
+ * in case of underlying exception
+ */
public static JaxrsMetamodel get(final IJavaProject javaProject) throws CoreException {
if (javaProject == null || javaProject.getProject() == null) {
return null;
@@ -141,19 +158,23 @@
return metamodel;
}
- /** Accessor to the metamodel from the given project's session properties.
+ /**
+ * Accessor to the metamodel from the given project's session properties.
*
* @param project
* the project
* @return the metamodel or null if none was found
* @throws CoreException
- * in case of underlying exception */
+ * in case of underlying exception
+ */
public static JaxrsMetamodel get(final IProject project) throws CoreException {
return get(JavaCore.create(project));
}
- /** @throws CoreException
- * in case of underlying exception */
+ /**
+ * @throws CoreException
+ * in case of underlying exception
+ */
public final void remove() throws CoreException {
Logger.debug("JAX-RS Metamodel removed for project " +
javaProject.getElementName());
javaProject.getProject().setSessionProperty(METAMODEL_QUALIFIED_NAME, null);
@@ -173,20 +194,13 @@
this.resources.add((IJaxrsResource) element);
break;
/*
- * case RESOURCE_FIELD:
- * final JaxrsResource fieldParent = findResource((IType)
- * element.getJavaElement().getParent());
- * if (fieldParent != null) {
- * fieldParent.addField((JaxrsParamField) element);
- * }
- * break;
- * case RESOURCE_METHOD:
- * final JaxrsResource methodParent = findResource((IType)
- * element.getJavaElement().getParent());
- * if (methodParent != null) {
- * methodParent.addMethod((IJaxrsResourceMethod) element);
- * }
- * break;
+ * case RESOURCE_FIELD: final JaxrsResource fieldParent =
+ * findResource((IType) element.getJavaElement().getParent()); if
+ * (fieldParent != null) { fieldParent.addField((JaxrsParamField)
+ * element); } break; case RESOURCE_METHOD: final JaxrsResource
+ * methodParent = findResource((IType)
+ * element.getJavaElement().getParent()); if (methodParent != null) {
+ * methodParent.addMethod((IJaxrsResourceMethod) element); } break;
*/
}
indexElement(element);
@@ -196,9 +210,12 @@
protected void indexElement(final IJaxrsElement<?> element) {
final IJavaElement javaElement = element.getJavaElement();
indexElement(element, javaElement);
- indexElement(element, JdtUtils.getCompilationUnit(javaElement));
- indexElement(element, JdtUtils.getPackageFragmentRoot(javaElement));
- indexElement(element, javaElement.getJavaProject());
+ // index element that are bound to a java type, not a field or a method
+ if (element.getJavaElement().getElementType() == IJavaElement.TYPE) {
+ indexElement(element, JdtUtils.getCompilationUnit(javaElement));
+ indexElement(element, JdtUtils.getPackageFragmentRoot(javaElement));
+ indexElement(element, javaElement.getJavaProject());
+ }
for (Annotation annotation : element.getAnnotations()) {
indexElement(element, annotation);
}
@@ -210,8 +227,10 @@
}
}
- /** @param jaxrsElement
- * @param javaElement */
+ /**
+ * @param jaxrsElement
+ * @param javaElement
+ */
@SuppressWarnings("unchecked")
private void indexElement(final IJaxrsElement<?> jaxrsElement, final IJavaElement
javaElement) {
if (javaElement == null) {
@@ -260,21 +279,17 @@
return Collections.unmodifiableList(providers);
}
- /** @param field
+ /**
+ * @param field
* @param iJavaElement
- * @return
- * private JaxrsResource findResource(final IType javaElement) {
+ * @return private JaxrsResource findResource(final IType javaElement) {
* final String targetIdentifier =
- * javaElement.getHandleIdentifier();
- * for (IJaxrsResource resource : resources) {
- * final String resourceIdentifier =
- * resource.getJavaElement().getHandleIdentifier();
- * if (resourceIdentifier.equals(targetIdentifier)) {
- * return (JaxrsResource) resource;
- * }
- * }
- * return null;
- * } */
+ * javaElement.getHandleIdentifier(); for (IJaxrsResource resource :
+ * resources) { final String resourceIdentifier =
+ * resource.getJavaElement().getHandleIdentifier(); if
+ * (resourceIdentifier.equals(targetIdentifier)) { return
+ * (JaxrsResource) resource; } } return null; }
+ */
@Override
public final List<IJaxrsHttpMethod> getAllHttpMethods() {
@@ -290,10 +305,12 @@
return serviceUri;
}
- /** Sets the Base URI for the URI mapping templates.
+ /**
+ * Sets the Base URI for the URI mapping templates.
*
* @param uri
- * the serviceUri to set */
+ * the serviceUri to set
+ */
public final void setServiceUri(final String uri) {
// remove trailing "*" character, if present.
if (uri.endsWith("*")) {
@@ -303,13 +320,15 @@
}
}
- /** Returns the JAX-RS ElementKind associated with the given java element.
+ /**
+ * Returns the JAX-RS ElementKind associated with the given java element.
*
* @param element
* the underlying java element (can be IType or IMethod)
* @return the associated JAX-RS element, or null if none found
* @throws JavaModelException
- * in case of underlying exception */
+ * in case of underlying exception
+ */
public final IJaxrsElement<?> find(final IJavaElement element) throws
JavaModelException {
switch (element.getElementType()) {
case IJavaElement.TYPE:
@@ -322,7 +341,8 @@
return null;
}
- /** Report errors from the given markers into the JAX-RS element(s)
+ /**
+ * Report errors from the given markers into the JAX-RS element(s)
* associated with the given compiltation unit.
*
* @param compilationUnit
@@ -331,7 +351,8 @@
* the markers
* @return true if errors were found and reported, false otherwise
* @throws JavaModelException
- * in case of underlying exception */
+ * in case of underlying exception
+ */
public final boolean reportErrors(final ICompilationUnit compilationUnit, final
IMarker[] markers)
throws JavaModelException {
boolean hasErrors = false;
@@ -350,11 +371,13 @@
return hasErrors;
}
- /** Resets this metamodel for further re-use (ie, before a new 'full/clean'
+ /**
+ * Resets this metamodel for further re-use (ie, before a new 'full/clean'
* build). Keeping the same instance of Metamodel in the project's session
* properties is a convenient thing, especially on the UI side, where some
* caching system is use to maintain the state of nodes in the Common
- * Navigator (framework). */
+ * Navigator (framework).
+ */
public void reset() {
Logger.debug("Reseting the JAX-RS Metamodel fpr project {}",
this.javaProject.getElementName());
this.applications.clear();
@@ -364,11 +387,13 @@
this.elementsIndex.clear();
}
- /** @param annotation
+ /**
+ * @param annotation
* @param metamodel
* @param annotationName
* @return
- * @throws CoreException */
+ * @throws CoreException
+ */
public IJaxrsHttpMethod getHttpMethod(final String annotationName) throws CoreException
{
IType annotationType = JdtUtils.resolveType(annotationName, javaProject, new
NullProgressMonitor());
if (annotationType != null) {
@@ -382,6 +407,9 @@
@Override
public IJaxrsElement<?> getElement(IJavaElement element) {
+ if (element == null) {
+ return null;
+ }
final String handleIdentifier = element.getHandleIdentifier();
final Set<IJaxrsElement<?>> elements =
elementsIndex.get(handleIdentifier);
if (elements == null || elements.isEmpty()) {
@@ -423,10 +451,12 @@
return elements;
}
- /** Remove the given JAX-RS Resource from the metamodel.
+ /**
+ * Remove the given JAX-RS Resource from the metamodel.
*
* @param resource
- * @return true if the resource was actually removed, false otherwise. */
+ * @return true if the resource was actually removed, false otherwise.
+ */
public void remove(IJaxrsElement<?> element) {
if (element == null) {
return;
@@ -476,4 +506,9 @@
return true;
}
+ public IJaxrsElement<?> getElement(IResource resource) {
+
+ return null;
+ }
+
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamBeanProperty.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamBeanProperty.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamBeanProperty.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -3,9 +3,11 @@
*/
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.wst.validation.ValidatorMessage;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
@@ -27,10 +29,12 @@
}
@Override
- public void validate(IProgressMonitor progressMonitor) throws CoreException {
-
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ return messages;
}
+
@Override
public EnumKind getKind() {
return null;
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamField.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamField.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamField.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -3,6 +3,7 @@
*/
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
+import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.DefaultValue;
@@ -10,9 +11,8 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IField;
+import org.eclipse.wst.validation.ValidatorMessage;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
@@ -58,10 +58,12 @@
}
@Override
- public void validate(IProgressMonitor progressMonitor) throws CoreException {
-
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ return messages;
}
+
@Override
public EnumKind getKind() {
if (getPathParamAnnotation() != null) {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsProvider.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsProvider.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsProvider.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -11,14 +11,17 @@
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IType;
+import org.eclipse.wst.validation.ValidatorMessage;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsProvider;
-import org.jboss.tools.ws.jaxrs.core.metamodel.InvalidModelElementException;
/** JAX-RS Provider class Providers *must* implement MessageBodyReader,
* MessageBodyWriter or ExceptionMapper Providers *may* be annotated with
@@ -50,7 +53,7 @@
* @return
* @throws InvalidModelElementException
* @throws CoreException */
- public JaxrsProvider build(IProgressMonitor progressMonitor) throws
InvalidModelElementException, CoreException {
+ public JaxrsProvider build(IProgressMonitor progressMonitor) throws CoreException {
JaxrsProvider provider = new JaxrsProvider(this);
// provider.merge(javaType, progressMonitor);
return provider;
@@ -119,12 +122,13 @@
* entry.getKey()); addProviderKind(entry.getKey(),
* entry.getValue(), mediaTypes); } } return changes; } */
- /** {@inheritDoc} */
@Override
- public void validate(IProgressMonitor progressMonitor) {
-
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ return messages;
}
+
@Override
public EnumKind getKind() {
// TODO Auto-generated method stub
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -23,13 +23,10 @@
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
-import
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelFullBuilder;
-import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
+import org.eclipse.wst.validation.ValidatorMessage;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
@@ -143,30 +140,7 @@
return EnumKind.UNDEFINED;
}
- /** {@inheritDoc}
- *
- * @throws CoreException */
@Override
- public void validate(IProgressMonitor progressMonitor) throws CoreException {
- Logger.debug("Validating " +
super.getJavaElement().getFullyQualifiedName());
- super.getJavaElement()
- .getResource()
- .deleteMarkers(JaxrsMetamodelFullBuilder.JAXRS_PROBLEM, true,
- org.eclipse.core.resources.IResource.DEPTH_INFINITE);
- for (Entry<String, IJaxrsResourceMethod> entry : resourceMethods.entrySet()) {
- ((JaxrsResourceMethod) entry.getValue()).validate(progressMonitor);
- }
- Logger.debug("Validation done.");
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.jboss.tools.ws.jaxrs.core.internal.metamodel.IResource#hasErrors(
- * boolean)
- */
- @Override
public final void hasErrors(final boolean hasErrors) {
super.hasErrors(hasErrors);
if (!hasErrors) {
@@ -349,4 +323,15 @@
return new ArrayList<IJaxrsResourceMethod>(resourceMethods.values());
}
+ @Override
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ // delegating the validation to the undelying resource methods
+ for(Entry<String, IJaxrsResourceMethod> entry : resourceMethods.entrySet()) {
+ final IJaxrsResourceMethod resourceMethod = entry.getValue();
+ messages.addAll(resourceMethod.validate());
+ }
+ return messages;
+ }
+
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -20,13 +20,17 @@
import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.wst.validation.ValidatorMessage;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuilder;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.jdt.JavaMethodParameter;
import org.jboss.tools.ws.jaxrs.core.jdt.JavaMethodSignature;
@@ -34,15 +38,12 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
-import org.jboss.tools.ws.jaxrs.core.metamodel.InvalidModelElementException;
/** @author xcoulon */
public class JaxrsResourceMethod extends JaxrsElement<IMethod> implements
IJaxrsResourceMethod {
private final JaxrsResource parentResource;
- private final EnumKind kind = null;
-
/** return type of the java javaMethod. Null if this is not a subresource
* locator. */
private IType returnedJavaType = null;
@@ -178,11 +179,26 @@
return EnumElementKind.RESOURCE_METHOD;
}
- /** {@inheritDoc}
- *
- * @throws CoreException */
@Override
- public void validate(IProgressMonitor progressMonitor) throws CoreException {
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ final List<String> pathParamValueProposals = getPathParamValueProposals();
+ for (JavaMethodParameter parameter : this.javaMethodParameters) {
+ final Annotation annotation = parameter.getAnnotation(PathParam.class.getName());
+ if(annotation != null) {
+ final String value = annotation.getValue("value");
+ if(!pathParamValueProposals.contains(value)) {
+ final ValidatorMessage message = ValidatorMessage.create("Invalid @PathParam
value: expected " + pathParamValueProposals, this.getResource());
+ message.setAttribute(IMarker.MARKER, JaxrsMetamodelBuilder.JAXRS_PROBLEM);
+ message.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ message.setAttribute(IMarker.CHAR_START, annotation.getRegion().getOffset());
+ message.setAttribute(IMarker.CHAR_END, annotation.getRegion().getOffset() +
annotation.getRegion().getLength());
+ messages.add(message);
+ Logger.debug("Validation message for {}: {}",
this.getJavaElement().getElementName(), message);
+ }
+ }
+ }
+ return messages;
}
/*
@@ -367,4 +383,5 @@
return params;
}
+
}
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidator.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidator.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidator.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -0,0 +1,69 @@
+package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+import org.eclipse.wst.validation.ValidatorMessage;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuilder;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.ConstantUtils;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
+import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
+
+public class JaxrsMetamodelValidator extends AbstractValidator {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.wst.validation.AbstractValidator#validate(org.eclipse.core
+ * .resources.IResource, int, org.eclipse.wst.validation.ValidationState,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state,
IProgressMonitor monitor) {
+ final ValidationResult validationResult = new ValidationResult();
+ final IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
+ try {
+ subMonitor.beginTask("Validating the JAX-RS Metamodel", 1);
+ if (resource.getType() == IResource.FILE &&
"java".equals(resource.getFileExtension())) {
+ clearMarkers((IFile) resource);
+ final JaxrsMetamodel jaxrsMetamodel = JaxrsMetamodel.get(resource.getProject());
+ if (jaxrsMetamodel == null) {
+ return validationResult;
+ }
+ IJaxrsElement<?> element =
jaxrsMetamodel.getElement(JdtUtils.getCompilationUnit(resource));
+ if (element != null) {
+ Logger.debug("Validating the JAX-RS Metamodel after {} was {}",
resource.getName(), ConstantUtils.getStaticFieldName(IResourceDelta.class, kind));
+ List<ValidatorMessage> validationMessages = element.validate();
+ for (ValidatorMessage validationMessage : validationMessages) {
+ validationResult.add(validationMessage);
+ }
+ }
+ }
+ } catch (CoreException e) {
+ Logger.error("Failed to validate the resource change", e);
+ } finally {
+ subMonitor.done();
+ }
+ return validationResult;
+ }
+
+ private void clearMarkers(IFile file) {
+ try {
+ file.deleteMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true,
+ org.eclipse.core.resources.IResource.DEPTH_INFINITE);
+ } catch (CoreException e) {
+ }
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -17,13 +17,15 @@
private final Map<String, List<String>> javaAnnotationElements;
- private final TypedRegion region;
+ private TypedRegion region;
- /** Full constructor
+ /**
+ * Full constructor
*
* @param annotation
* @param name
- * @param annotationElements */
+ * @param annotationElements
+ */
public Annotation(IAnnotation annotation, String name, Map<String,
List<String>> annotationElements,
final TypedRegion region) {
this.javaAnnotation = annotation;
@@ -40,6 +42,9 @@
}
this.javaAnnotationElements.clear();
this.javaAnnotationElements.putAll(annotation.getJavaAnnotationElements());
+ if (annotation.getRegion() != null) {
+ this.region = annotation.getRegion();
+ }
return true;
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -6,6 +6,7 @@
import java.util.Map;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
@@ -21,6 +22,7 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TypedRegion;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
public class JavaMethodSignaturesVisitor extends ASTVisitor {
@@ -60,7 +62,11 @@
@Override
public boolean visit(MethodDeclaration declaration) {
try {
- IMethod method = (IMethod)
compilationUnit.getElementAt(declaration.getStartPosition());
+ final IJavaElement element =
compilationUnit.getElementAt(declaration.getStartPosition());
+ if(element.getElementType() != IJavaElement.METHOD) {
+ return true;
+ }
+ IMethod method = (IMethod) element;
if (this.method != null &&
!this.method.getHandleIdentifier().equals(method.getHandleIdentifier())) {
return true;
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsElement.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsElement.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsElement.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -3,6 +3,7 @@
import java.util.List;
import org.eclipse.jdt.core.IMember;
+import org.eclipse.wst.validation.ValidatorMessage;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
public interface IJaxrsElement<T extends IMember> {
@@ -25,4 +26,6 @@
EnumKind getKind();
+ List<ValidatorMessage> validate();
+
}
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -6,9 +6,10 @@
import
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JavaElementChangedEventFilterTestCase;
import
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JavaElementChangedProcessorTestCase;
import
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementChangedProcessorTestCase;
-import
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelFullBuildJobTestCase;
+import
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuildJobTestCase;
import
org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsElementFactoryTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodelTestCase;
+import
org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation.JaxrsMetamodelValidatorTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtilsTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.utils.PathParamValidationTestCase;
import org.jboss.tools.ws.jaxrs.core.jdt.CompilationUnitsRepositoryTestCase;
@@ -22,9 +23,9 @@
@SuiteClasses({ ProjectBuilderUtilsTestCase.class, ProjectNatureUtilsTestCase.class,
JdtUtilsTestCase.class,
CompilationUnitsRepositoryTestCase.class, ElementChangedEventScannerTestCase.class,
JavaElementChangedEventFilterTestCase.class,
JavaElementChangedProcessorTestCase.class,
- JaxrsElementChangedProcessorTestCase.class, JaxrsMetamodelFullBuildJobTestCase.class,
+ JaxrsElementChangedProcessorTestCase.class, JaxrsMetamodelBuildJobTestCase.class,
JaxrsElementFactoryTestCase.class, JaxrsMetamodelTestCase.class,
CollectionUtilsTestCase.class,
- PathParamValidationTestCase.class, PubSubServiceTestCase.class })
+ PathParamValidationTestCase.class, PubSubServiceTestCase.class,
JaxrsMetamodelValidatorTestCase.class })
public class AllTests {
}
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -828,6 +828,7 @@
throws JavaModelException {
Annotation annotation = JdtUtils.resolveAnnotation(member, JdtUtils.parse(member,
null),
annotationClass);
+
Map<String, List<String>> elements = new HashMap<String,
List<String>>();
elements.put("value", Arrays.asList(values));
annotation.update(new Annotation(annotation.getJavaAnnotation(), annotation.getName(),
elements, null));
Copied:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJobTestCase.java
(from rev 36531,
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuildJobTestCase.java)
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJobTestCase.java
(rev 0)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJobTestCase.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Coulon - Initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder;
+
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getMethod;
+import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getType;
+import static org.junit.Assert.assertThat;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsEndpoint;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResource;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
+import org.junit.Assert;
+import org.junit.Test;
+
+/** @author xcoulon */
+public class JaxrsMetamodelBuildJobTestCase extends AbstractMetamodelBuilderTestCase {
+
+ @Test
+ public void shouldAssertHTTPMethods() throws CoreException {
+ // 6 HttpMethods in the jax-rs API (@GET, etc.) + 1 in the project
+ // (@FOO)
+ Assert.assertEquals(1 * 7, metamodel.getAllHttpMethods().size());
+ Set<IJaxrsHttpMethod> jaxrsHttpMethods = new HashSet<IJaxrsHttpMethod>();
+ for (IJaxrsHttpMethod httpMethod : metamodel.getAllHttpMethods()) {
+ // toString() called for code coverage
+ Assert.assertNotNull(httpMethod.toString());
+ Assert.assertTrue(jaxrsHttpMethods.add(httpMethod));
+ }
+ }
+
+ @Test
+ public void shouldAssertResourcesAndMethods() throws CoreException {
+ // for now, the result excludes the (binary) AsynchronousDispatcher, and
+ // hence, its (sub)resources
+ Assert.assertEquals(5, metamodel.getAllResources().size());
+ for (IJaxrsResource jaxrsResource : metamodel.getAllResources()) {
+ assertThat(jaxrsResource.getJavaElement(), notNullValue());
+ assertThat(jaxrsResource.getKind(), notNullValue());
+ assertThat(jaxrsResource.getAllMethods().size(), greaterThan(0));
+ }
+ }
+
+ @Test
+ public void shouldAssertResolvedEndpoints() throws CoreException {
+ List<IJaxrsEndpoint> endpoints = metamodel.getAllEndpoints();
+ Assert.assertEquals("Wrong result", 11, endpoints.size());
+ for (IJaxrsEndpoint endpoint : endpoints) {
+ Assert.assertFalse("Empty list of resourceMethods",
endpoint.getResourceMethods().isEmpty());
+ Assert.assertNotNull("No URI Path template",
endpoint.getUriPathTemplate());
+ Assert.assertFalse("No URI Path template:" + endpoint.getUriPathTemplate(),
endpoint.getUriPathTemplate()
+ .contains("null"));
+ Assert.assertFalse("Found some '//' in the uri path template in " +
endpoint.getUriPathTemplate(), endpoint
+ .getUriPathTemplate().contains("//"));
+ Assert.assertNotNull("No Http Method", endpoint.getHttpMethod());
+ Assert.assertFalse("No consumed media types",
endpoint.getConsumedMediaTypes().isEmpty());
+ Assert.assertFalse("No produced media types",
endpoint.getProducedMediaTypes().isEmpty());
+ }
+ }
+
+ @Test
+ public void shouldRetrieveCustomerResource() throws CoreException {
+ IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
+ final IJaxrsResource customerResource = (IJaxrsResource)
metamodel.getElement(customerType);
+ Assert.assertNotNull("CustomerResource not found", customerType);
+ Assert.assertEquals("Wrong number of resource resourceMethods", 6,
customerResource.getResourceMethods().size());
+ }
+
+ @Test
+ public void shouldRetrieveCustomerResourceMethodProposals() throws CoreException {
+ IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
+ IMethod customerMethod = getMethod(customerType, "getCustomers");
+ final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod)
metamodel.getElement(customerMethod);
+ Assert.assertThat(customerResourceMethod, notNullValue());
+ Assert.assertThat(customerResourceMethod.getPathParamValueProposals().size(),
equalTo(0));
+ }
+
+ @Test
+ public void shouldRetrieveCustomerSubresourceMethodProposals() throws CoreException {
+ IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
+ IMethod customerMethod = getMethod(customerType, "getCustomer");
+ final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod)
metamodel.getElement(customerMethod);
+ Assert.assertThat(customerResourceMethod, notNullValue());
+ Assert.assertThat(customerResourceMethod.getPathParamValueProposals(),
containsInAnyOrder("id"));
+ }
+
+ @Test
+ public void shouldRetrieveBookResourceMethodProposals() throws CoreException {
+ IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
+ IMethod customerMethod = getMethod(customerType, "getAllProducts");
+ final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod)
metamodel.getElement(customerMethod);
+ Assert.assertThat(customerResourceMethod, notNullValue());
+ Assert.assertThat(customerResourceMethod.getPathParamValueProposals().size(),
equalTo(0));
+ }
+
+ @Test
+ public void shouldRetrieveBooksubresourceMethodProposals() throws CoreException {
+ IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
+ IMethod customerMethod = getMethod(customerType, "getProduct");
+ final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod)
metamodel.getElement(customerMethod);
+ Assert.assertThat(customerResourceMethod, notNullValue());
+ Assert.assertThat(customerResourceMethod.getPathParamValueProposals(),
containsInAnyOrder("id"));
+ }
+
+}
Property changes on:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJobTestCase.java
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ text/plain
Deleted:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuildJobTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuildJobTestCase.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuildJobTestCase.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -1,129 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Xavier Coulon - Initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder;
-
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.hamcrest.Matchers.empty;
-import static org.hamcrest.Matchers.emptyIterable;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getMethod;
-import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getType;
-import static org.junit.Assert.assertThat;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
-import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsEndpoint;
-import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
-import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResource;
-import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
-import org.junit.Assert;
-import org.junit.Test;
-
-/** @author xcoulon */
-public class JaxrsMetamodelFullBuildJobTestCase extends AbstractMetamodelBuilderTestCase
{
-
- @Test
- public void shouldAssertHTTPMethods() throws CoreException {
- // 6 HttpMethods in the jax-rs API (@GET, etc.) + 1 in the project
- // (@FOO)
- Assert.assertEquals(1 * 7, metamodel.getAllHttpMethods().size());
- Set<IJaxrsHttpMethod> jaxrsHttpMethods = new HashSet<IJaxrsHttpMethod>();
- for (IJaxrsHttpMethod httpMethod : metamodel.getAllHttpMethods()) {
- // toString() called for code coverage
- Assert.assertNotNull(httpMethod.toString());
- Assert.assertTrue(jaxrsHttpMethods.add(httpMethod));
- }
- }
-
- @Test
- public void shouldAssertResourcesAndMethods() throws CoreException {
- // for now, the result excludes the (binary) AsynchronousDispatcher, and
- // hence, its (sub)resources
- Assert.assertEquals(5, metamodel.getAllResources().size());
- for (IJaxrsResource jaxrsResource : metamodel.getAllResources()) {
- assertThat(jaxrsResource.getJavaElement(), notNullValue());
- assertThat(jaxrsResource.getKind(), notNullValue());
- assertThat(jaxrsResource.getAllMethods().size(), greaterThan(0));
- }
- }
-
- @Test
- public void shouldAssertResolvedEndpoints() throws CoreException {
- List<IJaxrsEndpoint> endpoints = metamodel.getAllEndpoints();
- Assert.assertEquals("Wrong result", 11, endpoints.size());
- for (IJaxrsEndpoint endpoint : endpoints) {
- Assert.assertFalse("Empty list of resourceMethods",
endpoint.getResourceMethods().isEmpty());
- Assert.assertNotNull("No URI Path template",
endpoint.getUriPathTemplate());
- Assert.assertFalse("No URI Path template:" + endpoint.getUriPathTemplate(),
endpoint.getUriPathTemplate()
- .contains("null"));
- Assert.assertFalse("Found some '//' in the uri path template in " +
endpoint.getUriPathTemplate(), endpoint
- .getUriPathTemplate().contains("//"));
- Assert.assertNotNull("No Http Method", endpoint.getHttpMethod());
- Assert.assertFalse("No consumed media types",
endpoint.getConsumedMediaTypes().isEmpty());
- Assert.assertFalse("No produced media types",
endpoint.getProducedMediaTypes().isEmpty());
- }
- }
-
- @Test
- public void shouldRetrieveCustomerResource() throws CoreException {
- IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- final IJaxrsResource customerResource = (IJaxrsResource)
metamodel.getElement(customerType);
- Assert.assertNotNull("CustomerResource not found", customerType);
- Assert.assertEquals("Wrong number of resource resourceMethods", 6,
customerResource.getResourceMethods().size());
- }
-
- @Test
- public void shouldRetrieveCustomerResourceMethodProposals() throws CoreException {
- IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- IMethod customerMethod = getMethod(customerType, "getCustomers");
- final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod)
metamodel.getElement(customerMethod);
- Assert.assertThat(customerResourceMethod, notNullValue());
- Assert.assertThat(customerResourceMethod.getPathParamValueProposals().size(),
equalTo(0));
- }
-
- @Test
- public void shouldRetrieveCustomerSubresourceMethodProposals() throws CoreException {
- IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
- IMethod customerMethod = getMethod(customerType, "getCustomer");
- final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod)
metamodel.getElement(customerMethod);
- Assert.assertThat(customerResourceMethod, notNullValue());
- Assert.assertThat(customerResourceMethod.getPathParamValueProposals(),
containsInAnyOrder("id"));
- }
-
- @Test
- public void shouldRetrieveBookResourceMethodProposals() throws CoreException {
- IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
- IMethod customerMethod = getMethod(customerType, "getAllProducts");
- final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod)
metamodel.getElement(customerMethod);
- Assert.assertThat(customerResourceMethod, notNullValue());
- Assert.assertThat(customerResourceMethod.getPathParamValueProposals().size(),
equalTo(0));
- }
-
- @Test
- public void shouldRetrieveBooksubresourceMethodProposals() throws CoreException {
- IType customerType =
getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
- IMethod customerMethod = getMethod(customerType, "getProduct");
- final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod)
metamodel.getElement(customerMethod);
- Assert.assertThat(customerResourceMethod, notNullValue());
- Assert.assertThat(customerResourceMethod.getPathParamValueProposals(),
containsInAnyOrder("id"));
- }
-
-}
Added:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java
(rev 0)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -0,0 +1,80 @@
+/**
+ *
+ */
+package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.util.List;
+
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.Path;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.wst.validation.ValidatorMessage;
+import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
+import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
+import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
+import org.junit.Test;
+
+/**
+ * @author Xi
+ *
+ */
+public class JaxrsMetamodelValidatorTestCase extends AbstractMetamodelBuilderTestCase {
+
+ @Test
+ public void shouldValidateHttpMethod() throws CoreException {
+ // preconditions
+ IType fooType =
WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject);
+ final IJaxrsElement<?> httpMethod = metamodel.getElement(fooType);
+ // operation
+ final List<ValidatorMessage> validationMessages = httpMethod.validate();
+ // validation
+ assertThat(validationMessages.size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldNotValidateHttpMethod() throws CoreException {
+ // preconditions
+ IType fooType =
WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject);
+ final IJaxrsElement<?> httpMethod = metamodel.getElement(fooType);
+ Annotation httpAnnotation = WorkbenchUtils.getAnnotation(fooType, HttpMethod.class, new
String[0]);
+ httpMethod.addOrUpdateAnnotation(httpAnnotation);
+ // operation
+ final List<ValidatorMessage> validationMessages = httpMethod.validate();
+ // validation
+ assertThat(validationMessages.size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldValidateResourceMethod() throws CoreException {
+ // preconditions
+ IType customerJavaType =
WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
+ final IJaxrsElement<?> customerResource =
metamodel.getElement(customerJavaType);
+ // operation
+ final List<ValidatorMessage> validationMessages = customerResource.validate();
+ // validation
+ assertThat(validationMessages.size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldNotValidateResourceMethod() throws CoreException {
+ // preconditions
+ IType customerJavaType =
WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject);
+ final IJaxrsElement<?> customerResource =
metamodel.getElement(customerJavaType);
+ IMethod customerJavaMethod = WorkbenchUtils.getMethod(customerJavaType,
"getCustomer");
+ final IJaxrsElement<?> customerResourceMethod =
metamodel.getElement(customerJavaMethod);
+ Annotation pathAnnotation = WorkbenchUtils.getAnnotation(customerJavaMethod,
Path.class, "/{foo}");
+ customerResourceMethod.addOrUpdateAnnotation(pathAnnotation);
+ // operation
+ final List<ValidatorMessage> validationMessages = customerResource.validate();
+ // validation
+ assertThat(validationMessages.size(), equalTo(1));
+ }
+
+}
Property changes on:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/PathParamValidationTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/PathParamValidationTestCase.java 2011-11-22
19:53:40 UTC (rev 36541)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/PathParamValidationTestCase.java 2011-11-22
21:07:06 UTC (rev 36542)
@@ -20,7 +20,7 @@
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
-import
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelFullBuilder;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuilder;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResource;
import org.junit.Assert;
import org.junit.Ignore;
@@ -34,14 +34,14 @@
// pre-conditions : add a standard class : no new root resource (yet)
ICompilationUnit fooCompilationUnit = WorkbenchUtils.createCompilationUnit(javaProject,
"FooResource.txt",
"org.jboss.tools.ws.jaxrs.sample.services", "FooResource.java",
bundle);
- IMarker[] markers =
fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelFullBuilder.JAXRS_PROBLEM,
true,
+ IMarker[] markers =
fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true,
IResource.DEPTH_INFINITE);
Assert.assertEquals("No marker expected", 0, markers.length);
// operation : replace @PathParam("id") with @PathParam("ide")
WorkbenchUtils.replaceAllOccurrencesOfCode(fooCompilationUnit,
"@PathParam(\"id\")", "@PathParam(\"ide\")",
true);
// post-conditions: expect a validation error
- markers =
fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelFullBuilder.JAXRS_PROBLEM,
true,
+ markers =
fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true,
IResource.DEPTH_INFINITE);
Assert.assertEquals("Wrong number of markers", 1, markers.length);
@@ -54,7 +54,7 @@
"org.jboss.tools.ws.jaxrs.sample.services", "FooResource.java",
bundle);
List<IJaxrsResource> resources = metamodel.getAllResources();
Assert.assertEquals(6, resources.size());
- IMarker[] markers =
fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelFullBuilder.JAXRS_PROBLEM,
true,
+ IMarker[] markers =
fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true,
IResource.DEPTH_INFINITE);
Assert.assertEquals("No marker expected", 0, markers.length);
// operation : change both @Path and @PathParam values
@@ -63,7 +63,7 @@
WorkbenchUtils.replaceAllOccurrencesOfCode(fooCompilationUnit,
"@PathParam(\"id\")", "@PathParam(\"ide\")",
true);
// post-conditions: expect no validation error
- markers =
fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelFullBuilder.JAXRS_PROBLEM,
true,
+ markers =
fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true,
IResource.DEPTH_INFINITE);
Assert.assertEquals("No marker expected", 0, markers.length);