[jbosstools-commits] JBoss Tools SVN: r30403 - in trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi: core/extension/feature and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Apr 6 19:38:44 EDT 2011


Author: scabanovich
Date: 2011-04-06 19:38:44 -0400 (Wed, 06 Apr 2011)
New Revision: 30403

Modified:
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreBuilder.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IClassBean.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/feature/IBuildParticipantFeature.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java
Log:
JBIDE-3120
https://issues.jboss.org/browse/JBIDE-3120

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreBuilder.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreBuilder.java	2011-04-06 23:03:01 UTC (rev 30402)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreBuilder.java	2011-04-06 23:38:44 UTC (rev 30403)
@@ -166,8 +166,10 @@
 
 			//4. Create working copy of context.
 			n.getDefinitions().newWorkingCopy(kind == FULL_BUILD);
+		
+			for (IBuildParticipantFeature p: buildParticipants) p.beginVisiting();
 
-			//5. Build bean definitions.
+			//5. Discover sources and build definitions.
 			if(isClassPathUpdated) {
 				buildJars(newJars);
 				
@@ -188,6 +190,7 @@
 					incrementalBuild(delta, monitor);
 				}
 			}
+			for (IBuildParticipantFeature p: buildParticipants) p.buildDefinitions();
 
 			// 6. Save created definitions to project context and build beans.
 			getCDICoreNature().getDefinitions().applyWorkingCopy();
@@ -267,6 +270,8 @@
 			}
 			XModelObject beansXML = newJars.get(jar);
 			fileSet.setBeanXML(path, beansXML);
+			
+			for (IBuildParticipantFeature p: buildParticipants) p.visitJar(path, root, beansXML);
 		}
 		addBasicTypes(fileSet);
 		builderDelegate.build(fileSet, getCDICoreNature());
@@ -397,11 +402,15 @@
 							&& "META-INF".equals(path.segments()[path.segmentCount() - 2])) {
 							addBeansXML(f, fileSet);
 						}
+						for (IBuildParticipantFeature p: buildParticipants) p.visit(f, srcs[i], null);
 						return false;
 					}
 				}
-				if(webinf != null && webinf.isPrefixOf(path) && webinf.segmentCount() == path.segmentCount() - 1) {
-					addBeansXML(f, fileSet);
+				if(webinf != null && webinf.isPrefixOf(path)) {
+					if(webinf.segmentCount() == path.segmentCount() - 1) {
+						addBeansXML(f, fileSet);
+					}
+					for (IBuildParticipantFeature p: buildParticipants) p.visit(f, null, webinf);
 				}
 			}
 			

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IClassBean.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IClassBean.java	2011-04-06 23:03:01 UTC (rev 30402)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IClassBean.java	2011-04-06 23:38:44 UTC (rev 30403)
@@ -60,4 +60,11 @@
 	 * @return all the directly derived classes that declare annotation @Specializes
 	 */
 	Set<? extends IClassBean> getSpecializingBeans();
+
+	IParametedType getSuperType();
+
+	IClassBean getSuperClassBean();
+
+	void setSuperClassBean(IClassBean bean);
+
 }
\ No newline at end of file

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/feature/IBuildParticipantFeature.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/feature/IBuildParticipantFeature.java	2011-04-06 23:03:01 UTC (rev 30402)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/extension/feature/IBuildParticipantFeature.java	2011-04-06 23:38:44 UTC (rev 30403)
@@ -10,13 +10,21 @@
  ******************************************************************************/
 package org.jboss.tools.cdi.core.extension.feature;
 
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
 import org.jboss.tools.cdi.core.CDICoreNature;
 import org.jboss.tools.cdi.core.extension.IDefinitionContextExtension;
+import org.jboss.tools.common.model.XModelObject;
 
 /**
  * This feature includes BeforeBeanDiscovery event of CDI runtime, but also it should provide
  * facilities for incremental build and clean of project at design time. 
  * 
+ * Method buildBeans() corresponds to AfterBeanDiscovery event of CDI runtime. 
+ * It is added here because it seams obvious that extensions which participate
+ * in bean discovering would apply result to build CDI artifacts.
+ * 
  * @author Viacheslav Kabanovich
  *
  */
@@ -35,4 +43,39 @@
 	 */
 	public IDefinitionContextExtension getContext();
 
+	/**
+	 * Prepares storage of bean sources.
+	 */
+	public void beginVisiting();
+
+	/**
+	 * Looks for jar entries that are bean sources.
+	 * 
+	 * @param path
+	 * @param beansXML
+	 */
+	public void visitJar(IPath path, IPackageFragmentRoot root, XModelObject beansXML);
+
+	/**
+	 * Adds file to discovered bean sources if relevant.
+	 * 
+	 * @param file
+	 * @param src parent Java source folder path or null
+	 * @param webinf parent WEB-INF folder path or null
+	 */
+	public void visit(IFile file, IPath src, IPath webinf);
+
+	/**
+	 * Builds specific models for discovered bean sources.
+	 * This method is the final stage of BeforeBeanDiscovery event.
+	 */
+	public void buildDefinitions();
+
+	/**
+	 * Builds CDI artifacts by definitions and already existing CDI model.
+	 * 
+	 * This method corresponds to AfterBeanDiscovery event.
+	 */
+	public void buildBeans();
+
 }

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java	2011-04-06 23:03:01 UTC (rev 30402)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java	2011-04-06 23:38:44 UTC (rev 30403)
@@ -56,6 +56,7 @@
 import org.jboss.tools.cdi.core.IQualifierDeclaration;
 import org.jboss.tools.cdi.core.IScope;
 import org.jboss.tools.cdi.core.IStereotype;
+import org.jboss.tools.cdi.core.extension.feature.IBuildParticipantFeature;
 import org.jboss.tools.cdi.internal.core.impl.definition.AnnotationDefinition;
 import org.jboss.tools.cdi.internal.core.impl.definition.BeansXMLDefinition;
 import org.jboss.tools.cdi.internal.core.impl.definition.DefinitionContext;
@@ -88,7 +89,7 @@
 	private Map<IPath, Set<IBean>> beansByPath = new HashMap<IPath, Set<IBean>>();
 	private Map<String, Set<IBean>> beansByName = new HashMap<String, Set<IBean>>();
 	private Set<IBean> namedBeans = new HashSet<IBean>();
-	private Map<IType, ClassBean> classBeans = new HashMap<IType, ClassBean>();
+	private Map<IType, IClassBean> classBeans = new HashMap<IType, IClassBean>();
 	private Set<IBean> alternatives = new HashSet<IBean>();
 	private Set<IDecorator> decorators = new HashSet<IDecorator>();
 	private Set<IInterceptor> interceptors = new HashSet<IInterceptor>();
@@ -1014,6 +1015,9 @@
 		rebuildXML();
 		rebuildAnnotationTypes();
 		rebuildBeans();
+
+		Set<IBuildParticipantFeature> buildParticipants = n.getExtensionManager().getBuildParticipantFeature();
+		for (IBuildParticipantFeature p: buildParticipants) p.buildBeans();
 		
 		CDICoreNature[] ps = n.getDependentProjects().toArray(new CDICoreNature[0]);
 		for (CDICoreNature p: ps) {
@@ -1081,7 +1085,7 @@
 	void rebuildBeans() {
 		List<TypeDefinition> typeDefinitions = n.getAllTypeDefinitions();
 		List<IBean> beans = new ArrayList<IBean>();
-		Map<IType, ClassBean> newClassBeans = new HashMap<IType, ClassBean>();
+		Map<IType, IClassBean> newClassBeans = new HashMap<IType, IClassBean>();
 	
 		ImplementationCollector ic = new ImplementationCollector(typeDefinitions);
 
@@ -1113,16 +1117,13 @@
 			}
 		}
 	
-		for (ClassBean bean: newClassBeans.values()) {
-			ParametedType s = bean.getDefinition().getSuperType();
+		for (IClassBean bean: newClassBeans.values()) {
+			IParametedType s = bean.getSuperType();
 			if(s != null && s.getType() != null) {
-				ClassBean superClassBean = newClassBeans.get(s.getType());
-				if(superClassBean != null) {
-					bean.setSuperClassBean(superClassBean);
-				}
+				IClassBean superClassBean = newClassBeans.get(s.getType());
+				bean.setSuperClassBean(superClassBean);
 			}
-		}
-	
+		}	
 
 		synchronized (beansByPath) {
 			beansByPath.clear();
@@ -1161,7 +1162,7 @@
 //		System.out.println("Bean paths=" + beansByPath.size());
 	}
 
-	void addBean(IBean bean) {
+	public void addBean(IBean bean) {
 		String name = bean.getName();
 		if(name != null && name.length() > 0) {
 			Set<IBean> bs = beansByName.get(name);
@@ -1204,6 +1205,13 @@
 				interceptors.add((IInterceptor)bean);
 			}
 		}
+		if(bean instanceof IClassBean) {
+			IClassBean c = (IClassBean)bean;
+			IType t = c.getBeanClass();
+			if(t != null && !classBeans.containsKey(t)) {
+				classBeans.put(t, c);
+			}
+		}
 		synchronized (allBeans) {
 			allBeans.add(bean);
 		}

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java	2011-04-06 23:03:01 UTC (rev 30402)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java	2011-04-06 23:38:44 UTC (rev 30403)
@@ -10,8 +10,6 @@
  ******************************************************************************/ 
 package org.jboss.tools.cdi.internal.core.impl;
 
-
-
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -44,7 +42,6 @@
 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.common.model.project.ext.impl.ValueInfo;
 import org.jboss.tools.common.text.ITextSourceReference;
 
 /**
@@ -123,10 +120,12 @@
 		return result;
 	}
 
-	public void setSuperClassBean(ClassBean bean) {
-		HashSet<ClassBean> beans = new HashSet<ClassBean>();
+	public void setSuperClassBean(IClassBean bean) {
+		if(!(bean instanceof ClassBean)) return;
+		
+		HashSet<IClassBean> beans = new HashSet<IClassBean>();
 		beans.add(this);
-		ClassBean b = bean;
+		IClassBean b = bean;
 		while(b != null) {
 			if(beans.contains(b)) {
 				bean = null;
@@ -135,13 +134,13 @@
 			b = b.getSuperClassBean();
 		}		
 		
-		superClassBean = bean;
+		superClassBean = (ClassBean)bean;
 		if(superClassBean != null && isSpecializing()) {
 			superClassBean.addSpecializingClassBean(this);
 		}
-		if(bean != null) {
+		if(superClassBean != null) {
 			Map<String, ProducerMethod> thisProducers = getProducerMethodsForSignatures();
-			Map<String, ProducerMethod> superProducers = bean.getProducerMethodsForSignatures();
+			Map<String, ProducerMethod> superProducers = superClassBean.getProducerMethodsForSignatures();
 			for (String s: thisProducers.keySet()) {
 				ProducerMethod thisProducer = thisProducers.get(s);
 				ProducerMethod superProducer = superProducers.get(s);
@@ -531,4 +530,9 @@
 	public String getSimpleJavaName() {
 		return this.getBeanClass().getElementName();
 	}
+
+	public ParametedType getSuperType() {
+		return getDefinition().getSuperType();
+	}
+
 }
\ No newline at end of file



More information about the jbosstools-commits mailing list