Author: akazakov
Date: 2007-07-12 12:33:22 -0400 (Thu, 12 Jul 2007)
New Revision: 2410
Removed:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/internal/project/
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/validation/SeamJavaValidator.java
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/SeamValidator.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/messages.properties
Log:
http://jira.jboss.com/jira/browse/EXIN-327 Added @In, @Stateful , @Remove, @Destroy
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-12
15:38:49 UTC (rev 2409)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamComponentMethodType.java 2007-07-12
16:33:22 UTC (rev 2410)
@@ -15,5 +15,6 @@
*/
public enum SeamComponentMethodType {
CREATE,
- DESTROY
+ DESTROY,
+ REMOVE
}
\ No newline at end of file
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-12
15:38:49 UTC (rev 2409)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java 2007-07-12
16:33:22 UTC (rev 2410)
@@ -12,7 +12,6 @@
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
import org.eclipse.core.resources.IFile;
@@ -23,6 +22,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.jdt.core.IMethod;
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;
@@ -30,10 +30,14 @@
import org.jboss.tools.seam.core.IBijectedAttribute;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamComponentDeclaration;
+import org.jboss.tools.seam.core.ISeamComponentMethod;
import org.jboss.tools.seam.core.ISeamContextVariable;
import org.jboss.tools.seam.core.ISeamJavaComponentDeclaration;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.ISeamTextSourceReference;
+import org.jboss.tools.seam.core.ScopeType;
+import org.jboss.tools.seam.core.SeamComponentMethodType;
+import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.internal.core.SeamComponentDeclaration;
import org.jboss.tools.seam.internal.core.SeamProject;
@@ -45,9 +49,14 @@
private static final String MARKED_COMPONENT_MESSAGE_GROUP =
"markedComponent";
- public static final String NONUNIQUE_COMPONENT_NAME_MESSAGE_ID =
"NONUNIQUE_COMPONENT_NAME_MESSAGE";
+ 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 STATEFUL_COMPONENT_DUPLICATE_METHOD__SUFIX_MESSAGE_ID =
"STATEFUL_COMPONENT_DUPLICATE_";
+ private static final String REMOVE_METHOD_POSTFIX_MESSAGE_ID = "REMOVE";
+ private static final String DESTROY_METHOD_POSTFIX_MESSAGE_ID = "DESTROY";
- public static final String UNKNOWN_INJECTION_NAME_MESSAGE_ID =
"UNKNOWN_INJECTION_NAME";
+ private static final String STATEFUL_COMPONENT_WRONG_SCOPE_MESSAGE_ID =
"STATEFUL_COMPONENT_WRONG_SCOPE";
private SeamValidationContext validationContext;
@@ -64,20 +73,16 @@
if (uris.length > 0) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile currentFile = null;
- Set<IPath> checkedResources = new HashSet<IPath>();
Set<ISeamComponent> checkedComponents = new HashSet<ISeamComponent>();
+ // Collect all resources which we must validate.
+ Set<IPath> resources = new HashSet<IPath>(); // Resources which we have to
validate.
for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) {
currentFile = root.getFile(new Path(uris[i]));
- // Don't validate one resource twice.
- if(checkedResources.contains(currentFile)) {
- continue;
- }
+ // Don't handle one resource twice.
if (currentFile != null && currentFile.exists()) {
// Get all variable names that were linked with this resource.
Set<String> oldVariablesNamesOfChangedFile =
validationContext.getVariableNamesByResource(currentFile.getFullPath());
if(oldVariablesNamesOfChangedFile!=null) {
- Set<IPath> resources = new HashSet<IPath>(); // Resources which we have
to validate.
-
// Check if variable name was changed in java file
Set<String> newVariableNamesOfChangedFile =
getVariablesNameByResource(currentFile.getFullPath(), project);
for (String newVariableName : newVariableNamesOfChangedFile) {
@@ -90,10 +95,7 @@
}
}
}
- // Check if changed file is not linked to any variables anymore.
- if(newVariableNamesOfChangedFile.size() == 0) {
- resources.add(currentFile.getFullPath());
- }
+ resources.add(currentFile.getFullPath());
// Collect all linked resources with old variable names.
for (String name : oldVariablesNamesOfChangedFile) {
@@ -103,26 +105,21 @@
}
}
- // Validate all collected linked resources.
- // Remove all links between resources and variables names because they will be
linked again during validation.
- validationContext.clear();
- for (IPath linkedResource : resources) {
- // Don't validate one resource twice.
- if(checkedResources.contains(linkedResource)) {
- continue;
- }
- // Remove markers from collected java file
- reporter.removeMessageSubset(this, linkedResource,
MARKED_COMPONENT_MESSAGE_GROUP);
- validateComponent(project, linkedResource, checkedComponents, helper, reporter);
- checkedResources.add(linkedResource);
- }
} else {
- // Validate new (unmarked) Java file.
- validateComponent(project, currentFile.getFullPath(), checkedComponents, helper,
reporter);
+ // Validate new (unlinked) Java file.
+ resources.add(currentFile.getFullPath());
}
- // TODO
}
}
+ // Validate all collected linked resources.
+ // Remove all links between resources and variables names because they will be linked
again during validation.
+ validationContext.clear();
+ for (IPath linkedResource : resources) {
+ // Remove markers from collected java file
+ reporter.removeMessageSubset(this, linkedResource, MARKED_COMPONENT_MESSAGE_GROUP);
+ validateComponent(project, linkedResource, checkedComponents, helper, reporter);
+ // TODO
+ }
} else {
return validateAll(project, helper, reporter);
}
@@ -187,7 +184,7 @@
// Save link between component name and java source file.
validationContext.addLinkedResource(declaration.getName(),
declaration.getSourcePath());
// Validate all elements in declaration but @Name.
- validateInjections(project, firstJavaDeclaration, helper, reporter);
+ validateJavaDeclaration(project, firstJavaDeclaration, helper, reporter);
}
if(declaration instanceof ISeamJavaComponentDeclaration &&
declaration!=firstJavaDeclaration) {
// Validate @Name
@@ -205,7 +202,7 @@
IResource checkedDeclarationResource = checkedDeclaration.getResource();
ISeamTextSourceReference location =
((SeamComponentDeclaration)checkedDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
if(location!=null) {
- addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, location,
checkedDeclarationResource, MARKED_COMPONENT_MESSAGE_GROUP);
+ addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, new String[]{component.getName()},
location, checkedDeclarationResource, MARKED_COMPONENT_MESSAGE_GROUP);
}
markedDeclarations.add(checkedDeclaration);
}
@@ -213,36 +210,81 @@
markedDeclarations.add(javaDeclaration);
ISeamTextSourceReference location =
((SeamComponentDeclaration)javaDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
if(location!=null) {
- addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, location, javaDeclarationResource,
MARKED_COMPONENT_MESSAGE_GROUP);
+ addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, new String[]{component.getName()},
location, javaDeclarationResource, MARKED_COMPONENT_MESSAGE_GROUP);
}
}
}
}
+ validateStatefulComponent(project, component, helper, reporter);
}
}
+ private void validateStatefulComponent(ISeamProject project, ISeamComponent component,
IValidationContext helper, IReporter reporter) {
+ ISeamJavaComponentDeclaration javaDeclaration = component.getJavaDeclaration();
+ if(javaDeclaration!=null && javaDeclaration.isStateful()) {
+ int length = 0;
+ int offset = 0;
+ try {
+ length = javaDeclaration.getSourceMember().getNameRange().getLength();
+ offset = javaDeclaration.getSourceMember().getNameRange().getOffset();
+ } catch (Exception e) {
+ SeamCorePlugin.getDefault().logError(e);
+ }
+ validateStatefulComponentMethods(project, SeamComponentMethodType.DESTROY, component,
length, offset, DESTROY_METHOD_POSTFIX_MESSAGE_ID, helper, reporter);
+ validateStatefulComponentMethods(project, SeamComponentMethodType.REMOVE, component,
length, offset, REMOVE_METHOD_POSTFIX_MESSAGE_ID, helper, reporter);
+ ScopeType scope = component.getScope();
+ if(scope == ScopeType.PAGE || scope == ScopeType.STATELESS) {
+ addError(STATEFUL_COMPONENT_WRONG_SCOPE_MESSAGE_ID, new
String[]{component.getName()}, length, offset, javaDeclaration.getResource(),
MARKED_COMPONENT_MESSAGE_GROUP);
+ }
+ }
+ }
+
+ private void validateStatefulComponentMethods(ISeamProject project,
SeamComponentMethodType methodType, ISeamComponent component, int lengthOfClassName, int
offsetOfClassName, String postfixMessageId, IValidationContext helper, IReporter reporter)
{
+ ISeamJavaComponentDeclaration javaDeclaration = component.getJavaDeclaration();
+ Set<ISeamComponentMethod> methods =
javaDeclaration.getMethodsByType(methodType);
+ if(methods==null || methods.size()==0) {
+ addError(STATEFUL_COMPONENT_DOES_NOT_CONTENT_METHOD_SUFIX_MESSAGE_ID +
postfixMessageId, new String[]{component.getName()}, lengthOfClassName, offsetOfClassName,
javaDeclaration.getResource(), MARKED_COMPONENT_MESSAGE_GROUP);
+ } else if(methods.size()>1) {
+ for (ISeamComponentMethod method : methods) {
+ try {
+ IMethod javaMethod = (IMethod)method.getSourceMember();
+ String methodName = javaMethod.getElementName();
+ addError(STATEFUL_COMPONENT_DUPLICATE_METHOD__SUFIX_MESSAGE_ID + postfixMessageId,
new String[]{methodName}, method, javaDeclaration.getResource(),
MARKED_COMPONENT_MESSAGE_GROUP);
+ } catch (Exception e) {
+ SeamCorePlugin.getDefault().logError(e);
+ }
+ }
+ }
+ }
+
private void validateJavaDeclaration(ISeamProject project, ISeamJavaComponentDeclaration
declaration, IValidationContext helper, IReporter reporter) {
- validateInjections(project, declaration, helper, reporter);
+ validateBijections(project, declaration, helper, reporter);
+ // TODO
}
- private void validateInjections(ISeamProject project, ISeamJavaComponentDeclaration
declaration, IValidationContext helper, IReporter reporter) {
- Set<IBijectedAttribute> injections =
declaration.getBijectedAttributesByType(BijectedAttributeType.IN);
- for (IBijectedAttribute injection : injections) {
- String name = injection.getName();
+ private void validateBijections(ISeamProject project, ISeamJavaComponentDeclaration
declaration, IValidationContext helper, IReporter reporter) {
+ Set<IBijectedAttribute> bijections = declaration.getBijectedAttributes();
+ if(bijections==null) {
+ return;
+ }
+ for (IBijectedAttribute bijection : bijections) {
+ String name = bijection.getName();
if(name.startsWith("#{")) {
// TODO Validate EL
} else {
- Set<ISeamContextVariable> variables = project.getVariablesByName(name);
- for (ISeamContextVariable variable : variables) {
- // save link between java source and variable name
- validationContext.addLinkedResource(name, declaration.getSourcePath());
+ // save link between java source and variable name
+ validationContext.addLinkedResource(name, declaration.getSourcePath());
+
+ if(bijection.isOfType(BijectedAttributeType.IN)) {
+ // Validate injection
+ Set<ISeamContextVariable> variables = project.getVariablesByName(name);
+ if(variables==null || variables.size()<1) {
+ // Injection has unknown name. Mark it.
+ // TODO check preferences to mark it as Error or Warning or ignore it.
+ IResource declarationResource = declaration.getResource();
+ addError(UNKNOWN_INJECTION_NAME_MESSAGE_ID, new String[]{name}, bijection,
declarationResource, MARKED_COMPONENT_MESSAGE_GROUP);
+ }
}
- if(variables.size()<1) {
- // Injection has unknown name. Mark it.
- // TODO check preferences to mark it as Error or Warning or ignore it.
- IResource declarationResource = declaration.getResource();
- addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, injection, declarationResource,
MARKED_COMPONENT_MESSAGE_GROUP);
- }
}
}
}
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-12
15:38:49 UTC (rev 2409)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidationContext.java 2007-07-12
16:33:22 UTC (rev 2410)
@@ -38,19 +38,16 @@
linkedResources = new HashSet<IPath>();
resourcesByVariableName.put(variableName, linkedResources);
}
- if(!linkedResources.contains(linkedResourcePath)) {
- // save linked resources.
- linkedResources.add(linkedResourcePath);
- }
+ // save linked resources.
+ linkedResources.add(linkedResourcePath);
+
// Save link between resource and variable names. It's needed if variable name
changes in resource file.
Set<String> variableNames = variableNamesByResource.get(linkedResourcePath);
if(variableNames==null) {
variableNames = new HashSet<String>();
variableNamesByResource.put(linkedResourcePath, variableNames);
}
- if(!variableNames.contains(variableName)) {
- variableNames.add(variableName);
- }
+ variableNames.add(variableName);
}
/**
@@ -60,13 +57,13 @@
*/
public void removeLinkedResource(String oldVariableName, IPath linkedResourcePath) {
Set<IPath> linkedResources = resourcesByVariableName.get(oldVariableName);
- if(linkedResources!=null && linkedResources.contains(linkedResourcePath)) {
+ if(linkedResources!=null) {
// remove linked resource.
linkedResources.remove(linkedResourcePath);
}
// Remove link between resource and variable names.
Set<String> variableNames = variableNamesByResource.get(linkedResourcePath);
- if(variableNames!=null && variableNames.contains(oldVariableName)) {
+ if(variableNames!=null) {
variableNames.remove(oldVariableName);
}
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java 2007-07-12
15:38:49 UTC (rev 2409)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java 2007-07-12
16:33:22 UTC (rev 2410)
@@ -12,7 +12,6 @@
import java.util.Set;
-import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.wst.validation.internal.core.Message;
@@ -55,12 +54,14 @@
}
protected void addError(String messageId, String[] messageArguments,
ISeamTextSourceReference location, IResource target, String messageGroup) {
+ addError(messageId, messageArguments, location.getLength(),
location.getStartPosition(), target, messageGroup);
+ }
+
+ protected void addError(String messageId, String[] messageArguments, int length, int
offset, IResource target, String messageGroup) {
IMessage message = new Message(getBaseName(), IMessage.HIGH_SEVERITY, messageId,
messageArguments, target, messageGroup);
- message.setLength(location.getLength());
- message.setOffset(location.getStartPosition());
+ message.setLength(length);
+ message.setOffset(offset);
message.setSeverity(IMessage.HIGH_SEVERITY);
-// message.setAttribute(IMarker.TRANSIENT, Boolean.TRUE);
-// message.setMarkerId("org.jboss.tools.seam.core.seamProblem");
reporter.addMessage(this, message);
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/messages.properties
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/messages.properties 2007-07-12
15:38:49 UTC (rev 2409)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/messages.properties 2007-07-12
16:33:22 UTC (rev 2410)
@@ -8,5 +8,10 @@
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
-NONUNIQUE_COMPONENT_NAME_MESSAGE=Component name must be unique if it has the same
precedence.
-UNKNOWN_INJECTION_NAME=Unknown context variable name.
\ No newline at end of file
+NONUNIQUE_COMPONENT_NAME_MESSAGE=Duplicate component name {0}
+UNKNOWN_INJECTION_NAME=Unknown context variable name: {0}
+STATEFUL_COMPONENT_DOES_NOT_CONTENT_REMOVE=Stateful component {0} must have a method
marked @Remove
+STATEFUL_COMPONENT_DOES_NOT_CONTENT_DESTROY=Stateful component {0} must have a method
marked @Destroy
+STATEFUL_COMPONENT_WRONG_SCOPE=Stateful component {0} should not have
org.jboss.seam.ScopeType.PAGE, nor org.jboss.seam.ScopeType.STATELESS
+STATEFUL_COMPONENT_DUPLICATE_REMOVE=Duplicate @Remove method {0}
+STATEFUL_COMPONENT_DUPLICATE_DESTROY=Duplicate @Destroy method {0}
\ No newline at end of file