Author: scabanovich
Date: 2007-07-09 10:22:33 -0400 (Mon, 09 Jul 2007)
New Revision: 2359
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/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/java/AnnotatedASTNode.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ComponentBuilder.java
Log:
EXIN-217 Java source scanner is being developed.
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-09
13:38:58 UTC (rev 2358)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2007-07-09
14:22:33 UTC (rev 2359)
@@ -14,6 +14,7 @@
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
import org.jboss.tools.seam.core.event.ISeamProjectChangeListener;
public interface ISeamProject extends IProjectNature {
@@ -37,10 +38,10 @@
public Set<ISeamComponent> getComponentsByScope(ScopeType type);
/**
- * @param resource of ISeamComponentDeclaration that belongs to component
- * @return Set of ISeamComponents by resource.
+ * @param resource path of ISeamComponentDeclaration that belongs to component
+ * @return Set of ISeamComponents by resource path.
*/
- public Set<ISeamComponent> getComponentsByResource(IResource resource);
+ public Set<ISeamComponent> getComponentsByPath(IPath path);
/**
* @param className
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-09
13:38:58 UTC (rev 2358)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-07-09
14:22:33 UTC (rev 2359)
@@ -452,15 +452,15 @@
listeners.remove(listener);
}
- /* (non-Javadoc)
+ /**
* @see
org.jboss.tools.seam.core.ISeamProject#getComponentsByResource(org.eclipse.core.resources.IResource)
*/
- public Set<ISeamComponent> getComponentsByResource(IResource resource) {
+ public Set<ISeamComponent> getComponentsByPath(IPath path) {
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())) {
+ if(path.equals(di.getSourcePath())) {
result.add(c);
break;
}
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-09
13:38:58 UTC (rev 2358)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java 2007-07-09
14:22:33 UTC (rev 2359)
@@ -38,11 +38,13 @@
IType type;
- AnnotatedASTNode annotatedType = null;
- Set<AnnotatedASTNode> annotatedFields = new HashSet<AnnotatedASTNode>();
- Set<AnnotatedASTNode> annotatedMethods = new HashSet<AnnotatedASTNode>();
+ AnnotatedASTNode<TypeDeclaration> annotatedType = null;
+ Set<AnnotatedASTNode<FieldDeclaration>> annotatedFields = new
HashSet<AnnotatedASTNode<FieldDeclaration>>();
+ Set<AnnotatedASTNode<MethodDeclaration>> annotatedMethods = new
HashSet<AnnotatedASTNode<MethodDeclaration>>();
- AnnotatedASTNode currentAnnotatedNode = null;
+ AnnotatedASTNode<?> currentAnnotatedNode = null;
+ AnnotatedASTNode<FieldDeclaration> currentAnnotatedField = null;
+ AnnotatedASTNode<MethodDeclaration> currentAnnotatedMethod = null;
public boolean hasSeamComponent() {
if(annotatedFields.size() > 0 || annotatedMethods.size() > 0) return true;
@@ -103,9 +105,8 @@
return false;
}
-
public boolean visit(TypeDeclaration node) {
- annotatedType = new AnnotatedASTNode(node);
+ annotatedType = new AnnotatedASTNode<TypeDeclaration>(node);
currentAnnotatedNode = annotatedType;
return true;
}
@@ -115,7 +116,7 @@
}
public boolean visit(FieldDeclaration node) {
- currentAnnotatedNode = new AnnotatedASTNode(node);
+ currentAnnotatedField = new AnnotatedASTNode<FieldDeclaration>(node);
return true;
}
@@ -126,22 +127,24 @@
String name = vd.getName().getIdentifier();
System.out.println("-->" + name);
}
- if(currentAnnotatedNode != null && currentAnnotatedNode.getAnnotations() !=
null) {
- annotatedFields.add(currentAnnotatedNode);
+ if(currentAnnotatedField != null && currentAnnotatedField.getAnnotations() !=
null) {
+ annotatedFields.add(currentAnnotatedField);
}
- currentAnnotatedNode = null;
+ currentAnnotatedField = null;
+ currentAnnotatedNode = annotatedType;
}
public boolean visit(MethodDeclaration node) {
- currentAnnotatedNode = new AnnotatedASTNode(node);
+ currentAnnotatedMethod = new AnnotatedASTNode<MethodDeclaration>(node);
return true;
}
public void endVisit(MethodDeclaration node) {
- if(currentAnnotatedNode != null && currentAnnotatedNode.getAnnotations() !=
null) {
- annotatedMethods.add(currentAnnotatedNode);
+ if(currentAnnotatedMethod != null && currentAnnotatedMethod.getAnnotations() !=
null) {
+ annotatedMethods.add(currentAnnotatedMethod);
}
- currentAnnotatedNode = null;
+ currentAnnotatedMethod = null;
+ currentAnnotatedNode = annotatedType;
}
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/AnnotatedASTNode.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/AnnotatedASTNode.java 2007-07-09
13:38:58 UTC (rev 2358)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/AnnotatedASTNode.java 2007-07-09
14:22:33 UTC (rev 2359)
@@ -17,11 +17,11 @@
*
* @author Viacheslav Kabanovich
*/
-public class AnnotatedASTNode {
- ASTNode node;
+public class AnnotatedASTNode<T extends ASTNode> {
+ T node;
ResolvedAnnotation[] annotations = null;
- public AnnotatedASTNode(ASTNode node) {
+ public AnnotatedASTNode(T node) {
this.node = node;
}
@@ -36,7 +36,7 @@
}
}
- public ASTNode getNode() {
+ public T getNode() {
return node;
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ComponentBuilder.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ComponentBuilder.java 2007-07-09
13:38:58 UTC (rev 2358)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ComponentBuilder.java 2007-07-09
14:22:33 UTC (rev 2359)
@@ -12,13 +12,18 @@
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
+import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.VariableDeclaration;
import org.jboss.tools.seam.core.ISeamXmlComponentDeclaration;
import org.jboss.tools.seam.internal.core.SeamAnnotatedFactory;
import org.jboss.tools.seam.internal.core.SeamJavaComponentDeclaration;
@@ -33,8 +38,8 @@
LoadedDeclarations ds = null;
AnnotatedASTNode annotatedType = null;
- Set<AnnotatedASTNode> annotatedFields = new HashSet<AnnotatedASTNode>();
- Set<AnnotatedASTNode> annotatedMethods = new HashSet<AnnotatedASTNode>();
+ Set<AnnotatedASTNode<FieldDeclaration>> annotatedFields = null;
+ Set<AnnotatedASTNode<MethodDeclaration>> annotatedMethods = null;
SeamJavaComponentDeclaration component = new SeamJavaComponentDeclaration();
@@ -89,10 +94,10 @@
}
void processFactories() {
- for (AnnotatedASTNode n: annotatedMethods) {
+ for (AnnotatedASTNode<MethodDeclaration> n: annotatedMethods) {
Annotation a = findAnnotation(n, FACTORY_ANNOTATION_TYPE);
if(a == null) continue;
- MethodDeclaration m = (MethodDeclaration)n.getNode();
+ MethodDeclaration m = n.getNode();
ValueInfo factoryName = ValueInfo.getValueInfo(a, null);
if(factoryName == null) {
factoryName = new ValueInfo();
@@ -136,10 +141,66 @@
}
private IMethod findMethod(MethodDeclaration m) {
-// IType type = (IType)component.getSourceMember();
- IJavaElement e = m.resolveBinding().getJavaElement();
- if(e instanceof IMethod) return (IMethod)e;
+ if(m == null || m.getName() == null) return null;
+ IType type = (IType)component.getSourceMember();
+ IMethod[] ms = null;
+ try {
+ ms = type.getMethods();
+ } catch (Exception e) {
+ //ignore
+ }
+ String name = m.getName().getIdentifier();
+ if(ms != null) for (int i = 0; i < ms.length; i++) {
+ if(!name.equals(ms[i].getElementName())) continue;
+ int s = m.getStartPosition() + m.getLength() / 2;
+ try {
+ int b = ms[i].getSourceRange().getOffset();
+ int e = b + ms[i].getSourceRange().getLength();
+ if(s >= b && s <= e) return ms[i];
+ } catch (JavaModelException e) {
+ return ms[i];
+ }
+ }
return null;
}
+ private IField findField(FieldDeclaration f) {
+ if(f == null || getFieldName(f) == null) return null;
+ IType type = (IType)component.getSourceMember();
+ IField[] fs = null;
+ try {
+ fs = type.getFields();
+ } catch (Exception e) {
+ //ignore
+ }
+ String name = getFieldName(f);
+ if(fs != null) for (int i = 0; i < fs.length; i++) {
+ if(!name.equals(fs[i].getElementName())) continue;
+ int s = f.getStartPosition() + f.getLength() / 2;
+ try {
+ int b = fs[i].getSourceRange().getOffset();
+ int e = b + fs[i].getSourceRange().getLength();
+ if(s >= b && s <= e) return fs[i];
+ } catch (JavaModelException e) {
+ return fs[i];
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns name of first field
+ * @param node
+ * @return
+ */
+ String getFieldName(FieldDeclaration node) {
+ List<?> fragments = node.fragments();
+ for (int i = 0; i < fragments.size(); i++) {
+ VariableDeclaration vd = (VariableDeclaration)fragments.get(i);
+ String name = vd.getName().getIdentifier();
+ return name;
+ }
+ return null;
+ }
+
}
Show replies by date