Author: scabanovich
Date: 2007-07-06 07:46:13 -0400 (Fri, 06 Jul 2007)
New Revision: 2338
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/SeamAnnotations.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamJavaComponentDeclaration.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamComponentPrecedenceType.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.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/scanner/java/ASTVisitorImpl.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/ClassScanner.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java
Log:
EXIN-217 Java class scanner is being developed.
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamJavaComponentDeclaration.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamJavaComponentDeclaration.java 2007-07-06
11:45:21 UTC (rev 2337)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamJavaComponentDeclaration.java 2007-07-06
11:46:13 UTC (rev 2338)
@@ -18,7 +18,7 @@
*/
public interface ISeamJavaComponentDeclaration extends ISeamComponentDeclaration,
ISeamJavaSourceReference {
- public static final SeamComponentPrecedenceType DEFAULT_PRECEDENCE =
SeamComponentPrecedenceType.APPLICATION;
+ public static final int DEFAULT_PRECEDENCE = SeamComponentPrecedenceType.APPLICATION;
/**
* @return qualified class name
@@ -113,11 +113,11 @@
/**
* @return precedence of component.
*/
- public SeamComponentPrecedenceType getPrecedence();
+ public int getPrecedence();
/**
* Sets precedence of component.
* @param precedence
*/
- public void setPrecedence(SeamComponentPrecedenceType precedence);
+ public void setPrecedence(int precedence);
}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamComponentPrecedenceType.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamComponentPrecedenceType.java 2007-07-06
11:45:21 UTC (rev 2337)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamComponentPrecedenceType.java 2007-07-06
11:46:13 UTC (rev 2338)
@@ -14,10 +14,12 @@
* List of component precedence types
* @author Alexey Kazakov
*/
-public enum SeamComponentPrecedenceType {
- BUILT_IN,
- FRAMEWORK,
- APPLICATION,
- DEPLOYMENT,
- MOCK
+public interface SeamComponentPrecedenceType {
+ int BUILT_IN = 0;
+ int FRAMEWORK = 10;
+ int APPLICATION = 20;
+ int DEPLOYMENT = 30;
+ int MOCK = 40;
+
+ int DEFAULT = APPLICATION;
}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java 2007-07-06
11:45:21 UTC (rev 2337)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java 2007-07-06
11:46:13 UTC (rev 2338)
@@ -23,7 +23,7 @@
protected ScopeType scopeType = ScopeType.UNSPECIFIED;
protected boolean stateful = false;
protected boolean entity = false;
- protected SeamComponentPrecedenceType precedence;
+ protected int precedence = SeamComponentPrecedenceType.DEFAULT;
protected IType type;
@@ -185,17 +185,17 @@
return changes;
}
- /* (non-Javadoc)
+ /**
* @see org.jboss.tools.seam.core.ISeamJavaComponentDeclaration#getPrecedence()
*/
- public SeamComponentPrecedenceType getPrecedence() {
+ public int getPrecedence() {
return precedence;
}
/* (non-Javadoc)
* @see
org.jboss.tools.seam.core.ISeamJavaComponentDeclaration#setPrecedence(org.jboss.tools.seam.core.SeamComponentPrecedenceType)
*/
- public void setPrecedence(SeamComponentPrecedenceType precedence) {
+ public void setPrecedence(int precedence) {
this.precedence = precedence;
}
}
\ 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-06
11:45:21 UTC (rev 2337)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-07-06
11:46:13 UTC (rev 2338)
@@ -119,6 +119,7 @@
loaded.setSourcePath(source);
String name = loaded.getName();
+
SeamComponent c = getComponent(name);
if(current != null) {
@@ -133,17 +134,18 @@
continue;
}
- if(c == null) {
+ if(c == null && name != null) {
c = newComponent(name);
allComponents.put(name, c);
allVariables.add(c);
addedComponents = Change.addChange(addedComponents, new Change(this, null, null,
c));
}
- c.addDeclaration(components[i]);
+ if(c != null) c.addDeclaration(components[i]);
if(loaded instanceof ISeamJavaComponentDeclaration) {
- javaDeclarations.put(c.getClassName(), (SeamJavaComponentDeclaration)components[i]);
- Set<ISeamComponent> cs = getComponentsByClass(c.getClassName());
+ SeamJavaComponentDeclaration jd = (SeamJavaComponentDeclaration)loaded;
+ javaDeclarations.put(jd.getClassName(), jd);
+ Set<ISeamComponent> cs = getComponentsByClass(jd.getClassName());
for (ISeamComponent ci: cs) {
if(ci == c) continue;
SeamComponent cii = (SeamComponent)ci;
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java 2007-07-06
11:45:21 UTC (rev 2337)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java 2007-07-06
11:46:13 UTC (rev 2338)
@@ -37,10 +37,7 @@
*
* @author Viacheslav Kabanovich
*/
-public class ASTVisitorImpl extends ASTVisitor {
- public static String SEAM_ANNOTATION_TYPE_PREFIX =
"org.jboss.seam.annotations.";
- public static String NAME_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Name";
- public static String SCOPE_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Scope";
+public class ASTVisitorImpl extends ASTVisitor implements SeamAnnotations {
static int UNDEFINED_CONTEXT = -1;
static int TYPE_CONTEXT = 0;
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/SeamAnnotations.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/SeamAnnotations.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/SeamAnnotations.java 2007-07-06
11:46:13 UTC (rev 2338)
@@ -0,0 +1,10 @@
+package org.jboss.tools.seam.internal.core.scanner.java;
+
+public interface SeamAnnotations {
+
+ public static String SEAM_ANNOTATION_TYPE_PREFIX =
"org.jboss.seam.annotations.";
+ public static String NAME_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Name";
+ public static String SCOPE_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Scope";
+ public static String INSTALL_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Install";
+
+}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/ClassScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/ClassScanner.java 2007-07-06
11:45:21 UTC (rev 2337)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/ClassScanner.java 2007-07-06
11:46:13 UTC (rev 2338)
@@ -11,18 +11,22 @@
package org.jboss.tools.seam.internal.core.scanner.lib;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IType;
+import org.jboss.tools.seam.internal.core.SeamJavaComponentDeclaration;
import org.jboss.tools.seam.internal.core.scanner.LoadedDeclarations;
-import org.jboss.tools.seam.internal.core.scanner.java.ASTVisitorImpl;
+import org.jboss.tools.seam.internal.core.scanner.java.SeamAnnotations;
/**
* Loads seam components from Class object.
*
* @author Viacheslav Kabanovich
*/
-public class ClassScanner {
+public class ClassScanner implements SeamAnnotations {
/**
* Checks if class may be a source of seam components.
@@ -45,6 +49,13 @@
if(!isLikelyComponentSource(cls)) return null;
LoadedDeclarations ds = new LoadedDeclarations();
+ SeamJavaComponentDeclaration component = new SeamJavaComponentDeclaration();
+ component.setSourcePath(path);
+ component.setId(type);
+ component.setClassName(type.getFullyQualifiedName());
+ process(cls, component);
+
+ ds.getComponents().add(component);
return ds;
}
@@ -58,11 +69,63 @@
Annotation[] as = cls.getAnnotations();
for (int i = 0; i < as.length; i++) {
Class<?> acls = as[i].annotationType();
- if(acls.getName().startsWith(ASTVisitorImpl.SEAM_ANNOTATION_TYPE_PREFIX)) {
+ if(acls.getName().startsWith(SEAM_ANNOTATION_TYPE_PREFIX)) {
return true;
}
}
return false;
}
+
+ Map<String,Annotation> getSeamAnnotations(Annotation[] as) {
+ if(as == null || as.length == 0) return null;
+ Map<String,Annotation> map = null;
+ for (int i = 0; i < as.length; i++) {
+ Class<?> acls = as[i].annotationType();
+ if(acls.getName().startsWith(SEAM_ANNOTATION_TYPE_PREFIX)) {
+ if(map == null) map = new HashMap<String, Annotation>();
+ map.put(acls.getName(), as[i]);
+ }
+ }
+ return map;
+ }
+
+ private void process(Class<?> cls, SeamJavaComponentDeclaration component) {
+ Map<String, Annotation> map = getSeamAnnotations(cls.getAnnotations());
+ if(map != null) {
+ Annotation a = map.get(NAME_ANNOTATION_TYPE);
+ if(a != null) {
+ String name = (String)getValue(a, "value");
+ if(name != null) component.setName(name);
+ }
+ a = map.get(SCOPE_ANNOTATION_TYPE);
+ if(a != null) {
+ Object scope = getValue(a, "value");
+ if(scope != null) component.setScope(scope.toString());
+ }
+ a = map.get(INSTALL_ANNOTATION_TYPE);
+ if(a != null) {
+ Object precedence = getValue(a, "precedence");
+ if(precedence instanceof Integer) component.setPrecedence((Integer)precedence);
+ }
+ }
+ Method[] ms = cls.getMethods();
+ for (int i = 0; i < ms.length; i++) {
+ map = getSeamAnnotations(ms[i].getAnnotations());
+ if(map == null || map.isEmpty()) continue;
+
+
+ }
+ }
+
+ private Object getValue(Annotation a, String method) {
+ try {
+ Method m = a.annotationType().getMethod(method, new Class[0]);
+ if(m == null) return null;
+ return m.invoke(a, new Object[0]);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java 2007-07-06
11:45:21 UTC (rev 2337)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java 2007-07-06
11:46:13 UTC (rev 2338)
@@ -17,14 +17,12 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClassFile;
-import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IParent;
import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.common.model.XModelObject;
@@ -101,10 +99,7 @@
if(componentsXML != null) {
LoadedDeclarations ds1 = new XMLScanner().parse(componentsXML, path);
- if(ds1 != null) {
- ds.getComponents().addAll(ds1.getComponents());
- ds.getFactories().addAll(ds1.getFactories());
- }
+ if(ds1 != null) ds.add(ds1);
}
if(seamProperties != null) {
XModelObject[] properties = seamProperties.getChildren();
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
11:45:21 UTC (rev 2337)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamJavaValidator.java 2007-07-06
11:46:13 UTC (rev 2338)
@@ -80,9 +80,9 @@
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) {
+ HashMap<Integer, ISeamJavaComponentDeclaration> usedPrecedences = new
HashMap<Integer, ISeamJavaComponentDeclaration>();
+ int firstJavaDeclarationPrecedence = firstJavaDeclaration.getPrecedence();
+ if(firstJavaDeclarationPrecedence < 0) {
firstJavaDeclarationPrecedence = ISeamJavaComponentDeclaration.DEFAULT_PRECEDENCE;
}
usedPrecedences.put(firstJavaDeclarationPrecedence, firstJavaDeclaration);
@@ -91,7 +91,7 @@
if(declaration instanceof ISeamJavaComponentDeclaration &&
declaration!=firstJavaDeclaration) {
// Component class with the same component name. Check precedence.
ISeamJavaComponentDeclaration javaDeclaration =
(ISeamJavaComponentDeclaration)declaration;
- SeamComponentPrecedenceType javaDeclarationPrecedence =
javaDeclaration.getPrecedence();
+ int javaDeclarationPrecedence = javaDeclaration.getPrecedence();
ISeamJavaComponentDeclaration usedDeclaration =
usedPrecedences.get(javaDeclarationPrecedence);
if(usedDeclaration==null) {
usedPrecedences.put(javaDeclarationPrecedence, javaDeclaration);