Author: scabanovich
Date: 2007-08-07 09:22:54 -0400 (Tue, 07 Aug 2007)
New Revision: 2932
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/helpers/bean/AnnotatedBeans.java
Log:
JBIDE-670, EXIN-161 - Old simple scanning for seam components removed.
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/helpers/bean/AnnotatedBeans.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/helpers/bean/AnnotatedBeans.java 2007-08-07
13:11:15 UTC (rev 2931)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/helpers/bean/AnnotatedBeans.java 2007-08-07
13:22:54 UTC (rev 2932)
@@ -13,7 +13,6 @@
import java.util.*;
import org.eclipse.core.resources.*;
import org.eclipse.jdt.core.*;
-import org.eclipse.jdt.core.dom.*;
import org.jboss.tools.common.model.*;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.jsf.JSFModelPlugin;
@@ -34,7 +33,7 @@
IProject project;
Map<String,XModelObject> beans = new HashMap<String,XModelObject>();
- String annotationType = "org.jboss.seam.annotations.Name";
+// String annotationType = "org.jboss.seam.annotations.Name";
private AnnotatedBeans() {}
@@ -62,26 +61,21 @@
if(src == null) {
return;
}
- IJavaProject javaProject = (IJavaProject)project.getNature(JavaCore.NATURE_ID);
+// IJavaProject javaProject = (IJavaProject)project.getNature(JavaCore.NATURE_ID);
+
+/**
+ //This is how we can obtain annotated seam components.
+ //However, it may be not needed now since we have separate Seam Components view
+ //and separate code assist based on seam model.
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
- ASTRequestorImpl requestor = new ASTRequestorImpl();
- Set<ICompilationUnit> units = new HashSet<ICompilationUnit>();
+ Set<ISeamComponent> cs = seamProject.getComponents();
- for (IResource resource : src) {
- IPackageFragmentRoot pfr = javaProject.getPackageFragmentRoot(resource);
- collectCompilationUnits(pfr, units);
- }
-
- ICompilationUnit[] us = units.toArray(new ICompilationUnit[0]);
- // This triggers a full resolve of all types, even inside jars...NOT scalable at all!
- ASTParser.newParser(AST.JLS3).createASTs(us, new String[0], requestor, null);
-
- Map map = requestor.getBeans();
Set<String> set = new HashSet<String>();
- Iterator it = map.keySet().iterator();
- while(it.hasNext()) {
- String name = it.next().toString();
- String cls = map.get(name).toString();
+ for (ISeamComponent c : cs) {
+ String name = c.getName();
+ String cls = c.getClassName();
+ if(cls == null) cls = "";
XModelObject o = beans.get(name);
if(o == null) {
o = model.createModelObject("JSFManagedBean", null);
@@ -94,10 +88,11 @@
set.add(name);
}
// TODO: why does the beans set have to double checkked for duplicates ?
- it = beans.keySet().iterator();
+ Iterator<String> it = beans.keySet().iterator();
while(it.hasNext()) {
if(!set.contains(it.next())) it.remove();
}
+*/
}
void collectCompilationUnits(IParent parent, Set<ICompilationUnit> units) throws
Exception {
@@ -114,86 +109,86 @@
}
}
- class ASTRequestorImpl extends ASTRequestor {
- private ASTVisitorImpl visitor = new ASTVisitorImpl();
- private Map<String, String> beans = new HashMap<String, String>();
-
- public Map<String, String> getBeans() {
- return beans;
- }
-
- public void acceptAST(ICompilationUnit source, CompilationUnit ast) {
- visitor.name = null;
-
- try {
- IType[] ts = source.getTypes();
- if(ts != null && ts.length > 0) {
- visitor.type = ts[0];
- }
- } catch (Exception e) {
- //ignore
- }
- ast.accept(visitor);
- if(visitor.name != null && visitor.type != null) {
- String n = visitor.type.getElementName();
- n = getResolvedType(visitor.type, n);
- beans.put(visitor.name, n);
- }
- }
- }
+// class ASTRequestorImpl extends ASTRequestor {
+// private ASTVisitorImpl visitor = new ASTVisitorImpl();
+// private Map<String, String> beans = new HashMap<String, String>();
+//
+// public Map<String, String> getBeans() {
+// return beans;
+// }
+//
+// public void acceptAST(ICompilationUnit source, CompilationUnit ast) {
+// visitor.name = null;
+//
+// try {
+// IType[] ts = source.getTypes();
+// if(ts != null && ts.length > 0) {
+// visitor.type = ts[0];
+// }
+// } catch (Exception e) {
+// //ignore
+// }
+// ast.accept(visitor);
+// if(visitor.name != null && visitor.type != null) {
+// String n = visitor.type.getElementName();
+// n = getResolvedType(visitor.type, n);
+// beans.put(visitor.name, n);
+// }
+// }
+// }
- class ASTVisitorImpl extends ASTVisitor {
- IType type;
- String name = null;
- public boolean visit(SingleMemberAnnotation node) {
- if(!checkAnnotationType(node)) return false;
- checkExpression(node.getValue());
- return true;
- }
- public boolean visit(NormalAnnotation node) {
- if(!checkAnnotationType(node)) return false;
- List vs = node.values();
- if(vs != null) for (int i = 0; i < vs.size(); i++) {
- MemberValuePair p = (MemberValuePair)vs.get(i);
- if("value".equals(p.getName().getIdentifier())) {
- checkExpression(p.getValue());
- }
- }
- return true;
- }
-
- boolean checkAnnotationType(Annotation node) {
- Name nm = node.getTypeName();
- if(nm instanceof SimpleName) {
- SimpleName sn = (SimpleName)nm;
- String n = sn.getIdentifier();
- if(type != null) {
- n = getResolvedType(type, n);
- }
- if(!annotationType.equals(n)) return false;
- } else if(nm instanceof QualifiedName) {
- QualifiedName qn = (QualifiedName)nm;
- if(!qn.getFullyQualifiedName().equals(annotationType)) return false;
- //improve
- } else {
- return false;
- }
- return true;
- }
-
- void checkExpression(Expression exp) {
- if(exp instanceof StringLiteral) {
- name = ((StringLiteral)exp).getLiteralValue();
- }
- }
-
- public boolean visit(Block node) {
- return false;
- }
- public boolean visit(MethodDeclaration node) {
- return false;
- }
- }
+// class ASTVisitorImpl extends ASTVisitor {
+// IType type;
+// String name = null;
+// public boolean visit(SingleMemberAnnotation node) {
+// if(!checkAnnotationType(node)) return false;
+// checkExpression(node.getValue());
+// return true;
+// }
+// public boolean visit(NormalAnnotation node) {
+// if(!checkAnnotationType(node)) return false;
+// List vs = node.values();
+// if(vs != null) for (int i = 0; i < vs.size(); i++) {
+// MemberValuePair p = (MemberValuePair)vs.get(i);
+// if("value".equals(p.getName().getIdentifier())) {
+// checkExpression(p.getValue());
+// }
+// }
+// return true;
+// }
+//
+// boolean checkAnnotationType(Annotation node) {
+// Name nm = node.getTypeName();
+// if(nm instanceof SimpleName) {
+// SimpleName sn = (SimpleName)nm;
+// String n = sn.getIdentifier();
+// if(type != null) {
+// n = getResolvedType(type, n);
+// }
+// if(!annotationType.equals(n)) return false;
+// } else if(nm instanceof QualifiedName) {
+// QualifiedName qn = (QualifiedName)nm;
+// if(!qn.getFullyQualifiedName().equals(annotationType)) return false;
+// //improve
+// } else {
+// return false;
+// }
+// return true;
+// }
+//
+// void checkExpression(Expression exp) {
+// if(exp instanceof StringLiteral) {
+// name = ((StringLiteral)exp).getLiteralValue();
+// }
+// }
+//
+// public boolean visit(Block node) {
+// return false;
+// }
+// public boolean visit(MethodDeclaration node) {
+// return false;
+// }
+// }
String getResolvedType(IType type, String n) {
try {
Show replies by date