[jbosstools-commits] JBoss Tools SVN: r35556 - trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Tue Oct 11 16:22:21 EDT 2011


Author: dazarov
Date: 2011-10-11 16:22:21 -0400 (Tue, 11 Oct 2011)
New Revision: 35556

Modified:
   trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIBeanQueryParticipant.java
   trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointQueryParticipant.java
Log:
Updated CDI Query Participants in order to search in related projects and check search scope https://issues.jboss.org/browse/JBIDE-9801

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIBeanQueryParticipant.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIBeanQueryParticipant.java	2011-10-11 20:20:56 UTC (rev 35555)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIBeanQueryParticipant.java	2011-10-11 20:22:21 UTC (rev 35556)
@@ -27,19 +27,16 @@
 import org.eclipse.jdt.ui.search.QuerySpecification;
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.osgi.util.NLS;
 import org.eclipse.search.ui.text.Match;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.ui.PartInitException;
+import org.jboss.tools.cdi.core.CDICoreNature;
 import org.jboss.tools.cdi.core.CDICorePlugin;
 import org.jboss.tools.cdi.core.CDIImages;
 import org.jboss.tools.cdi.core.IBean;
 import org.jboss.tools.cdi.core.ICDIElement;
 import org.jboss.tools.cdi.core.ICDIProject;
-import org.jboss.tools.cdi.core.IInitializerMethod;
 import org.jboss.tools.cdi.core.IInjectionPoint;
-import org.jboss.tools.cdi.core.IInjectionPointField;
-import org.jboss.tools.cdi.core.IInjectionPointParameter;
 import org.jboss.tools.cdi.core.util.BeanPresentationUtil;
 import org.jboss.tools.cdi.ui.CDIUIMessages;
 import org.jboss.tools.cdi.ui.CDIUIPlugin;
@@ -60,38 +57,57 @@
 			ElementQuerySpecification qs = (ElementQuerySpecification)querySpecification;
 			IJavaElement element = qs.getElement();
 			IProject project = element.getJavaProject().getProject();
+			
 			ICDIProject cdiProject = CDICorePlugin.getCDIProject(project, true);
+			
+			
+			
 			if(cdiProject == null) {
 				return;
 			}
-			Set<IBean> sourceBeans = cdiProject.getBeans(element);
 			
-			Set<IInjectionPoint> injectionPoints = new HashSet<IInjectionPoint>();
-			for (IBean b: sourceBeans) {
-				Set<IParametedType> ts = b.getLegalTypes();
-				for (IParametedType t: ts) {
-					injectionPoints.addAll(cdiProject.getInjections(t.getType().getFullyQualifiedName()));
+			searchInProject(requestor, querySpecification, cdiProject, monitor, element);
+			
+			CDICoreNature[] natures = cdiProject.getNature().getAllDependentProjects();
+			for(CDICoreNature nature : natures){
+				ICDIProject p = nature.getDelegate();
+				if(p != null){
+					searchInProject(requestor, querySpecification, p, monitor, element);
 				}
 			}
 			
-			monitor.beginTask(CDIUIMessages.CDI_BEAN_QUERY_PARTICIPANT_TASK, injectionPoints.size());
+		}
+	}
+	
+	private void searchInProject(ISearchRequestor requestor, QuerySpecification querySpecification, ICDIProject cdiProject, IProgressMonitor monitor, IJavaElement element){
+		Set<IBean> sourceBeans = cdiProject.getBeans(element);
+		
+		Set<IInjectionPoint> injectionPoints = new HashSet<IInjectionPoint>();
+		for (IBean b: sourceBeans) {
+			Set<IParametedType> ts = b.getLegalTypes();
+			for (IParametedType t: ts) {
+				injectionPoints.addAll(cdiProject.getInjections(t.getType().getFullyQualifiedName()));
+			}
+		}
+		
+		monitor.beginTask(CDIUIMessages.CDI_BEAN_QUERY_PARTICIPANT_TASK, injectionPoints.size());
+			
+		for(IInjectionPoint injectionPoint : injectionPoints){
+			if(monitor.isCanceled())
+				break;
+			Set<IBean> resultBeans = cdiProject.getBeans(false, injectionPoint);
+			monitor.worked(1);
 				
-			for(IInjectionPoint injectionPoint : injectionPoints){
-				if(monitor.isCanceled())
+			for(IBean cBean : resultBeans){
+				if(sourceBeans.contains(cBean) && InjectionPointQueryParticipant.containsInSearchScope(querySpecification, cBean)){
+					Match match = new CDIMatch(injectionPoint);
+					requestor.reportMatch(match);
 					break;
-				Set<IBean> resultBeans = cdiProject.getBeans(false, injectionPoint);
-				monitor.worked(1);
-					
-				for(IBean cBean : resultBeans){
-					if(sourceBeans.contains(cBean)){
-						Match match = new CDIMatch(injectionPoint);
-						requestor.reportMatch(match);
-						break;
-					}
 				}
 			}
-			monitor.done();
 		}
+		monitor.done();
+		
 	}
 	
 	public boolean isSearchForReferences(int limitTo) {

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointQueryParticipant.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointQueryParticipant.java	2011-10-11 20:20:56 UTC (rev 35555)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointQueryParticipant.java	2011-10-11 20:22:21 UTC (rev 35556)
@@ -15,7 +15,9 @@
 import java.util.Set;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jdt.core.IField;
 import org.eclipse.jdt.core.IJavaElement;
@@ -23,6 +25,7 @@
 import org.eclipse.jdt.core.IMethod;
 import org.eclipse.jdt.core.JavaModelException;
 import org.eclipse.jdt.core.search.IJavaSearchConstants;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
 import org.eclipse.jdt.ui.search.ElementQuerySpecification;
 import org.eclipse.jdt.ui.search.IMatchPresentation;
 import org.eclipse.jdt.ui.search.IQueryParticipant;
@@ -32,7 +35,7 @@
 import org.jboss.tools.cdi.core.CDICorePlugin;
 import org.jboss.tools.cdi.core.CDIUtil;
 import org.jboss.tools.cdi.core.IBean;
-import org.jboss.tools.cdi.core.IBeanMethod;
+import org.jboss.tools.cdi.core.ICDIElement;
 import org.jboss.tools.cdi.core.ICDIProject;
 import org.jboss.tools.cdi.core.IClassBean;
 import org.jboss.tools.cdi.core.IInjectionPoint;
@@ -49,11 +52,26 @@
 	public IMatchPresentation getUIParticipant() {
 		return new InjectionPointMatchPresentation();
 	}
+	
+	private static boolean containsInSearchScope(QuerySpecification querySpecification, IPath projectPath){
+		IJavaSearchScope searchScope = querySpecification.getScope();
+		if(searchScope == null)
+			return true;
+		IPath[] paths = searchScope.enclosingProjectsAndJars();
+		for(IPath path : paths){
+			if(path.equals(projectPath))
+				return true;
+		}
+		return false;
+	}
+	
+	public static boolean containsInSearchScope(QuerySpecification querySpecification, ICDIElement element){
+		return containsInSearchScope(querySpecification, element.getResource().getProject().getFullPath());
+	}
 
 	public void search(ISearchRequestor requestor,
 			QuerySpecification querySpecification, IProgressMonitor monitor)
 			throws CoreException {
-		
 		objects.clear();
 		
 		if(querySpecification instanceof ElementQuerySpecification){
@@ -84,7 +102,7 @@
 					Set<IBean> resultBeanSet = cdiProject.getBeans(false, injectionPoint);
 					List<IBean> resultBeanList = CDIUtil.sortBeans(resultBeanSet);
 					for(IBean bean : resultBeanList){
-						if(bean != null){
+						if(bean != null && containsInSearchScope(querySpecification, bean)){
 							CDIMatch match = new CDIMatch(bean);
 							if(!objects.contains(match.getPath())){
 								requestor.reportMatch(match);
@@ -94,11 +112,13 @@
 					}
 					Set<IObserverMethod> observerMethods = cdiProject.resolveObserverMethods(injectionPoint);
 					for(IObserverMethod observerMethod : observerMethods){
-						// match observer method
-						CDIMatch match = new CDIMatch(observerMethod);
-						if(!objects.contains(match.getPath())){
-							requestor.reportMatch(match);
-							objects.add(match.getPath());
+						if(containsInSearchScope(querySpecification, observerMethod)){
+							// match observer method
+							CDIMatch match = new CDIMatch(observerMethod);
+							if(!objects.contains(match.getPath())){
+								requestor.reportMatch(match);
+								objects.add(match.getPath());
+							}
 						}
 					}
 				}
@@ -107,11 +127,13 @@
 					if(param != null){
 						Set<IInjectionPoint> events = cdiProject.findObservedEvents(param);
 						for(IInjectionPoint event : events){
-							// match event
-							CDIMatch match = new CDIMatch(event);
-							if(!objects.contains(match.getPath())){
-								requestor.reportMatch(match);
-								objects.add(match.getPath());
+							if(containsInSearchScope(querySpecification, event)){
+								// match event
+								CDIMatch match = new CDIMatch(event);
+								if(!objects.contains(match.getPath())){
+									requestor.reportMatch(match);
+									objects.add(match.getPath());
+								}
 							}
 						}
 					}



More information about the jbosstools-commits mailing list