Author: akazakov
Date: 2007-07-16 14:18:34 -0400 (Mon, 16 Jul 2007)
New Revision: 2449
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamScope.java
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/ScopeType.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
Log:
http://jira.jboss.com/jira/browse/EXIN-327 @Factory validation
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2007-07-16
18:07:11 UTC (rev 2448)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2007-07-16
18:18:34 UTC (rev 2449)
@@ -122,6 +122,12 @@
public Set<ISeamFactory> getFactoriesByScope(ScopeType scope);
/**
+ * @param resource path of ISeamFactory that belongs to factory declaration
+ * @return Set of ISeamFactory by resource path.
+ */
+ public Set<ISeamFactory> getFactoriesByPath(IPath path);
+
+ /**
* Adds factory method into project
* @param factory
*/
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ScopeType.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ScopeType.java 2007-07-16
18:07:11 UTC (rev 2448)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ScopeType.java 2007-07-16
18:18:34 UTC (rev 2449)
@@ -14,14 +14,28 @@
* Types of Seam Scopes.
* @author Alexey Kazakov
*/
-public enum ScopeType {
- STATELESS,
- METHOD,
- EVENT,
- PAGE,
- CONVERSATION,
- SESSION,
- APPLICATION,
- BUSINESS_PROCESS,
- UNSPECIFIED;
+public enum ScopeType implements SeamScope {
+ STATELESS(),
+ METHOD(),
+ EVENT(EVENT_PRIORITY_ORDER),
+ PAGE(PAGE_PRIORITY_ORDER),
+ CONVERSATION(CONVERSATION_PRIORITY_ORDER),
+ SESSION(SESSION_PRIORITY_ORDER),
+ APPLICATION(APPLICATION_PRIORITY_ORDER),
+ BUSINESS_PROCESS(BUSINESS_PROCESS_PRIORITY_ORDER),
+ UNSPECIFIED(UNDEFINED_PRIORITY_ORDER);
+
+ int priority;
+
+ ScopeType(int priority) {
+ this.priority = priority;
+ }
+
+ ScopeType() {
+ this.priority = UNDEFINED_PRIORITY_ORDER;
+ }
+
+ public int getPriority() {
+ return priority;
+ }
}
\ No newline at end of file
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamScope.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamScope.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamScope.java 2007-07-16
18:18:34 UTC (rev 2449)
@@ -0,0 +1,25 @@
+ /*******************************************************************************
+ * 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.core;
+
+/**
+ * @author Alexey Kazakov
+ */
+public interface SeamScope {
+
+ public static final int UNDEFINED_PRIORITY_ORDER = -1;
+ public static final int EVENT_PRIORITY_ORDER = 0;
+ public static final int PAGE_PRIORITY_ORDER = 1;
+ public static final int CONVERSATION_PRIORITY_ORDER = 2;
+ public static final int SESSION_PRIORITY_ORDER = 3;
+ public static final int BUSINESS_PROCESS_PRIORITY_ORDER = 4;
+ public static final int APPLICATION_PRIORITY_ORDER = 5;
+}
\ No newline at end of file
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-16
18:07:11 UTC (rev 2448)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-07-16
18:18:34 UTC (rev 2449)
@@ -636,6 +636,19 @@
return result;
}
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.seam.core.ISeamProject#getFactoriesByPath(org.eclipse.core.runtime.IPath)
+ */
+ public Set<ISeamFactory> getFactoriesByPath(IPath path) {
+ Set<ISeamFactory> result = new HashSet<ISeamFactory>();
+ for (ISeamFactory f: allFactories) {
+ if(path.equals(f.getSourcePath())) {
+ result.add(f);
+ }
+ }
+ return result;
+ }
+
public void removeFactory(ISeamFactory factory) {
allFactories.remove(factory);
allVariables.remove(factory);
@@ -781,5 +794,4 @@
return;
}
}
-
-}
+}
\ 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-16
18:07:11 UTC (rev 2448)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java 2007-07-16
18:18:34 UTC (rev 2449)
@@ -22,17 +22,21 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.wst.validation.internal.core.ValidationException;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
import org.jboss.tools.seam.core.BijectedAttributeType;
import org.jboss.tools.seam.core.IBijectedAttribute;
+import org.jboss.tools.seam.core.ISeamAnnotatedFactory;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamComponentDeclaration;
import org.jboss.tools.seam.core.ISeamComponentMethod;
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.ISeamTextSourceReference;
@@ -123,6 +127,7 @@
IFile sourceFile = root.getFile(linkedResource);
reporter.removeMessageSubset(this, sourceFile, MARKED_COMPONENT_MESSAGE_GROUP);
validateComponent(linkedResource, checkedComponents);
+ validateFactory(linkedResource);
// TODO
}
} else {
@@ -132,6 +137,58 @@
return OK_STATUS;
}
+ private void validateFactory(IPath sourceFilePath) {
+ Set<ISeamFactory> factories = project.getFactoriesByPath(sourceFilePath);
+ for (ISeamFactory factory : factories) {
+ if(factory instanceof ISeamAnnotatedFactory) {
+ validateFactory((ISeamAnnotatedFactory)factory);
+ }
+ }
+ }
+
+ private void validateFactory(ISeamAnnotatedFactory factory) {
+ IMember sourceMember = factory.getSourceMember();
+ if(sourceMember instanceof IMethod) {
+ IMethod method = (IMethod)sourceMember;
+ try {
+ String returnType = method.getReturnType();
+ if("V".equals(returnType)) {
+ // return type is void
+ String factoryName = factory.getName();
+ if(factoryName==null) {
+ String methodName = method.getElementName();
+ if(methodName.startsWith("get") && methodName.length()>3) {
+ // This is getter
+ factoryName = methodName.substring(3);
+ } else {
+ // TODO
+ // Unknown factory name
+ factoryName = methodName;
+ }
+ }
+ ScopeType factoryScope = factory.getScope();
+ Set<ISeamContextVariable> variables =
project.getVariablesByName(factoryName);
+ boolean unknownVariable = true;
+ for (ISeamContextVariable variable : variables) {
+ if((factoryScope == variable.getScope() ||
factoryScope.getPriority()>variable.getScope().getPriority()) && !(variable
instanceof ISeamFactory)) {
+ // It's OK. We have that variable name
+ unknownVariable = false;
+ break;
+ }
+ if(unknownVariable) {
+ // TODO
+ // mark unknown factory name
+ }
+ }
+ }
+ } catch (Exception e) {
+ SeamCorePlugin.getDefault().logError(e);
+ }
+ } else {
+ // factory must be java method!
+ }
+ }
+
private void validateComponent(IPath sourceFilePath, Set<ISeamComponent>
checkedComponents) {
Set<ISeamComponent> components = project.getComponentsByPath(sourceFilePath);
for (ISeamComponent component : components) {
@@ -168,8 +225,14 @@
Set<ISeamComponent> components = project.getComponents();
for (ISeamComponent component : components) {
validateComponent(component);
- // TODO
}
+ Set<ISeamFactory> factories = project.getFactories();
+ for (ISeamFactory factory : factories) {
+ if(factory instanceof ISeamAnnotatedFactory) {
+ validateFactory((ISeamAnnotatedFactory)factory);
+ }
+ }
+ // TODO
return OK_STATUS;
}