Author: scabanovich
Date: 2011-05-19 20:09:19 -0400 (Thu, 19 May 2011)
New Revision: 31388
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/definition/GenericProducerField.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/generic/GenericClassBean.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/META-INF/MANIFEST.MF
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/CDISeamSolderConstants.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/generic/CDISeamSolderGenericBeanExtension.java
Log:
JBIDE-8674
https://issues.jboss.org/browse/JBIDE-8674
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/META-INF/MANIFEST.MF 2011-05-20
00:05:45 UTC (rev 31387)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/META-INF/MANIFEST.MF 2011-05-20
00:09:19 UTC (rev 31388)
@@ -28,5 +28,6 @@
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: JBoss by Red Hat
-Export-Package: org.jboss.tools.cdi.seam.solder.core
+Export-Package: org.jboss.tools.cdi.seam.solder.core,
+ org.jboss.tools.cdi.seam.solder.core.generic
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/CDISeamSolderConstants.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/CDISeamSolderConstants.java 2011-05-20
00:05:45 UTC (rev 31387)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/CDISeamSolderConstants.java 2011-05-20
00:09:19 UTC (rev 31388)
@@ -37,5 +37,7 @@
public String GENERIC_ANNOTATION_KIND = "genericAnnotation";
public String GENERIC_QUALIFIER_TYPE_NAME =
"org.jboss.seam.solder.bean.generic.Generic";
public String GENERIC_CONFIGURATION_ANNOTATION_TYPE_NAME =
"org.jboss.seam.solder.bean.generic.GenericConfiguration";
+ public String APPLY_SCOPE_ANNOTATION_TYPE_NAME =
"org.jboss.seam.solder.bean.generic.ApplyScope";
+ public String INJECT_GENERIC_ANNOTATION_TYPE_NAME =
"org.jboss.seam.solder.bean.generic.InjectGeneric";
}
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/definition/GenericProducerField.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/definition/GenericProducerField.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/definition/GenericProducerField.java 2011-05-20
00:09:19 UTC (rev 31388)
@@ -0,0 +1,7 @@
+package org.jboss.tools.cdi.seam.solder.core.definition;
+
+import org.jboss.tools.cdi.internal.core.impl.ProducerField;
+
+public class GenericProducerField extends ProducerField {
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/definition/GenericProducerField.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/generic/CDISeamSolderGenericBeanExtension.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/generic/CDISeamSolderGenericBeanExtension.java 2011-05-20
00:05:45 UTC (rev 31387)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/generic/CDISeamSolderGenericBeanExtension.java 2011-05-20
00:09:19 UTC (rev 31388)
@@ -23,6 +23,7 @@
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
+import org.jboss.tools.cdi.core.IJavaAnnotation;
import org.jboss.tools.cdi.core.IProducer;
import org.jboss.tools.cdi.core.IQualifierDeclaration;
import org.jboss.tools.cdi.core.IRootDefinitionContext;
@@ -39,6 +40,7 @@
import org.jboss.tools.cdi.internal.core.impl.definition.AnnotationDefinition;
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.ParameterDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.TypeDefinition;
import org.jboss.tools.cdi.internal.core.scanner.FileSet;
import org.jboss.tools.cdi.seam.solder.core.CDISeamSolderConstants;
@@ -80,13 +82,23 @@
public void buildBeans() {
CDIProject p = ((CDIProject)project.getDelegate());
- for (GenericConfiguration c: context.getGenericConfigurations().values()) {
+ for (GenericConfiguration c: context.getGenericConfigurations().values()) {
+ //Create fake bean for injection of generic type annotation.
+ AnnotationDefinition genericTypeDef = c.getGenericTypeDefinition();
+ if(genericTypeDef != null) {
+ TypeDefinition fakeGenericType = new TypeDefinition();
+ fakeGenericType.setType(genericTypeDef.getType(), context.getRootContext(), 0);
+ ClassBean b = new ClassBean();
+ b.setDefinition(fakeGenericType);
+ b.setParent(p);
+ p.addBean(b);
+ }
+
Map<AbstractMemberDefinition, List<IAnnotationDeclaration>> ms =
c.getGenericProducerBeans();
- //TODO scopes!
-
Set<TypeDefinition> ts = c.getGenericConfigurationBeans();
- for (List<IAnnotationDeclaration> list: ms.values()) {
+ for (AbstractMemberDefinition gp: ms.keySet()) {
+ List<IAnnotationDeclaration> list = ms.get(gp);
for (TypeDefinition t: ts) {
TypeDefinition ti = new TypeDefinition();
ti.setType(t.getType(), context.getRootContext(), 0);
@@ -98,9 +110,14 @@
}
}
}
- ClassBean cb = new ClassBean();
+ replaceGenericInjections(ti, list);
+
+ GenericClassBean cb = new GenericClassBean();
+ cb.setGenericProducerBeanDefinition(gp);
cb.setParent(p);
cb.setDefinition(ti);
+
+ p.addBean(cb);
Set<IProducer> producers = cb.getProducers();
for (IProducer producer: producers) {
p.addBean(producer);
@@ -110,9 +127,51 @@
}
}
+ private void replaceGenericInjections(TypeDefinition ti,
List<IAnnotationDeclaration> list) {
+ List<FieldDefinition> fs = ti.getFields();
+ for (FieldDefinition f: fs) {
+ if(f.isAnnotationPresent(INJECT_ANNOTATION_TYPE_NAME) &&
f.isAnnotationPresent(GENERIC_QUALIFIER_TYPE_NAME)) {
+ for (IAnnotationDeclaration d: list) {
+ f.addAnnotation(((AnnotationDeclaration)d).getDeclaration(),
context.getRootContext());
+ }
+ AnnotationDeclaration gd = f.getAnnotation(GENERIC_QUALIFIER_TYPE_NAME);
+ f.removeAnnotation(gd);
+ f.addAnnotation(createInjectGenericAnnotation(gd), context.getRootContext());
+ }
+ }
+
+ List<MethodDefinition> ms = ti.getMethods();
+ for (MethodDefinition m: ms) {
+ if(m.isAnnotationPresent(INJECT_ANNOTATION_TYPE_NAME)) {
+ boolean isMethodGeneric = m.isAnnotationPresent(GENERIC_QUALIFIER_TYPE_NAME);
+ List<ParameterDefinition> ps = m.getParameters();
+ for (ParameterDefinition p: ps) {
+ if(isMethodGeneric || p.isAnnotationPresent(GENERIC_QUALIFIER_TYPE_NAME)) {
+ for (IAnnotationDeclaration d: list) {
+ p.addAnnotation(((AnnotationDeclaration)d).getDeclaration(),
context.getRootContext());
+ }
+ AnnotationDeclaration gd = p.getAnnotation(GENERIC_QUALIFIER_TYPE_NAME);
+ if(gd != null) {
+ p.removeAnnotation(gd);
+ p.addAnnotation(createInjectGenericAnnotation(gd), context.getRootContext());
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private IJavaAnnotation createInjectGenericAnnotation(AnnotationDeclaration
genericAnnotation) {
+ IType type = project.getType(INJECT_GENERIC_ANNOTATION_TYPE_NAME);
+ return (type != null) ? new AnnotationLiteral(genericAnnotation.getResource(),
+ genericAnnotation.getStartPosition(), genericAnnotation.getLength(), null, 0, type)
+ : null;
+ }
+
@Override
public void processAnnotatedType(TypeDefinition typeDefinition, IRootDefinitionContext
context) {
if(typeDefinition.isAnnotationPresent(GENERIC_CONFIGURATION_ANNOTATION_TYPE_NAME)) {
+ typeDefinition.veto();
IAnnotationDeclaration d =
typeDefinition.getAnnotation(GENERIC_CONFIGURATION_ANNOTATION_TYPE_NAME);
Object o = d.getMemberValue(null);
if(o != null) {
@@ -129,43 +188,28 @@
}
}
}
- List<MethodDefinition> ms = typeDefinition.getMethods();
- for (MethodDefinition m: ms) {
- if(m.isAnnotationPresent(PRODUCES_ANNOTATION_TYPE_NAME)) {
- IType q = project.getType(GENERIC_QUALIFIER_TYPE_NAME);
- if(q != null) {
- AnnotationLiteral a = new AnnotationLiteral(m.getResource(), 0, 0, null, 0, q);
- m.addAnnotation(a, context);
- }
- }
- }
} else {
- IAnnotationDeclaration d = findAnnotationAnnotatedWithGenericType(typeDefinition);
- if(d != null) {
- addGenericProducerBean(typeDefinition,
findAnnotationAnnotatedWithGenericType(typeDefinition).getTypeName());
- }
- List<MethodDefinition> ms = typeDefinition.getMethods();
- for (MethodDefinition m: ms) {
+ addGenericProducerBean(typeDefinition);
+ for (MethodDefinition m: typeDefinition.getMethods()) {
if(m.isAnnotationPresent(PRODUCES_ANNOTATION_TYPE_NAME)) {
- d = findAnnotationAnnotatedWithGenericType(m);
- if(d != null) {
- addGenericProducerBean(m, d.getTypeName());
- }
+ addGenericProducerBean(m);
}
}
- List<FieldDefinition> fs = typeDefinition.getFields();
- for (FieldDefinition f: fs) {
+ for (FieldDefinition f: typeDefinition.getFields()) {
if(f.isAnnotationPresent(PRODUCES_ANNOTATION_TYPE_NAME)) {
- d = findAnnotationAnnotatedWithGenericType(f);
- if(d != null) {
- addGenericProducerBean(f, d.getTypeName());
- }
+ addGenericProducerBean(f);
}
}
}
-
}
+ private void addGenericProducerBean(AbstractMemberDefinition def) {
+ IAnnotationDeclaration d = findAnnotationAnnotatedWithGenericType(def);
+ if(d != null) {
+ addGenericProducerBean(def, d.getTypeName());
+ }
+ }
+
private void addGenericProducerBean(AbstractMemberDefinition def, String genericType) {
GenericConfiguration c =
((GenericBeanDefinitionContext)this.context.getWorkingCopy()).getGenericConfiguration(genericType);
@@ -177,13 +221,7 @@
}
}
c.getGenericProducerBeans().put(def, list);
- if(c.getGenericProducerBeans().size() == 1) {
- IType q = project.getType(GENERIC_QUALIFIER_TYPE_NAME);
- if(q != null) {
- AnnotationLiteral a = new AnnotationLiteral(def.getResource(), 0, 0, null, 0, q);
- def.addAnnotation(a, context.getRootContext());
- }
- }
+
IResource r = def.getResource();
if(r != null && r.exists() &&
!c.getInvolvedTypes().contains(r.getFullPath())) {
IPath newPath = r.getFullPath();
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/generic/GenericClassBean.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/generic/GenericClassBean.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/generic/GenericClassBean.java 2011-05-20
00:09:19 UTC (rev 31388)
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.seam.solder.core.generic;
+
+import java.util.Set;
+
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.internal.core.impl.AbstractBeanElement;
+import org.jboss.tools.cdi.internal.core.impl.ClassBean;
+import org.jboss.tools.cdi.internal.core.impl.definition.AbstractMemberDefinition;
+import org.jboss.tools.cdi.seam.solder.core.CDISeamSolderConstants;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public class GenericClassBean extends ClassBean {
+ protected AbstractMemberDefinition genericProducerBean;
+
+ public GenericClassBean() {}
+
+ public void setGenericProducerBeanDefinition(AbstractMemberDefinition def) {
+ genericProducerBean = def;
+ }
+
+ public IBean getGenericProducerBean() {
+ Set<IBean> bs =
getCDIProject().getBeans(genericProducerBean.getTypeDefinition().getType().getPath());
+ for (IBean b: bs) {
+ if(b instanceof AbstractBeanElement) {
+ if(((AbstractBeanElement)b).getDefinition() == genericProducerBean) {
+ return b;
+ }
+ }
+ }
+ return null;
+ }
+
+ protected void computeScope() {
+ if(definition.isAnnotationPresent(CDISeamSolderConstants.APPLY_SCOPE_ANNOTATION_TYPE_NAME))
{
+ IBean generic = getGenericProducerBean();
+ if(generic != null) {
+ scope = generic.getScope();
+ }
+ }
+ if(scope == null) {
+ super.computeScope();
+ }
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/generic/GenericClassBean.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain