[jbosstools-commits] JBoss Tools SVN: r30596 - in trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui: search and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Apr 15 12:50:51 EDT 2011


Author: dazarov
Date: 2011-04-15 12:50:51 -0400 (Fri, 15 Apr 2011)
New Revision: 30596

Added:
   trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/BeanMatch.java
   trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/EventMatch.java
   trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/ObserverMethodMatch.java
Modified:
   trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java
   trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties
   trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointLabelProvider.java
   trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointMatchPresentation.java
   trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointQueryParticipant.java
Log:
https://issues.jboss.org/browse/JBIDE-8704

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java	2011-04-15 16:44:43 UTC (rev 30595)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java	2011-04-15 16:50:51 UTC (rev 30596)
@@ -20,7 +20,10 @@
 		NLS.initializeMessages(BUNDLE_NAME, CDIUIMessages.class);
 	}
 	
-	public static String INJECTION_POINT_LABEL_PROVIDER;
+	public static String INJECTION_POINT_LABEL_PROVIDER_INJECT_BEAN;
+	public static String INJECTION_POINT_LABEL_PROVIDER_OBSERVER_METHOD;
+	public static String INJECTION_POINT_LABEL_PROVIDER_EVENT;
+	
 	public static String CDI_UI_IMAGESBASE_URL_FOR_IMAGE_REGISTRY_CANNOT_BE_NULL;
 	public static String CDI_UI_IMAGESIMAGE_NAME_CANNOT_BE_NULL;
 	

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties	2011-04-15 16:44:43 UTC (rev 30595)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties	2011-04-15 16:50:51 UTC (rev 30596)
@@ -9,7 +9,9 @@
 ###     Red Hat, Inc. - initial API and implementation
 ##################################################################################
 
-INJECTION_POINT_LABEL_PROVIDER=Injected class
+INJECTION_POINT_LABEL_PROVIDER_INJECT_BEAN=@Inject Bean ''{0}''
+INJECTION_POINT_LABEL_PROVIDER_OBSERVER_METHOD=CDI Observer Method ''{0}.{1}()''
+INJECTION_POINT_LABEL_PROVIDER_EVENT=CDI Event ''{0}.{1}''
 CDI_UI_IMAGESBASE_URL_FOR_IMAGE_REGISTRY_CANNOT_BE_NULL=Base url for image registry cannot be null.
 CDI_UI_IMAGESIMAGE_NAME_CANNOT_BE_NULL=Image name cannot be null.
 CDI_REFACTOR_CONTRIBUTOR_MENU_NAME=CDI Refactor

Copied: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/BeanMatch.java (from rev 30578, trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointMatch.java)
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/BeanMatch.java	                        (rev 0)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/BeanMatch.java	2011-04-15 16:50:51 UTC (rev 30596)
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.ui.search;
+
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.search.ui.text.Match;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.ui.CDIUIPlugin;
+
+public class BeanMatch extends Match {
+	private IBean bean;
+	public BeanMatch(IBean bean){
+		super(bean, 0, 0);
+		try{
+			ISourceRange range = bean.getBeanClass().getNameRange();
+			setOffset(range.getOffset());
+			setLength(range.getLength());
+		}catch(JavaModelException ex){
+			CDIUIPlugin.getDefault().logError(ex);
+		}
+		this.bean = bean;
+	}
+	
+	public IBean getBean(){
+		return bean;
+	}
+}


Property changes on: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/BeanMatch.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/EventMatch.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/EventMatch.java	                        (rev 0)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/EventMatch.java	2011-04-15 16:50:51 UTC (rev 30596)
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * 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.ui.search;
+
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.search.ui.text.Match;
+import org.jboss.tools.cdi.core.IInjectionPoint;
+import org.jboss.tools.cdi.core.IInjectionPointField;
+import org.jboss.tools.cdi.core.IInjectionPointMethod;
+import org.jboss.tools.cdi.core.IInjectionPointParameter;
+import org.jboss.tools.cdi.ui.CDIUIPlugin;
+
+public class EventMatch extends Match {
+	private IInjectionPoint event;
+
+	public EventMatch(IInjectionPoint event) {
+		super(event, 0, 0);
+		try{
+			ISourceRange range = null;
+			if(event instanceof IInjectionPointField){
+				range = ((IInjectionPointField)event).getField().getNameRange();
+			}else if(event instanceof IInjectionPointMethod){
+				range = ((IInjectionPointMethod)event).getMethod().getNameRange();
+			}else if(event instanceof IInjectionPointParameter){
+				range = ((IInjectionPointParameter)event).getBeanMethod().getMethod().getNameRange();
+			}
+
+			if(range != null){
+				setOffset(range.getOffset());
+				setLength(range.getLength());
+			}
+		}catch(JavaModelException ex){
+			CDIUIPlugin.getDefault().logError(ex);
+		}
+		this.event = event;
+	}
+
+	public IInjectionPoint getEvent(){
+		return event;
+	}
+}


Property changes on: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/EventMatch.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointLabelProvider.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointLabelProvider.java	2011-04-15 16:44:43 UTC (rev 30595)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointLabelProvider.java	2011-04-15 16:50:51 UTC (rev 30596)
@@ -12,8 +12,13 @@
 
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.graphics.Image;
 import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.IInjectionPointField;
+import org.jboss.tools.cdi.core.IInjectionPointMethod;
+import org.jboss.tools.cdi.core.IInjectionPointParameter;
+import org.jboss.tools.cdi.core.IObserverMethod;
 import org.jboss.tools.cdi.ui.CDIUIMessages;
 import org.jboss.tools.cdi.ui.CDIUiImages;
 
@@ -26,7 +31,15 @@
 
 	public String getText(Object element) {
 		if(element instanceof IBean){
-			return CDIUIMessages.INJECTION_POINT_LABEL_PROVIDER+" "+((IBean)element).getBeanClass().getElementName(); //$NON-NLS-1$
+			return NLS.bind(CDIUIMessages.INJECTION_POINT_LABEL_PROVIDER_INJECT_BEAN, ((IBean)element).getBeanClass().getElementName());
+		}else if(element instanceof IObserverMethod){
+			return NLS.bind(CDIUIMessages.INJECTION_POINT_LABEL_PROVIDER_OBSERVER_METHOD, ((IObserverMethod)element).getMethod().getDeclaringType().getElementName(), ((IObserverMethod)element).getMethod().getElementName());
+		}else if(element instanceof IInjectionPointField){
+			return NLS.bind(CDIUIMessages.INJECTION_POINT_LABEL_PROVIDER_EVENT, ((IInjectionPointField)element).getField().getDeclaringType().getElementName(), ((IInjectionPointField)element).getField().getElementName());
+		}else if(element instanceof IInjectionPointMethod){
+			return NLS.bind(CDIUIMessages.INJECTION_POINT_LABEL_PROVIDER_EVENT, ((IInjectionPointMethod)element).getMethod().getDeclaringType().getElementName(), ((IInjectionPointMethod)element).getMethod().getElementName());
+		}else if(element instanceof IInjectionPointParameter){
+			return NLS.bind(CDIUIMessages.INJECTION_POINT_LABEL_PROVIDER_EVENT, ((IInjectionPointParameter)element).getBeanMethod().getMethod().getDeclaringType().getElementName(), ((IInjectionPointParameter)element).getBeanMethod().getMethod().getElementName());
 		}else
 			return ""; //$NON-NLS-1$
 	}

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointMatchPresentation.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointMatchPresentation.java	2011-04-15 16:44:43 UTC (rev 30595)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointMatchPresentation.java	2011-04-15 16:50:51 UTC (rev 30596)
@@ -16,6 +16,10 @@
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.search.ui.text.Match;
 import org.eclipse.ui.PartInitException;
+import org.jboss.tools.cdi.core.IInjectionPoint;
+import org.jboss.tools.cdi.core.IInjectionPointField;
+import org.jboss.tools.cdi.core.IInjectionPointMethod;
+import org.jboss.tools.cdi.core.IInjectionPointParameter;
 import org.jboss.tools.cdi.ui.CDIUIPlugin;
 
 public class InjectionPointMatchPresentation implements IMatchPresentation {
@@ -27,14 +31,26 @@
 
 	public void showMatch(Match match, int currentOffset, int currentLength,
 			boolean activate) throws PartInitException {
-		if(match instanceof InjectionPointMatch){
-			try{
-				JavaUI.openInEditor(((InjectionPointMatch)match).getBean().getBeanClass());
-			}catch(JavaModelException ex){
-				CDIUIPlugin.getDefault().logError(ex);
-			}catch(PartInitException ex){
-				CDIUIPlugin.getDefault().logError(ex);
+		
+		try{
+			if(match instanceof BeanMatch){
+				JavaUI.openInEditor(((BeanMatch)match).getBean().getBeanClass());
+			}else if(match instanceof ObserverMethodMatch){
+				JavaUI.openInEditor(((ObserverMethodMatch)match).getObserverMethod().getMethod());
+			}else if(match instanceof EventMatch){
+				IInjectionPoint iPoint = ((EventMatch)match).getEvent();
+				if(iPoint instanceof IInjectionPointField){
+					JavaUI.openInEditor(((IInjectionPointField)iPoint).getField());
+				}else if(iPoint instanceof IInjectionPointMethod){
+					JavaUI.openInEditor(((IInjectionPointMethod)iPoint).getMethod());
+				}else if(iPoint instanceof IInjectionPointParameter){
+					JavaUI.openInEditor(((IInjectionPointParameter)iPoint).getBeanMethod().getMethod());
+				}
 			}
+		}catch(JavaModelException ex){
+			CDIUIPlugin.getDefault().logError(ex);
+		}catch(PartInitException ex){
+			CDIUIPlugin.getDefault().logError(ex);
 		}
 	}
 

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-15 16:44:43 UTC (rev 30595)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointQueryParticipant.java	2011-04-15 16:50:51 UTC (rev 30596)
@@ -10,36 +10,37 @@
  ******************************************************************************/
 package org.jboss.tools.cdi.ui.search;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.IAnnotatable;
-import org.eclipse.jdt.core.IAnnotation;
 import org.eclipse.jdt.core.IField;
 import org.eclipse.jdt.core.IJavaElement;
 import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.ISourceRange;
-import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
 import org.eclipse.jdt.core.search.IJavaSearchConstants;
-import org.eclipse.jdt.internal.core.Member;
 import org.eclipse.jdt.ui.search.ElementQuerySpecification;
 import org.eclipse.jdt.ui.search.IMatchPresentation;
 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.CDIConstants;
 import org.jboss.tools.cdi.core.CDICoreNature;
 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.ICDIProject;
+import org.jboss.tools.cdi.core.IClassBean;
 import org.jboss.tools.cdi.core.IInjectionPoint;
+import org.jboss.tools.cdi.core.IObserverMethod;
+import org.jboss.tools.cdi.core.IParameter;
 
 public class InjectionPointQueryParticipant implements IQueryParticipant{
+	ArrayList<Object> objects = new ArrayList<Object>();
 	
 	public int estimateTicks(QuerySpecification specification) {
 		return 10;
@@ -53,6 +54,8 @@
 			QuerySpecification querySpecification, IProgressMonitor monitor)
 			throws CoreException {
 		
+		objects.clear();
+		
 		if(querySpecification instanceof ElementQuerySpecification){
 			if (!isSearchForReferences(querySpecification.getLimitTo()))
 				return;
@@ -76,30 +79,69 @@
 				
 				Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
 				
-				if (element instanceof IAnnotatable) {
-					IAnnotatable annotatable = (IAnnotatable)element;
-					
-					IAnnotation annotation = annotatable.getAnnotation(CDIConstants.INJECT_ANNOTATION_TYPE_NAME);
-					if (annotation == null)
-						return;
-					IInjectionPoint injectionPoint = CDIUtil.findInjectionPoint(beans, element, 0);
-					if(injectionPoint != null){
-						Set<IBean> resultBeanSet = cdiProject.getBeans(false, injectionPoint);
-						List<IBean> resultBeanList = CDIUtil.sortBeans(resultBeanSet);
-						for(IBean bean : resultBeanList){
-							if(bean != null){
-								IType type = bean.getBeanClass();
-								ISourceRange range = ((Member)type).getNameRange();
-								Match match = new InjectionPointMatch(bean, range.getOffset(), range.getLength());
+				IInjectionPoint injectionPoint = CDIUtil.findInjectionPoint(beans, element, 0);
+				if(injectionPoint != null){
+					Set<IBean> resultBeanSet = cdiProject.getBeans(false, injectionPoint);
+					List<IBean> resultBeanList = CDIUtil.sortBeans(resultBeanSet);
+					for(IBean bean : resultBeanList){
+						if(bean != null){
+							if(!objects.contains(bean)){
+								Match match = new BeanMatch(bean);
 								requestor.reportMatch(match);
+								objects.add(bean);
 							}
 						}
 					}
+					Set<IObserverMethod> observerMethods = cdiProject.resolveObserverMethods(injectionPoint);
+					for(IObserverMethod observerMethod : observerMethods){
+						// match observer method
+						if(!objects.contains(observerMethod)){
+							Match match = new ObserverMethodMatch(observerMethod);
+							requestor.reportMatch(match);
+							objects.add(observerMethod);
+						}
+					}
 				}
+				if(element instanceof IMethod){
+					IParameter param = findObserverParameter(beans, (IMethod)element);
+					if(param != null){
+						Set<IInjectionPoint> events = cdiProject.findObservedEvents(param);
+						for(IInjectionPoint event : events){
+							// match event
+							if(!objects.contains(event)){
+								Match match = new EventMatch(event);
+								requestor.reportMatch(match);
+								objects.add(event);
+							}
+						}
+					}
+				}
 			}
 		}
 	}
 	
+	private IParameter findObserverParameter(Set<IBean> beans, IMethod method) throws JavaModelException {
+		for (IBean bean: beans) {
+			if(bean instanceof IClassBean) {
+				Set<IBeanMethod> observers = ((IClassBean)bean).getObserverMethods();
+				for (IBeanMethod bm: observers) {
+					if(bm instanceof IObserverMethod) {
+						if(bm.getMethod().equals(method)){
+							IObserverMethod obs = (IObserverMethod)bm;
+							Set<IParameter> ps = obs.getObservedParameters();
+							if(!ps.isEmpty()) {
+								return ps.iterator().next();
+							}
+						}
+					}
+				}
+			}
+		}
+		
+		return null;
+	}
+
+	
 	public boolean isSearchForReferences(int limitTo) {
     	int maskedLimitTo = limitTo & ~(IJavaSearchConstants.IGNORE_DECLARING_TYPE+IJavaSearchConstants.IGNORE_RETURN_TYPE);
     	if (maskedLimitTo == IJavaSearchConstants.REFERENCES || maskedLimitTo == IJavaSearchConstants.ALL_OCCURRENCES) {

Added: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/ObserverMethodMatch.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/ObserverMethodMatch.java	                        (rev 0)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/ObserverMethodMatch.java	2011-04-15 16:50:51 UTC (rev 30596)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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.ui.search;
+
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.search.ui.text.Match;
+import org.jboss.tools.cdi.core.IObserverMethod;
+import org.jboss.tools.cdi.ui.CDIUIPlugin;
+
+public class ObserverMethodMatch extends Match {
+	private IObserverMethod observerMethod;
+
+	public ObserverMethodMatch(IObserverMethod observerMethod) {
+		super(observerMethod, 0, 0);
+		try{
+			ISourceRange range = observerMethod.getMethod().getNameRange();
+			setOffset(range.getOffset());
+			setLength(range.getLength());
+		}catch(JavaModelException ex){
+			CDIUIPlugin.getDefault().logError(ex);
+		}
+
+		this.observerMethod = observerMethod;
+	}
+
+	public IObserverMethod getObserverMethod(){
+		return observerMethod;
+	}
+}


Property changes on: trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/ObserverMethodMatch.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list