Author: scabanovich
Date: 2010-09-02 08:22:10 -0400 (Thu, 02 Sep 2010)
New Revision: 24640
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMethod.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/InjectionPointMethod.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/InjectionPointParameter.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ObserverMethod.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/Parameter.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/lib/ClassPathMonitor.java
Log:
https://jira.jboss.org/browse/JBIDE-6977
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java 2010-09-02
12:00:50 UTC (rev 24639)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java 2010-09-02
12:22:10 UTC (rev 24640)
@@ -13,7 +13,9 @@
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
@@ -48,6 +50,10 @@
private boolean isStorageResolved = false;
+ Set<CDICoreNature> dependsOn = new HashSet<CDICoreNature>();
+
+ Set<CDICoreNature> usedBy = new HashSet<CDICoreNature>();
+
public CDICoreNature() {
definitions.setProject(this);
}
@@ -74,6 +80,36 @@
cdiProject.setNature(this);
}
+ public Set<CDICoreNature> getCDIProjects() {
+ return dependsOn;
+ }
+
+ public Set<CDICoreNature> getDependentProjects() {
+ return usedBy;
+ }
+
+ public void addCDIProject(CDICoreNature p) {
+ if(dependsOn.contains(p)) return;
+ dependsOn.add(p);
+ p.addDependentCDIProject(this);
+ //TODO
+ p.resolve();
+ if(p.getDelegate() != null) {
+ p.getDelegate().update();
+ }
+ }
+
+ public void removeCDIProject(CDICoreNature p) {
+ if(!dependsOn.contains(p)) return;
+ p.usedBy.remove(this);
+ dependsOn.remove(p);
+ //TODO
+ }
+
+ public void addDependentCDIProject(CDICoreNature p) {
+ usedBy.add(p);
+ }
+
public DefinitionContext getDefinitions() {
return definitions;
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java 2010-09-02
12:00:50 UTC (rev 24639)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java 2010-09-02
12:22:10 UTC (rev 24640)
@@ -283,7 +283,7 @@
* @return the set of injection points with event type observed by given
* parameter of an observer method
*/
- public Set<IInjectionPoint> findObservedEvents(IInjectionPointParameter
observedEventParameter);
+ public Set<IInjectionPoint> findObservedEvents(IParameter
observedEventParameter);
/**
* Applies the ambiguous dependency resolution rules to a set of beans.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMethod.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMethod.java 2010-09-02
12:00:50 UTC (rev 24639)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMethod.java 2010-09-02
12:22:10 UTC (rev 24640)
@@ -45,14 +45,17 @@
List<ParameterDefinition> ps = definition.getParameters();
for (ParameterDefinition p: ps) {
- Parameter parameter = newParameter();
+// if(p.isAnnotationPresent(CDIConstants.OBSERVERS_ANNOTATION_TYPE_NAME)) {
+// continue;
+// }
+ Parameter parameter = newParameter(p);
parameter.setBeanMethod(this);
parameter.setDefinition(p);
parameters.add(parameter);
}
}
- protected Parameter newParameter() {
+ protected Parameter newParameter(ParameterDefinition p) {
return ((MethodDefinition)definition).parametersAreInjectionPoints() ? new
InjectionPointParameter() : new Parameter();
}
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 2010-09-02
12:00:50 UTC (rev 24639)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2010-09-02
12:22:10 UTC (rev 24640)
@@ -745,7 +745,7 @@
if(!((ParametedType)eventType).isAssignableTo((ParametedType)paramType, true)) {
continue;
}
- if(areMatchingEventQualifiers((InjectionPointParameter)param, injectionPoint)) {
+ if(areMatchingEventQualifiers(param, injectionPoint)) {
result.add(om);
}
}
@@ -770,8 +770,8 @@
return ps.isEmpty() ? null : ps.get(0);
}
- private boolean areMatchingEventQualifiers(IInjectionPointParameter observerParam,
IInjectionPoint event) {
- Set<IQualifier> qs = ((InjectionPointParameter)observerParam).getQualifiers();
+ private boolean areMatchingEventQualifiers(IParameter observerParam, IInjectionPoint
event) {
+ Set<IQualifier> qs = ((Parameter)observerParam).getQualifiers();
List<IType> paramQualifiers = new ArrayList<IType>();
for (IQualifier q: qs) {
if(q.getSourceType() != null) paramQualifiers.add(q.getSourceType());
@@ -786,7 +786,7 @@
return false;
}
- public Set<IInjectionPoint> findObservedEvents(IInjectionPointParameter
observedEventParameter) {
+ public Set<IInjectionPoint> findObservedEvents(IParameter observedEventParameter)
{
Set<IInjectionPoint> result = new HashSet<IInjectionPoint>();
if(observedEventParameter.getBeanMethod() instanceof IObserverMethod) {
@@ -948,6 +948,11 @@
rebuildXML();
rebuildAnnotationTypes();
rebuildBeans();
+
+ CDICoreNature[] ps = n.getDependentProjects().toArray(new CDICoreNature[0]);
+ for (CDICoreNature p: ps) {
+ p.getDelegate().update();
+ }
}
void rebuildAnnotationTypes() {
@@ -959,7 +964,7 @@
interceptorBindingsByPath.clear();
scopes.clear();
scopesByPath.clear();
- List<AnnotationDefinition> ds = n.getDefinitions().getAllAnnotations();
+ List<AnnotationDefinition> ds = getAllAnnotations();
for (AnnotationDefinition d: ds) {
if((d.getKind() & AnnotationDefinition.STEREOTYPE) > 0) {
StereotypeElement s = new StereotypeElement();
@@ -1005,8 +1010,60 @@
}
}
+ List<AnnotationDefinition> getAllAnnotations() {
+ Set<CDICoreNature> ps = n.getCDIProjects();
+ if(ps == null || ps.isEmpty()) {
+ return n.getDefinitions().getAllAnnotations();
+ }
+ List<AnnotationDefinition> ds = n.getDefinitions().getAllAnnotations();
+ List<AnnotationDefinition> result = new ArrayList<AnnotationDefinition>();
+ result.addAll(ds);
+ Set<IType> types = new HashSet<IType>();
+ for (AnnotationDefinition d: ds) {
+ IType t = d.getType();
+ if(t != null) types.add(t);
+ }
+ for (CDICoreNature p: ps) {
+ List<AnnotationDefinition> ds2 = p.getDefinitions().getAllAnnotations();
+ for (AnnotationDefinition d: ds2) {
+ IType t = d.getType();
+ if(t != null && !types.contains(t)) {
+ types.add(t);
+ result.add(d);
+ }
+ }
+ }
+ return result;
+ }
+
+ List<TypeDefinition> getAllTypeDefinitions() {
+ Set<CDICoreNature> ps = n.getCDIProjects();
+ if(ps == null || ps.isEmpty()) {
+ return n.getDefinitions().getTypeDefinitions();
+ }
+ List<TypeDefinition> ds = n.getDefinitions().getTypeDefinitions();
+ List<TypeDefinition> result = new ArrayList<TypeDefinition>();
+ result.addAll(ds);
+ Set<IType> types = new HashSet<IType>();
+ for (TypeDefinition d: ds) {
+ IType t = d.getType();
+ if(t != null) types.add(t);
+ }
+ for (CDICoreNature p: ps) {
+ List<TypeDefinition> ds2 = p.getDefinitions().getTypeDefinitions();
+ for (TypeDefinition d: ds2) {
+ IType t = d.getType();
+ if(t != null && !types.contains(t)) {
+ types.add(t);
+ result.add(d);
+ }
+ }
+ }
+ return result;
+ }
+
void rebuildBeans() {
- List<TypeDefinition> typeDefinitions = n.getDefinitions().getTypeDefinitions();
+ List<TypeDefinition> typeDefinitions = getAllTypeDefinitions();
List<IBean> beans = new ArrayList<IBean>();
Map<IType, ClassBean> newClassBeans = new HashMap<IType, ClassBean>();
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/InjectionPointMethod.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/InjectionPointMethod.java 2010-09-02
12:00:50 UTC (rev 24639)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/InjectionPointMethod.java 2010-09-02
12:22:10 UTC (rev 24640)
@@ -13,6 +13,7 @@
import org.jboss.tools.cdi.core.CDIUtil;
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
import org.jboss.tools.cdi.core.IInjectionPointMethod;
+import org.jboss.tools.cdi.internal.core.impl.definition.ParameterDefinition;
/**
*
@@ -31,7 +32,7 @@
}
@Override
- protected Parameter newParameter() {
+ protected Parameter newParameter(ParameterDefinition p) {
return new InjectionPointParameter();
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/InjectionPointParameter.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/InjectionPointParameter.java 2010-09-02
12:00:50 UTC (rev 24639)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/InjectionPointParameter.java 2010-09-02
12:22:10 UTC (rev 24640)
@@ -47,16 +47,6 @@
return result;
}
- public Set<IQualifier> getQualifiers() {
- Set<IQualifier> result = new HashSet<IQualifier>();
- Set<String> as = getAnnotationTypes();
- for (String s: as) {
- IQualifier q = getCDIProject().getQualifier(s);
- if (q != null) result.add(q);
- }
- return result;
- }
-
/*
* (non-Javadoc)
* @see org.jboss.tools.cdi.core.IInjectionPoint#isDelegate()
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ObserverMethod.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ObserverMethod.java 2010-09-02
12:00:50 UTC (rev 24639)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ObserverMethod.java 2010-09-02
12:22:10 UTC (rev 24640)
@@ -6,11 +6,15 @@
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.IObserverMethod;
import org.jboss.tools.cdi.core.IParameter;
+import org.jboss.tools.cdi.internal.core.impl.definition.ParameterDefinition;
public class ObserverMethod extends BeanMethod implements IObserverMethod {
@Override
- protected Parameter newParameter() {
+ protected Parameter newParameter(ParameterDefinition p) {
+ if(p.isAnnotationPresent(CDIConstants.OBSERVERS_ANNOTATION_TYPE_NAME)) {
+ return new Parameter();
+ }
return new InjectionPointParameter();
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/Parameter.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/Parameter.java 2010-09-02
12:00:50 UTC (rev 24639)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/Parameter.java 2010-09-02
12:22:10 UTC (rev 24640)
@@ -1,5 +1,6 @@
package org.jboss.tools.cdi.internal.core.impl;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -9,6 +10,7 @@
import org.jboss.tools.cdi.core.IClassBean;
import org.jboss.tools.cdi.core.IParametedType;
import org.jboss.tools.cdi.core.IParameter;
+import org.jboss.tools.cdi.core.IQualifier;
import org.jboss.tools.cdi.internal.core.impl.definition.ParameterDefinition;
import org.jboss.tools.common.text.ITextSourceReference;
@@ -101,4 +103,15 @@
public IBeanMethod getBeanMethod() {
return beanMethod;
}
+
+ public Set<IQualifier> getQualifiers() {
+ Set<IQualifier> result = new HashSet<IQualifier>();
+ Set<String> as = getAnnotationTypes();
+ for (String s: as) {
+ IQualifier q = getCDIProject().getQualifier(s);
+ if (q != null) result.add(q);
+ }
+ return result;
+ }
+
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java 2010-09-02
12:00:50 UTC (rev 24639)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java 2010-09-02
12:22:10 UTC (rev 24640)
@@ -30,6 +30,7 @@
import org.jboss.tools.cdi.core.IStereotypeDeclaration;
import org.jboss.tools.cdi.core.ITypeDeclaration;
import org.jboss.tools.cdi.internal.core.impl.definition.MethodDefinition;
+import org.jboss.tools.cdi.internal.core.impl.definition.ParameterDefinition;
import org.jboss.tools.common.model.project.ext.impl.ValueInfo;
import org.jboss.tools.common.text.ITextSourceReference;
@@ -53,7 +54,7 @@
}
@Override
- protected Parameter newParameter() {
+ protected Parameter newParameter(ParameterDefinition p) {
return new InjectionPointParameter();
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java 2010-09-02
12:00:50 UTC (rev 24639)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java 2010-09-02
12:22:10 UTC (rev 24640)
@@ -86,6 +86,9 @@
int paramEnd = content.lastIndexOf(')', declEnd);
if(paramEnd < 0) return;
String paramsString = content.substring(paramStart + 1, paramEnd);
+ if(!parametersAreInjectionPoints && paramsString.indexOf("@Observes")
>= 0) {
+ parametersAreInjectionPoints = true;
+ }
if(!parametersAreInjectionPoints && paramsString.indexOf('@') < 0)
return;
String[] params = getParams(paramsString);
String[] ps = method.getParameterTypes();
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/lib/ClassPathMonitor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/lib/ClassPathMonitor.java 2010-09-02
12:00:50 UTC (rev 24639)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/lib/ClassPathMonitor.java 2010-09-02
12:22:10 UTC (rev 24640)
@@ -20,15 +20,18 @@
import java.util.Set;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
import org.jboss.tools.cdi.core.CDICoreNature;
+import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.project.ext.AbstractClassPathMonitor;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
-import org.jboss.tools.jst.web.kb.internal.scanner.LibraryScanner;
-import org.jboss.tools.jst.web.kb.internal.scanner.LoadedDeclarations;
-import org.jboss.tools.jst.web.kb.internal.scanner.ScannerException;
public class ClassPathMonitor extends AbstractClassPathMonitor<CDICoreNature>{
IPath[] srcs = new IPath[0];
@@ -41,10 +44,6 @@
model = EclipseResourceUtil.createObjectForResource(getProjectResource()).getModel();
}
- public void validateProjectDependencies() {
- //TODO
- }
-
public Map<String, XModelObject> process() {
Map<String, XModelObject> newJars = new HashMap<String, XModelObject>();
Iterator<String> it = processedPaths.iterator();
@@ -69,15 +68,10 @@
newJars.put(p, b);
}
+ validateProjectDependencies();
return newJars;
-// validateProjectDependencies();
}
- public boolean hasToUpdateProjectDependencies() {
- //TODO
- return false;
- }
-
public IProject getProjectResource() {
return project.getProject();
}
@@ -95,4 +89,66 @@
srcs = newSrcs;
}
+ public void validateProjectDependencies() {
+ List<CDICoreNature> ps = null;
+
+ try {
+ ps = getProjects(project.getProject());
+ } catch (CoreException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ if(ps != null) {
+ Set<CDICoreNature> set = project.getCDIProjects();
+ Set<CDICoreNature> removable = new HashSet<CDICoreNature>();
+ removable.addAll(set);
+ removable.removeAll(ps);
+ ps.removeAll(set);
+ for (CDICoreNature p : ps) {
+ project.addCDIProject(p);
+ }
+ for (CDICoreNature p : removable) {
+ project.removeCDIProject(p);
+ }
+ }
+ }
+
+ public boolean hasToUpdateProjectDependencies() {
+ List<CDICoreNature> ps = null;
+
+ try {
+ ps = getProjects(project.getProject());
+ } catch (CoreException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ if(ps != null) {
+ Set<CDICoreNature> set = project.getCDIProjects();
+ Set<CDICoreNature> removable = new HashSet<CDICoreNature>();
+ removable.addAll(set);
+ removable.removeAll(ps);
+ ps.removeAll(set);
+ for (CDICoreNature p : ps) {
+ return true;
+ }
+ for (CDICoreNature p : removable) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ List<CDICoreNature> getProjects(IProject project) throws CoreException {
+ List<CDICoreNature> list = new ArrayList<CDICoreNature>();
+ IJavaProject javaProject = JavaCore.create(project);
+ IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
+ for (int i = 0; i < es.length; i++) {
+ if(es[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
+ IProject p =
ResourcesPlugin.getWorkspace().getRoot().getProject(es[i].getPath().lastSegment());
+ if(p == null || !p.isAccessible()) continue;
+ CDICoreNature sp = CDICorePlugin.getCDI(p, false);
+ if(sp != null) list.add(sp);
+ }
+ }
+ return list;
+ }
+
}