[jbosstools-commits] JBoss Tools SVN: r30649 - in trunk/cdi: tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon Apr 18 16:37:05 EDT 2011


Author: dazarov
Date: 2011-04-18 16:37:04 -0400 (Mon, 18 Apr 2011)
New Revision: 30649

Modified:
   trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIElementWrapper.java
   trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIMatch.java
   trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointQueryParticipant.java
   trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/CDIUIAllTests.java
   trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/search/CDISearchParticipantTest.java
Log:
https://issues.jboss.org/browse/JBIDE-8705, https://issues.jboss.org/browse/JBIDE-8704

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIElementWrapper.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIElementWrapper.java	2011-04-18 20:22:30 UTC (rev 30648)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIElementWrapper.java	2011-04-18 20:37:04 UTC (rev 30649)
@@ -30,6 +30,7 @@
 	private static String BRACKETS = OPEN+CLOSE;
 	private ICDIElement element;
 	private String label;
+	private String path;
 	private IJavaElement javaElement;
 	
 	public CDIElementWrapper(ICDIElement element){
@@ -52,7 +53,7 @@
 			String type = Signature.getSignatureSimpleName(((ILocalVariable)javaElement).getTypeSignature());
 			label = method.getDeclaringType().getElementName()+DOT+method.getElementName()+OPEN+type+SPACE+javaElement.getElementName()+CLOSE;
 		}
-
+		path = javaElement.getResource().getFullPath()+"/"+label;
 	}
 	
 	public ICDIElement getCDIElement(){
@@ -66,4 +67,8 @@
 	public String getLabel(){
 		return label;
 	}
+
+	public String getPath(){
+		return label;
+	}
 }

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIMatch.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIMatch.java	2011-04-18 20:22:30 UTC (rev 30648)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIMatch.java	2011-04-18 20:37:04 UTC (rev 30649)
@@ -23,6 +23,10 @@
 		return ((CDIElementWrapper)getElement()).getLabel();
 	}
 
+	public String getPath(){
+		return ((CDIElementWrapper)getElement()).getPath();
+	}
+
 	public IJavaElement getJavaElement(){
 		return ((CDIElementWrapper)getElement()).getJavaElement();
 	}

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-04-18 20:22:30 UTC (rev 30648)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointQueryParticipant.java	2011-04-18 20:37:04 UTC (rev 30649)
@@ -28,7 +28,6 @@
 import org.eclipse.jdt.ui.search.IQueryParticipant;
 import org.eclipse.jdt.ui.search.ISearchRequestor;
 import org.eclipse.jdt.ui.search.QuerySpecification;
-import org.eclipse.search.ui.text.Match;
 import org.jboss.tools.cdi.core.CDICoreNature;
 import org.jboss.tools.cdi.core.CDICorePlugin;
 import org.jboss.tools.cdi.core.CDIUtil;
@@ -41,7 +40,7 @@
 import org.jboss.tools.cdi.core.IParameter;
 
 public class InjectionPointQueryParticipant implements IQueryParticipant{
-	ArrayList<Object> objects = new ArrayList<Object>();
+	ArrayList<String> objects = new ArrayList<String>();
 	
 	public int estimateTicks(QuerySpecification specification) {
 		return 10;
@@ -86,20 +85,20 @@
 					List<IBean> resultBeanList = CDIUtil.sortBeans(resultBeanSet);
 					for(IBean bean : resultBeanList){
 						if(bean != null){
-							if(!objects.contains(bean)){
-								Match match = new CDIMatch(bean);
+							CDIMatch match = new CDIMatch(bean);
+							if(!objects.contains(match.getPath())){
 								requestor.reportMatch(match);
-								objects.add(bean);
+								objects.add(match.getPath());
 							}
 						}
 					}
 					Set<IObserverMethod> observerMethods = cdiProject.resolveObserverMethods(injectionPoint);
 					for(IObserverMethod observerMethod : observerMethods){
 						// match observer method
-						if(!objects.contains(observerMethod)){
-							Match match = new CDIMatch(observerMethod);
+						CDIMatch match = new CDIMatch(observerMethod);
+						if(!objects.contains(match.getPath())){
 							requestor.reportMatch(match);
-							objects.add(observerMethod);
+							objects.add(match.getPath());
 						}
 					}
 				}
@@ -109,10 +108,10 @@
 						Set<IInjectionPoint> events = cdiProject.findObservedEvents(param);
 						for(IInjectionPoint event : events){
 							// match event
-							if(!objects.contains(event)){
-								Match match = new CDIMatch(event);
+							CDIMatch match = new CDIMatch(event);
+							if(!objects.contains(match.getPath())){
 								requestor.reportMatch(match);
-								objects.add(event);
+								objects.add(match.getPath());
 							}
 						}
 					}

Modified: trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/CDIUIAllTests.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/CDIUIAllTests.java	2011-04-18 20:22:30 UTC (rev 30648)
+++ trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/CDIUIAllTests.java	2011-04-18 20:37:04 UTC (rev 30649)
@@ -17,6 +17,7 @@
 import org.jboss.tools.cdi.ui.test.marker.CDIMarkerResolutionTest;
 import org.jboss.tools.cdi.ui.test.perspective.CDIPerspectiveTest;
 import org.jboss.tools.cdi.ui.test.preferences.CDIPreferencePageTest;
+import org.jboss.tools.cdi.ui.test.search.CDISearchParticipantTest;
 import org.jboss.tools.cdi.ui.test.wizard.NewCDIClassWizardFactoryTest;
 import org.jboss.tools.cdi.ui.test.wizard.NewCDIWizardTest;
 
@@ -36,6 +37,7 @@
 		suite.addTestSuite(CDIPreferencePageTest.class);
 		suite.addTestSuite(NewCDIClassWizardFactoryTest.class);
 		suite.addTestSuite(CDIPerspectiveTest.class);
+		suite.addTestSuite(CDISearchParticipantTest.class);
 
 		return suite;
 	}

Modified: trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/search/CDISearchParticipantTest.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/search/CDISearchParticipantTest.java	2011-04-18 20:22:30 UTC (rev 30648)
+++ trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/search/CDISearchParticipantTest.java	2011-04-18 20:37:04 UTC (rev 30649)
@@ -10,6 +10,7 @@
 import org.eclipse.jdt.core.IJavaElement;
 import org.eclipse.jdt.core.IMethod;
 import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
 import org.eclipse.jdt.core.search.IJavaSearchConstants;
 import org.eclipse.jdt.core.search.IJavaSearchScope;
 import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
@@ -18,9 +19,16 @@
 import org.eclipse.jdt.ui.search.ISearchRequestor;
 import org.eclipse.jdt.ui.search.QuerySpecification;
 import org.eclipse.search.ui.text.Match;
+import org.eclipse.ui.IMarkerResolution;
+import org.jboss.tools.cdi.core.ICDIElement;
 import org.jboss.tools.cdi.core.test.tck.TCKTest;
+import org.jboss.tools.cdi.internal.core.impl.ClassBean;
+import org.jboss.tools.cdi.internal.core.impl.InjectionPointField;
+import org.jboss.tools.cdi.internal.core.impl.InjectionPointParameter;
 import org.jboss.tools.cdi.ui.marker.MarkerResolutionUtils;
+import org.jboss.tools.cdi.ui.search.CDIBeanQueryParticipant;
 import org.jboss.tools.cdi.ui.search.CDIMatch;
+import org.jboss.tools.cdi.ui.search.InjectionPointQueryParticipant;
 import org.jboss.tools.common.EclipseUtil;
 
 public class CDISearchParticipantTest  extends TCKTest {
@@ -29,7 +37,9 @@
 	private static final int TYPE_SEARCH = 3;
 	private static final int PARAMETER_SEARCH = 4;
 	
-	private void testSearchParticipant(IFile file, int searchType, String elementName, String parameterName, IQueryParticipant participant, List<MatchStructure> matches){
+	private void testSearchParticipant(String fileName, int searchType, String elementName, String parameterName, IQueryParticipant participant, List<MatchStructure> matches){
+		IFile file = tckProject.getFile(fileName);
+		assertNotNull("File - "+fileName+" not found", file);
 		try{
 			ICompilationUnit compilationUnit = EclipseUtil.getCompilationUnit(file);
 			IJavaElement element = null;
@@ -39,11 +49,11 @@
 			if(searchType == FIELD_SEARCH){
 				element = type.getField(elementName);
 			}else if(searchType == METHOD_SEARCH){
-				element = type.getMethod(elementName, new String[]{});
+				element = getMethod(type, elementName);
 			}else if(searchType == TYPE_SEARCH){
 				element = type;
 			}else if(searchType == PARAMETER_SEARCH){
-				IMethod method = type.getMethod(elementName, new String[]{});
+				IMethod method = getMethod(type, elementName);
 				element = MarkerResolutionUtils.getParameter(method, parameterName);
 			}
 			
@@ -67,18 +77,25 @@
 		}
 	}
 	
+	private IMethod getMethod(IType type, String name) throws JavaModelException{
+		IMethod[] methods = type.getMethods();
+		for(IMethod method : methods){
+			if(method.getElementName().equals(name))
+				return method;
+		}
+		return null;
+	}
+	
 	private void checkMatches(List<Match> matchesForCheck, List<MatchStructure> matchList) throws CoreException {
-		assertEquals("There is unexpected number of matches",matchList.size(), matchesForCheck.size());
-
 		for(Match match : matchesForCheck){
 			assertTrue("Match must be CDIMatch", match instanceof CDIMatch);
 			MatchStructure ms = findMatch(matchList, (CDIMatch)match);
-			assertNotNull("Match not found", ms);
+			assertNotNull("Unexpected mutch found (class - "+((CDIMatch)match).getCDIElement().getClass()+" label - "+((CDIMatch)match).getLabel()+")", ms);
 			ms.checked = true;
 		}
 		
 		for(MatchStructure ms : matchList){
-			assertTrue("Not all matches found", ms.checked);
+			assertTrue("Match not found (class - "+ms.type+" label - "+ms.name, ms.checked);
 		}
 	}
 	
@@ -104,23 +121,46 @@
 	}
 	
 	class MatchStructure{
-		String type; // CDIElement.getClass()
+		Class<? extends ICDIElement> type;
 		String name; // label
 		boolean checked;
 		
-		public MatchStructure(String type, String name){
+		public MatchStructure(Class<? extends ICDIElement> type, String name){
 			this.type = type;
 			this.name = name;
 			checked = false;
 		}
 	}
 	
-	public void testInjectionPointQueryParticipant(){
+	public void testInjectionPointQueryParticipant1(){
+		ArrayList<MatchStructure> matches = new ArrayList<MatchStructure>();
 		
-		//testSearchParticipant();
+		matches.add(new MatchStructure(ClassBean.class, "BeanWithInjectionPointMetadata"));
+		
+		testSearchParticipant("JavaSource/org/jboss/jsr299/tck/tests/lookup/injectionpoint/FieldInjectionPointBean.java", FIELD_SEARCH, "injectedBean", "", new InjectionPointQueryParticipant(), matches);
 	}
 
+	public void testInjectionPointQueryParticipant2(){
+		ArrayList<MatchStructure> matches = new ArrayList<MatchStructure>();
+		
+		matches.add(new MatchStructure(ClassBean.class, "BeanWithInjectionPointMetadata"));
+		
+		testSearchParticipant("JavaSource/org/jboss/jsr299/tck/tests/lookup/injectionpoint/ConstructorInjectionPointBean.java", PARAMETER_SEARCH, "ConstructorInjectionPointBean", "injectedBean", new InjectionPointQueryParticipant(), matches);
+	}
+
 	public void testCDIBeanQueryParticipant(){
+		ArrayList<MatchStructure> matches = new ArrayList<MatchStructure>();
 		
+		matches.add(new MatchStructure(InjectionPointField.class, "FieldInjectionPointBean.injectedBean"));
+		matches.add(new MatchStructure(InjectionPointField.class, "NamedDecoratorBroken.logger"));
+		matches.add(new MatchStructure(InjectionPointField.class, "NamedStereotypedDecoratorBroken.logger"));
+		matches.add(new MatchStructure(InjectionPointField.class, "TransientFieldInjectionPointBean.injectedBean"));
+		matches.add(new MatchStructure(InjectionPointField.class, "SpecializingDecoratorBroken.logger"));
+		matches.add(new MatchStructure(InjectionPointField.class, "ObserverMethodInDecoratorBroken.logger"));
+		
+		matches.add(new MatchStructure(InjectionPointParameter.class, "ConstructorInjectionPointBean.ConstructorInjectionPointBean(BeanWithInjectionPointMetadata injectedBean)"));
+		matches.add(new MatchStructure(InjectionPointParameter.class, "MethodInjectionPointBean.methodWithInjectedMetadata(BeanWithInjectionPointMetadata injectedBean)"));
+		
+		testSearchParticipant("JavaSource/org/jboss/jsr299/tck/tests/lookup/injectionpoint/BeanWithInjectionPointMetadata.java", TYPE_SEARCH, "BeanWithInjectionPointMetadata", "", new CDIBeanQueryParticipant(), matches);
 	}
 }



More information about the jbosstools-commits mailing list