Author: scabanovich
Date: 2010-11-17 09:59:18 -0500 (Wed, 17 Nov 2010)
New Revision: 26670
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamImport.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/internal/core/SeamJavaComponentDeclaration.java
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/PackageInfoRequestor.java
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/validation/SeamCoreValidator.java
Log:
JBIDE-7616
https://jira.jboss.org/browse/JBIDE-7616
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 2010-11-17
14:54:38 UTC (rev 26669)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamJavaComponentDeclaration.java 2010-11-17
14:59:18 UTC (rev 26670)
@@ -137,4 +137,12 @@
public ISeamJavaComponentDeclaration clone() throws CloneNotSupportedException;
+ /**
+ * Returns only variables resolved with @Import annotation
+ *
+ * @param name
+ * @return
+ */
+ public Set<ISeamContextVariable> getVariablesByName(String name);
+
}
\ No newline at end of file
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamImport.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamImport.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamImport.java 2010-11-17
14:59:18 UTC (rev 26670)
@@ -0,0 +1,51 @@
+package org.jboss.tools.seam.internal.core;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.jboss.tools.common.xml.XMLUtilities;
+import org.jboss.tools.seam.core.ISeamNamespace;
+import org.w3c.dom.Element;
+
+public class SeamImport {
+ static String ATTR_PACKAGE = "package";
+
+ protected String seamPackage;
+ protected String javaPackage;
+
+ public SeamImport() {}
+
+ public String getSeamPackage() {
+ return seamPackage;
+ }
+
+ public String getJavaPackage() {
+ return javaPackage;
+ }
+
+ public void setSeamPackage(String seamPackage) {
+ this.seamPackage = seamPackage;
+ }
+
+ public void setJavaPackage(String javaPackage) {
+ this.javaPackage = javaPackage;
+ }
+
+ public Element toXML(Element parent) {
+ Element element = XMLUtilities.createElement(parent, "import");
+ if(seamPackage != null) {
+ element.setAttribute(SeamXMLConstants.ATTR_VALUE, seamPackage);
+ }
+ if(javaPackage != null) {
+ element.setAttribute(ATTR_PACKAGE, javaPackage);
+ }
+ return element;
+ }
+
+ public void loadXML(Element element) {
+ if(element.hasAttribute(ATTR_PACKAGE)) {
+ javaPackage = element.getAttribute(ATTR_PACKAGE);
+ }
+ seamPackage = element.getAttribute(SeamXMLConstants.ATTR_VALUE);
+ }
+
+}
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamImport.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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 2010-11-17
14:54:38 UTC (rev 26669)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java 2010-11-17
14:59:18 UTC (rev 26670)
@@ -62,6 +62,19 @@
protected Set<IBijectedAttribute> bijectedAttributes = new
HashSet<IBijectedAttribute>();
protected Set<ISeamComponentMethod> componentMethods = new
HashSet<ISeamComponentMethod>();
protected Set<IRole> roles = new HashSet<IRole>();
+
+ protected Set<String> imports = new HashSet<String>();
+
+ public Set<ISeamContextVariable> getVariablesByName(String name) {
+ Set<ISeamContextVariable> result = new HashSet<ISeamContextVariable>();
+ for (String s: imports) {
+ String qname = s + "." + name;
+ Set<ISeamContextVariable> c = getSeamProject().getVariablesByName(qname);
+ if((c == null || c.isEmpty()) && getSeamProject().getParentProject() != null)
c = getSeamProject().getParentProject().getVariablesByName(qname);
+ if(c != null && !c.isEmpty()) result.addAll(c);
+ }
+ return result;
+ }
public void setType(IType type) {
this.type = type;
@@ -115,6 +128,10 @@
adopt(role);
}
+ public void addImport(String value) {
+ imports.add(value);
+ }
+
public Set<IBijectedAttribute> getBijectedAttributes() {
return bijectedAttributes;
}
@@ -208,6 +225,10 @@
public Set<IRole> getRoles() {
return roles;
}
+
+ public Set<String> getImports() {
+ return imports;
+ }
public boolean isOfType(BeanType type) {
return types != null && types.containsKey(type);
@@ -237,6 +258,10 @@
roles.remove(role);
}
+ public void removeImport(String value) {
+ imports.remove(value);
+ }
+
public IMember getSourceMember() {
return type;
}
@@ -275,6 +300,7 @@
mergeComponentMethods(jd, children);
mergeBijected(jd, children);
mergeRoles(jd, children);
+ mergeImports(jd, children);
changes = Change.addChange(changes, children);
@@ -354,6 +380,30 @@
}
+ public void mergeImports(SeamJavaComponentDeclaration jd, Change children) {
+ Map<Object, String> importMap = new HashMap<Object, String>();
+ for (String r: imports) importMap.put(r, r);
+
+ for (String r: jd.imports) {
+ String loaded = r;
+ String current = importMap.remove(loaded);
+ if(current == null) {
+ imports.add(loaded);
+ Change change = new Change(this, null, null, loaded);
+ children.addChildren(Change.addChange(null, change));
+ } else {
+ //nothing to merge as long as import is a String
+ }
+ }
+
+ for (String r: importMap.values()) {
+ imports.remove(r);
+ Change change = new Change(this, null, r, null);
+ children.addChildren(Change.addChange(null, change));
+ }
+
+ }
+
public void mergeComponentMethods(SeamJavaComponentDeclaration jd, Change children) {
Map<Object, SeamComponentMethod> methodsMap = new HashMap<Object,
SeamComponentMethod>();
@@ -481,6 +531,8 @@
for (IRole r : roles) {
c.addRole(r.clone());
}
+ c.imports = new HashSet<String>();
+ c.imports.addAll(imports);
return c;
}
@@ -542,6 +594,14 @@
o.toXML(b, context);
}
}
+
+ if(!imports.isEmpty()) {
+ Element b = XMLUtilities.createElement(element, "imports");
+ for (String s: imports) {
+ Element i = XMLUtilities.createElement(b, "import");
+ i.setAttribute(SeamXMLConstants.ATTR_VALUE, s);
+ }
+ }
context.remove(SeamXMLConstants.ATTR_TYPE);
@@ -553,6 +613,15 @@
setScope(element.getAttribute(SeamXMLConstants.ATTR_SCOPE));
+ Element e_imports = XMLUtilities.getUniqueChild(element, "imports");
+ if(e_imports != null) {
+ Element[] cs = XMLUtilities.getChildren(e_imports, "import");
+ for (Element c: cs) {
+ String v = c.getAttribute(SeamXMLConstants.ATTR_VALUE);
+ if(v != null && v.length() > 0) imports.add(v);
+ }
+ }
+
Element e_types = XMLUtilities.getUniqueChild(element, "bean-types");
if(e_types != null) {
types = new HashMap<BeanType, IValueInfo>();
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 2010-11-17
14:54:38 UTC (rev 26669)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ComponentBuilder.java 2010-11-17
14:59:18 UTC (rev 26670)
@@ -24,10 +24,13 @@
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.ArrayInitializer;
+import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.NormalAnnotation;
+import org.eclipse.jdt.core.dom.QualifiedName;
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.eclipse.jdt.core.dom.StringLiteral;
import org.eclipse.jdt.core.dom.VariableDeclaration;
import org.jboss.tools.common.model.project.ext.IValueInfo;
import org.jboss.tools.common.model.project.ext.impl.ValueInfo;
@@ -90,6 +93,8 @@
component.setScope(scope);
} else if(INSTALL_ANNOTATION_TYPE.equals(type)) {
component.setPrecedence(ValueInfo.getValueInfo(as[i].getAnnotation(),
"precedence")); //$NON-NLS-1$
+ } else if(IMPORT_ANNOTATION_TYPE.equals(type)) {
+ processImport(as[i].getAnnotation());
}
}
@@ -340,6 +345,11 @@
component.addRole(r);
}
+ private void processImport(Annotation a) {
+ List<String> vs = getArrayValue(a);
+ for (String v: vs) component.addImport(v);
+ }
+
private Annotation findAnnotation(AnnotatedASTNode<?> n, String type) {
ResolvedAnnotation[] as = n.getAnnotations();
if(as == null) return null;
@@ -423,6 +433,31 @@
}
return null;
}
+
+ static List<String> getArrayValue(Annotation a) {
+ List<String> result = new ArrayList<String>();
+ if(a instanceof SingleMemberAnnotation) {
+ SingleMemberAnnotation s = (SingleMemberAnnotation)a;
+ Expression exp = s.getValue();
+ if(exp instanceof StringLiteral) {
+ result.add(((StringLiteral)exp).getLiteralValue());
+ } else if(exp instanceof QualifiedName) {
+ Object o = exp.resolveConstantExpressionValue();
+ if(o != null) result.add(o.toString());
+ result.add(exp.toString());
+ } else if(exp instanceof ArrayInitializer) {
+ ArrayInitializer arr = (ArrayInitializer)exp;
+ List<?> es = arr.expressions();
+ if(es != null) for (Object e: es) {
+ Expression exp1 = (Expression)e;
+ if(exp1 instanceof StringLiteral) {
+ result.add(((StringLiteral)exp1).getLiteralValue());
+ }
+ }
+ }
+ }
+ return result;
+ }
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/PackageInfoRequestor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/PackageInfoRequestor.java 2010-11-17
14:54:38 UTC (rev 26669)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/PackageInfoRequestor.java 2010-11-17
14:59:18 UTC (rev 26670)
@@ -22,6 +22,7 @@
import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.eclipse.jdt.core.dom.NormalAnnotation;
import org.eclipse.jdt.core.dom.PackageDeclaration;
+import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
import org.jboss.tools.common.model.project.ext.impl.ValueInfo;
import org.jboss.tools.seam.internal.core.SeamNamespace;
import org.jboss.tools.seam.internal.core.scanner.LoadedDeclarations;
@@ -75,7 +76,6 @@
if(b != null) {
String type = b.getAnnotationType().getQualifiedName();
if(NAMESPACE_ANNOTATION_TYPE.equals(type)) {
- System.out.println("!!!\n" + node);
ValueInfo value = ValueInfo.getValueInfo(node, "value");
ValueInfo prefix = ValueInfo.getValueInfo(node, "prefix");
SeamNamespace ns = new SeamNamespace();
@@ -86,9 +86,23 @@
//
}
namespaces.add(ns);
+ } else if(IMPORT_ANNOTATION_TYPE.equals(type)) {
+ List<String> imports = ComponentBuilder.getArrayValue(node);
+ for (String s: imports) System.out.println("NormalAnnotation " + s);
}
}
return true;
}
+ public boolean visit(SingleMemberAnnotation node) {
+ IAnnotationBinding b = node.resolveAnnotationBinding();
+ if(b != null) {
+ String type = b.getAnnotationType().getQualifiedName();
+ if(IMPORT_ANNOTATION_TYPE.equals(type)) {
+ List<String> imports = ComponentBuilder.getArrayValue(node);
+ for (String s: imports) System.out.println("SingleMemberAnnotation " +
s);
+ }
+ }
+ return true;
+ }
}
Modified:
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 2010-11-17
14:54:38 UTC (rev 26669)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/SeamAnnotations.java 2010-11-17
14:59:18 UTC (rev 26670)
@@ -22,6 +22,7 @@
public static final String NAME_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Name"; //$NON-NLS-1$
public static final String SCOPE_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Scope"; //$NON-NLS-1$
public static final String INSTALL_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Install"; //$NON-NLS-1$
+ public static final String IMPORT_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Import"; //$NON-NLS-1$
public static final String NAMESPACE_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Namespace"; //$NON-NLS-1$
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java 2010-11-17
14:54:38 UTC (rev 26669)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java 2010-11-17
14:59:18 UTC (rev 26670)
@@ -857,8 +857,9 @@
// save link between java source and variable name
validationContext.addLinkedCoreResource(name, declaration.getSourcePath(), false);
- Set<ISeamContextVariable> variables = seamProject.getVariablesByName(name);
- if(variables==null || variables.size()<1) {
+ Set<ISeamContextVariable> variables = declaration.getVariablesByName(name);
+ if(variables == null || variables.isEmpty()) variables =
seamProject.getVariablesByName(name);
+ if(variables == null || variables.isEmpty()) {
ISeamProject parentProject = seamProject.getParentProject();
if(parentProject != null) {
variables = parentProject.getVariablesByName(name);