Author: scabanovich
Date: 2011-10-21 15:07:38 -0400 (Fri, 21 Oct 2011)
New Revision: 35908
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/IBeanMember.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanField.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMethod.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/Parameter.java
Log:
JBIDE-9989
https://issues.jboss.org/browse/JBIDE-9244
Fixed CDIUtil.findInjectionPoint()
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 2011-10-21
18:30:12 UTC (rev 35907)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2011-10-21
19:07:38 UTC (rev 35908)
@@ -217,16 +217,9 @@
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()))
+ if (element != null && iPoint.isDeclaredFor(element)) {
return iPoint;
- }else if(element instanceof ILocalVariable && iPoint instanceof
IInjectionPointParameter){
- IInjectionPointParameter param = (IInjectionPointParameter)iPoint;
- if (param.getBeanMethod().getMethod().equals(element.getParent())
- && param.getName().equals(element.getElementName())) {
- return iPoint;
- }
- }else if(iPoint instanceof IInjectionPointParameter && position != 0){
+ } 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.core/src/org/jboss/tools/cdi/core/IBeanMember.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanMember.java 2011-10-21
18:30:12 UTC (rev 35907)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanMember.java 2011-10-21
19:07:38 UTC (rev 35908)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.cdi.core;
+import org.eclipse.jdt.core.IJavaElement;
import org.jboss.tools.common.java.IAnnotated;
import org.jboss.tools.common.java.IJavaSourceReference;
import org.jboss.tools.common.java.IParametedType;
@@ -34,4 +35,12 @@
* @return
*/
IParametedType getMemberType();
+
+ /**
+ * Returns true if this element references the same Java element and false otherwise.
+ *
+ * @param element
+ * @return
+ */
+ boolean isDeclaredFor(IJavaElement element);
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanField.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanField.java 2011-10-21
18:30:12 UTC (rev 35907)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanField.java 2011-10-21
19:07:38 UTC (rev 35908)
@@ -11,6 +11,7 @@
package org.jboss.tools.cdi.internal.core.impl;
import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
import org.jboss.tools.cdi.core.IBeanField;
import org.jboss.tools.cdi.internal.core.impl.definition.FieldDefinition;
@@ -55,4 +56,16 @@
public String getElementName() {
return getClassBean().getBeanClass().getElementName() + "." +
getField().getElementName();
}
+
+ @Override
+ public boolean isDeclaredFor(IJavaElement element) {
+ if(getField() == element) {
+ return true;
+ }
+ if(element instanceof IField && element.exists() && field.exists()) {
+ return element.getElementName().equals(getField().getElementName())
+ &&
((IField)element).getDeclaringType().getFullyQualifiedName().equals(getField().getDeclaringType().getFullyQualifiedName());
+ }
+ 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/BeanMethod.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMethod.java 2011-10-21
18:30:12 UTC (rev 35907)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMethod.java 2011-10-21
19:07:38 UTC (rev 35908)
@@ -14,6 +14,7 @@
import java.util.List;
import java.util.Set;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.jboss.tools.cdi.core.CDIConstants;
@@ -118,4 +119,30 @@
public String getElementName() {
return getClassBean().getBeanClass().getElementName() + "." +
getMethod().getElementName() + "()"; //$NON-NLS-1$
}
+
+ @Override
+ public boolean isDeclaredFor(IJavaElement element) {
+ if(getMethod() == element) {
+ return true;
+ }
+ if(element instanceof IMethod) {
+ IMethod other = (IMethod)element;
+ return getMethod().getElementName().equals(other.getElementName())
+ &&
getMethod().getDeclaringType().getFullyQualifiedName().equals(other.getDeclaringType().getFullyQualifiedName())
+ && equalArrays(getMethod().getParameterTypes(), other.getParameterTypes());
+ }
+ return false;
+ }
+
+ private boolean equalArrays(String[] a1, String[] a2) {
+ if(a1.length != a2.length) {
+ return false;
+ }
+ for (int i = 0; i < a1.length; i++) {
+ if(!a1[i].equals(a2[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/Parameter.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/Parameter.java 2011-10-21
18:30:12 UTC (rev 35907)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/Parameter.java 2011-10-21
19:07:38 UTC (rev 35908)
@@ -4,6 +4,7 @@
import java.util.List;
import java.util.Set;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.ILocalVariable;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.ISourceReference;
@@ -109,4 +110,16 @@
public String getElementName() {
return getName();
}
+
+ @Override
+ public boolean isDeclaredFor(IJavaElement element) {
+ if(getDefinition().getVariable() == element) {
+ return true;
+ }
+ if(element instanceof ILocalVariable) {
+ ILocalVariable vThat = (ILocalVariable)element;
+ return getName().equals(vThat.getElementName()) &&
getBeanMethod().isDeclaredFor(vThat.getDeclaringMember());
+ }
+ return false;
+ }
}
\ No newline at end of file