Author: akazakov
Date: 2007-07-05 13:12:54 -0400 (Thu, 05 Jul 2007)
New Revision: 2330
Added:
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/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java
Log:
http://jira.jboss.com/jira/browse/EXIN-327 Validation nonunique name of component
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-05
17:11:58 UTC (rev 2329)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java 2007-07-05
17:12:54 UTC (rev 2330)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.seam.internal.core.validation;
+import java.util.HashMap;
import java.util.Set;
import org.eclipse.core.resources.IFile;
@@ -21,44 +22,86 @@
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.ISeamComponent;
+import org.jboss.tools.seam.core.ISeamComponentDeclaration;
+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;
-public class SeamJavaValidator implements IValidatorJob {
+public class SeamJavaValidator extends SeamValidator {
+ // TODO
+ public static final String NONUNIQUE_COMPONENT_NAME_MESSAGE_ID="";
+
public ISchedulingRule getSchedulingRule(IValidationContext helper) {
// TODO
return null;
}
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();
- Set<ISeamComponent> components = project.getComponents();
- for (ISeamComponent seamComponent : components) {
-// seamComponent.
- }
- String[] uris = seamJavaHelper.getURIs();
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
if (uris.length > 0) {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile currentFile = null;
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);
+ // TODO
}
}
+ } else {
+ return validateAll(project, helper, reporter);
}
return OK_STATUS;
}
public void cleanup(IReporter reporter) {
- // TODO
}
- public void validate(IValidationContext helper, IReporter reporter) throws
ValidationException {
- validateInJob(helper, reporter);
+ private IStatus validateAll(ISeamProject project, IValidationContext helper, IReporter
reporter) {
+ Set<ISeamComponent> components = project.getComponents();
+ for (ISeamComponent component : components) {
+ // TODO
+ }
+ return OK_STATUS;
}
+
+ /*
+ * Validates that component has unique name
+ */
+ private void validateUniqueComponentName(ISeamProject project, ISeamComponent component,
IValidationContext helper, IReporter reporter) {
+ ISeamJavaComponentDeclaration firstJavaDeclaration = component.getJavaDeclaration();
+ if(firstJavaDeclaration!=null) {
+ HashMap<SeamComponentPrecedenceType, ISeamJavaComponentDeclaration>
usedPrecedences = new HashMap<SeamComponentPrecedenceType,
ISeamJavaComponentDeclaration>();
+ SeamComponentPrecedenceType firstJavaDeclarationPrecedence =
firstJavaDeclaration.getPrecedence();
+ if(firstJavaDeclarationPrecedence==null) {
+ firstJavaDeclarationPrecedence = ISeamJavaComponentDeclaration.DEFAULT_PRECEDENCE;
+ }
+ usedPrecedences.put(firstJavaDeclarationPrecedence, firstJavaDeclaration);
+ Set<ISeamComponentDeclaration> declarations = component.getAllDeclarations();
+ for (ISeamComponentDeclaration declaration : declarations) {
+ if(declaration instanceof ISeamJavaComponentDeclaration &&
declaration!=firstJavaDeclaration) {
+ // Component class with the same component name. Check precedence.
+ ISeamJavaComponentDeclaration javaDeclaration =
(ISeamJavaComponentDeclaration)declaration;
+ SeamComponentPrecedenceType javaDeclarationPrecedence =
javaDeclaration.getPrecedence();
+ ISeamJavaComponentDeclaration usedDeclaration =
usedPrecedences.get(javaDeclarationPrecedence);
+ if(usedDeclaration==null) {
+ usedPrecedences.put(javaDeclarationPrecedence, javaDeclaration);
+ } else {
+ // Mark nonunique name.
+ ISeamTextSourceReference target =
((SeamComponentDeclaration)javaDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
+ addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID, target);
+ }
+ }
+ }
+ }
+ }
}
\ 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-05
17:12:54 UTC (rev 2330)
@@ -0,0 +1,60 @@
+ /*******************************************************************************
+ * 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 org.eclipse.core.runtime.IStatus;
+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.ISeamTextSourceReference;
+
+/**
+ * @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;
+ return OK_STATUS;
+ }
+
+ public void cleanup(IReporter reporter) {
+ reporter = null;
+ }
+
+ public void validate(IValidationContext helper, IReporter reporter) throws
ValidationException {
+ validateInJob(helper, reporter);
+ }
+
+ protected String getBundleName() {
+ // TODO
+ return "seamvalitation";
+ }
+
+ protected void addError(String messageId, String[] messageArguments,
ISeamTextSourceReference target) {
+ IMessage message = new Message(getBundleName(), IMessage.HIGH_SEVERITY, messageId,
messageArguments, target.getResource());
+ 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);
+ }
+}
\ No newline at end of file