Author: akazakov
Date: 2007-07-18 08:21:00 -0400 (Wed, 18 Jul 2007)
New Revision: 2499
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamComponentMethodType.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/SeamAnnotations.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidationContext.java
Log:
http://jira.jboss.com/jira/browse/EXIN-327 @Unwrap validation
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamComponentMethodType.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamComponentMethodType.java 2007-07-18
11:44:26 UTC (rev 2498)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamComponentMethodType.java 2007-07-18
12:21:00 UTC (rev 2499)
@@ -19,7 +19,8 @@
CREATE(CREATE_ANNOTATION_TYPE),
DESTROY(DESTROY_ANNOTATION_TYPE),
REMOVE(REMOVE_ANNOTATION_TYPE),
- UNWRAP(UNWRAP_ANNOTATION_TYPE);
+ UNWRAP(UNWRAP_ANNOTATION_TYPE),
+ OBSERVER(OBSERVER_ANNOTATION_TYPE);
String annotationType;
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-07-18
11:44:26 UTC (rev 2498)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-07-18
12:21:00 UTC (rev 2499)
@@ -650,7 +650,21 @@
public Map<String, SeamJavaComponentDeclaration> getAllJavaComponentDeclarations()
{
return javaDeclarations;
}
-
+
+ /**
+ * Returns set of java classes that contain seam annotations with specified path.
+ * They may be seam components, as well as cases of incomplete annotating
+ * that does not create a seam component.
+ * @return
+ */
+ public Set<SeamJavaComponentDeclaration> findJavaDeclarations(IPath source) {
+ Set<SeamJavaComponentDeclaration> set = new
HashSet<SeamJavaComponentDeclaration>();
+ for (SeamJavaComponentDeclaration d: javaDeclarations.values()) {
+ if(source.equals(d.getSourcePath())) set.add(d);
+ }
+ return set;
+ }
+
public SeamComponent getComponent(String name) {
return name == null ? null : allComponents.get(name);
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/SeamAnnotations.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/SeamAnnotations.java 2007-07-18
11:44:26 UTC (rev 2498)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/SeamAnnotations.java 2007-07-18
12:21:00 UTC (rev 2499)
@@ -31,6 +31,7 @@
public static String CREATE_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Create";
public static String DESTROY_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Destroy";
public static String UNWRAP_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Unwrap";
+ public static String OBSERVER_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Observer";
public static String REMOVE_ANNOTATION_TYPE = "javax.ejb.Remove";
public static String FACTORY_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Factory";
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java 2007-07-18
11:44:26 UTC (rev 2498)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java 2007-07-18
12:21:00 UTC (rev 2499)
@@ -10,8 +10,10 @@
******************************************************************************/
package org.jboss.tools.seam.internal.core.validation;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IFile;
@@ -25,6 +27,7 @@
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.wst.validation.internal.core.ValidationException;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
@@ -46,6 +49,7 @@
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.internal.core.AbstractContextVariable;
import org.jboss.tools.seam.internal.core.SeamComponentDeclaration;
+import org.jboss.tools.seam.internal.core.SeamJavaComponentDeclaration;
import org.jboss.tools.seam.internal.core.SeamProject;
import org.jboss.tools.seam.internal.core.SeamTextSourceReference;
@@ -60,10 +64,13 @@
private static final String NONUNIQUE_COMPONENT_NAME_MESSAGE_ID =
"NONUNIQUE_COMPONENT_NAME_MESSAGE";
private static final String UNKNOWN_INJECTION_NAME_MESSAGE_ID =
"UNKNOWN_INJECTION_NAME";
private static final String STATEFUL_COMPONENT_DOES_NOT_CONTENT_METHOD_SUFIX_MESSAGE_ID
= "STATEFUL_COMPONENT_DOES_NOT_CONTENT_";
- private static final String DUPLICATE_METHOD_SUFIX_MESSAGE_ID = "DUPLICATE_";
- private static final String REMOVE_METHOD_POSTFIX_MESSAGE_ID = "REMOVE";
- private static final String DESTROY_METHOD_POSTFIX_MESSAGE_ID = "DESTROY";
- private static final String CREATE_METHOD_POSTFIX_MESSAGE_ID = "CREATE";
+ private static final String DUPLICATE_METHOD_PREFIX_MESSAGE_ID =
"DUPLICATE_";
+ private static final String REMOVE_METHOD_SUFIX_MESSAGE_ID = "REMOVE";
+ private static final String DESTROY_METHOD_SUFIX_MESSAGE_ID = "DESTROY";
+ private static final String CREATE_METHOD_SUFIX_MESSAGE_ID = "CREATE";
+ private static final String UNWRAP_METHOD_SUFIX_MESSAGE_ID = "UNWRAP";
+ private static final String OBSERVER_METHOD_SUFIX_MESSAGE_ID = "OBSERVER";
+ private static final String NONCOMPONENTS_METHOD_SUFIX_MESSAGE_ID =
"_DOESNT_BELONG_TO_COMPONENT";
private static final String STATEFUL_COMPONENT_WRONG_SCOPE_MESSAGE_ID =
"STATEFUL_COMPONENT_WRONG_SCOPE";
private static final String ENTITY_COMPONENT_WRONG_SCOPE_MESSAGE_ID =
"ENTITY_COMPONENT_WRONG_SCOPE";
private static final String UNKNOWN_FACTORY_NAME_MESSAGE_ID =
"UNKNOWN_FACTORY_NAME";
@@ -71,7 +78,6 @@
private static final String DUPLICATE_VARIABLE_NAME_MESSAGE_ID =
"DUPLICATE_VARIABLE_NAME";
private static final String UNKNOWN_DATA_MODEL_MESSAGE_ID =
"UNKNOWN_DATA_MODEL";
-
private SeamValidationContext validationContext;
private ISeamProject project;
@@ -92,6 +98,7 @@
Set<String> markedDuplicateFactoryNames = new HashSet<String>();
// Collect all resources which we must validate.
Set<IPath> resources = new HashSet<IPath>(); // Resources which we have to
validate.
+ Set<IPath> newResources = new HashSet<IPath>(); // New (unlinked)
resources file
for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) {
currentFile = root.getFile(new Path(uris[i]));
// Don't handle one resource twice.
@@ -120,11 +127,11 @@
resources.addAll(linkedResources);
}
}
-
} else {
// Validate new (unlinked) Java file.
resources.add(currentFile.getFullPath());
}
+ newResources.add(currentFile.getFullPath());
}
}
// Validate all collected linked resources.
@@ -138,6 +145,16 @@
validateFactory(linkedResource, markedDuplicateFactoryNames);
// TODO
}
+
+ // Validate all unnamed resources.
+ Set<IPath> unnamedResources = validationContext.getUnnamedResources();
+ newResources.addAll(unnamedResources);
+ for (IPath path : newResources) {
+ Set<SeamJavaComponentDeclaration> declarations =
((SeamProject)project).findJavaDeclarations(path);
+ for (SeamJavaComponentDeclaration d : declarations) {
+ validateMethodsOfUnknownComponent(d);
+ }
+ }
} else {
return validateAll();
}
@@ -213,7 +230,7 @@
this.addError(UNKNOWN_FACTORY_NAME_MESSAGE_ID, new String[]{factoryName},
getLocationOfName(factory), factory.getResource(), MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
}
}
- } catch (Exception e) {
+ } catch (JavaModelException e) {
SeamCorePlugin.getDefault().logError(e);
}
} else {
@@ -298,6 +315,13 @@
validateFactory((ISeamAnnotatedFactory)factory, markedDuplicateFactoryNames);
}
}
+
+ Map<String,SeamJavaComponentDeclaration> declarations =
((SeamProject)project).getAllJavaComponentDeclarations();
+ Collection<SeamJavaComponentDeclaration> values = declarations.values();
+ for (SeamJavaComponentDeclaration d : values) {
+ validateMethodsOfUnknownComponent(d);
+ }
+
// TODO
return OK_STATUS;
}
@@ -389,7 +413,7 @@
try {
length = declaration.getSourceMember().getNameRange().getLength();
offset = declaration.getSourceMember().getNameRange().getOffset();
- } catch (Exception e) {
+ } catch (JavaModelException e) {
SeamCorePlugin.getDefault().logError(e);
}
return new SeamTextSourceReference(length, offset);
@@ -398,8 +422,8 @@
private void validateStatefulComponent(ISeamComponent component) {
if(component.isStateful()) {
ISeamJavaComponentDeclaration javaDeclaration = component.getJavaDeclaration();
- validateStatefulComponentMethods(SeamComponentMethodType.DESTROY, component,
DESTROY_METHOD_POSTFIX_MESSAGE_ID);
- validateStatefulComponentMethods(SeamComponentMethodType.REMOVE, component,
REMOVE_METHOD_POSTFIX_MESSAGE_ID);
+ validateStatefulComponentMethods(SeamComponentMethodType.DESTROY, component,
DESTROY_METHOD_SUFIX_MESSAGE_ID);
+ validateStatefulComponentMethods(SeamComponentMethodType.REMOVE, component,
REMOVE_METHOD_SUFIX_MESSAGE_ID);
ScopeType scope = component.getScope();
if(scope == ScopeType.PAGE || scope == ScopeType.STATELESS) {
ISeamTextSourceReference location = getScopeLocation(component);
@@ -418,9 +442,10 @@
}
private void validateDuplicateComponentMethods(ISeamComponent component) {
- validateDuplicateComponentMethod(SeamComponentMethodType.DESTROY, component,
DESTROY_METHOD_POSTFIX_MESSAGE_ID);
- validateDuplicateComponentMethod(SeamComponentMethodType.REMOVE, component,
REMOVE_METHOD_POSTFIX_MESSAGE_ID);
- validateDuplicateComponentMethod(SeamComponentMethodType.CREATE, component,
CREATE_METHOD_POSTFIX_MESSAGE_ID);
+ validateDuplicateComponentMethod(SeamComponentMethodType.DESTROY, component,
DESTROY_METHOD_SUFIX_MESSAGE_ID);
+ validateDuplicateComponentMethod(SeamComponentMethodType.REMOVE, component,
REMOVE_METHOD_SUFIX_MESSAGE_ID);
+ validateDuplicateComponentMethod(SeamComponentMethodType.CREATE, component,
CREATE_METHOD_SUFIX_MESSAGE_ID);
+ validateDuplicateComponentMethod(SeamComponentMethodType.UNWRAP, component,
UNWRAP_METHOD_SUFIX_MESSAGE_ID);
}
private void validateDuplicateComponentMethod(SeamComponentMethodType methodType,
ISeamComponent component, String postfixMessageId) {
@@ -428,13 +453,9 @@
Set<ISeamComponentMethod> methods =
javaDeclaration.getMethodsByType(methodType);
if(methods!=null && methods.size()>1) {
for (ISeamComponentMethod method : methods) {
- try {
- IMethod javaMethod = (IMethod)method.getSourceMember();
- String methodName = javaMethod.getElementName();
- addError(DUPLICATE_METHOD_SUFIX_MESSAGE_ID + postfixMessageId, new
String[]{methodName}, method, javaDeclaration.getResource(),
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
- } catch (Exception e) {
- SeamCorePlugin.getDefault().logError(e);
- }
+ IMethod javaMethod = (IMethod)method.getSourceMember();
+ String methodName = javaMethod.getElementName();
+ addError(DUPLICATE_METHOD_PREFIX_MESSAGE_ID + postfixMessageId, new
String[]{methodName}, method, javaDeclaration.getResource(),
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
}
}
}
@@ -500,4 +521,32 @@
addError(UNKNOWN_DATA_MODEL_MESSAGE_ID, new String[]{name},
getLocationOfName(bijection), declaration.getResource(),
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
}
}
+
+ /*
+ * Validates methods of java classes. They must belong components.
+ */
+ private void validateMethodsOfUnknownComponent(ISeamJavaComponentDeclaration
declaration) {
+ if(project.getComponentsByPath(declaration.getSourcePath()).size()>0) {
+ validationContext.removeUnnamedResource(declaration.getSourcePath());
+ return;
+ }
+ validateMethodOfUnknownComponent(SeamComponentMethodType.DESTROY, declaration,
DESTROY_METHOD_SUFIX_MESSAGE_ID);
+ validateMethodOfUnknownComponent(SeamComponentMethodType.CREATE, declaration,
CREATE_METHOD_SUFIX_MESSAGE_ID);
+ validateMethodOfUnknownComponent(SeamComponentMethodType.UNWRAP, declaration,
UNWRAP_METHOD_SUFIX_MESSAGE_ID);
+ validateMethodOfUnknownComponent(SeamComponentMethodType.OBSERVER, declaration,
OBSERVER_METHOD_SUFIX_MESSAGE_ID);
+ }
+
+ private void validateMethodOfUnknownComponent(SeamComponentMethodType methodType,
ISeamJavaComponentDeclaration declaration, String sufixMessageId) {
+ Set<ISeamComponentMethod> methods = declaration.getMethodsByType(methodType);
+ if(methods!=null && methods.size()>0) {
+ for (ISeamComponentMethod method : methods) {
+ IMethod javaMethod = (IMethod)method.getSourceMember();
+ String methodName = javaMethod.getElementName();
+ addError(sufixMessageId + NONCOMPONENTS_METHOD_SUFIX_MESSAGE_ID, new
String[]{methodName}, method, declaration.getResource(),
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ validationContext.addUnnamedResource(declaration.getSourcePath());
+ }
+ } else {
+ validationContext.removeUnnamedResource(declaration.getSourcePath());
+ }
+ }
}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidationContext.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidationContext.java 2007-07-18
11:44:26 UTC (rev 2498)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidationContext.java 2007-07-18
12:21:00 UTC (rev 2499)
@@ -12,7 +12,6 @@
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -31,6 +30,7 @@
private Map<String, Set<IPath>> resourcesByVariableName = new
HashMap<String, Set<IPath>>();
private Map<IPath, Set<String>> variableNamesByResource = new
HashMap<IPath, Set<String>>();
+ private Set<IPath> unnamedResources = new HashSet<IPath>();
/**
* Save link between resource and variable name.
@@ -96,15 +96,40 @@
return resourcesByVariableName.get(variableName);
}
- public Set<String> getVariableNamesByResource(IPath sourcePath) {
- return variableNamesByResource.get(sourcePath);
+ public Set<String> getVariableNamesByResource(IPath fullPath) {
+ return variableNamesByResource.get(fullPath);
}
+ /**
+ * Adds resource without any link to any context variable name.
+ * @param fullPath
+ */
+ public void addUnnamedResource(IPath fullPath) {
+ unnamedResources.add(fullPath);
+ }
+
+ /**
+ * @return Set of resources without any link to any context variable name.
+ * @param fullPath
+ */
+ public Set<IPath> getUnnamedResources() {
+ return unnamedResources;
+ }
+
+ /**
+ * Removes unnamed resource.
+ * @param fullPath
+ */
+ public void removeUnnamedResource(IPath fullPath) {
+ unnamedResources.remove(fullPath);
+ }
+
public void clear() {
resourcesByVariableName.clear();
variableNamesByResource.clear();
+ unnamedResources.clear();
}
-
+
public void store(Element root) {
Element validation = XMLUtilities.createElement(root, "validation");
Set<String> variables = resourcesByVariableName.keySet();
@@ -117,8 +142,12 @@
linkedResource.setAttribute("path", path.toString());
}
}
+ for (IPath unnamedPath: unnamedResources) {
+ Element unnamedPathElement = XMLUtilities.createElement(validation,
"unnamed-path");
+ unnamedPathElement.setAttribute("path", unnamedPath.toString());
+ }
}
-
+
public void load(Element root) {
Element validation = XMLUtilities.getUniqueChild(root, "validation");
if(validation == null) return;
@@ -128,13 +157,22 @@
if(name == null || name.trim().length() == 0) continue;
String path = linkedResources[i].getAttribute("path");
if(path == null || path.trim().length() == 0) continue;
- IPath pathObject = null;
try {
- pathObject = new Path(path);
+ IPath pathObject = new Path(path);
+ addLinkedResource(name, pathObject);
} catch (Exception e) {
SeamCorePlugin.getPluginLog().logError(e);
}
- addLinkedResource(name, pathObject);
- }
+ }
+ Element[] unnamedPathElement = XMLUtilities.getChildren(validation,
"unnamed-path");
+ if(unnamedPathElement != null) for (int i = 0; i < unnamedPathElement.length; i++)
{
+ String path = unnamedPathElement[i].getAttribute("path");
+ try {
+ IPath pathObject = new Path(path);
+ addUnnamedResource(pathObject);
+ } catch (Exception e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ }
}
}
\ No newline at end of file