Author: dazarov
Date: 2010-05-28 11:50:37 -0400 (Fri, 28 May 2010)
New Revision: 22413
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
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointListHyperlink.java
trunk/cdi/tests/org.jboss.tools.cdi.text.ext.test/src/org/jboss/tools/cdi/text/ext/test/InjectedPointHyperlinkDetectorTest.java
Log:
https://jira.jboss.org/browse/JBIDE-6386
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-28
15:18:20 UTC (rev 22412)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2010-05-28
15:50:37 UTC (rev 22413)
@@ -77,7 +77,7 @@
* @param beans
* @param element
*/
- public static IInjectionPoint findInjectionPoint(Set<IBean> beans, IJavaElement
element) {
+ public static IInjectionPoint findInjectionPoint(Set<IBean> beans, IJavaElement
element, int position) {
if (!(element instanceof IField) && (element instanceof IMethod) &&
(element instanceof ILocalVariable)) {
return null;
}
@@ -86,17 +86,17 @@
Set<IInjectionPoint> injectionPoints = bean.getInjectionPoints();
for (IInjectionPoint iPoint : injectionPoints) {
if (element instanceof IField && iPoint instanceof IInjectionPointField) {
- if (((IInjectionPointField) iPoint).getField() != null &&
((IInjectionPointField) iPoint).getField().equals(element)) {
+ if (((IInjectionPointField) iPoint).getField() != null &&
((IInjectionPointField) iPoint).getField().equals(element))
return iPoint;
- }
- } else if (element instanceof IMethod && iPoint instanceof
IInjectionPointMethod) {
- if (((IInjectionPointMethod) iPoint).getMethod() != null &&
((IInjectionPointMethod) iPoint).getMethod().equals(element)) {
+ } else if (element instanceof IMethod && iPoint instanceof
IInjectionPointMethod && position == 0) {
+ 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()))
{
+ if (((IInjectionPointParameter) iPoint).getName().equals(element.getElementName()))
return iPoint;
- }
+ }else if(iPoint instanceof IInjectionPointParameter && position != 0){
+ if(iPoint.getStartPosition() <= position &&
(iPoint.getStartPosition()+iPoint.getLength()) >= position)
+ 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-28
15:18:20 UTC (rev 22412)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointHyperlinkDetector.java 2010-05-28
15:50:37 UTC (rev 22413)
@@ -11,18 +11,17 @@
package org.jboss.tools.cdi.text.ext.hyperlink;
import java.util.ArrayList;
+import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
-import org.eclipse.jdt.core.IAnnotatable;
-import org.eclipse.jdt.core.IAnnotation;
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.IMethod;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.ResolvedBinaryType;
+import org.eclipse.jdt.internal.core.ResolvedSourceType;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
import org.eclipse.jdt.internal.ui.text.JavaWordFinder;
@@ -32,10 +31,13 @@
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.ui.texteditor.ITextEditor;
-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.ICDIProject;
+import org.jboss.tools.cdi.core.IInjectionPoint;
import org.jboss.tools.cdi.text.ext.CDIExtensionsPlugin;
-import org.jboss.tools.common.model.util.EclipseJavaUtil;
public class InjectedPointHyperlinkDetector extends AbstractHyperlinkDetector{
@@ -72,8 +74,8 @@
if(file == null)
return null;
-
- if(CDICorePlugin.getCDI(file.getProject(), true) == null)
+ CDICoreNature cdiNature = CDICorePlugin.getCDI(file.getProject(), true);
+ if(cdiNature == null)
return null;
IJavaElement[] elements = null;
@@ -85,18 +87,20 @@
ArrayList<IHyperlink> hyperlinks = new ArrayList<IHyperlink>();
for (IJavaElement element : elements) {
-
- if(element instanceof IType){
- if(CDIConstants.INJECT_ANNOTATION_TYPE_NAME.equals(((IType)
element).getFullyQualifiedName())){
- ICompilationUnit cUnit = (ICompilationUnit)input;
- element = cUnit.getElementAt(wordRegion.getOffset());
- if(element == null)
- continue;
+ int position = 0;
+ if(element instanceof ResolvedSourceType || element instanceof ResolvedBinaryType){
+ ICompilationUnit cUnit = (ICompilationUnit)input;
+ element = cUnit.getElementAt(wordRegion.getOffset());
+ if(element == null)
+ continue;
+
+ if(element instanceof IMethod){
+ position = offset;
}
}
- if(findAnnotation(element)){
- hyperlinks.add(new InjectedPointListHyperlink(file, textViewer, wordRegion, element,
document));
+ if(findInjectedBeans(cdiNature, element, position, file)){
+ hyperlinks.add(new InjectedPointListHyperlink(file, textViewer, wordRegion, element,
position, document));
}
}
@@ -109,42 +113,24 @@
return null;
}
- private IMember findMember(IJavaElement element){
- IJavaElement elem = element;
- while(elem != null){
- if(elem instanceof IMember)
- return (IMember)elem;
- elem = elem.getParent();
+ private boolean findInjectedBeans(CDICoreNature nature, IJavaElement element, int
offset, IFile file){
+ ICDIProject cdiProject = nature.getDelegate();
+
+ if(cdiProject == null){
+ return false;
}
- 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;
- }
-
+
+ Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
+
+ IInjectionPoint injectionPoint = CDIUtil.findInjectionPoint(beans, element, offset);
+ if(injectionPoint == null){
+ return false;
}
+
+ Set<IBean> resultBeanSet = cdiProject.getBeans(injectionPoint);
+ if(resultBeanSet.size() > 0)
+ return true;
+
return false;
-
}
-
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointListHyperlink.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointListHyperlink.java 2010-05-28
15:18:20 UTC (rev 22412)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointListHyperlink.java 2010-05-28
15:50:37 UTC (rev 22413)
@@ -33,19 +33,20 @@
public class InjectedPointListHyperlink extends AbstractHyperlink{
private IFile file;
private IJavaElement element;
+ private int position;
private IRegion region;
private ITextViewer viewer;
private static MultipleHyperlinkPresenter mhp = new MultipleHyperlinkPresenter(new
RGB(0, 0, 255));
private static boolean installed = false;
- public InjectedPointListHyperlink(IFile file, ITextViewer viewer, IRegion region,
IJavaElement element, IDocument document){
+ public InjectedPointListHyperlink(IFile file, ITextViewer viewer, IRegion region,
IJavaElement element, int position, IDocument document){
this.file = file;
this.element = element;
+ this.position = position;
this.region = region;
this.viewer = viewer;
setDocument(document);
-
}
@@ -71,7 +72,7 @@
Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
- IInjectionPoint injectionPoint = CDIUtil.findInjectionPoint(beans, element);
+ IInjectionPoint injectionPoint = CDIUtil.findInjectionPoint(beans, element, position);
if(injectionPoint == null){
openFileFailed();
return;
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.text.ext.test/src/org/jboss/tools/cdi/text/ext/test/InjectedPointHyperlinkDetectorTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.text.ext.test/src/org/jboss/tools/cdi/text/ext/test/InjectedPointHyperlinkDetectorTest.java 2010-05-28
15:18:20 UTC (rev 22412)
+++
trunk/cdi/tests/org.jboss.tools.cdi.text.ext.test/src/org/jboss/tools/cdi/text/ext/test/InjectedPointHyperlinkDetectorTest.java 2010-05-28
15:50:37 UTC (rev 22413)
@@ -19,6 +19,7 @@
public void testInjectedPointHyperlinkDetector() throws Exception {
ArrayList<Region> regionList = new ArrayList<Region>();
regionList.add(new Region(115, 6)); // Inject
+ regionList.add(new Region(133, 6)); // Logger
regionList.add(new Region(140, 6)); // logger
regionList.add(new Region(196, 6)); // logger
regionList.add(new Region(250, 6)); // logger
@@ -28,9 +29,10 @@
public void testInjectedProducerMethodParametersHyperlinkDetector() throws Exception {
ArrayList<Region> regionList = new ArrayList<Region>();
+ regionList.add(new Region(552, 3)); // Foo
+ regionList.add(new Region(556, 3)); // Foo
+ regionList.add(new Region(567, 3)); // Foo
regionList.add(new Region(571, 5)); // order
- regionList.add(new Region(659, 3));
- regionList.add(new Region(695, 3));
checkRegions("JavaSource/org/jboss/jsr299/tck/tests/jbt/openon/CustomProducerImpl.java",
regionList, new InjectedPointHyperlinkDetector());
}
@@ -47,9 +49,9 @@
public void testInjectedConstructorParametersHyperlinkDetector() throws Exception {
ArrayList<Region> regionList = new ArrayList<Region>();
regionList.add(new Region(880, 6));
+ regionList.add(new Region(894, 3)); // Fox
regionList.add(new Region(898, 3));
- regionList.add(new Region(950, 6));
- regionList.add(new Region(967, 7));
+ regionList.add(new Region(975, 3));
regionList.add(new Region(979, 3));
regionList.add(new Region(1017, 3));
@@ -59,9 +61,9 @@
public void testInjectedInitializerParametersHyperlinkDetector() throws Exception {
ArrayList<Region> regionList = new ArrayList<Region>();
regionList.add(new Region(880, 6));
+ regionList.add(new Region(894, 3)); // Fox
regionList.add(new Region(898, 3));
- regionList.add(new Region(945, 6));
- regionList.add(new Region(967, 4));
+ regionList.add(new Region(972, 3));
regionList.add(new Region(976, 3));
regionList.add(new Region(1014, 3));