Author: dazarov
Date: 2010-01-22 10:30:50 -0500 (Fri, 22 Jan 2010)
New Revision: 19884
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/META-INF/MANIFEST.MF
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/CDIExtensionsPlugin.java
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointHyperlink.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/jira/browse/JBIDE-3125
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/META-INF/MANIFEST.MF 2010-01-22
14:36:31 UTC (rev 19883)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/META-INF/MANIFEST.MF 2010-01-22
15:30:50 UTC (rev 19884)
@@ -17,6 +17,7 @@
org.eclipse.jdt.core;bundle-version="3.5.0",
org.eclipse.ui.ide;bundle-version="3.5.0",
org.jboss.tools.cdi.core;bundle-version="1.0.0",
- org.jboss.tools.common;bundle-version="2.0.0"
+ org.jboss.tools.common;bundle-version="2.0.0",
+ org.jboss.tools.common.el.core;bundle-version="2.0.0"
Bundle-Version: 2.0.0
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/CDIExtensionsPlugin.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/CDIExtensionsPlugin.java 2010-01-22
14:36:31 UTC (rev 19883)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/CDIExtensionsPlugin.java 2010-01-22
15:30:50 UTC (rev 19884)
@@ -10,8 +10,78 @@
******************************************************************************/
package org.jboss.tools.cdi.text.ext;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.ui.plugin.AbstractUIPlugin;
public class CDIExtensionsPlugin extends AbstractUIPlugin{
+ //The shared instance.
+ private static CDIExtensionsPlugin plugin;
+ //Resource bundle.
+ private ResourceBundle resourceBundle;
+
+ public static final String PLUGIN_ID = "org.jboss.tools.cdi.text.ext";
//$NON-NLS-1$
+
+ /**
+ * The constructor.
+ */
+ public CDIExtensionsPlugin() {
+ plugin = this;
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static CDIExtensionsPlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns the workspace instance.
+ */
+ public static IWorkspace getWorkspace() {
+ return ResourcesPlugin.getWorkspace();
+ }
+
+ /**
+ * Returns the string from the plugin's resource bundle,
+ * or 'key' if not found.
+ */
+ public static String getResourceString(String key) {
+ ResourceBundle bundle= CDIExtensionsPlugin.getDefault().getResourceBundle();
+ try {
+ return bundle.getString(key);
+ } catch (MissingResourceException e) {
+ return key;
+ }
+ }
+
+ /**
+ * Returns the plugin's resource bundle,
+ */
+ public ResourceBundle getResourceBundle() {
+ return resourceBundle;
+ }
+
+ static public void log(String msg) {
+ CDIExtensionsPlugin.getDefault().getLog().log(new Status(Status.INFO, PLUGIN_ID,
Status.OK, msg, null));
+ }
+
+ public static void log(IStatus status) {
+ CDIExtensionsPlugin.getDefault().getLog().log(status);
+ }
+ public static void log(String message, Exception exception) {
+ CDIExtensionsPlugin.getDefault().getLog().log(new Status(Status.ERROR,
CDIExtensionsPlugin.PLUGIN_ID, Status.OK, message, exception));
+ }
+ static public void log(Exception ex) {
+ CDIExtensionsPlugin.getDefault().getLog().log(new Status(Status.ERROR,
CDIExtensionsPlugin.PLUGIN_ID, Status.OK, "No message", ex));
+ }
+
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointHyperlink.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointHyperlink.java 2010-01-22
14:36:31 UTC (rev 19883)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointHyperlink.java 2010-01-22
15:30:50 UTC (rev 19884)
@@ -10,26 +10,56 @@
******************************************************************************/
package org.jboss.tools.cdi.text.ext.hyperlink;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.text.IRegion;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.text.ext.CDIExtensionsPlugin;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
public class InjectedPointHyperlink extends AbstractHyperlink{
+ IBean bean;
+ IRegion region;
+
+ public InjectedPointHyperlink(IRegion region, IBean bean){
+ this.bean = bean;
+ this.region = region;
+ }
+
@Override
protected IRegion doGetHyperlinkRegion(int offset) {
- // TODO Auto-generated method stub
- return null;
+ return region;
}
- @Override
protected void doHyperlink(IRegion region) {
- // TODO Auto-generated method stub
+ IEditorPart part = null;
+
+
+ if(bean != null && bean.getBeanClass() != null){
+ try{
+ part = JavaUI.openInEditor(bean.getBeanClass());
+ }catch(JavaModelException ex){
+ CDIExtensionsPlugin.log(ex);
+ }catch(PartInitException ex){
+ CDIExtensionsPlugin.log(ex);
+ }
+ if (part != null) {
+ JavaUI.revealInEditor(part, (IJavaElement)bean.getBeanClass());
+ }
+ }
+ if (part == null)
+ openFileFailed();
}
@Override
public String getHyperlinkText() {
- // TODO Auto-generated method stub
+ if(bean != null)
+ return bean.getName();
return null;
}
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-01-22
14:36:31 UTC (rev 19883)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointHyperlinkDetector.java 2010-01-22
15:30:50 UTC (rev 19884)
@@ -11,15 +11,18 @@
package org.jboss.tools.cdi.text.ext.hyperlink;
import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
+import java.util.TreeSet;
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.IField;
import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IMemberValuePair;
+import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
@@ -33,6 +36,11 @@
import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.IBean;
+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.IInjectionPointField;
+import org.jboss.tools.cdi.core.IInjectionPointMethod;
public class InjectedPointHyperlinkDetector extends AbstractHyperlinkDetector{
@@ -69,8 +77,19 @@
if(file == null)
return null;
- CDICoreNature cdiProject = CDICorePlugin.getCDI(file.getProject(), false);
- Set<IBean> beans = cdiProject.getDelegate().getBeans(file.getFullPath());
+ CDICoreNature cdiNature = CDICorePlugin.getCDI(file.getProject(), false);
+
+ if(cdiNature == null)
+ return null;
+
+ ICDIProject cdiProject = cdiNature.getDelegate();
+
+ if(cdiProject == null)
+ return null;
+
+ Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
+
+ System.out.println("beans - "+beans.size());
int[] range = new int[]{wordRegion.getOffset(), wordRegion.getOffset() +
wordRegion.getLength()};
@@ -81,34 +100,26 @@
if (elements == null)
return null;
+ System.out.println("elements - "+elements.length);
+
ArrayList<IHyperlink> hyperlinks = new ArrayList<IHyperlink>();
for (IJavaElement element : elements) {
if (element instanceof IAnnotatable) {
+ System.out.println("element - "+element.getElementName());
+
IAnnotatable annotatable = (IAnnotatable)element;
IAnnotation annotation = annotatable.getAnnotation("Injected");
if (annotation == null)
continue;
-
- String nameToSearch = element.getElementName();
-
- IMemberValuePair[] mvPairs = annotation.getMemberValuePairs();
- if (mvPairs != null) {
- for (IMemberValuePair mvPair : mvPairs) {
- if ("value".equals(mvPair.getMemberName()) && mvPair.getValue()
!= null) {
- String name = mvPair.getValue().toString();
- if (name != null && name.trim().length() != 0) {
- nameToSearch = name;
- break;
- }
- }
+ IInjectionPoint injectionPoint = findInjectionPoint(beans, element);
+ if(injectionPoint != null){
+ Set<IBean> resultBeanSet = cdiProject.getBeans(injectionPoint);
+ List<IBean> resultBeanList = sortBeans(resultBeanSet);
+ for(IBean bean : resultBeanList){
+ hyperlinks.add(new InjectedPointHyperlink(wordRegion, bean));
}
}
-
-
- if (nameToSearch == null && nameToSearch.trim().length() == 0)
- continue;
-
}
}
if (hyperlinks != null && !hyperlinks.isEmpty()) {
@@ -119,5 +130,44 @@
}
return null;
}
+
+ private IInjectionPoint findInjectionPoint(Set<IBean> beans, IJavaElement
element){
+ if(!(element instanceof IField) && (element instanceof IMethod) )
+ return null;
+
+ for(IBean bean : beans){
+ if(bean instanceof IClassBean){
+ 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))
+ return iPoint;
+ }else if(element instanceof IMethod && iPoint instanceof
IInjectionPointMethod){
+ if(((IInjectionPointMethod)iPoint).getMethod() != null &&
((IInjectionPointMethod)iPoint).getMethod().equals(element))
+ return iPoint;
+
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private List<IBean> sortBeans(Set<IBean> beans){
+ TreeSet<IBean> alternativeBeans = new TreeSet<IBean>();
+ TreeSet<IBean> nonAlternativeBeans = new TreeSet<IBean>();
+
+ for(IBean bean : beans){
+ if(bean.isAlternative())
+ alternativeBeans.add(bean);
+ else
+ nonAlternativeBeans.add(bean);
+ }
+
+ ArrayList<IBean> sortedBeans = new ArrayList<IBean>();
+ sortedBeans.addAll(alternativeBeans);
+ sortedBeans.addAll(nonAlternativeBeans);
+ return sortedBeans;
+ }
}