Author: scabanovich
Date: 2011-04-29 16:37:57 -0400 (Fri, 29 Apr 2011)
New Revision: 30981
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/ConfigDefinitionContext.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamBeanDefinition.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamBeansDefinition.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamMemberDefinition.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/scanner/SeamDefinitionBuilder.java
Log:
JBIDE-3120
https://issues.jboss.org/browse/JBIDE-3120
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/ConfigDefinitionContext.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/ConfigDefinitionContext.java 2011-04-29
20:37:39 UTC (rev 30980)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/ConfigDefinitionContext.java 2011-04-29
20:37:57 UTC (rev 30981)
@@ -10,8 +10,10 @@
******************************************************************************/
package org.jboss.tools.cdi.seam.config.core;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -20,6 +22,7 @@
import org.jboss.tools.cdi.core.extension.AbstractDefinitionContextExtension;
import org.jboss.tools.cdi.internal.core.impl.definition.AnnotationDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.DefinitionContext;
+import org.jboss.tools.cdi.internal.core.impl.definition.TypeDefinition;
import org.jboss.tools.cdi.seam.config.core.definition.SeamBeansDefinition;
/**
@@ -134,4 +137,15 @@
((DefinitionContext)root).addType(path, typeName, def);
}
+ public List<TypeDefinition> getTypeDefinitions() {
+ List<TypeDefinition> result = new ArrayList<TypeDefinition>();
+ for (SeamBeansDefinition def: beanXMLs.values()) {
+ result.addAll(def.getTypeDefinitions());
+ }
+ for (SeamBeansDefinition def: seambeanXMLs.values()) {
+ result.addAll(def.getTypeDefinitions());
+ }
+ return result;
+ }
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamBeanDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamBeanDefinition.java 2011-04-29
20:37:39 UTC (rev 30980)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamBeanDefinition.java 2011-04-29
20:37:57 UTC (rev 30981)
@@ -13,6 +13,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.jboss.tools.cdi.seam.config.core.scanner.SAXElement;
@@ -68,4 +69,15 @@
return methods;
}
+ public SeamMethodDefinition getMethod(IMethod method) {
+ for (SeamMethodDefinition m: methods) {
+ IMethod c = m.getMethod();
+ if(c != null && c.getElementName().equals(method.getElementName())
+ && c.equals(method)) {
+ return m;
+ }
+ }
+ return null;
+ }
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamBeansDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamBeansDefinition.java 2011-04-29
20:37:39 UTC (rev 30980)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamBeansDefinition.java 2011-04-29
20:37:57 UTC (rev 30981)
@@ -17,7 +17,14 @@
import java.util.Map;
import java.util.Set;
+import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
+import org.jboss.tools.cdi.core.IAnnotationDeclaration;
+import org.jboss.tools.cdi.core.IJavaAnnotation;
+import org.jboss.tools.cdi.internal.core.impl.definition.AbstractMemberDefinition;
+import org.jboss.tools.cdi.internal.core.impl.definition.DefinitionContext;
+import org.jboss.tools.cdi.internal.core.impl.definition.FieldDefinition;
+import org.jboss.tools.cdi.internal.core.impl.definition.MethodDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.TypeDefinition;
import org.jboss.tools.cdi.seam.config.core.ConfigDefinitionContext;
import org.jboss.tools.cdi.seam.config.core.scanner.SAXNode;
@@ -67,17 +74,26 @@
}
public void buildTypeDefinitions(ConfigDefinitionContext context) {
+ typeDefinitions.clear();
+
for (SeamBeanDefinition def: beanDefinitions) {
IType type = def.getType();
TypeDefinition typeDef = new TypeDefinition();
boolean replaces = def.getReplacesLocation() != null;
boolean modifies = def.getModifiesLocation() != null;
if(replaces || modifies) {
- //TODO veto type in root context
+ replacedAndModified.add(type);
+ ((DefinitionContext)context.getRootContext()).veto(type);
}
- //TODO Initialize typeDef taking into account replaces and modifies
- typeDef.setType(type, context.getRootContext());
- //TODO merge seam definitions into typeDef and add to typeDefinitions
+ //Initialize typeDef taking into account replaces and modifies
+ int flags = AbstractMemberDefinition.FLAG_ALL_MEMBERS;
+ if(replaces) flags |= AbstractMemberDefinition.FLAG_NO_ANNOTATIONS;
+ typeDef.setType(type, context.getRootContext(), flags);
+
+ System.out.println("--merge type def-->" +
def.getType().getFullyQualifiedName());
+ mergeTypeDefinition(def, typeDef, context);
+
+ typeDefinitions.add(typeDef);
}
}
@@ -85,8 +101,43 @@
List<IType> ds = replacedAndModified;
replacedAndModified = new ArrayList<IType>();
for (IType type: ds) {
- //TODO unveto type in root context
+ ((DefinitionContext)context.getRootContext()).unveto(type);
}
}
+ private void mergeTypeDefinition(SeamBeanDefinition def, TypeDefinition typeDef,
ConfigDefinitionContext context) {
+ mergeAnnotations(def, typeDef, context);
+
+ List<FieldDefinition> fieldDefs = typeDef.getFields();
+ for (FieldDefinition fieldDef:fieldDefs) {
+ if(fieldDef.getField() == null) continue;
+ String n = fieldDef.getField().getElementName();
+ SeamFieldDefinition f = def.getField(n);
+ if(f != null) {
+ mergeAnnotations(f, fieldDef, context);
+ }
+ }
+
+ List<MethodDefinition> methodDefs = typeDef.getMethods();
+ for (MethodDefinition methodDef: methodDefs) {
+ IMethod method = methodDef.getMethod();
+ if(method == null) continue;
+ SeamMethodDefinition m = def.getMethod(method);
+ if(m != null) {
+ mergeAnnotations(m, methodDef, context);
+ }
+ }
+
+ }
+
+ private void mergeAnnotations(SeamMemberDefinition def, AbstractMemberDefinition
memberDef, ConfigDefinitionContext context) {
+ Map<String, IJavaAnnotation> annotations = def.getAnnotations();
+ for (String typeName: annotations.keySet()) {
+ IJavaAnnotation ja = annotations.get(typeName);
+ IAnnotationDeclaration current = memberDef.getAnnotation(typeName);
+ if(current != null) memberDef.removeAnnotation(current);
+ memberDef.addAnnotation(ja, context.getRootContext());
+ }
+ }
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamMemberDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamMemberDefinition.java 2011-04-29
20:37:39 UTC (rev 30980)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamMemberDefinition.java 2011-04-29
20:37:57 UTC (rev 30981)
@@ -51,6 +51,10 @@
annotations.put(a.getTypeName(), a);
}
+ public Map<String, IJavaAnnotation> getAnnotations() {
+ return annotations;
+ }
+
public IJavaAnnotation getAnnotation(String typeName) {
return annotations.get(typeName);
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/scanner/SeamDefinitionBuilder.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/scanner/SeamDefinitionBuilder.java 2011-04-29
20:37:39 UTC (rev 30980)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/scanner/SeamDefinitionBuilder.java 2011-04-29
20:37:57 UTC (rev 30981)
@@ -104,7 +104,7 @@
private void scanAnnotation(SAXElement element, IType type) {
context.getRootContext().getAnnotationKind(type); // kick it
AnnotationDefinition def = new AnnotationDefinition();
- def.setType(type, context.getRootContext());
+ def.setType(type, context.getRootContext(), 0);
List<SAXElement> es = element.getChildElements();
//children should be annotation declarations.
@@ -253,7 +253,7 @@
if(q != null) {
inline.addAnnotation(q);
def.addAnnotation(q);
- IJavaAnnotation inject = createInject();
+ IJavaAnnotation inject = createInject(element);
if(inject != null) def.addAnnotation(inject);
}
}
@@ -337,7 +337,7 @@
SeamParameterDefinition pd = scanParameter(element);
if(pd != null) def.addParameter(pd);
}
- IJavaAnnotation inject = createInject();
+ IJavaAnnotation inject = createInject(element);
def.addAnnotation(inject);
IMethod method = null;
try {
@@ -463,12 +463,12 @@
return new AnnotationLiteral(resource, 0, 0, "" + id,
IMemberValuePair.K_STRING, type);
}
- IJavaAnnotation createInject() {
+ IJavaAnnotation createInject(SAXElement forElement) {
IType type = project.getType(CDIConstants.INJECT_ANNOTATION_TYPE_NAME);
if(type == null) {
return null;
}
- return new AnnotationLiteral(resource, 0, 0, null, 0, type);
+ return new AnnotationLiteral(resource, forElement.getLocation().getStartPosition(),
forElement.getLocation().getLength(), null, 0, type);
}
}