Author: scabanovich
Date: 2011-09-07 17:04:34 -0400 (Wed, 07 Sep 2011)
New Revision: 34574
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/lookup/typesafe/resolution/Zoo.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/el/CdiElResolver.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIBeanQueryParticipant.java
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/search/CDISearchParticipantTest.java
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/testmodel/CDIProject.java
Log:
JBIDE-9672
https://issues.jboss.org/browse/JBIDE-9672
Search for matches of producers in injections and EL fixed.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java 2011-09-07
19:40:46 UTC (rev 34573)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java 2011-09-07
21:04:34 UTC (rev 34574)
@@ -14,6 +14,7 @@
import java.util.Set;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
import org.jboss.tools.common.java.IParametedType;
import org.jboss.tools.common.text.INodeReference;
@@ -161,6 +162,14 @@
Set<IBean> getBeans(IPath path);
/**
+ * Returns the set of beans based on the Java element.
+ * Current implementation is slow - it iterates over all beans.
+ *
+ * @param element
+ * @return
+ */
+ public Set<IBean> getBeans(IJavaElement element);
+ /**
* Returns all the available qualifiers.
*
* @return all the available qualifiers.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/el/CdiElResolver.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/el/CdiElResolver.java 2011-09-07
19:40:46 UTC (rev 34573)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/el/CdiElResolver.java 2011-09-07
21:04:34 UTC (rev 34574)
@@ -11,11 +11,13 @@
package org.jboss.tools.cdi.internal.core.el;
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.IProject;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
import org.eclipse.swt.graphics.Image;
import org.jboss.tools.cdi.core.CDICoreNature;
@@ -24,11 +26,14 @@
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.IBeanManager;
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.common.el.core.ca.AbstractELCompletionEngine;
+import org.jboss.tools.common.el.core.ca.DefaultJavaRelevanceCheck;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.common.el.core.parser.ELParserFactory;
import org.jboss.tools.common.el.core.parser.ELParserUtil;
+import org.jboss.tools.common.el.core.resolver.IRelevanceCheck;
import org.jboss.tools.common.el.core.resolver.TypeInfoCollector;
import org.jboss.tools.common.el.core.resolver.TypeInfoCollector.MemberInfo;
@@ -150,4 +155,39 @@
protected boolean isStaticMethodsCollectingEnabled() {
return true;
}
+
+ public IRelevanceCheck createRelevanceCheck(IJavaElement element) {
+ return new BeanRelevanceCheck(element);
+ }
+
+}
+
+class BeanRelevanceCheck extends DefaultJavaRelevanceCheck {
+ Set<String> names = new HashSet<String>();
+
+ public BeanRelevanceCheck(IJavaElement element) {
+ super(element);
+ IProject project = element.getJavaProject().getProject();
+ ICDIProject cdi = CDICorePlugin.getCDIProject(project, true);
+ if(cdi != null) {
+ Set<IBean> beans = cdi.getBeans(element);
+ for (IBean b: beans) {
+ if(b.getName() != null) {
+ names.add(b.getName());
+ }
+ }
+ }
+ }
+
+ public boolean isRelevant(String content) {
+ if(super.isRelevant(content)) {
+ return true;
+ }
+ for (String name: names) {
+ if(content.contains(name)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2011-09-07
19:40:46 UTC (rev 34573)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2011-09-07
21:04:34 UTC (rev 34574)
@@ -29,6 +29,8 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
@@ -65,6 +67,7 @@
import org.jboss.tools.cdi.internal.core.impl.definition.TypeDefinition;
import org.jboss.tools.cdi.internal.core.scanner.ImplementationCollector;
import org.jboss.tools.common.java.IAnnotationDeclaration;
+import org.jboss.tools.common.java.IJavaMemberReference;
import org.jboss.tools.common.java.IParametedType;
import org.jboss.tools.common.java.ParametedType;
import org.jboss.tools.common.model.XModelObject;
@@ -567,7 +570,22 @@
if(beans != null && !beans.isEmpty()) result.addAll(beans);
return result;
}
+
+ static int q = 0;
+ public synchronized Set<IBean> getBeans(IJavaElement element) {
+ Set<IBean> result = new HashSet<IBean>();
+ for (IBean bean: allBeans) {
+ if(bean instanceof IJavaMemberReference) {
+ IMember m = ((IJavaMemberReference)bean).getSourceMember();
+ if(((IJavaMemberReference)bean).getSourceMember().equals(element)) {
+ result.add(bean);
+ }
+ }
+ }
+ return result;
+ }
+
public List<INodeReference> getDecoratorClasses() {
List<INodeReference> result = new ArrayList<INodeReference>();
synchronized (allBeansXMLData) {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIBeanQueryParticipant.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIBeanQueryParticipant.java 2011-09-07
19:40:46 UTC (rev 34573)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/search/CDIBeanQueryParticipant.java 2011-09-07
21:04:34 UTC (rev 34574)
@@ -10,13 +10,13 @@
******************************************************************************/
package org.jboss.tools.cdi.ui.search;
+import java.util.HashSet;
import java.util.Set;
-import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.ui.JavaUI;
@@ -31,12 +31,10 @@
import org.eclipse.search.ui.text.Match;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.PartInitException;
-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.ICDIElement;
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;
@@ -44,6 +42,7 @@
import org.jboss.tools.cdi.ui.CDIUIMessages;
import org.jboss.tools.cdi.ui.CDIUIPlugin;
import org.jboss.tools.cdi.ui.CDIUiImages;
+import org.jboss.tools.common.java.IParametedType;
public class CDIBeanQueryParticipant implements IQueryParticipant{
static CDIBeanLabelProvider labelProvider = new CDIBeanLabelProvider();
@@ -53,53 +52,44 @@
QuerySpecification querySpecification, IProgressMonitor monitor)
throws CoreException {
if(querySpecification instanceof ElementQuerySpecification){
- if (!isSearchForReferences(querySpecification.getLimitTo()))
+ if (!isSearchForReferences(querySpecification.getLimitTo())) {
return;
+ }
ElementQuerySpecification qs = (ElementQuerySpecification)querySpecification;
IJavaElement element = qs.getElement();
- if(element instanceof IType){
- IFile file = (IFile)element.getResource();
- if(file == null)
- return;
+ IProject project = element.getJavaProject().getProject();
+ ICDIProject cdiProject = CDICorePlugin.getCDIProject(project, true);
+ if(cdiProject == null) {
+ return;
+ }
+ Set<IBean> sourceBeans = cdiProject.getBeans(element);
+
+ Set<IInjectionPoint> injectionPoints = new HashSet<IInjectionPoint>();
+ for (IBean b: sourceBeans) {
+ Set<IParametedType> ts = b.getLegalTypes();
+ for (IParametedType t: ts) {
+ injectionPoints.addAll(cdiProject.getInjections(t.getType().getFullyQualifiedName()));
+ }
+ }
+
+ monitor.beginTask(CDIUIMessages.CDI_BEAN_QUERY_PARTICIPANT_TASK,
injectionPoints.size());
- CDICoreNature cdiNature = CDICorePlugin.getCDI(file.getProject(), true);
-
- if(cdiNature == null)
- return;
-
- ICDIProject cdiProject = cdiNature.getDelegate();
-
- if(cdiProject == null)
- return;
-
- IClassBean sourceBean = cdiProject.getBeanClass((IType)element);
-
- IBean[] beans = cdiProject.getBeans();
-
- monitor.beginTask(CDIUIMessages.CDI_BEAN_QUERY_PARTICIPANT_TASK, beans.length);
-
- for(IBean bean : beans){
- if(monitor.isCanceled())
- break;
+ for(IInjectionPoint injectionPoint : injectionPoints){
+ if(monitor.isCanceled())
+ break;
+ Set<IBean> resultBeans = cdiProject.getBeans(false, injectionPoint);
+ monitor.worked(1);
- monitor.worked(1);
-
- Set<IInjectionPoint> injectionPoints = bean.getInjectionPoints();
-
- for(IInjectionPoint injectionPoint : injectionPoints){
- Set<IBean> resultBeans = cdiProject.getBeans(false, injectionPoint);
-
- for(IBean cBean : resultBeans){
- if(cBean == sourceBean){
- Match match = new CDIMatch(injectionPoint);
- requestor.reportMatch(match);
- }
- }
+ for(IBean cBean : resultBeans){
+ if(sourceBeans.contains(cBean)){
+ Match match = new CDIMatch(injectionPoint);
+ requestor.reportMatch(match);
+ break;
}
}
- monitor.done();
}
+ monitor.done();
}
}
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/lookup/typesafe/resolution/Zoo.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/lookup/typesafe/resolution/Zoo.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/lookup/typesafe/resolution/Zoo.java 2011-09-07
21:04:34 UTC (rev 34574)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.jsr299.tck.tests.lookup.typesafe.resolution;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+public class Zoo {
+
+ @Inject @Wild PetShop p;
+
+ String str = "#{aaaf.aslan}";
+
+ @Produces @Named("aaaf") @Wild PetShop petShop;
+
+// @Produces @Named("aaaf") @Wild PetShop getPetShop() {
+// return null;
+// }
+
+}
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/lookup/typesafe/resolution/Zoo.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/search/CDISearchParticipantTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/search/CDISearchParticipantTest.java 2011-09-07
19:40:46 UTC (rev 34573)
+++
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/search/CDISearchParticipantTest.java 2011-09-07
21:04:34 UTC (rev 34574)
@@ -192,4 +192,17 @@
testSearchParticipant("JavaSource/org/jboss/jsr299/tck/tests/lookup/injectionpoint/BeanWithInjectionPointMetadata.java",
TYPE_SEARCH, "BeanWithInjectionPointMetadata", "", new
CDIBeanQueryParticipant(), matches);
}
+
+ public void testCDIBeanQueryParticipant2(){
+ ArrayList<MatchStructure> matches = new ArrayList<MatchStructure>();
+
+ matches.add(new MatchStructure(InjectionPointField.class, "Zoo.p"));
+ matches.add(new MatchStructure(InjectionPointField.class,
"NamedDecoratorBroken.logger"));
+ matches.add(new MatchStructure(InjectionPointField.class,
"NamedStereotypedDecoratorBroken.logger"));
+ matches.add(new MatchStructure(InjectionPointField.class,
"NamedStereotypedDecoratorBroken.logger"));
+ matches.add(new MatchStructure(InjectionPointField.class,
"SpecializingDecoratorBroken.logger"));
+ matches.add(new MatchStructure(InjectionPointField.class,
"ObserverMethodInDecoratorBroken.logger"));
+
+ testSearchParticipant("JavaSource/org/jboss/jsr299/tck/tests/lookup/typesafe/resolution/Zoo.java",
FIELD_SEARCH, "petShop", "", new CDIBeanQueryParticipant(), matches);
+ }
}
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/testmodel/CDIProject.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/testmodel/CDIProject.java 2011-09-07
19:40:46 UTC (rev 34573)
+++
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/testmodel/CDIProject.java 2011-09-07
21:04:34 UTC (rev 34574)
@@ -5,6 +5,7 @@
import java.util.Set;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.CDICoreNature;
@@ -300,4 +301,10 @@
public void update(boolean updateDependent) {
}
+ @Override
+ public Set<IBean> getBeans(IJavaElement element) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}