Author: akazakov
Date: 2007-07-06 14:05:50 -0400 (Fri, 06 Jul 2007)
New Revision: 2351
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/SeamValidator.java
Log:
http://jira.jboss.com/jira/browse/EXIN-327 Incremental validation for nonunique component
names.
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-06
16:17:06 UTC (rev 2350)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java 2007-07-06
18:05:50 UTC (rev 2351)
@@ -12,9 +12,11 @@
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
@@ -36,8 +38,12 @@
*/
public class SeamJavaValidator extends SeamValidator {
- public static final String
NONUNIQUE_COMPONENT_NAME_MESSAGE_ID="NONUNIQUE_COMPONENT_NAME_MESSAGE";
+ private static final String NONUNIQUE_NAME_MESSAGE_GROUP = "nonuniqueName";
+ private Map<String, Set<IResource>> markedNonuniqueNamedResources = new
HashMap<String, Set<IResource>>();
+ private Map<IResource, String> nonuniqueNames = new HashMap<IResource,
String>();
+ public static final String NONUNIQUE_COMPONENT_NAME_MESSAGE_ID =
"NONUNIQUE_COMPONENT_NAME_MESSAGE";
+
public ISchedulingRule getSchedulingRule(IValidationContext helper) {
// TODO
return null;
@@ -45,20 +51,64 @@
public IStatus validateInJob(IValidationContext helper, IReporter reporter) throws
ValidationException {
super.validateInJob(helper, reporter);
- System.out.println("Seam validation in job.");
SeamJavaHelper seamJavaHelper = (SeamJavaHelper)helper;
String[] uris = seamJavaHelper.getURIs();
ISeamProject project = seamJavaHelper.getSeamProject();
if (uris.length > 0) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile currentFile = null;
+ Set<IResource> checkedResource = new HashSet<IResource>();
+ Set<ISeamComponent> checkedComponent = new HashSet<ISeamComponent>();
for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) {
currentFile = root.getFile(new Path(uris[i]));
if (currentFile != null && currentFile.exists()) {
- Set<ISeamComponent> components =
project.getComponentsByResource(currentFile);
- for (ISeamComponent component : components) {
- validateUniqueComponentName(project, component, helper, reporter);
+ String oldComponentNameOfChangedFile = nonuniqueNames.get(currentFile);
+ if(oldComponentNameOfChangedFile!=null) {
+ Set<IResource> resources = new HashSet<IResource>(); // Resources which
we have to validate.
+
+ // Check if component name was changed in java file
+ String newComponentNameOfChangedFile = getComponentNameByResource(currentFile,
project);
+ if(newComponentNameOfChangedFile!=null &&
!oldComponentNameOfChangedFile.equals(newComponentNameOfChangedFile)) {
+ // Name was changed. Remove markers from resources with new component name.
+ Set<IResource> rs =
markedNonuniqueNamedResources.get(newComponentNameOfChangedFile);
+ if(rs!=null) {
+ for (IResource resource : rs) {
+ reporter.removeMessageSubset(this, resource, NONUNIQUE_NAME_MESSAGE_GROUP);
+ resources.add(resource);
+ }
+ }
+ }
+
+ Set<IResource> linkedResources =
markedNonuniqueNamedResources.get(oldComponentNameOfChangedFile);
+ if(linkedResources!=null) {
+ resources.addAll(linkedResources);
+ }
+
+ // Validate all collected linked resources.
+ for (IResource linkedResource : resources) {
+ if(checkedResource.contains(linkedResource)) {
+ continue;
+ }
+ reporter.removeMessageSubset(this, linkedResource, NONUNIQUE_NAME_MESSAGE_GROUP);
// Remove markers from java file
+ Set<ISeamComponent> components =
project.getComponentsByResource(linkedResource);
+ for (ISeamComponent component : components) {
+ if(checkedComponent.contains(component)) {
+ continue;
+ }
+ validateUniqueComponentName(project, component, helper, reporter);
+ checkedComponent.add(component);
+ }
+ checkedResource.add(linkedResource);
+ }
+ } else {
+ // Validate new (unmarked) Java file.
+ // TODO
}
+// reporter.removeAllMessages(this, currentFile); // Remove all markers from java
file
+// Set<ISeamComponent> components =
project.getComponentsByResource(currentFile);
+// for (ISeamComponent component : components) {
+// validateUniqueComponentName(project, component, helper, reporter);
+// }
// TODO
}
}
@@ -69,6 +119,14 @@
return OK_STATUS;
}
+ public String getComponentNameByResource(IResource resource, ISeamProject project) {
+ Set<ISeamComponent> components = project.getComponentsByResource(resource);
+ for (ISeamComponent component : components) {
+ return component.getName();
+ }
+ return null;
+ }
+
public void cleanup(IReporter reporter) {
}
@@ -101,20 +159,42 @@
if(checkedDeclaration==null) {
usedPrecedences.put(javaDeclarationPrecedence, javaDeclaration);
} else {
+ IResource javaDeclarationResource = javaDeclaration.getResource();
// Mark nonunique name.
if(!markedDeclarations.contains(checkedDeclaration)) {
- // Mark first wrong declaration
+ // Mark first wrong declaration with that name
ISeamTextSourceReference target =
((SeamComponentDeclaration)checkedDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
- addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, target);
+ addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, target,
NONUNIQUE_NAME_MESSAGE_GROUP);
markedDeclarations.add(checkedDeclaration);
+ addLinkedResource(checkedDeclaration.getName(),
checkedDeclaration.getResource());
}
- // Mark next wrong declaration
+ // Mark next wrong declaration with that name
markedDeclarations.add(javaDeclaration);
+ addLinkedResource(javaDeclaration.getName(), javaDeclaration.getResource());
ISeamTextSourceReference target =
((SeamComponentDeclaration)javaDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
- addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, target);
+ addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, target,
NONUNIQUE_NAME_MESSAGE_GROUP);
}
}
}
}
}
+
+ /*
+ * Save linked resources of component name that we marked.
+ * It's needed for incremental validation because we must save all linked resources
of changed java file.
+ */
+ private void addLinkedResource(String componentName, IResource linkedResource) {
+ Set<IResource> linkedResources =
markedNonuniqueNamedResources.get(componentName);
+ if(linkedResources==null) {
+ // create set of linked resources with component name that we must mark.
+ linkedResources = new HashSet<IResource>();
+ markedNonuniqueNamedResources.put(componentName, linkedResources);
+ }
+ if(!linkedResources.contains(linkedResource)) {
+ // save linked resources that we must mark.
+ linkedResources.add(linkedResource);
+ }
+ // Save link between component name and marked resource. It's needed if component
name changes in java file.
+ nonuniqueNames.put(linkedResource, componentName);
+ }
}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java 2007-07-06
16:17:06 UTC (rev 2350)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java 2007-07-06
18:05:50 UTC (rev 2351)
@@ -46,14 +46,14 @@
return "org.jboss.tools.seam.internal.core.validation.messages";
}
- protected void addError(String messageId, String[] messageArguments,
ISeamTextSourceReference target) {
- IMessage message = new Message(getBaseName(), IMessage.HIGH_SEVERITY, messageId,
messageArguments, target.getResource());
+ protected void addError(String messageId, String[] messageArguments,
ISeamTextSourceReference target, String messageGroup) {
+ IMessage message = new Message(getBaseName(), IMessage.HIGH_SEVERITY, messageId,
messageArguments, target.getResource(), messageGroup);
message.setLength(target.getLength());
message.setOffset(target.getStartPosition());
reporter.addMessage(this, message);
}
- protected void addError(String messageId, ISeamTextSourceReference target) {
- addError(messageId, new String[0], target);
+ protected void addError(String messageId, ISeamTextSourceReference target, String
messageGroup) {
+ addError(messageId, new String[0], target, messageGroup);
}
}
\ No newline at end of file