[jbosstools-commits] JBoss Tools SVN: r22276 - in trunk/cdi/plugins: org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon May 24 08:14:52 EDT 2010


Author: dazarov
Date: 2010-05-24 08:14:51 -0400 (Mon, 24 May 2010)
New Revision: 22276

Modified:
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java
   trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointHyperlinkDetector.java
Log:
https://jira.jboss.org/browse/JBIDE-6311

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java	2010-05-24 11:33:28 UTC (rev 22275)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java	2010-05-24 12:14:51 UTC (rev 22276)
@@ -23,6 +23,7 @@
 import org.eclipse.jdt.core.IAnnotation;
 import org.eclipse.jdt.core.IField;
 import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.ILocalVariable;
 import org.eclipse.jdt.core.IMethod;
 import org.eclipse.jdt.core.IType;
 import org.eclipse.jdt.core.JavaModelException;
@@ -75,7 +76,7 @@
 	 * @param element
 	 */
 	public static IInjectionPoint findInjectionPoint(Set<IBean> beans, IJavaElement element) {
-		if (!(element instanceof IField) && (element instanceof IMethod)) {
+		if (!(element instanceof IField) && (element instanceof IMethod) && (element instanceof ILocalVariable)) {
 			return null;
 		}
 
@@ -90,6 +91,10 @@
 					if (((IInjectionPointMethod) iPoint).getMethod() != null && ((IInjectionPointMethod) iPoint).getMethod().equals(element)) {
 						return iPoint;
 					}
+				}else if(element instanceof ILocalVariable && iPoint instanceof IInjectionPointParameter){
+					if (((IInjectionPointParameter) iPoint).getName().equals(element.getElementName())) {
+						return iPoint;
+					}
 				}
 			}
 		}

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointHyperlinkDetector.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointHyperlinkDetector.java	2010-05-24 11:33:28 UTC (rev 22275)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointHyperlinkDetector.java	2010-05-24 12:14:51 UTC (rev 22276)
@@ -19,6 +19,7 @@
 import org.eclipse.jdt.core.ICodeAssist;
 import org.eclipse.jdt.core.ICompilationUnit;
 import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.ILocalVariable;
 import org.eclipse.jdt.core.IMember;
 import org.eclipse.jdt.core.IType;
 import org.eclipse.jdt.core.JavaModelException;
@@ -94,12 +95,7 @@
 					}
 				}
 
-				if (element instanceof IAnnotatable && element instanceof IMember) {
-					IAnnotatable annotatable = (IAnnotatable)element;
-					
-					if(!findAnnotation(annotatable, ((IMember)element).getDeclaringType()))
-						continue;
-					
+				if(findAnnotation(element)){
 					hyperlinks.add(new InjectedPointListHyperlink(file, textViewer, wordRegion, element, document));
 				}
 			}
@@ -113,15 +109,39 @@
 		return null;
 	}
 	
-	private boolean findAnnotation(IAnnotatable annotatable, IType type){
-		try{
-			IAnnotation[] annotations = annotatable.getAnnotations();
-			for(IAnnotation annotation : annotations){
-				if(annotation != null && annotation.getElementName() != null && CDIConstants.INJECT_ANNOTATION_TYPE_NAME.equals(EclipseJavaUtil.resolveType(type, annotation.getElementName())))
-					return true;
+	private IMember findMember(IJavaElement element){
+		IJavaElement elem = element;
+		while(elem != null){
+			if(elem instanceof IMember)
+				return (IMember)elem;
+			elem = elem.getParent();
+		}
+		return null;
+	}
+	
+	private boolean findAnnotation(IJavaElement element){
+		if(element instanceof IAnnotatable){
+			IAnnotatable annotatable = (IAnnotatable) element;
+			IType type = null;
+			if(element instanceof IMember){
+				type = ((IMember)element).getDeclaringType();
+				try{
+					IAnnotation[] annotations = annotatable.getAnnotations();
+					for(IAnnotation annotation : annotations){
+						if(annotation != null && annotation.getElementName() != null && CDIConstants.INJECT_ANNOTATION_TYPE_NAME.equals(EclipseJavaUtil.resolveType(type, annotation.getElementName())))
+							return true;
+					}
+				}catch (JavaModelException jme) {
+					CDIExtensionsPlugin.log(jme);
+				}
+			}else if(element instanceof ILocalVariable){
+				IMember member = findMember(element);
+				if(member == null)
+					return false;
+				type = member.getDeclaringType();
+				return true;
 			}
-		}catch (JavaModelException jme) {
-			CDIExtensionsPlugin.log(jme);
+			
 		}
 		return false;
 			



More information about the jbosstools-commits mailing list