Author: akazakov
Date: 2007-07-25 11:18:25 -0400 (Wed, 25 Jul 2007)
New Revision: 2653
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/ISeamValidator.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/SeamValidatorManager.java
Removed:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidationHelper.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.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 EL Incremental validation.
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml 2007-07-25 14:11:35 UTC (rev
2652)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml 2007-07-25 15:18:25 UTC (rev
2653)
@@ -130,8 +130,8 @@
<extension
point="org.eclipse.wst.validation.validator"
- id="SeamCoreValidator"
- name="Seam Core Validator">
+ id="SeamValidator"
+ name="Seam Validator">
<validator>
<projectNature id="org.jboss.tools.seam.core.seamnature" />
<filter
@@ -140,33 +140,8 @@
<filter
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.xml"/>
- <markerId
- markerIdValue="seamCoreProblem">
- </markerId>
- <helper
- class="org.jboss.tools.seam.internal.core.validation.SeamValidationHelper">
- </helper>
- <run
-
class="org.jboss.tools.seam.internal.core.validation.SeamCoreValidator"
- incremental="true"
- fullBuild="true"
- />
- </validator>
- </extension>
- <extension
- point="org.eclipse.wst.validation.validator"
- id="SeamELValidator"
- name="Seam EL Validator">
- <validator>
- <projectNature id="org.jboss.tools.seam.core.seamnature" />
<filter
objectClass="org.eclipse.core.resources.IFile"
- nameFilter="*.java"/>
- <filter
- objectClass="org.eclipse.core.resources.IFile"
- nameFilter="*.xml"/>
- <filter
- objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.xhtml"/>
<filter
objectClass="org.eclipse.core.resources.IFile"
@@ -192,36 +167,27 @@
<contentTypeBinding
contentTypeId="org.eclipse.jst.jsp.core.jspfragmentsource"/>
<contentTypeBinding
contentTypeId="org.eclipse.jst.jsp.core.tagsource"/>
<markerId
- markerIdValue="seamELProblem">
+ markerIdValue="seamProblem">
</markerId>
<helper
- class="org.jboss.tools.seam.internal.core.validation.SeamELValidationHelper">
+ class="org.jboss.tools.seam.internal.core.validation.SeamValidationHelper">
</helper>
<run
-
class="org.jboss.tools.seam.internal.core.validation.SeamELValidator"
+
class="org.jboss.tools.seam.internal.core.validation.SeamValidatorManager"
incremental="true"
fullBuild="true"
/>
</validator>
- </extension>
+ </extension>
<extension
- id="seamCoreProblem"
- name="Seam Core Problem"
+ id="seamProblem"
+ name="Seam Problem"
point="org.eclipse.core.resources.markers">
<super type="org.eclipse.wst.validation.problemmarker"/>
<persistent
value="true">
</persistent>
</extension>
- <extension
- id="seamELProblem"
- name="Seam EL Problem"
- point="org.eclipse.core.resources.markers">
- <super type="org.eclipse.wst.validation.problemmarker"/>
- <persistent
- value="true">
- </persistent>
- </extension>
-</plugin>
+</plugin>
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2007-07-25
14:11:35 UTC (rev 2652)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2007-07-25
15:18:25 UTC (rev 2653)
@@ -102,11 +102,11 @@
List<List<ELToken>> variations = getPossibleVarsFromPrefix(tokens);
if (variations.isEmpty()) {
- resolvedVariables = resolveVariables(project, scope, tokens, tokens);
+ resolvedVariables = resolveVariables(project, scope, tokens, tokens,
returnEqualedVariablesOnly);
} else {
for (List<ELToken> variation : variations) {
List<ISeamContextVariable>resolvedVars = new
ArrayList<ISeamContextVariable>();
- resolvedVars = resolveVariables(project, scope, variation, tokens);
+ resolvedVars = resolveVariables(project, scope, variation, tokens,
returnEqualedVariablesOnly);
if (resolvedVars != null && !resolvedVars.isEmpty()) {
resolvedVariables = resolvedVars;
resolvedExpressionPart = variation;
@@ -140,7 +140,7 @@
int startTokenIndex = (resolvedExpressionPart == null ? 0 :
resolvedExpressionPart.size());
Set<IMember> members = new HashSet<IMember>();
for (ISeamContextVariable var : resolvedVariables) {
- IMember member = SeamExpressionResolver.getMemberByVariable(var);
+ IMember member = SeamExpressionResolver.getMemberByVariable(var,
returnEqualedVariablesOnly);
if (member != null && !members.contains(member))
members.add(member);
}
@@ -327,11 +327,11 @@
* @param tokens
* @return
*/
- private List<ISeamContextVariable> resolveVariables(ISeamProject project,
ScopeType scope, List<ELToken>part, List<ELToken> tokens) {
+ private List<ISeamContextVariable> resolveVariables(ISeamProject project,
ScopeType scope, List<ELToken>part, List<ELToken> tokens, boolean
onlyEqualNames) {
List<ISeamContextVariable>resolvedVars = new
ArrayList<ISeamContextVariable>();
String varName = computeVariableName(part);
if (varName != null) {
- resolvedVars = SeamExpressionResolver.resolveVariables(project, scope, varName);
+ resolvedVars = SeamExpressionResolver.resolveVariables(project, scope, varName,
onlyEqualNames);
}
if (resolvedVars != null && resolvedVars.size() > 0) {
List<ISeamContextVariable> newResolvedVars = new
ArrayList<ISeamContextVariable>();
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java 2007-07-25
14:11:35 UTC (rev 2652)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java 2007-07-25
15:18:25 UTC (rev 2653)
@@ -51,10 +51,10 @@
* @param name
* @return
*/
- public static List<ISeamContextVariable> resolveVariables(ISeamProject project,
ScopeType scope, String name) {
+ public static List<ISeamContextVariable> resolveVariables(ISeamProject project,
ScopeType scope, String name, boolean onlyEqualNames) {
if (project == null || name == null) return null;
- return (scope == null ? internalResolveVariables(project, name) :
- internalResolveVariablesByScope(project, scope, name));
+ return (scope == null ? internalResolveVariables(project, name, onlyEqualNames) :
+ internalResolveVariablesByScope(project, scope, name, onlyEqualNames));
}
/**
@@ -65,12 +65,18 @@
* @param name
* @return
*/
- private static List<ISeamContextVariable> internalResolveVariables(ISeamProject
project, String name) {
+ private static List<ISeamContextVariable> internalResolveVariables(ISeamProject
project, String name, boolean onlyEqualNames) {
List<ISeamContextVariable> resolvedVariables = new
ArrayList<ISeamContextVariable>();
Set<ISeamContextVariable> variables = project.getVariables();
for (ISeamContextVariable variable : variables) {
- if (variable.getName().startsWith(name)) {
- resolvedVariables.add(variable);
+ if(onlyEqualNames) {
+ if (variable.getName().equals(name)) {
+ resolvedVariables.add(variable);
+ }
+ } else {
+ if (variable.getName().startsWith(name)) {
+ resolvedVariables.add(variable);
+ }
}
}
return resolvedVariables;
@@ -85,12 +91,18 @@
* @param name
* @return
*/
- private static List<ISeamContextVariable>
internalResolveVariablesByScope(ISeamProject project, ScopeType scope, String name) {
+ private static List<ISeamContextVariable>
internalResolveVariablesByScope(ISeamProject project, ScopeType scope, String name,
boolean onlyEqualNames) {
List<ISeamContextVariable> resolvedVariables = new
ArrayList<ISeamContextVariable>();
Set<ISeamContextVariable> variables = project.getVariablesByScope(scope);
for (ISeamContextVariable variable : variables) {
- if (variable.getName().startsWith(name)) {
- resolvedVariables.add(variable);
+ if(onlyEqualNames) {
+ if (variable.getName().equals(name)) {
+ resolvedVariables.add(variable);
+ }
+ } else {
+ if (variable.getName().startsWith(name)) {
+ resolvedVariables.add(variable);
+ }
}
}
return resolvedVariables;
@@ -102,7 +114,7 @@
* @param variable
* @return
*/
- public static IMember getMemberByVariable(ISeamContextVariable variable) {
+ public static IMember getMemberByVariable(ISeamContextVariable variable, boolean
onlyEqualNames) {
IMember member = null;
if (variable instanceof ISeamComponent) {
ISeamComponent component = (ISeamComponent)variable;
@@ -132,10 +144,10 @@
ISeamProject project = ((ISeamElement)factory).getSeamProject();
// ISeamProject project = getSeamProject(factory.getResource());
if (project != null) {
- List<ISeamContextVariable> resolvedValues = resolveVariables(project,
factory.getScope(), value);
+ List<ISeamContextVariable> resolvedValues = resolveVariables(project,
factory.getScope(), value, onlyEqualNames);
for (ISeamContextVariable var : resolvedValues) {
if (var.getName().equals(value)) {
- member = getMemberByVariable(var);
+ member = getMemberByVariable(var, onlyEqualNames);
break;
}
}
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/ISeamValidator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/ISeamValidator.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/ISeamValidator.java 2007-07-25
15:18:25 UTC (rev 2653)
@@ -0,0 +1,45 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.validation;
+
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.wst.validation.internal.core.ValidationException;
+
+/**
+ * Seam valodator that is managed by SeamValidatorManager.
+ * @author Alexey Kazakov
+ */
+public interface ISeamValidator {
+
+ public static final String MARKED_SEAM_RESOURCE_MESSAGE_GROUP =
"markedSeamResource";
+
+ /**
+ * @return true if validator is enabled.
+ */
+ public boolean isEnabled();
+
+ /**
+ * Incremental Validation
+ * @return
+ * @throws ValidationException
+ */
+ public IStatus validate(Set<IFile> changedFiles) throws ValidationException;
+
+ /**
+ * Full Validation
+ * @return
+ * @throws ValidationException
+ */
+ public IStatus validateAll() throws ValidationException;
+}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java 2007-07-25
14:11:35 UTC (rev 2652)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java 2007-07-25
15:18:25 UTC (rev 2653)
@@ -40,6 +40,7 @@
import org.jboss.tools.seam.core.ISeamContextVariable;
import org.jboss.tools.seam.core.ISeamFactory;
import org.jboss.tools.seam.core.ISeamJavaComponentDeclaration;
+import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.ISeamProperty;
import org.jboss.tools.seam.core.ISeamTextSourceReference;
import org.jboss.tools.seam.core.ISeamXmlComponentDeclaration;
@@ -59,14 +60,43 @@
*/
public class SeamCoreValidator extends SeamValidator {
+ protected static final String NONUNIQUE_COMPONENT_NAME_MESSAGE_ID =
"NONUNIQUE_COMPONENT_NAME_MESSAGE";
+ protected static final String UNKNOWN_VARIABLE_NAME_MESSAGE_ID =
"UNKNOWN_VARIABLE_NAME";
+ protected static final String
STATEFUL_COMPONENT_DOES_NOT_CONTAIN_METHOD_SUFIX_MESSAGE_ID =
"STATEFUL_COMPONENT_DOES_NOT_CONTAIN_";
+ protected static final String DUPLICATE_METHOD_PREFIX_MESSAGE_ID =
"DUPLICATE_";
+ protected static final String REMOVE_METHOD_SUFIX_MESSAGE_ID = "REMOVE";
+ protected static final String DESTROY_METHOD_SUFIX_MESSAGE_ID = "DESTROY";
+ protected static final String CREATE_METHOD_SUFIX_MESSAGE_ID = "CREATE";
+ protected static final String UNWRAP_METHOD_SUFIX_MESSAGE_ID = "UNWRAP";
+ protected static final String OBSERVER_METHOD_SUFIX_MESSAGE_ID = "OBSERVER";
+ protected static final String NONCOMPONENTS_METHOD_SUFIX_MESSAGE_ID =
"_DOESNT_BELONG_TO_COMPONENT";
+ protected static final String STATEFUL_COMPONENT_WRONG_SCOPE_MESSAGE_ID =
"STATEFUL_COMPONENT_WRONG_SCOPE";
+ protected static final String ENTITY_COMPONENT_WRONG_SCOPE_MESSAGE_ID =
"ENTITY_COMPONENT_WRONG_SCOPE";
+ protected static final String UNKNOWN_FACTORY_NAME_MESSAGE_ID =
"UNKNOWN_FACTORY_NAME";
+ protected static final String MULTIPLE_DATA_BINDER_MESSAGE_ID =
"MULTIPLE_DATA_BINDER";
+ protected static final String DUPLICATE_VARIABLE_NAME_MESSAGE_ID =
"DUPLICATE_VARIABLE_NAME";
+ protected static final String UNKNOWN_DATA_MODEL_MESSAGE_ID =
"UNKNOWN_DATA_MODEL";
+ protected static final String UNKNOWN_COMPONENT_CLASS_NAME_MESSAGE_ID =
"UNKNOWN_COMPONENT_CLASS_NAME";
+ protected static final String UNKNOWN_COMPONENT_PROPERTY_MESSAGE_ID =
"UNKNOWN_COMPONENT_PROPERTY";
+
+ public SeamCoreValidator(SeamValidatorManager validatorManager,
+ SeamValidationHelper coreHelper, IReporter reporter,
+ SeamValidationContext validationContext, ISeamProject project) {
+ super(validatorManager, coreHelper, reporter, validationContext, project);
+ }
+
/* (non-Javadoc)
- * @see
org.jboss.tools.seam.internal.core.validation.SeamValidator#validate(java.util.Set)
+ * @see org.jboss.tools.seam.internal.core.validation.ISeamValidator#isEnabled()
*/
- @Override
+ public boolean isEnabled() {
+ return SeamPreferences.isValidateCore(project);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.seam.internal.core.validation.ISeamValidator#validate(java.util.Set)
+ */
public IStatus validate(Set<IFile> changedFiles) throws ValidationException {
- if(!SeamPreferences.isValidateCore(project)) {
- return OK_STATUS;
- }
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
Set<ISeamComponent> checkedComponents = new HashSet<ISeamComponent>();
Set<String> markedDuplicateFactoryNames = new HashSet<String>();
@@ -77,9 +107,9 @@
if(reporter.isCancelled()) {
break;
}
- if (currentFile != null) {
- // Get all variable names that were linked with this resource.
- Set<String> oldVariablesNamesOfChangedFile =
validationContext.getVariableNamesByResource(currentFile.getFullPath());
+ if (checkFileExtension(currentFile)) {
+ // Get all variable names which were linked with this resource.
+ Set<String> oldVariablesNamesOfChangedFile =
validationContext.getVariableNamesByCoreResource(currentFile.getFullPath());
if(oldVariablesNamesOfChangedFile!=null) {
// Check if variable name was changed in source file
Set<String> newVariableNamesOfChangedFile =
getVariablesNameByResource(currentFile.getFullPath());
@@ -87,7 +117,7 @@
if(!oldVariablesNamesOfChangedFile.contains(newVariableName)) {
// Name was changed.
// Collect resources with new component name.
- Set<IPath> linkedResources =
validationContext.getResourcesByVariableName(newVariableName);
+ Set<IPath> linkedResources =
validationContext.getCoreResourcesByVariableName(newVariableName);
if(linkedResources!=null) {
resources.addAll(linkedResources);
}
@@ -97,10 +127,12 @@
// Collect all linked resources with old variable names.
for (String name : oldVariablesNamesOfChangedFile) {
- Set<IPath> linkedResources =
validationContext.getResourcesByVariableName(name);
+ Set<IPath> linkedResources =
validationContext.getCoreResourcesByVariableName(name);
if(linkedResources!=null) {
resources.addAll(linkedResources);
}
+ // Save old names for EL validation. We need to validate all EL resources which use
this variable name.
+ validationContext.addVariableNameForELValidation(name);
}
} else {
// Validate new (unlinked) source file.
@@ -111,17 +143,17 @@
}
// Validate all collected linked resources.
// Remove all links between collected resources and variables names because they will
be linked again during validation.
- validationContext.removeLinkedResources(resources);
+ validationContext.removeLinkedCoreResources(resources);
for (IPath linkedResource : resources) {
// Remove markers from collected source file
IFile sourceFile = root.getFile(linkedResource);
- reporter.removeMessageSubset(this, sourceFile, MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ reporter.removeMessageSubset(validationManager, sourceFile,
ISeamValidator.MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
validateComponent(linkedResource, checkedComponents);
validateFactory(linkedResource, markedDuplicateFactoryNames);
}
// Validate all unnamed resources.
- Set<IPath> unnamedResources = validationContext.getUnnamedResources();
+ Set<IPath> unnamedResources = validationContext.getUnnamedCoreResources();
newResources.addAll(unnamedResources);
for (IPath path : newResources) {
Set<SeamJavaComponentDeclaration> declarations =
((SeamProject)project).findJavaDeclarations(path);
@@ -133,30 +165,36 @@
return OK_STATUS;
}
- /* (non-Javadoc)
- * @see org.jboss.tools.seam.internal.core.validation.SeamValidator#validateAll()
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.seam.internal.core.validation.ISeamValidator#validateAll()
*/
- @Override
public IStatus validateAll() throws ValidationException {
- reporter.removeAllMessages(this);
- validationContext.clear();
- if(SeamPreferences.isValidateCore(project)) {
- Set<ISeamComponent> components = project.getComponents();
- for (ISeamComponent component : components) {
- validateComponent(component);
+ Set<ISeamComponent> components = project.getComponents();
+ for (ISeamComponent component : components) {
+ if(reporter.isCancelled()) {
+ return OK_STATUS;
}
- Set<ISeamFactory> factories = project.getFactories();
- Set<String> markedDuplicateFactoryNames = new HashSet<String>();
- for (ISeamFactory factory : factories) {
- validateFactory(factory, markedDuplicateFactoryNames);
+ validateComponent(component);
+ }
+ Set<ISeamFactory> factories = project.getFactories();
+ Set<String> markedDuplicateFactoryNames = new HashSet<String>();
+ for (ISeamFactory factory : factories) {
+ if(reporter.isCancelled()) {
+ return OK_STATUS;
}
+ validateFactory(factory, markedDuplicateFactoryNames);
+ }
- Map<String,SeamJavaComponentDeclaration> declarations =
((SeamProject)project).getAllJavaComponentDeclarations();
- Collection<SeamJavaComponentDeclaration> values = declarations.values();
- for (SeamJavaComponentDeclaration d : values) {
- validateMethodsOfUnknownComponent(d);
+ Map<String,SeamJavaComponentDeclaration> declarations =
((SeamProject)project).getAllJavaComponentDeclarations();
+ Collection<SeamJavaComponentDeclaration> values = declarations.values();
+ for (SeamJavaComponentDeclaration d : values) {
+ if(reporter.isCancelled()) {
+ return OK_STATUS;
}
+ validateMethodsOfUnknownComponent(d);
}
+
return OK_STATUS;
}
@@ -234,16 +272,16 @@
if(!firstDuplicateVariableWasMarked) {
firstDuplicateVariableWasMarked = true;
// mark original factory
- validationContext.addLinkedResource(factoryName, factory.getSourcePath());
+ validationContext.addLinkedCoreResource(factoryName, factory.getSourcePath());
location = coreHelper.getLocationOfName(factory);
- this.addError(DUPLICATE_VARIABLE_NAME_MESSAGE_ID,
SeamPreferences.DUPLICATE_VARIABLE_NAME, new String[]{factoryName}, location,
factory.getResource(), MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ this.addError(DUPLICATE_VARIABLE_NAME_MESSAGE_ID,
SeamPreferences.DUPLICATE_VARIABLE_NAME, new String[]{factoryName}, location,
factory.getResource());
}
// mark duplicate variable
IResource resource = coreHelper.getComponentResourceWithName(variable);
if(!coreHelper.isJar(resource)) {
- validationContext.addLinkedResource(factoryName, resource.getFullPath());
+ validationContext.addLinkedCoreResource(factoryName, resource.getFullPath());
location = coreHelper.getLocationOfName(variable);
- this.addError(DUPLICATE_VARIABLE_NAME_MESSAGE_ID,
SeamPreferences.DUPLICATE_VARIABLE_NAME, new String[]{factoryName}, location, resource,
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ this.addError(DUPLICATE_VARIABLE_NAME_MESSAGE_ID,
SeamPreferences.DUPLICATE_VARIABLE_NAME, new String[]{factoryName}, location, resource);
}
markedDuplicateFactoryNames.add(factoryName);
}
@@ -256,8 +294,8 @@
if(unknownVariable && validateUnknownName) {
// mark unknown factory name
// save link to factory resource
- validationContext.addLinkedResource(factoryName, factory.getSourcePath());
- this.addError(UNKNOWN_FACTORY_NAME_MESSAGE_ID, SeamPreferences.UNKNOWN_FACTORY_NAME,
new String[]{factoryName}, coreHelper.getLocationOfName(factory), factory.getResource(),
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ validationContext.addLinkedCoreResource(factoryName, factory.getSourcePath());
+ this.addError(UNKNOWN_FACTORY_NAME_MESSAGE_ID, SeamPreferences.UNKNOWN_FACTORY_NAME,
new String[]{factoryName}, coreHelper.getLocationOfName(factory), factory.getResource());
}
}
@@ -280,17 +318,11 @@
Set<String> result = new HashSet<String>();
for (ISeamContextVariable variable : variables) {
String name = variable.getName();
- if(!result.contains(name)) {
- result.add(name);
- }
+ result.add(name);
}
return result;
}
- public void cleanup(IReporter reporter) {
- super.cleanup(reporter);
- }
-
/*
* Validates the component
*/
@@ -308,7 +340,7 @@
boolean sourceJavaDeclaration = !((IType)jd.getSourceMember()).isBinary();
if(sourceJavaDeclaration) {
// Save link between component name and java source file.
- validationContext.addLinkedResource(component.getName(),
declaration.getSourcePath());
+ validationContext.addLinkedCoreResource(component.getName(),
declaration.getSourcePath());
}
if(declaration!=firstJavaDeclaration) {
// Validate @Name
@@ -327,7 +359,7 @@
IResource checkedDeclarationResource = checkedDeclaration.getResource();
ISeamTextSourceReference location =
((SeamComponentDeclaration)checkedDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
if(location!=null) {
- addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{component.getName()}, location,
checkedDeclarationResource, MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{component.getName()}, location,
checkedDeclarationResource);
}
markedDeclarations.add(checkedDeclaration);
}
@@ -335,7 +367,7 @@
markedDeclarations.add(javaDeclaration);
ISeamTextSourceReference location =
((SeamComponentDeclaration)javaDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
if(location!=null) {
- addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{component.getName()}, location,
javaDeclarationResource, MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{component.getName()}, location,
javaDeclarationResource);
}
}
}
@@ -358,7 +390,7 @@
if(coreHelper.isJar(declaration)) {
return;
}
- validationContext.addLinkedResource(componentName, declaration.getSourcePath());
+ validationContext.addLinkedCoreResource(componentName, declaration.getSourcePath());
String className = declaration.getClassName();
if(className!=null) {
IType type = null;
@@ -376,9 +408,9 @@
if(location==null) {
location = declaration;
}
- addError(UNKNOWN_COMPONENT_CLASS_NAME_MESSAGE_ID,
SeamPreferences.UNKNOWN_COMPONENT_CLASS_NAME, new String[]{className}, location,
declaration.getResource(), MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ addError(UNKNOWN_COMPONENT_CLASS_NAME_MESSAGE_ID,
SeamPreferences.UNKNOWN_COMPONENT_CLASS_NAME, new String[]{className}, location,
declaration.getResource());
} else if(!type.isBinary()) {
- validationContext.addLinkedResource(componentName,
type.getResource().getFullPath());
+ validationContext.addLinkedCoreResource(componentName,
type.getResource().getFullPath());
}
} catch (JavaModelException e) {
SeamCorePlugin.getDefault().logError("Error validating Seam Core", e);
@@ -395,7 +427,7 @@
}
boolean ok = type.isBinary() || coreHelper.findSetter(type, name)!=null;
if(!ok) {
- addError(UNKNOWN_COMPONENT_PROPERTY_MESSAGE_ID,
SeamPreferences.UNKNOWN_COMPONENT_PROPERTY, new String[]{type.getElementName(),
componentName, name}, property, declaration.getResource(),
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ addError(UNKNOWN_COMPONENT_PROPERTY_MESSAGE_ID,
SeamPreferences.UNKNOWN_COMPONENT_PROPERTY, new String[]{type.getElementName(),
componentName, name}, property, declaration.getResource());
}
}
}
@@ -409,7 +441,7 @@
ScopeType scope = component.getScope();
if(scope == ScopeType.STATELESS) {
ISeamTextSourceReference location = getScopeLocation(component);
- addError(ENTITY_COMPONENT_WRONG_SCOPE_MESSAGE_ID,
SeamPreferences.ENTITY_COMPONENT_WRONG_SCOPE, new String[]{component.getName()}, location,
javaDeclaration.getResource(), MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ addError(ENTITY_COMPONENT_WRONG_SCOPE_MESSAGE_ID,
SeamPreferences.ENTITY_COMPONENT_WRONG_SCOPE, new String[]{component.getName()}, location,
javaDeclaration.getResource());
}
}
}
@@ -443,7 +475,7 @@
ScopeType scope = component.getScope();
if(scope == ScopeType.PAGE || scope == ScopeType.STATELESS) {
ISeamTextSourceReference location = getScopeLocation(component);
- addError(STATEFUL_COMPONENT_WRONG_SCOPE_MESSAGE_ID,
SeamPreferences.STATEFUL_COMPONENT_WRONG_SCOPE, new String[]{component.getName()},
location, javaDeclaration.getResource(), MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ addError(STATEFUL_COMPONENT_WRONG_SCOPE_MESSAGE_ID,
SeamPreferences.STATEFUL_COMPONENT_WRONG_SCOPE, new String[]{component.getName()},
location, javaDeclaration.getResource());
}
}
}
@@ -453,7 +485,7 @@
ISeamTextSourceReference classNameLocation = getClassNameLocation(javaDeclaration);
Set<ISeamComponentMethod> methods =
javaDeclaration.getMethodsByType(methodType);
if(methods==null || methods.size()==0) {
- addError(STATEFUL_COMPONENT_DOES_NOT_CONTAIN_METHOD_SUFIX_MESSAGE_ID +
postfixMessageId, preferenceKey, new String[]{component.getName()}, classNameLocation,
javaDeclaration.getResource(), MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ addError(STATEFUL_COMPONENT_DOES_NOT_CONTAIN_METHOD_SUFIX_MESSAGE_ID +
postfixMessageId, preferenceKey, new String[]{component.getName()}, classNameLocation,
javaDeclaration.getResource());
}
}
@@ -471,7 +503,7 @@
for (ISeamComponentMethod method : methods) {
IMethod javaMethod = (IMethod)method.getSourceMember();
String methodName = javaMethod.getElementName();
- addError(DUPLICATE_METHOD_PREFIX_MESSAGE_ID + postfixMessageId, preferenceKey, new
String[]{methodName}, method, javaDeclaration.getResource(),
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ addError(DUPLICATE_METHOD_PREFIX_MESSAGE_ID + postfixMessageId, preferenceKey, new
String[]{methodName}, method, javaDeclaration.getResource());
}
}
}
@@ -504,7 +536,7 @@
return;
}
// save link between java source and variable name
- validationContext.addLinkedResource(name, declaration.getSourcePath());
+ validationContext.addLinkedCoreResource(name, declaration.getSourcePath());
// Validate @In
if(bijection.isOfType(BijectedAttributeType.IN)) {
@@ -512,7 +544,7 @@
if(variables==null || variables.size()<1) {
// Injection has unknown name. Mark it.
IResource declarationResource = declaration.getResource();
- addError(UNKNOWN_VARIABLE_NAME_MESSAGE_ID, SeamPreferences.UNKNOWN_VARIABLE_NAME, new
String[]{name}, bijection, declarationResource, MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ addError(UNKNOWN_VARIABLE_NAME_MESSAGE_ID, SeamPreferences.UNKNOWN_VARIABLE_NAME, new
String[]{name}, bijection, declarationResource);
}
}
}
@@ -524,19 +556,19 @@
Set<IBijectedAttribute> dataBinders =
declaration.getBijectedAttributesByType(BijectedAttributeType.DATA_BINDER);
if(dataBinders.size()>0) {
for (IBijectedAttribute dataBinder : dataBinders) {
- addError(MULTIPLE_DATA_BINDER_MESSAGE_ID, SeamPreferences.MULTIPLE_DATA_BINDER,
dataBinder, declaration.getResource(), MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ addError(MULTIPLE_DATA_BINDER_MESSAGE_ID, SeamPreferences.MULTIPLE_DATA_BINDER,
dataBinder, declaration.getResource());
}
}
} else {
// save link between java source and variable name
- validationContext.addLinkedResource(name, declaration.getSourcePath());
+ validationContext.addLinkedCoreResource(name, declaration.getSourcePath());
Set<IBijectedAttribute> dataBinders =
declaration.getBijectedAttributesByName(name);
for (IBijectedAttribute dataBinder : dataBinders) {
if(dataBinder.isOfType(BijectedAttributeType.DATA_BINDER) ||
dataBinder.isOfType(BijectedAttributeType.OUT)) {
return;
}
}
- addError(UNKNOWN_DATA_MODEL_MESSAGE_ID, SeamPreferences.UNKNOWN_DATA_MODEL, new
String[]{name}, coreHelper.getLocationOfName(bijection), declaration.getResource(),
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ addError(UNKNOWN_DATA_MODEL_MESSAGE_ID, SeamPreferences.UNKNOWN_DATA_MODEL, new
String[]{name}, coreHelper.getLocationOfName(bijection), declaration.getResource());
}
}
@@ -545,7 +577,7 @@
*/
private void validateMethodsOfUnknownComponent(ISeamJavaComponentDeclaration
declaration) {
if(project.getComponentsByPath(declaration.getSourcePath()).size()>0) {
- validationContext.removeUnnamedResource(declaration.getSourcePath());
+ validationContext.removeUnnamedCoreResource(declaration.getSourcePath());
return;
}
validateMethodOfUnknownComponent(SeamComponentMethodType.DESTROY, declaration,
DESTROY_METHOD_SUFIX_MESSAGE_ID, SeamPreferences.DESTROY_DOESNT_BELONG_TO_COMPONENT);
@@ -560,11 +592,23 @@
for (ISeamComponentMethod method : methods) {
IMethod javaMethod = (IMethod)method.getSourceMember();
String methodName = javaMethod.getElementName();
- addError(sufixMessageId + NONCOMPONENTS_METHOD_SUFIX_MESSAGE_ID, preferenceKey, new
String[]{methodName}, method, declaration.getResource(),
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
- validationContext.addUnnamedResource(declaration.getSourcePath());
+ addError(sufixMessageId + NONCOMPONENTS_METHOD_SUFIX_MESSAGE_ID, preferenceKey, new
String[]{methodName}, method, declaration.getResource());
+ validationContext.addUnnamedCoreResource(declaration.getSourcePath());
}
} else {
- validationContext.removeUnnamedResource(declaration.getSourcePath());
+ validationContext.removeUnnamedCoreResource(declaration.getSourcePath());
}
}
+
+ private final static String[] extns = new String[]{"java", "xml"};
+
+ private boolean checkFileExtension(IFile file) {
+ String ext = file.getFileExtension();
+ for (int i = 0; i < extns.length; i++) {
+ if(extns[i].equalsIgnoreCase(ext)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
\ No newline at end of file
Deleted:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidationHelper.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidationHelper.java 2007-07-25
14:11:35 UTC (rev 2652)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidationHelper.java 2007-07-25
15:18:25 UTC (rev 2653)
@@ -1,24 +0,0 @@
- /*******************************************************************************
- * Copyright (c) 2007 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.internal.core.validation;
-
-import java.util.Collection;
-
-/**
- * Helper for EL Seam valodator
- * @author Alexey Kazakov
- */
-public class SeamELValidationHelper extends SeamValidationHelper {
-
- public Collection getAllFilesForValidation() {
- return getFiles(SeamELValidator.class.getName());
- }
-}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java 2007-07-25
14:11:35 UTC (rev 2652)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java 2007-07-25
15:18:25 UTC (rev 2653)
@@ -11,7 +11,6 @@
package org.jboss.tools.seam.internal.core.validation;
import java.io.IOException;
-import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -19,7 +18,10 @@
import java.util.Set;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
@@ -36,10 +38,12 @@
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
import org.eclipse.wst.validation.internal.core.ValidationException;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.core.SeamPreferences;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
@@ -50,32 +54,58 @@
*/
public class SeamELValidator extends SeamValidator {
+ protected static final String INVALID_EXPRESSION_MESSAGE_ID =
"INVALID_EXPRESSION";
+ protected static final String UNPAIRED_GETTER_OR_SETTER_MESSAGE_ID =
"UNPAIRED_GETTER_OR_SETTER";
+
private SeamELCompletionEngine engine= new SeamELCompletionEngine();
- private IJavaProject javaProject = null;
+ private IJavaProject javaProject;
+ public SeamELValidator(SeamValidatorManager validatorManager,
+ SeamValidationHelper coreHelper, IReporter reporter,
+ SeamValidationContext validationContext, ISeamProject project) {
+ super(validatorManager, coreHelper, reporter, validationContext, project);
+ }
+
/* (non-Javadoc)
- * @see
org.jboss.tools.seam.internal.core.validation.SeamValidator#validate(java.util.Set)
+ * @see org.jboss.tools.seam.internal.core.validation.ISeamValidator#isEnabled()
*/
- @Override
+ public boolean isEnabled() {
+ return SeamPreferences.isValidateEL(project);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.seam.internal.core.validation.ISeamValidator#validate(java.util.Set)
+ */
public IStatus validate(Set<IFile> changedFiles) throws ValidationException {
- // TODO Incremental validation
- validateAll();
+ IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
+ Set<IPath> files = validationContext.getElResourcesForValidation(changedFiles);
+ validationContext.removeLinkedElResources(files);
+ for (IPath path : files) {
+ if(!reporter.isCancelled()) {
+ validationContext.removeUnnamedElResource(path);
+ IFile file = wsRoot.getFile(path);
+ if(file.exists()) {
+ reporter.removeMessageSubset(validationManager, file,
ISeamValidator.MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ validateFile(file);
+ }
+ }
+ }
+
+ validationContext.clearOldVariableNameForElValidation();
return OK_STATUS;
}
- /* (non-Javadoc)
- * @see org.jboss.tools.seam.internal.core.validation.SeamValidator#validateAll()
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.seam.internal.core.validation.ISeamValidator#validateAll()
*/
- @Override
public IStatus validateAll() throws ValidationException {
- reporter.removeAllMessages(this);
- if(SeamPreferences.isValidateEL(project)) {
- SeamELValidationHelper vlh = (SeamELValidationHelper)coreHelper;
- Collection files = vlh.getAllFilesForValidation();
- for (Object file : files) {
- if(file instanceof IFile && !reporter.isCancelled()) {
- validateFile((IFile)file);
- }
+ validationContext.clearElResourceLinks();
+ Set<IFile> files = validationContext.getRegisteredFiles();
+ for (IFile file : files) {
+ if(!reporter.isCancelled()) {
+ validateFile(file);
}
}
return OK_STATUS;
@@ -205,29 +235,34 @@
String prefix = SeamELCompletionEngine.getPrefix(exp, offset);
if(prefix!=null) {
int possition = 0;
-
+
Set<ISeamContextVariable> usedVariables = new
HashSet<ISeamContextVariable>();
Map<String, IMethod> unpairedGettersOrSetters = new HashMap<String,
IMethod>();
-
+
List<String> suggestions = engine.getCompletions(project, file, exp, prefix,
possition, true, usedVariables, unpairedGettersOrSetters);
+ if(usedVariables.size()==0 && suggestions.size()==0) {
+ // Save resources with unknown variables names
+ validationContext.addUnnamedElResource(file.getFullPath());
+ } else {
+ // Save links between resource and used variables names
+ for(ISeamContextVariable variable: usedVariables) {
+ validationContext.addLinkedElResource(variable.getName(),
file.getFullPath());
+ }
+ }
+
// Check pair for getter/setter
if(unpairedGettersOrSetters.size()>0) {
IMethod unpairedMethod = unpairedGettersOrSetters.values().iterator().next();
String methodName = unpairedMethod.getElementName();
-// int indexOfPropertyName = 3;
-// if(methodName.startsWith("i")) {
-// indexOfPropertyName = 2;
-// }
String propertyName = unpairedGettersOrSetters.keySet().iterator().next();
-// propertyName.setCharAt(0, Character.toLowerCase(propertyName.charAt(0)));
String missingMethodName = "Setter";
String existedMethodName = "Getter";
if(methodName.startsWith("s")) {
missingMethodName = existedMethodName;
existedMethodName = "Setter";
}
- addError(UNPAIRED_GETTER_OR_SETTER_MESSAGE_ID,
SeamPreferences.UNPAIRED_GETTER_OR_SETTER, new String[]{propertyName, existedMethodName,
missingMethodName}, el.getLength(), el.getOffset(), file,
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ addError(UNPAIRED_GETTER_OR_SETTER_MESSAGE_ID,
SeamPreferences.UNPAIRED_GETTER_OR_SETTER, new String[]{propertyName, existedMethodName,
missingMethodName}, el.getLength(), el.getOffset(), file);
}
if (suggestions != null && suggestions.size() > 0) {
@@ -241,7 +276,7 @@
SeamCorePlugin.getDefault().logError("Error validating Seam EL", e);
}
// Mark invalid EL
- addError(INVALID_EXPRESSION_MESSAGE_ID, SeamPreferences.INVALID_EXPRESSION, new
String[]{el.getValue()}, el.getLength(), el.getOffset(), file,
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ addError(INVALID_EXPRESSION_MESSAGE_ID, SeamPreferences.INVALID_EXPRESSION, new
String[]{el.getValue()}, el.getLength(), el.getOffset(), file);
}
private IJavaProject getJavaProject() {
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-25
14:11:35 UTC (rev 2652)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidationContext.java 2007-07-25
15:18:25 UTC (rev 2653)
@@ -16,6 +16,7 @@
import java.util.Set;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.jboss.tools.common.xml.XMLUtilities;
@@ -29,162 +30,195 @@
*/
public class SeamValidationContext {
- 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>();
+ // We should load/save these collections between eclipse sessions.
+ private LinkCollection coreLinks = new LinkCollection();
+ private LinkCollection elLinks = new LinkCollection();
private Set<IFile> removedFiles = new HashSet<IFile>();
private Set<IFile> registeredResources = new HashSet<IFile>();
+ private Set<String> oldVariableNamesForELValidation = new
HashSet<String>();
/**
- * Save link between resource and variable name.
+ * Save link between core 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 variableName, IPath linkedResourcePath) {
- if(linkedResourcePath==null) {
- throw new RuntimeException("Linked resource path must not be null!");
- }
- if(variableName==null) {
- throw new RuntimeException("Variable name must not be null!");
- }
- Set<IPath> linkedResources = resourcesByVariableName.get(variableName);
- if(linkedResources==null) {
- // create set of linked resources with variable name.
- linkedResources = new HashSet<IPath>();
- resourcesByVariableName.put(variableName, linkedResources);
- }
- // 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);
- }
- variableNames.add(variableName);
+ public void addLinkedCoreResource(String variableName, IPath linkedResourcePath) {
+ coreLinks.addLinkedResource(variableName, linkedResourcePath);
}
/**
- * Removes link between resource and variable name.
+ * Removes link between core resource and variable name.
* @param oldVariableName
* @param linkedResourcePath
*/
- public void removeLinkedResource(String name, IPath linkedResourcePath) {
- Set<IPath> linkedResources = resourcesByVariableName.get(name);
- 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.remove(name);
- }
+ public void removeLinkedCoreResource(String name, IPath linkedResourcePath) {
+ coreLinks.removeLinkedResource(name, linkedResourcePath);
}
/**
- * Removes link between resources and variable names.
+ * Removes link between core resources and variable names.
* @param linkedResources
*/
- public void removeLinkedResources(Set<IPath> resources) {
- for (IPath resource : resources) {
- Set<String> resourceNames = variableNamesByResource.get(resource);
- if(resourceNames!=null) {
- for (String name : resourceNames) {
- Set<IPath> linkedResources = resourcesByVariableName.get(name);
- if(linkedResources!=null) {
- linkedResources.remove(resource);
- }
- }
- }
- variableNamesByResource.remove(resource);
- }
+ public void removeLinkedCoreResources(Set<IPath> resources) {
+ coreLinks.removeLinkedResources(resources);
}
- public Set<IPath> getResourcesByVariableName(String variableName) {
- return resourcesByVariableName.get(variableName);
+ public Set<IPath> getCoreResourcesByVariableName(String variableName) {
+ return coreLinks.getResourcesByVariableName(variableName);
}
- public Set<String> getVariableNamesByResource(IPath fullPath) {
- return variableNamesByResource.get(fullPath);
+ public Set<String> getVariableNamesByCoreResource(IPath fullPath) {
+ return coreLinks.getVariableNamesByResource(fullPath);
}
/**
- * Adds resource without any link to any context variable name.
+ * Adds core resource without any link to any context variable name.
* @param fullPath
*/
- public void addUnnamedResource(IPath fullPath) {
- unnamedResources.add(fullPath);
+ public void addUnnamedCoreResource(IPath fullPath) {
+ coreLinks.addUnnamedResource(fullPath);
}
/**
- * @return Set of resources without any link to any context variable name.
+ * @return Set of coreresources without any link to any context variable name.
* @param fullPath
*/
- public Set<IPath> getUnnamedResources() {
- return unnamedResources;
+ public Set<IPath> getUnnamedCoreResources() {
+ return coreLinks.getUnnamedResources();
}
/**
- * Removes unnamed resource.
+ * Removes unnamed EL resource.
* @param fullPath
*/
- public void removeUnnamedResource(IPath fullPath) {
- unnamedResources.remove(fullPath);
+ public void removeUnnamedCoreResource(IPath fullPath) {
+ coreLinks.removeUnnamedResource(fullPath);
}
- public void clear() {
- resourcesByVariableName.clear();
- variableNamesByResource.clear();
- unnamedResources.clear();
+ /**
+ * Adds EL resource without any link to any context variable name.
+ * @param fullPath
+ */
+ public void addUnnamedElResource(IPath fullPath) {
+ elLinks.addUnnamedResource(fullPath);
+ }
+
+ /**
+ * @return Set of EL resources without any link to any context variable name.
+ * @param fullPath
+ */
+ public Set<IPath> getUnnamedElResources() {
+ return elLinks.getUnnamedResources();
+ }
+
+ /**
+ * Removes unnamed EL resource.
+ * @param fullPath
+ */
+ public void removeUnnamedElResource(IPath fullPath) {
+ elLinks.removeUnnamedResource(fullPath);
+ }
+
+ /**
+ * We should validate all EL resources which use these names.
+ * @param name
+ */
+ public void addVariableNameForELValidation(String name) {
+ oldVariableNamesForELValidation.add(name);
+ }
+
+ /**
+ * Save link between EL resource and variable name.
+ * It's needed for incremental validation because we must save all linked resources
of changed java file.
+ */
+ public void addLinkedElResource(String variableName, IPath linkedResourcePath) {
+ elLinks.addLinkedResource(variableName, linkedResourcePath);
+ }
+
+ /**
+ * Removes link between resources and variable names.
+ * @param linkedResources
+ */
+ public void removeLinkedElResources(Set<IPath> resources) {
+ elLinks.removeLinkedResources(resources);
+ }
+
+ /**
+ * @param changedFiles - files which were changed.
+ * @return Set of resources which we should validate during incremental EL validation.
+ */
+ public Set<IPath> getElResourcesForValidation(Set<IFile> changedFiles) {
+ Set<IPath> result = new HashSet<IPath>();
+ // Collect all resources which use old variables names.
+ for(String name : oldVariableNamesForELValidation) {
+ Set<IPath> oldResources = elLinks.getResourcesByVariableName(name);
+ if(oldResources!=null) {
+ result.addAll(oldResources);
+ }
+ }
+ // Collect all resources which use new variables names
+ for(IResource resource : changedFiles) {
+ result.add(resource.getFullPath());
+ Set<String> names = getVariableNamesByCoreResource(resource.getFullPath());
+ if(names!=null) {
+ for (String name : names) {
+ Set<IPath> newResources = elLinks.getResourcesByVariableName(name);
+ if(newResources!=null) {
+ result.addAll(newResources);
+ }
+ }
+ }
+ }
+ result.addAll(elLinks.getUnnamedResources());
+ return result;
+ }
+
+ public void clearAll() {
removedFiles.clear();
registeredResources.clear();
+ oldVariableNamesForELValidation.clear();
+ coreLinks.clearAll();
+ elLinks.clearAll();
}
+ public void clearAllResourceLinks() {
+ oldVariableNamesForELValidation.clear();
+ coreLinks.clearAll();
+ elLinks.clearAll();
+ }
+
+ public void clearRegisteredFiles() {
+ removedFiles.clear();
+ registeredResources.clear();
+ }
+
+ public void clearElResourceLinks() {
+ oldVariableNamesForELValidation.clear();
+ elLinks.clearAll();
+ }
+
+ public void clearOldVariableNameForElValidation() {
+ oldVariableNamesForELValidation.clear();
+ }
+
public void store(Element root) {
Element validation = XMLUtilities.createElement(root, "validation");
- Set<String> variables = resourcesByVariableName.keySet();
- for (String name: variables) {
- Set<IPath> paths = resourcesByVariableName.get(name);
- if(paths == null) continue;
- for (IPath path: paths) {
- Element linkedResource = XMLUtilities.createElement(validation,
"linked-resource");
- linkedResource.setAttribute("name", name);
- linkedResource.setAttribute("path", path.toString());
- }
- }
- for (IPath unnamedPath: unnamedResources) {
- Element unnamedPathElement = XMLUtilities.createElement(validation,
"unnamed-path");
- unnamedPathElement.setAttribute("path", unnamedPath.toString());
- }
+ Element core = XMLUtilities.createElement(validation, "core");
+ coreLinks.store(core);
+ Element el = XMLUtilities.createElement(validation, "el");
+ elLinks.store(el);
}
public void load(Element root) {
Element validation = XMLUtilities.getUniqueChild(root, "validation");
if(validation == null) return;
- Element[] linkedResources = XMLUtilities.getChildren(validation,
"linked-resource");
- if(linkedResources != null) for (int i = 0; i < linkedResources.length; i++) {
- String name = linkedResources[i].getAttribute("name");
- if(name == null || name.trim().length() == 0) continue;
- String path = linkedResources[i].getAttribute("path");
- if(path == null || path.trim().length() == 0) continue;
- try {
- IPath pathObject = new Path(path);
- addLinkedResource(name, pathObject);
- } catch (Exception e) {
- SeamCorePlugin.getPluginLog().logError(e);
- }
+ Element core = XMLUtilities.getUniqueChild(validation, "core");
+ if(core != null) {
+ coreLinks.load(core);
}
- 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);
- }
+ Element el = XMLUtilities.getUniqueChild(validation, "el");
+ if(el != null) {
+ elLinks.load(el);
}
}
@@ -203,4 +237,161 @@
public void registerFile(IFile file) {
registeredResources.add(file);
}
+
+ public static class LinkCollection {
+ 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.
+ * It's needed for incremental validation because we must save all linked resources
of changed java file.
+ */
+ public void addLinkedResource(String variableName, IPath linkedResourcePath) {
+ if(linkedResourcePath==null) {
+ throw new RuntimeException("Linked resource path must not be null!");
+ }
+ if(variableName==null) {
+ throw new RuntimeException("Variable name must not be null!");
+ }
+ Set<IPath> linkedResources = resourcesByVariableName.get(variableName);
+ if(linkedResources==null) {
+ // create set of linked resources with variable name.
+ linkedResources = new HashSet<IPath>();
+ resourcesByVariableName.put(variableName, linkedResources);
+ }
+ // 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);
+ }
+ variableNames.add(variableName);
+ }
+
+ /**
+ * Removes link between resource and variable name.
+ * @param oldVariableName
+ * @param linkedResourcePath
+ */
+ public void removeLinkedResource(String name, IPath linkedResourcePath) {
+ Set<IPath> linkedResources = resourcesByVariableName.get(name);
+ 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.remove(name);
+ }
+ }
+
+ /**
+ * Removes link between resources and variable names.
+ * @param linkedResources
+ */
+ public void removeLinkedResources(Set<IPath> resources) {
+ for (IPath resource : resources) {
+ Set<String> resourceNames = variableNamesByResource.get(resource);
+ if(resourceNames!=null) {
+ for (String name : resourceNames) {
+ Set<IPath> linkedResources = resourcesByVariableName.get(name);
+ if(linkedResources!=null) {
+ linkedResources.remove(resource);
+ if(linkedResources.isEmpty()) {
+ resourcesByVariableName.remove(name);
+ }
+ }
+ }
+ }
+ variableNamesByResource.remove(resource);
+ }
+ }
+
+ public Set<IPath> getResourcesByVariableName(String variableName) {
+ return resourcesByVariableName.get(variableName);
+ }
+
+ 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 clearAll() {
+ resourcesByVariableName.clear();
+ variableNamesByResource.clear();
+ unnamedResources.clear();
+ }
+
+ public void store(Element root) {
+ Set<String> variables = resourcesByVariableName.keySet();
+ for (String name: variables) {
+ Set<IPath> paths = resourcesByVariableName.get(name);
+ if(paths == null) continue;
+ for (IPath path: paths) {
+ Element linkedResource = XMLUtilities.createElement(root,
"linked-resource");
+ linkedResource.setAttribute("name", name);
+ linkedResource.setAttribute("path", path.toString());
+ }
+ }
+ for (IPath unnamedPath: unnamedResources) {
+ Element unnamedPathElement = XMLUtilities.createElement(root,
"unnamed-path");
+ unnamedPathElement.setAttribute("path", unnamedPath.toString());
+ }
+ }
+
+ public void load(Element root) {
+ if(root == null) return;
+ Element[] linkedResources = XMLUtilities.getChildren(root,
"linked-resource");
+ if(linkedResources != null) for (int i = 0; i < linkedResources.length; i++) {
+ String name = linkedResources[i].getAttribute("name");
+ if(name == null || name.trim().length() == 0) continue;
+ String path = linkedResources[i].getAttribute("path");
+ if(path == null || path.trim().length() == 0) continue;
+ try {
+ IPath pathObject = new Path(path);
+ addLinkedResource(name, pathObject);
+ } catch (Exception e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ }
+ Element[] unnamedPathElement = XMLUtilities.getChildren(root,
"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
Deleted:
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-25
14:11:35 UTC (rev 2652)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java 2007-07-25
15:18:25 UTC (rev 2653)
@@ -1,153 +0,0 @@
- /*******************************************************************************
- * Copyright (c) 2007 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.internal.core.validation;
-
-import java.util.Set;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.jobs.ISchedulingRule;
-import org.eclipse.wst.validation.internal.core.Message;
-import org.eclipse.wst.validation.internal.core.ValidationException;
-import org.eclipse.wst.validation.internal.provisional.core.IMessage;
-import org.eclipse.wst.validation.internal.provisional.core.IReporter;
-import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
-import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob;
-import org.jboss.tools.seam.core.ISeamProject;
-import org.jboss.tools.seam.core.ISeamTextSourceReference;
-import org.jboss.tools.seam.core.SeamPreferences;
-import org.jboss.tools.seam.internal.core.SeamProject;
-
-/**
- * Basic seam validator.
- * @author Alexey Kazakov
- */
-public abstract class SeamValidator implements IValidatorJob {
-
- protected static final String MARKED_SEAM_RESOURCE_MESSAGE_GROUP =
"markedSeamCoreResource";
-
- protected static final String NONUNIQUE_COMPONENT_NAME_MESSAGE_ID =
"NONUNIQUE_COMPONENT_NAME_MESSAGE";
- protected static final String UNKNOWN_VARIABLE_NAME_MESSAGE_ID =
"UNKNOWN_VARIABLE_NAME";
- protected static final String
STATEFUL_COMPONENT_DOES_NOT_CONTAIN_METHOD_SUFIX_MESSAGE_ID =
"STATEFUL_COMPONENT_DOES_NOT_CONTAIN_";
- protected static final String DUPLICATE_METHOD_PREFIX_MESSAGE_ID =
"DUPLICATE_";
- protected static final String REMOVE_METHOD_SUFIX_MESSAGE_ID = "REMOVE";
- protected static final String DESTROY_METHOD_SUFIX_MESSAGE_ID = "DESTROY";
- protected static final String CREATE_METHOD_SUFIX_MESSAGE_ID = "CREATE";
- protected static final String UNWRAP_METHOD_SUFIX_MESSAGE_ID = "UNWRAP";
- protected static final String OBSERVER_METHOD_SUFIX_MESSAGE_ID = "OBSERVER";
- protected static final String NONCOMPONENTS_METHOD_SUFIX_MESSAGE_ID =
"_DOESNT_BELONG_TO_COMPONENT";
- protected static final String STATEFUL_COMPONENT_WRONG_SCOPE_MESSAGE_ID =
"STATEFUL_COMPONENT_WRONG_SCOPE";
- protected static final String ENTITY_COMPONENT_WRONG_SCOPE_MESSAGE_ID =
"ENTITY_COMPONENT_WRONG_SCOPE";
- protected static final String UNKNOWN_FACTORY_NAME_MESSAGE_ID =
"UNKNOWN_FACTORY_NAME";
- protected static final String MULTIPLE_DATA_BINDER_MESSAGE_ID =
"MULTIPLE_DATA_BINDER";
- protected static final String DUPLICATE_VARIABLE_NAME_MESSAGE_ID =
"DUPLICATE_VARIABLE_NAME";
- protected static final String UNKNOWN_DATA_MODEL_MESSAGE_ID =
"UNKNOWN_DATA_MODEL";
- protected static final String UNKNOWN_COMPONENT_CLASS_NAME_MESSAGE_ID =
"UNKNOWN_COMPONENT_CLASS_NAME";
- protected static final String UNKNOWN_COMPONENT_PROPERTY_MESSAGE_ID =
"UNKNOWN_COMPONENT_PROPERTY";
- protected static final String INVALID_EXPRESSION_MESSAGE_ID =
"INVALID_EXPRESSION";
- protected static final String UNPAIRED_GETTER_OR_SETTER_MESSAGE_ID =
"UNPAIRED_GETTER_OR_SETTER";
-
- protected SeamValidationHelper coreHelper;
- protected IReporter reporter;
- protected SeamValidationContext validationContext;
-
- protected ISeamProject project;
-
- public SeamValidator() {
- super();
- }
-
- /* (non-Javadoc)
- * @see
org.eclipse.wst.validation.internal.provisional.core.IValidatorJob#getSchedulingRule(org.eclipse.wst.validation.internal.provisional.core.IValidationContext)
- */
- public ISchedulingRule getSchedulingRule(IValidationContext helper) {
- return null;
- }
-
- public IStatus validateInJob(IValidationContext helper, IReporter reporter) throws
ValidationException {
- this.coreHelper = (SeamValidationHelper)helper;
- this.reporter = reporter;
- this.project = coreHelper.getSeamProject();
- IStatus status = null;
- try {
- this.validationContext = ((SeamProject)project).getValidationContext();
- Set<IFile> changedFiles = coreHelper.getChangedFiles();
- if(changedFiles.size()>0) {
- status = validate(changedFiles);
- } else {
- status = validateAll();
- }
- } finally {
- validationContext.getRemovedFiles().clear();
- validationContext.getRegisteredFiles().clear();
- }
- return status;
- }
-
- /**
- * Incremental Validation
- * @return
- * @throws ValidationException
- */
- abstract public IStatus validate(Set<IFile> changedFiles) throws
ValidationException;
-
- /**
- * Full Validation
- * @return
- * @throws ValidationException
- */
- abstract public IStatus validateAll() throws ValidationException;
-
- public void cleanup(IReporter reporter) {
- reporter = null;
- }
-
- public void validate(IValidationContext helper, IReporter reporter) throws
ValidationException {
- validateInJob(helper, reporter);
- }
-
- protected String getBaseName() {
- return "org.jboss.tools.seam.internal.core.validation.messages";
- }
-
- protected void addError(String messageId, String preferenceKey, String[]
messageArguments, ISeamTextSourceReference location, IResource target, String
messageGroup) {
- addError(messageId, preferenceKey, messageArguments, location.getLength(),
location.getStartPosition(), target, messageGroup);
- }
-
- protected void addError(String messageId, String preferenceKey, ISeamTextSourceReference
location, IResource target, String messageGroup) {
- addError(messageId, preferenceKey, new String[0], location, target, messageGroup);
- }
-
- protected void addError(String messageId, String preferenceKey, String[]
messageArguments, int length, int offset, IResource target, String messageGroup) {
- String preferenceValue = SeamPreferences.getProjectPreference(project, preferenceKey);
- boolean ignore = false;
- int messageSeverity = IMessage.HIGH_SEVERITY;
- if(SeamPreferences.WARNING.equals(preferenceValue)) {
- messageSeverity = IMessage.NORMAL_SEVERITY;
- } else if(SeamPreferences.IGNORE.equals(preferenceValue)) {
- ignore = true;
- }
-
- IMessage message = new Message(getBaseName(), messageSeverity, messageId,
messageArguments, target, messageGroup);
- message.setLength(length);
- message.setOffset(offset);
- if(!ignore) {
- reporter.addMessage(this, message);
- }
- }
-
- protected void removeMessagesFromResources(Set<IResource> resources, String
messageGroup) {
- for (IResource r : resources) {
- reporter.removeMessageSubset(this, r, messageGroup);
- }
- }
-}
\ No newline at end of file
Added:
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
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java 2007-07-25
15:18:25 UTC (rev 2653)
@@ -0,0 +1,82 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.validation;
+
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.validation.internal.core.Message;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.ISeamTextSourceReference;
+import org.jboss.tools.seam.core.SeamPreferences;
+
+/**
+ * Abstract implementation of ISeamvalidator
+ * @author Alexey Kazakov
+ */
+public abstract class SeamValidator implements ISeamValidator {
+
+ IStatus OK_STATUS = new Status(IStatus.OK, "org.eclipse.wst.validation", 0,
"OK", null); //$NON-NLS-1$ //$NON-NLS-2$
+
+ protected SeamValidatorManager validationManager;
+ protected SeamValidationHelper coreHelper;
+ protected IReporter reporter;
+ protected SeamValidationContext validationContext;
+ protected ISeamProject project;
+
+ public SeamValidator(SeamValidatorManager validatorManager, SeamValidationHelper
coreHelper, IReporter reporter, SeamValidationContext validationContext, ISeamProject
project) {
+ this.validationManager = validatorManager;
+ this.coreHelper = coreHelper;
+ this.project = project;
+ this.reporter = reporter;
+ this.validationContext = validationContext;
+ }
+
+ protected String getBaseName() {
+ return "org.jboss.tools.seam.internal.core.validation.messages";
+ }
+
+ protected void addError(String messageId, String preferenceKey, String[]
messageArguments, ISeamTextSourceReference location, IResource target) {
+ addError(messageId, preferenceKey, messageArguments, location.getLength(),
location.getStartPosition(), target);
+ }
+
+ protected void addError(String messageId, String preferenceKey, ISeamTextSourceReference
location, IResource target) {
+ addError(messageId, preferenceKey, new String[0], location, target);
+ }
+
+ protected void addError(String messageId, String preferenceKey, String[]
messageArguments, int length, int offset, IResource target) {
+ String preferenceValue = SeamPreferences.getProjectPreference(project, preferenceKey);
+ boolean ignore = false;
+ int messageSeverity = IMessage.HIGH_SEVERITY;
+ if(SeamPreferences.WARNING.equals(preferenceValue)) {
+ messageSeverity = IMessage.NORMAL_SEVERITY;
+ } else if(SeamPreferences.IGNORE.equals(preferenceValue)) {
+ ignore = true;
+ }
+
+ IMessage message = new Message(getBaseName(), messageSeverity, messageId,
messageArguments, target, ISeamValidator.MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ message.setLength(length);
+ message.setOffset(offset);
+ if(!ignore) {
+ reporter.addMessage(validationManager, message);
+ }
+ }
+
+ protected void removeMessagesFromResources(Set<IResource> resources, String
messageGroup) {
+ for (IResource r : resources) {
+ reporter.removeMessageSubset(validationManager, r, messageGroup);
+ }
+ }
+}
\ No newline at end of file
Copied:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidatorManager.java
(from rev 2650,
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/SeamValidatorManager.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidatorManager.java 2007-07-25
15:18:25 UTC (rev 2653)
@@ -0,0 +1,105 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.validation;
+
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IStatus;
+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.eclipse.wst.validation.internal.provisional.core.IValidatorJob;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.internal.core.SeamProject;
+
+/**
+ * This Manager invokes all dependent seam validators that should be invoked in one job.
+ * We need this one because wst validation framework does not let us invoke
+ * dependent validators in the same job.
+ * @author Alexey Kazakov
+ */
+public class SeamValidatorManager implements IValidatorJob {
+
+ public SeamValidatorManager() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.wst.validation.internal.provisional.core.IValidatorJob#getSchedulingRule(org.eclipse.wst.validation.internal.provisional.core.IValidationContext)
+ */
+ public ISchedulingRule getSchedulingRule(IValidationContext helper) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.validation.internal.provisional.core.IValidatorJob#validateInJob(org.eclipse.wst.validation.internal.provisional.core.IValidationContext,
org.eclipse.wst.validation.internal.provisional.core.IReporter)
+ */
+ public IStatus validateInJob(IValidationContext helper, IReporter reporter) throws
ValidationException {
+ SeamValidationHelper coreHelper = (SeamValidationHelper)helper;
+ ISeamProject project = coreHelper.getSeamProject();
+ SeamValidationContext validationContext =
((SeamProject)project).getValidationContext();
+ IStatus status = null;
+ try {
+ ISeamValidator coreValidator = new SeamCoreValidator(this, coreHelper, reporter,
validationContext, project);
+ ISeamValidator elValidator = new SeamELValidator(this, coreHelper, reporter,
validationContext, project);
+ ISeamValidator[] validators = new ISeamValidator[]{coreValidator, elValidator};
+
+ Set<IFile> changedFiles = coreHelper.getChangedFiles();
+ if(changedFiles.size()>0) {
+ status = validate(validators, changedFiles);
+ } else {
+ reporter.removeAllMessages(this);
+ validationContext.clearAllResourceLinks();
+ status = validateAll(validators);
+ }
+ } finally {
+ validationContext.clearRegisteredFiles();
+ }
+ return status;
+ }
+
+ private IStatus validate(ISeamValidator[] validator, Set<IFile> changedFiles)
throws ValidationException {
+ for (int i = 0; i < validator.length; i++) {
+ if(validator[i].isEnabled()) {
+ validator[i].validate(changedFiles);
+ }
+ }
+ return OK_STATUS;
+ }
+
+ private IStatus validateAll(ISeamValidator[] validator) throws ValidationException {
+ for (int i = 0; i < validator.length; i++) {
+ if(validator[i].isEnabled()) {
+ validator[i].validateAll();
+ }
+ }
+ return OK_STATUS;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.validation.internal.provisional.core.IValidator#cleanup(org.eclipse.wst.validation.internal.provisional.core.IReporter)
+ */
+ public void cleanup(IReporter reporter) {
+ reporter = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.validation.internal.provisional.core.IValidator#validate(org.eclipse.wst.validation.internal.provisional.core.IValidationContext,
org.eclipse.wst.validation.internal.provisional.core.IReporter)
+ */
+ public void validate(IValidationContext helper, IReporter reporter) throws
ValidationException {
+ validateInJob(helper, reporter);
+ }
+}
\ No newline at end of file