Author: akazakov
Date: 2007-07-11 12:20:43 -0400 (Wed, 11 Jul 2007)
New Revision: 2393
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.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/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/messages.properties
Log:
http://jira.jboss.com/jira/browse/EXIN-327 Added @IN validation. Improved incremental
validation.
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2007-07-11
15:56:54 UTC (rev 2392)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2007-07-11
16:20:43 UTC (rev 2393)
@@ -96,6 +96,12 @@
public Set<ISeamContextVariable> getVariablesByScope(ScopeType scope);
/**
+ * @param full path of IResource where the variable is declared.
+ * @return Set of ISeamContextVariables by resource path.
+ */
+ public Set<ISeamContextVariable> getVariablesByPath(IPath path);
+
+ /**
* @return all factories methods of project
*/
public Set<ISeamFactory> getFactories();
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-11
15:56:54 UTC (rev 2392)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-07-11
16:20:43 UTC (rev 2393)
@@ -618,7 +618,33 @@
}
return result;
}
-
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.seam.core.ISeamProject#getVariablesByPath(org.eclipse.core.runtime.IPath)
+ */
+ public Set<ISeamContextVariable> getVariablesByPath(IPath path) {
+ Set<ISeamContextVariable> result = new HashSet<ISeamContextVariable>();
+ for (ISeamContextVariable variable : allVariables) {
+ if(variable instanceof ISeamComponent) {
+ ISeamComponent c = (ISeamComponent)variable;
+ for (ISeamComponentDeclaration d: c.getAllDeclarations()) {
+ SeamComponentDeclaration di = (SeamComponentDeclaration)d;
+ if(path.equals(di.getSourcePath())) {
+ result.add(variable);
+ break;
+ }
+ }
+ } else {
+ IResource variableResource = variable.getResource();
+ if(path.equals(variableResource.getFullPath())) {
+ result.add(variable);
+ }
+ }
+ }
+ return result;
+ }
+
int revalidateScopesLock = 0;
void revalidateScopes() {
List<Change> changes = null;
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-11
15:56:54 UTC (rev 2392)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java 2007-07-11
16:20:43 UTC (rev 2393)
@@ -12,6 +12,7 @@
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
import org.eclipse.core.resources.IFile;
@@ -21,13 +22,15 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
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;
+import org.jboss.tools.seam.core.BijectedAttributeType;
+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.ISeamContextVariable;
import org.jboss.tools.seam.core.ISeamJavaComponentDeclaration;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.ISeamTextSourceReference;
@@ -40,14 +43,15 @@
*/
public class SeamJavaValidator extends SeamValidator {
- private static final String NONUNIQUE_NAME_MESSAGE_GROUP = "nonuniqueName";
+ private static final String MARKED_COMPONENT_MESSAGE_GROUP =
"markedComponent";
public static final String NONUNIQUE_COMPONENT_NAME_MESSAGE_ID =
"NONUNIQUE_COMPONENT_NAME_MESSAGE";
+ public static final String UNKNOWN_INJECTION_NAME_MESSAGE_ID =
"UNKNOWN_INJECTION_NAME";
+
private SeamValidationContext validationContext;
public ISchedulingRule getSchedulingRule(IValidationContext helper) {
- // TODO
return null;
}
@@ -69,44 +73,52 @@
continue;
}
if (currentFile != null && currentFile.exists()) {
- String oldComponentNameOfChangedFile =
validationContext.getNonuniqueNameOfComponent(currentFile.getFullPath());
- if(oldComponentNameOfChangedFile!=null) {
+ // 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 component name was changed in java file
- String newComponentNameOfChangedFile =
getComponentNameByResource(currentFile.getFullPath(), project);
- if(newComponentNameOfChangedFile!=null &&
!oldComponentNameOfChangedFile.equals(newComponentNameOfChangedFile)) {
- // Name was changed.
- // Collect resources with new component name.
- Set<IPath> linkedResources =
validationContext.getMarkedNonuniqueNamedResources(newComponentNameOfChangedFile);
- if(linkedResources!=null) {
- resources.addAll(linkedResources);
+ // Check if variable name was changed in java file
+ Set<String> newVariableNamesOfChangedFile =
getVariablesNameByResource(currentFile.getFullPath(), project);
+ for (String newVariableName : newVariableNamesOfChangedFile) {
+ if(!oldVariablesNamesOfChangedFile.contains(newVariableName)) {
+ // Name was changed.
+ // Collect resources with new component name.
+ Set<IPath> linkedResources =
validationContext.getResourcesByVariableName(newVariableName);
+ if(linkedResources!=null) {
+ resources.addAll(linkedResources);
+ }
}
- // Check if changed file is not component anymore.
- } else if(newComponentNameOfChangedFile == null) {
+ }
+ // Check if changed file is not linked to any variables anymore.
+ if(newVariableNamesOfChangedFile.size() == 0) {
resources.add(currentFile.getFullPath());
}
- // Collect resources with old component name.
- Set<IPath> linkedResources =
validationContext.getMarkedNonuniqueNamedResources(oldComponentNameOfChangedFile);
- if(linkedResources!=null) {
- resources.addAll(linkedResources);
+ // Collect all linked resources with old variable names.
+ for (String name : oldVariablesNamesOfChangedFile) {
+ Set<IPath> linkedResources =
validationContext.getResourcesByVariableName(name);
+ if(linkedResources!=null) {
+ resources.addAll(linkedResources);
+ }
}
// 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, NONUNIQUE_NAME_MESSAGE_GROUP);
- validateUniqueComponentName(project, linkedResource, checkedComponents, helper,
reporter);
+ reporter.removeMessageSubset(this, linkedResource,
MARKED_COMPONENT_MESSAGE_GROUP);
+ validateComponent(project, linkedResource, checkedComponents, helper, reporter);
checkedResources.add(linkedResource);
}
} else {
// Validate new (unmarked) Java file.
- validateUniqueComponentName(project, currentFile.getFullPath(), checkedComponents,
helper, reporter);
+ validateComponent(project, currentFile.getFullPath(), checkedComponents, helper,
reporter);
}
// TODO
}
@@ -118,23 +130,30 @@
return OK_STATUS;
}
- private void validateUniqueComponentName(ISeamProject project, IPath sourceFilePath,
Set<ISeamComponent> checkedComponents, IValidationContext helper, IReporter
reporter) {
+ private void validateComponent(ISeamProject project, IPath sourceFilePath,
Set<ISeamComponent> checkedComponents, IValidationContext helper, IReporter
reporter) {
Set<ISeamComponent> components = project.getComponentsByPath(sourceFilePath);
for (ISeamComponent component : components) {
// Don't validate one component twice.
if(!checkedComponents.contains(component)) {
- validateUniqueComponentName(project, component, helper, reporter);
+ validateComponent(project, component, helper, reporter);
checkedComponents.add(component);
}
}
}
- public String getComponentNameByResource(IPath resourcePath, ISeamProject project) {
- Set<ISeamComponent> components = project.getComponentsByPath(resourcePath);
- for (ISeamComponent component : components) {
- return component.getName();
+ /*
+ * Returns set of variables which are linked with this resource
+ */
+ private Set<String> getVariablesNameByResource(IPath resourcePath, ISeamProject
project) {
+ Set<ISeamContextVariable> variables = project.getVariablesByPath(resourcePath);
+ Set<String> result = new HashSet<String>();
+ for (ISeamContextVariable variable : variables) {
+ String name = variable.getName();
+ if(!result.contains(name)) {
+ result.add(name);
+ }
}
- return null;
+ return result;
}
public void cleanup(IReporter reporter) {
@@ -146,16 +165,16 @@
validationContext.clear();
Set<ISeamComponent> components = project.getComponents();
for (ISeamComponent component : components) {
- validateUniqueComponentName(project, component, helper, reporter);
+ validateComponent(project, component, helper, reporter);
// TODO
}
return OK_STATUS;
}
/*
- * Validates that component has unique name
+ * Validates the component
*/
- private void validateUniqueComponentName(ISeamProject project, ISeamComponent component,
IValidationContext helper, IReporter reporter) {
+ private void validateComponent(ISeamProject project, ISeamComponent component,
IValidationContext helper, IReporter reporter) {
ISeamJavaComponentDeclaration firstJavaDeclaration = component.getJavaDeclaration();
if(firstJavaDeclaration!=null) {
HashMap<Integer, ISeamJavaComponentDeclaration> usedPrecedences = new
HashMap<Integer, ISeamJavaComponentDeclaration>();
@@ -164,7 +183,14 @@
usedPrecedences.put(firstJavaDeclarationPrecedence, firstJavaDeclaration);
Set<ISeamComponentDeclaration> declarations = component.getAllDeclarations();
for (ISeamComponentDeclaration declaration : declarations) {
+ if(declaration instanceof ISeamJavaComponentDeclaration &&
declaration.getResource() instanceof IFile) {
+ // 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);
+ }
if(declaration instanceof ISeamJavaComponentDeclaration &&
declaration!=firstJavaDeclaration) {
+ // Validate @Name
// Component class with the same component name. Check precedence.
ISeamJavaComponentDeclaration javaDeclaration =
(ISeamJavaComponentDeclaration)declaration;
int javaDeclarationPrecedence = javaDeclaration.getPrecedence();
@@ -178,18 +204,46 @@
// Mark first wrong declaration with that name
IResource checkedDeclarationResource = checkedDeclaration.getResource();
ISeamTextSourceReference location =
((SeamComponentDeclaration)checkedDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
- addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, location,
checkedDeclarationResource, NONUNIQUE_NAME_MESSAGE_GROUP);
+ if(location!=null) {
+ addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, location,
checkedDeclarationResource, MARKED_COMPONENT_MESSAGE_GROUP);
+ }
markedDeclarations.add(checkedDeclaration);
- validationContext.addLinkedResource(checkedDeclaration.getName(),
checkedDeclarationResource.getFullPath());
}
// Mark next wrong declaration with that name
markedDeclarations.add(javaDeclaration);
- validationContext.addLinkedResource(javaDeclaration.getName(),
javaDeclarationResource.getFullPath());
ISeamTextSourceReference location =
((SeamComponentDeclaration)javaDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
- addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, location, javaDeclarationResource,
NONUNIQUE_NAME_MESSAGE_GROUP);
+ if(location!=null) {
+ addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, location, javaDeclarationResource,
MARKED_COMPONENT_MESSAGE_GROUP);
+ }
}
}
}
}
}
+
+ private void validateJavaDeclaration(ISeamProject project, ISeamJavaComponentDeclaration
declaration, IValidationContext helper, IReporter reporter) {
+ validateInjections(project, declaration, helper, reporter);
+ }
+
+ 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();
+ 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());
+ }
+ 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);
+ }
+ }
+ }
+ }
}
\ 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-11
15:56:54 UTC (rev 2392)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidationContext.java 2007-07-11
16:20:43 UTC (rev 2393)
@@ -24,38 +24,63 @@
*/
public class SeamValidationContext {
- private Map<String, Set<IPath>> markedNonuniqueNamedResources = new
HashMap<String, Set<IPath>>();
- private Map<IPath, String> nonuniqueNames = new HashMap<IPath, String>();
+ private Map<String, Set<IPath>> resourcesByVariableName = new
HashMap<String, Set<IPath>>();
+ private Map<IPath, Set<String>> variableNamesByResource = new
HashMap<IPath, Set<String>>();
/**
- * Save linked resources of component name that we marked.
+ * Save link between resource and variable name.
* It's needed for incremental validation because we must save all linked resources
of changed java file.
*/
- public void addLinkedResource(String componentName, IPath linkedResourcePath) {
- Set<IPath> linkedResources = markedNonuniqueNamedResources.get(componentName);
+ public void addLinkedResource(String variableName, IPath linkedResourcePath) {
+ Set<IPath> linkedResources = resourcesByVariableName.get(variableName);
if(linkedResources==null) {
- // create set of linked resources with component name that we must mark.
+ // create set of linked resources with variable name.
linkedResources = new HashSet<IPath>();
- markedNonuniqueNamedResources.put(componentName, linkedResources);
+ resourcesByVariableName.put(variableName, linkedResources);
}
if(!linkedResources.contains(linkedResourcePath)) {
- // save linked resources that we must mark.
+ // save linked resources.
linkedResources.add(linkedResourcePath);
}
- // Save link between component name and marked resource. It's needed if component
name changes in java file.
- nonuniqueNames.put(linkedResourcePath, componentName);
+ // 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);
+ }
}
- public Set<IPath> getMarkedNonuniqueNamedResources(String componentName) {
- return markedNonuniqueNamedResources.get(componentName);
+ /**
+ * Removes link between resource and variable name.
+ * @param oldVariableName
+ * @param linkedResourcePath
+ */
+ public void removeLinkedResource(String oldVariableName, IPath linkedResourcePath) {
+ Set<IPath> linkedResources = resourcesByVariableName.get(oldVariableName);
+ if(linkedResources!=null && linkedResources.contains(linkedResourcePath)) {
+ // 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)) {
+ variableNames.remove(oldVariableName);
+ }
}
- public String getNonuniqueNameOfComponent(IPath sourcePath) {
- return nonuniqueNames.get(sourcePath);
+ public Set<IPath> getResourcesByVariableName(String variableName) {
+ return resourcesByVariableName.get(variableName);
}
+ public Set<String> getVariableNamesByResource(IPath sourcePath) {
+ return variableNamesByResource.get(sourcePath);
+ }
+
public void clear() {
- markedNonuniqueNamedResources.clear();
- nonuniqueNames.clear();
+ resourcesByVariableName.clear();
+ variableNamesByResource.clear();
}
}
\ No newline at end of file
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-11
15:56:54 UTC (rev 2392)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/messages.properties 2007-07-11
16:20:43 UTC (rev 2393)
@@ -8,4 +8,5 @@
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
-NONUNIQUE_COMPONENT_NAME_MESSAGE=Component name must be unique if it has the same
precedence.
\ No newline at end of file
+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