Author: akazakov
Date: 2007-07-06 10:08:17 -0400 (Fri, 06 Jul 2007)
New Revision: 2342
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/messages.properties
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/build.properties
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/SeamComponentDeclaration.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/SeamValidator.java
Log:
http://jira.jboss.com/jira/browse/EXIN-216 Validation of unique component name
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/build.properties
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/build.properties 2007-07-06 13:52:48 UTC
(rev 2341)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/build.properties 2007-07-06 14:08:17 UTC
(rev 2342)
@@ -1,5 +1,6 @@
source.seam-core.jar = src/
bin.includes = plugin.xml,\
META-INF/,\
- seam-core.jar
+ seam-core.jar,\
+ plugin.properties
jars.compile.order = seam-core.jar
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-06
13:52:48 UTC (rev 2341)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2007-07-06
14:08:17 UTC (rev 2342)
@@ -13,6 +13,7 @@
import java.util.Set;
import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.resources.IResource;
import org.jboss.tools.seam.core.event.ISeamProjectChangeListener;
public interface ISeamProject extends IProjectNature {
@@ -36,6 +37,12 @@
public Set<ISeamComponent> getComponentsByScope(ScopeType type);
/**
+ * @param resource of ISeamComponentDeclaration that belongs to component
+ * @return Set of ISeamComponents by resource.
+ */
+ public Set<ISeamComponent> getComponentsByResource(IResource resource);
+
+ /**
* @param className
* @return Set of ISeamComponents by class name.
*/
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponentDeclaration.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponentDeclaration.java 2007-07-06
13:52:48 UTC (rev 2341)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponentDeclaration.java 2007-07-06
14:08:17 UTC (rev 2342)
@@ -113,7 +113,7 @@
// TODO
ISeamTextSourceReference reference = new ISeamTextSourceReference() {
public int getLength() {
- return 0;
+ return 10;
}
public IResource getResource() {
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-06
13:52:48 UTC (rev 2341)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-07-06
14:08:17 UTC (rev 2342)
@@ -11,6 +11,7 @@
package org.jboss.tools.seam.internal.core;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -19,14 +20,15 @@
import java.util.Set;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
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.ISeamFactory;
import org.jboss.tools.seam.core.ISeamJavaComponentDeclaration;
import org.jboss.tools.seam.core.ISeamProject;
-import org.jboss.tools.seam.core.ISeamContextVariable;
import org.jboss.tools.seam.core.ISeamXmlComponentDeclaration;
import org.jboss.tools.seam.core.ScopeType;
import org.jboss.tools.seam.core.event.Change;
@@ -430,4 +432,20 @@
listeners.remove(listener);
}
-}
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.seam.core.ISeamProject#getComponentsByResource(org.eclipse.core.resources.IResource)
+ */
+ public Set<ISeamComponent> getComponentsByResource(IResource resource) {
+ Set<ISeamComponent> result = new HashSet<ISeamComponent>();
+ for (SeamComponent c: allComponents.values()) {
+ for (ISeamComponentDeclaration d: c.getAllDeclarations()) {
+ SeamComponentDeclaration di = (SeamComponentDeclaration)d;
+ if(resource.equals(di.getResource())) {
+ result.add(c);
+ break;
+ }
+ }
+ }
+ return result;
+ }
+}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java 2007-07-06
13:52:48 UTC (rev 2341)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java 2007-07-06
14:08:17 UTC (rev 2342)
@@ -11,6 +11,7 @@
package org.jboss.tools.seam.internal.core.validation;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.resources.IFile;
@@ -27,13 +28,15 @@
import org.jboss.tools.seam.core.ISeamJavaComponentDeclaration;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.ISeamTextSourceReference;
-import org.jboss.tools.seam.core.SeamComponentPrecedenceType;
import org.jboss.tools.seam.internal.core.SeamComponentDeclaration;
+/**
+ * Validator for Java files.
+ * @author Alexey Kazakov
+ */
public class SeamJavaValidator extends SeamValidator {
- // TODO
- public static final String NONUNIQUE_COMPONENT_NAME_MESSAGE_ID="";
+ public static final String
NONUNIQUE_COMPONENT_NAME_MESSAGE_ID="NONUNIQUE_COMPONENT_NAME_MESSAGE";
public ISchedulingRule getSchedulingRule(IValidationContext helper) {
// TODO
@@ -52,7 +55,10 @@
for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) {
currentFile = root.getFile(new Path(uris[i]));
if (currentFile != null && currentFile.exists()) {
- System.out.println(currentFile);
+ Set<ISeamComponent> components =
project.getComponentsByResource(currentFile);
+ for (ISeamComponent component : components) {
+ validateUniqueComponentName(project, component, helper, reporter);
+ }
// TODO
}
}
@@ -69,6 +75,7 @@
private IStatus validateAll(ISeamProject project, IValidationContext helper, IReporter
reporter) {
Set<ISeamComponent> components = project.getComponents();
for (ISeamComponent component : components) {
+ validateUniqueComponentName(project, component, helper, reporter);
// TODO
}
return OK_STATUS;
@@ -81,10 +88,8 @@
ISeamJavaComponentDeclaration firstJavaDeclaration = component.getJavaDeclaration();
if(firstJavaDeclaration!=null) {
HashMap<Integer, ISeamJavaComponentDeclaration> usedPrecedences = new
HashMap<Integer, ISeamJavaComponentDeclaration>();
+ Set<ISeamJavaComponentDeclaration> markedDeclarations = new
HashSet<ISeamJavaComponentDeclaration>();
int firstJavaDeclarationPrecedence = firstJavaDeclaration.getPrecedence();
- if(firstJavaDeclarationPrecedence < 0) {
- firstJavaDeclarationPrecedence = ISeamJavaComponentDeclaration.DEFAULT_PRECEDENCE;
- }
usedPrecedences.put(firstJavaDeclarationPrecedence, firstJavaDeclaration);
Set<ISeamComponentDeclaration> declarations = component.getAllDeclarations();
for (ISeamComponentDeclaration declaration : declarations) {
@@ -92,11 +97,19 @@
// Component class with the same component name. Check precedence.
ISeamJavaComponentDeclaration javaDeclaration =
(ISeamJavaComponentDeclaration)declaration;
int javaDeclarationPrecedence = javaDeclaration.getPrecedence();
- ISeamJavaComponentDeclaration usedDeclaration =
usedPrecedences.get(javaDeclarationPrecedence);
- if(usedDeclaration==null) {
+ ISeamJavaComponentDeclaration checkedDeclaration =
usedPrecedences.get(javaDeclarationPrecedence);
+ if(checkedDeclaration==null) {
usedPrecedences.put(javaDeclarationPrecedence, javaDeclaration);
} else {
// Mark nonunique name.
+ if(!markedDeclarations.contains(checkedDeclaration)) {
+ // Mark first wrong declaration
+ ISeamTextSourceReference target =
((SeamComponentDeclaration)checkedDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
+ addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, target);
+ markedDeclarations.add(checkedDeclaration);
+ }
+ // Mark next wrong declaration
+ markedDeclarations.add(javaDeclaration);
ISeamTextSourceReference target =
((SeamComponentDeclaration)javaDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, target);
}
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
13:52:48 UTC (rev 2341)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java 2007-07-06
14:08:17 UTC (rev 2342)
@@ -20,14 +20,14 @@
import org.jboss.tools.seam.core.ISeamTextSourceReference;
/**
+ * Basic seam validator.
* @author Alexey Kazakov
- *
*/
public abstract class SeamValidator implements IValidatorJob {
private IValidationContext helper;
private IReporter reporter;
-
+
public IStatus validateInJob(IValidationContext helper, IReporter reporter) throws
ValidationException {
this.helper = helper;
this.reporter = reporter;
@@ -42,13 +42,12 @@
validateInJob(helper, reporter);
}
- protected String getBundleName() {
- // TODO
- return "seamvalitation";
+ protected String getBaseName() {
+ return "org.jboss.tools.seam.internal.core.validation.messages";
}
protected void addError(String messageId, String[] messageArguments,
ISeamTextSourceReference target) {
- IMessage message = new Message(getBundleName(), IMessage.HIGH_SEVERITY, messageId,
messageArguments, target.getResource());
+ IMessage message = new Message(getBaseName(), IMessage.HIGH_SEVERITY, messageId,
messageArguments, target.getResource());
message.setLength(target.getLength());
message.setOffset(target.getStartPosition());
reporter.addMessage(this, message);
Added:
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
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/messages.properties 2007-07-06
14:08:17 UTC (rev 2342)
@@ -0,0 +1,11 @@
+ /*******************************************************************************
+ * 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
+ ******************************************************************************/
+NONUNIQUE_COMPONENT_NAME_MESSAGE=Component name must be unique if it has the same
precedence.
\ No newline at end of file