Author: scabanovich
Date: 2011-05-19 20:41:20 -0400 (Thu, 19 May 2011)
New Revision: 31391
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointHyperlink.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointHyperlinkDetector.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointListHyperlink.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/.classpath
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/META-INF/MANIFEST.MF
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/plugin.properties
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/plugin.xml
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/CDISeamExtMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/messages.properties
Log:
JBIDE-8692
https://issues.jboss.org/browse/JBIDE-8692
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/.classpath
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/.classpath 2011-05-20 00:24:15 UTC
(rev 31390)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/.classpath 2011-05-20 00:41:20 UTC
(rev 31391)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src"/>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/META-INF/MANIFEST.MF 2011-05-20
00:24:15 UTC (rev 31390)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/META-INF/MANIFEST.MF 2011-05-20
00:41:20 UTC (rev 31391)
@@ -9,12 +9,15 @@
Export-Package: org.jboss.tools.cdi.seam.text.ext,
org.jboss.tools.cdi.seam.text.ext.hyperlink
Require-Bundle: org.eclipse.ui;bundle-version="3.7.0",
+ org.jboss.tools.common.el.core,
org.jboss.tools.common.text.ext;bundle-version="2.0.0",
org.eclipse.jface.text;bundle-version="3.7.0",
org.eclipse.jdt.ui;bundle-version="3.7.0",
org.jboss.tools.cdi.ui;bundle-version="1.2.0",
org.jboss.tools.cdi.core,
+ org.jboss.tools.cdi.text.ext,
org.jboss.tools.cdi.seam.config.core,
+ org.jboss.tools.cdi.seam.solder.core,
org.jboss.tools.jst.text.ext,
org.jboss.tools.jst.web;bundle-version="3.2.0"
Bundle-Version: 1.0.0.qualifier
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/plugin.properties
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/plugin.properties 2011-05-20
00:24:15 UTC (rev 31390)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/plugin.properties 2011-05-20
00:41:20 UTC (rev 31391)
@@ -1,2 +1,3 @@
providerName=JBoss by Red Hat
Bundle-Name.0 = CDI Seam Text Editors Extensions
+GenericInjectedPointHyperlinkDetector = CDI Seam Generic Injected Point
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/plugin.xml
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/plugin.xml 2011-05-20 00:24:15 UTC
(rev 31390)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/plugin.xml 2011-05-20 00:41:20 UTC
(rev 31391)
@@ -13,6 +13,16 @@
</extension>
+ <extension
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
+ <hyperlinkDetector
+
class="org.jboss.tools.cdi.seam.text.ext.hyperlink.GenericInjectedPointHyperlinkDetector"
+
id="org.jboss.tools.cdi.seam.text.ext.hyperlink.GenericInjectedPointHyperlinkDetector"
+ name="%GenericInjectedPointHyperlinkDetector"
+ targetId="org.eclipse.jdt.ui.javaCode">
+ </hyperlinkDetector>
+ </extension>
+
<extension
point="org.jboss.tools.common.text.ext.hyperlinkPartitioner"
id="org.jboss.tools.cdi.text.ext.hyperlinkPartitioner"
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/CDISeamExtMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/CDISeamExtMessages.java 2011-05-20
00:24:15 UTC (rev 31390)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/CDISeamExtMessages.java 2011-05-20
00:41:20 UTC (rev 31391)
@@ -21,4 +21,8 @@
public static String CDI_SEAM_EXT_PLUGIN_NO_MESSAGE;
public static String CDI_SEAM_RESOURCE_LOADING_HYPERLINK;
public static String CDI_SEAM_CONFIG_OPEN_TAG;
+
+ public static String CDI_INJECTED_POINT_HYPERLINK_SHOW_GENERIC_BEANS;
+ public static String OPEN_GENERIC_BEAN;
+ public static String OPEN_GENERIC_PRODUCER_BEAN;
}
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointHyperlink.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointHyperlink.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointHyperlink.java 2011-05-20
00:41:20 UTC (rev 31391)
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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.seam.text.ext.hyperlink;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.IProducerField;
+import org.jboss.tools.cdi.core.IProducerMethod;
+import org.jboss.tools.cdi.seam.text.ext.CDISeamExtMessages;
+import org.jboss.tools.cdi.text.ext.hyperlink.InjectedPointHyperlink;
+
+public class GenericInjectedPointHyperlink extends InjectedPointHyperlink {
+
+ public GenericInjectedPointHyperlink(IRegion region, IBean bean, IDocument document,
boolean b) {
+ super(region, bean, document, b);
+ }
+
+ @Override
+ public String getHyperlinkText() {
+ String text="";
+ if (bean != null) {
+ String name = bean.getBeanClass().getElementName();
+ if (bean instanceof IProducerField) {
+ name += "."+((IProducerField)bean).getField().getElementName();
+ text = NLS.bind(CDISeamExtMessages.OPEN_GENERIC_PRODUCER_BEAN, name);
+ } else if (bean instanceof IProducerMethod) {
+ name +=
"."+((IProducerMethod)bean).getMethod().getElementName()+"()";
+ text = NLS.bind(CDISeamExtMessages.OPEN_GENERIC_PRODUCER_BEAN, name);
+ } else {
+ text = NLS.bind(CDISeamExtMessages.OPEN_GENERIC_BEAN, name);
+ }
+ }
+ return text;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointHyperlink.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointHyperlinkDetector.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointHyperlinkDetector.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointHyperlinkDetector.java 2011-05-20
00:41:20 UTC (rev 31391)
@@ -0,0 +1,203 @@
+/*******************************************************************************
+ * 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.seam.text.ext.hyperlink;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.ICodeAssist;
+import org.eclipse.jdt.core.ICompilationUnit;
+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.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;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+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.CDICoreNature;
+import org.jboss.tools.cdi.core.CDIUtil;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.IBeanMember;
+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;
+import org.jboss.tools.cdi.core.IInjectionPointParameter;
+import org.jboss.tools.cdi.seam.solder.core.CDISeamSolderConstants;
+import org.jboss.tools.cdi.seam.solder.core.generic.GenericClassBean;
+import org.jboss.tools.cdi.text.ext.CDIExtensionsPlugin;
+import org.jboss.tools.cdi.text.ext.hyperlink.AlternativeInjectedPointListHyperlink;
+import org.jboss.tools.cdi.text.ext.hyperlink.InjectedPointHyperlink;
+
+public class GenericInjectedPointHyperlinkDetector extends AbstractHyperlinkDetector{
+ private IRegion region;
+ private IDocument document;
+ private ITextViewer viewer;
+
+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
+ IRegion region, boolean canShowMultipleHyperlinks) {
+ this.region = region;
+ this.viewer = textViewer;
+
+ ITextEditor textEditor= (ITextEditor)getAdapter(ITextEditor.class);
+ if (region == null || !canShowMultipleHyperlinks || !(textEditor instanceof
JavaEditor))
+ return null;
+
+ int offset= region.getOffset();
+
+ IJavaElement input = EditorUtility.getEditorInputJavaElement(textEditor, false);
+ if (input == null)
+ return null;
+
+ if (input.getResource() == null || input.getResource().getProject() == null)
+ return null;
+
+ document= textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+ IRegion wordRegion= JavaWordFinder.findWord(document, offset);
+ if (wordRegion == null)
+ return null;
+
+ IFile file = null;
+
+ try {
+ IResource resource = input.getCorrespondingResource();
+ if (resource instanceof IFile)
+ file = (IFile) resource;
+ } catch (JavaModelException e) {
+ CDIExtensionsPlugin.log(e);
+ }
+
+ if(file == null)
+ return null;
+ CDICoreNature cdiNature = CDIUtil.getCDINatureWithProgress(file.getProject());
+ if(cdiNature == null)
+ return null;
+
+ IJavaElement[] elements = null;
+
+ try {
+ elements = ((ICodeAssist)input).codeSelect(wordRegion.getOffset(),
wordRegion.getLength());
+ if (elements == null)
+ return null;
+
+ ArrayList<IHyperlink> hyperlinks = new ArrayList<IHyperlink>();
+ for (IJavaElement element : elements) {
+ 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;
+ }
+ }
+
+ findInjectedBeans(cdiNature, element, position, file, hyperlinks);
+ }
+
+ if (hyperlinks != null && !hyperlinks.isEmpty()) {
+ return (IHyperlink[])hyperlinks.toArray(new IHyperlink[hyperlinks.size()]);
+ }
+ } catch (JavaModelException jme) {
+ CDIExtensionsPlugin.log(jme);
+ }
+ return null;
+ }
+
+ private void findInjectedBeans(CDICoreNature nature, IJavaElement element, int offset,
IFile file, ArrayList<IHyperlink> hyperlinks){
+ ICDIProject cdiProject = nature.getDelegate();
+
+ if(cdiProject == null) {
+ return;
+ }
+
+ Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
+
+ Set<IInjectionPoint> injectionPoints = findInjectionPoints(beans, element,
offset);
+ if(injectionPoints.isEmpty()) {
+ return;
+ }
+
+ Set<IBean> resultBeanSet2 = new HashSet<IBean>();
+
+ for (IInjectionPoint injectionPoint: injectionPoints) {
+ Set<IBean> resultBeanSet = cdiProject.getBeans(true, injectionPoint);
+
+ for (IBean b: resultBeanSet) {
+ IClassBean cb = null;
+ if(b instanceof IClassBean) {
+ cb = (IClassBean)b;
+ }
+ if(b instanceof IBeanMember) {
+ cb = ((IBeanMember)b).getClassBean();
+ }
+ if(cb instanceof GenericClassBean) {
+ GenericClassBean gcb = (GenericClassBean)cb;
+ IBean gpb = gcb.getGenericProducerBean();
+ if(gpb != null) {
+ resultBeanSet2.add(gpb);
+ }
+ } else if(injectionPoint.getClassBean() instanceof GenericClassBean
+ &&
injectionPoint.isAnnotationPresent(CDISeamSolderConstants.INJECT_GENERIC_ANNOTATION_TYPE_NAME))
{
+ resultBeanSet2.add(b);
+ }
+ }
+ }
+
+ List<IBean> resultBeanList = CDIUtil.sortBeans(resultBeanSet2);
+ if(resultBeanList.size() == 1) {
+ hyperlinks.add(new GenericInjectedPointHyperlink(region, resultBeanList.get(0),
document, true));
+ } else if(resultBeanList.size() > 0) {
+ hyperlinks.add(new GenericInjectedPointListHyperlink(region, resultBeanList, viewer,
document, hyperlinks.size()));
+ }
+ }
+
+ public static Set<IInjectionPoint> findInjectionPoints(Set<IBean> beans,
IJavaElement element, int position) {
+ Set<IInjectionPoint> results = new HashSet<IInjectionPoint>();
+
+ for (IBean bean : beans) {
+ Set<IInjectionPoint> injectionPoints = bean.getInjectionPoints();
+ for (IInjectionPoint iPoint : injectionPoints) {
+ if (element instanceof IField && iPoint instanceof IInjectionPointField) {
+ if (((IInjectionPointField) iPoint).getField() != null &&
((IInjectionPointField)
iPoint).getField().getElementName().equals(element.getElementName()))
+ results.add(iPoint);
+ } else if (element instanceof IMethod && iPoint instanceof
IInjectionPointMethod && position == 0) {
+ if (((IInjectionPointMethod) iPoint).getMethod() != null &&
((IInjectionPointMethod) iPoint).getMethod().equals(element))
+ results.add(iPoint);
+ }else if(element instanceof ILocalVariable && iPoint instanceof
IInjectionPointParameter){
+ if (((IInjectionPointParameter) iPoint).getName().equals(element.getElementName()))
+ results.add(iPoint);
+ }else if(iPoint instanceof IInjectionPointParameter && position != 0){
+ if(iPoint.getStartPosition() <= position &&
(iPoint.getStartPosition()+iPoint.getLength()) >= position)
+ results.add(iPoint);
+ }
+ }
+ }
+ return results;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointHyperlinkDetector.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointListHyperlink.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointListHyperlink.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointListHyperlink.java 2011-05-20
00:41:20 UTC (rev 31391)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.seam.text.ext.hyperlink;
+
+import java.util.List;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.seam.text.ext.CDISeamExtMessages;
+import org.jboss.tools.cdi.text.ext.hyperlink.AlternativeInjectedPointListHyperlink;
+
+public class GenericInjectedPointListHyperlink extends
+ AlternativeInjectedPointListHyperlink {
+
+ public GenericInjectedPointListHyperlink(IRegion region, List<IBean> beans,
+ ITextViewer viewer, IDocument document, int previousIndex) {
+ super(region, beans, viewer, document, previousIndex);
+ }
+
+ @Override
+ public String getHyperlinkText() {
+ return CDISeamExtMessages.CDI_INJECTED_POINT_HYPERLINK_SHOW_GENERIC_BEANS;
+ }
+
+ @Override
+ protected IHyperlink createHyperlink(IRegion region, IBean bean) {
+ return new GenericInjectedPointHyperlink(region, bean, getDocument(), false);
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/GenericInjectedPointListHyperlink.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/messages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/messages.properties 2011-05-20
00:24:15 UTC (rev 31390)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/messages.properties 2011-05-20
00:41:20 UTC (rev 31391)
@@ -1,3 +1,6 @@
CDI_SEAM_EXT_PLUGIN_NO_MESSAGE=No message
CDI_SEAM_RESOURCE_LOADING_HYPERLINK=Open Resource ''{0}''
CDI_SEAM_CONFIG_OPEN_TAG=Open Seam Config tag {0}
+CDI_INJECTED_POINT_HYPERLINK_SHOW_GENERIC_BEANS=Show All Generic Beans...
+OPEN_GENERIC_BEAN=Open Generic Bean {0}
+OPEN_GENERIC_PRODUCER_BEAN=Open Generic Producer Bean {0}