Author: dazarov
Date: 2010-01-26 11:52:15 -0500 (Tue, 26 Jan 2010)
New Revision: 19936
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointQueryParticipant.java
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.ui/META-INF/MANIFEST.MF
trunk/cdi/plugins/org.jboss.tools.cdi.ui/plugin.xml
Log:
https://jira.jboss.org/jira/browse/JBIDE-3125
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-01-26
16:51:37 UTC (rev 19935)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2010-01-26
16:52:15 UTC (rev 19936)
@@ -10,8 +10,16 @@
******************************************************************************/
package org.jboss.tools.cdi.core;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMethod;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.jst.web.kb.IKbProject;
@@ -51,4 +59,53 @@
CDICorePlugin.getDefault().logError(e);
}
}
+
+ /**
+ * Finds CDI injected point in beans for particular java element.
+ *
+ * @param beans
+ * @param element
+ */
+ public static IInjectionPoint findInjectionPoint(Set<IBean> beans, IJavaElement
element){
+ if(!(element instanceof IField) && (element instanceof IMethod) )
+ return null;
+
+ 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().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;
+ }
+
+ /**
+ * Sorts CDI beans. Sets for alternative beans higher position and for nonalternative
beans lower position.
+ *
+ * @param beans
+ * @param element
+ */
+ public static List<IBean> sortBeans(Set<IBean> beans){
+ Set<IBean> alternativeBeans = new HashSet<IBean>();
+ Set<IBean> nonAlternativeBeans = new HashSet<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;
+ }
}
\ No newline at end of file
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-26
16:51:37 UTC (rev 19935)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.text.ext/src/org/jboss/tools/cdi/text/ext/hyperlink/InjectedPointHyperlinkDetector.java 2010-01-26
16:52:15 UTC (rev 19936)
@@ -11,7 +11,6 @@
package org.jboss.tools.cdi.text.ext.hyperlink;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -20,9 +19,7 @@
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.IMethod;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
@@ -35,11 +32,10 @@
import org.eclipse.ui.texteditor.ITextEditor;
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.core.IInjectionPointField;
-import org.jboss.tools.cdi.core.IInjectionPointMethod;
public class InjectedPointHyperlinkDetector extends AbstractHyperlinkDetector{
@@ -102,13 +98,13 @@
if (element instanceof IAnnotatable) {
IAnnotatable annotatable = (IAnnotatable)element;
- IAnnotation annotation = annotatable.getAnnotation("Injected");
+ IAnnotation annotation = annotatable.getAnnotation("Injected");
//$NON-NLS-1$
if (annotation == null)
continue;
- IInjectionPoint injectionPoint = findInjectionPoint(beans, element);
+ IInjectionPoint injectionPoint = CDIUtil.findInjectionPoint(beans, element);
if(injectionPoint != null){
Set<IBean> resultBeanSet = cdiProject.getBeans(injectionPoint);
- List<IBean> resultBeanList = sortBeans(resultBeanSet);
+ List<IBean> resultBeanList = CDIUtil.sortBeans(resultBeanSet);
for(IBean bean : resultBeanList){
if(bean != null)
hyperlinks.add(new InjectedPointHyperlink(wordRegion, bean, document));
@@ -125,41 +121,6 @@
return null;
}
- private IInjectionPoint findInjectionPoint(Set<IBean> beans, IJavaElement
element){
- if(!(element instanceof IField) && (element instanceof IMethod) )
- return null;
-
- 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().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){
- Set<IBean> alternativeBeans = new HashSet<IBean>();
- Set<IBean> nonAlternativeBeans = new HashSet<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;
- }
}
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/META-INF/MANIFEST.MF 2010-01-26 16:51:37 UTC
(rev 19935)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/META-INF/MANIFEST.MF 2010-01-26 16:52:15 UTC
(rev 19936)
@@ -17,7 +17,9 @@
org.eclipse.jdt.ui,
org.eclipse.jface.text,
org.eclipse.wst.sse.ui,
- org.jboss.tools.jst.web.kb
+ org.jboss.tools.jst.web.kb,
+ org.eclipse.jdt.core;bundle-version="3.5.0",
+ org.eclipse.search;bundle-version="3.5.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: %Bundle-Vendor.0
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/plugin.xml
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/plugin.xml 2010-01-26 16:51:37 UTC (rev
19935)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/plugin.xml 2010-01-26 16:52:15 UTC (rev
19936)
@@ -97,5 +97,13 @@
<partition type="__java_string"/>
</javaCompletionProposalComputer>
</extension>
-
-</plugin>
\ No newline at end of file
+ <extension
+ point="org.eclipse.jdt.ui.queryParticipants">
+ <queryParticipant
+
class="org.jboss.tools.cdi.ui.search.InjectionPointQueryParticipant"
+ id="org.jboss.tools.cdi.ui.search.InjectionPointQueryParticipant"
+ name="cdi-InjectionPointReferencesParticipant"
+ nature="org.jboss.tools.cdi.core.cdinature">
+ </queryParticipant>
+ </extension>
+</plugin>
Added:
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
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointQueryParticipant.java 2010-01-26
16:52:15 UTC (rev 19936)
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * 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 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.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.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;
+
+public class InjectionPointQueryParticipant implements IQueryParticipant{
+
+ public int estimateTicks(QuerySpecification specification) {
+ return 10;
+ }
+
+ public IMatchPresentation getUIParticipant() {
+ return null;
+ }
+
+ public void search(ISearchRequestor requestor,
+ QuerySpecification querySpecification, IProgressMonitor monitor)
+ throws CoreException {
+
+ if(querySpecification instanceof ElementQuerySpecification){
+ if (!isSearchForReferences(querySpecification.getLimitTo()))
+ return;
+
+ ElementQuerySpecification qs = (ElementQuerySpecification)querySpecification;
+ IJavaElement element = qs.getElement();
+ if(element instanceof IMethod || element instanceof IField){
+ IFile file = (IFile)element.getResource();
+
+ CDICoreNature cdiNature = CDICorePlugin.getCDI(file.getProject(), true);
+
+ if(cdiNature == null)
+ return;
+
+ ICDIProject cdiProject = cdiNature.getDelegate();
+
+ if(cdiProject == null)
+ return;
+
+ Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
+
+ if (element instanceof IAnnotatable) {
+ IAnnotatable annotatable = (IAnnotatable)element;
+
+ IAnnotation annotation = annotatable.getAnnotation("Injected");
//$NON-NLS-1$
+ if (annotation == null)
+ return;
+ IInjectionPoint injectionPoint = CDIUtil.findInjectionPoint(beans, element);
+ if(injectionPoint != null){
+ Set<IBean> resultBeanSet = cdiProject.getBeans(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 Match(type.getResource(), range.getOffset(),
range.getLength());
+ requestor.reportMatch(match);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public boolean isSearchForReferences(int limitTo) {
+ int maskedLimitTo = limitTo &
~(IJavaSearchConstants.IGNORE_DECLARING_TYPE+IJavaSearchConstants.IGNORE_RETURN_TYPE);
+ if (maskedLimitTo == IJavaSearchConstants.REFERENCES || maskedLimitTo ==
IJavaSearchConstants.ALL_OCCURRENCES) {
+ return true;
+ }
+
+ return false;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/InjectionPointQueryParticipant.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain