Author: scabanovich
Date: 2011-04-29 20:39:38 -0400 (Fri, 29 Apr 2011)
New Revision: 30988
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IParameter.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.core/src/org/jboss/tools/cdi/internal/core/impl/InjectionPointParameter.java
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/definition/MethodDefinition.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParameterDefinition.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
Log:
JBIDE-8825
https://issues.jboss.org/browse/JBIDE-8825
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IParameter.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IParameter.java 2011-04-29
21:51:29 UTC (rev 30987)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IParameter.java 2011-04-30
00:39:38 UTC (rev 30988)
@@ -10,8 +10,6 @@
******************************************************************************/
package org.jboss.tools.cdi.core;
-import java.util.Set;
-
import org.jboss.tools.common.text.ITextSourceReference;
/**
@@ -22,13 +20,6 @@
public interface IParameter extends IBeanMember {
/**
- * Returns all the annotations of this parameter.
- *
- * @return all the annotations of this parameter.
- */
- Set<IAnnotationDeclaration> getAnnotationDeclarations();
-
- /**
* Returns the declared type of this parameter.
*
* @return the declared type of this parameter.
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-04-29
21:51:29 UTC (rev 30987)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2011-04-30
00:39:38 UTC (rev 30988)
@@ -314,7 +314,7 @@
}
}
- boolean isParameter = injectionPoint instanceof InjectionPointParameter;
+ boolean isParameter = false;// injectionPoint instanceof InjectionPointParameter;
boolean isNew = false;
Set<IQualifierDeclaration> qs = injectionPoint.getQualifierDeclarations();
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/InjectionPointParameter.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/InjectionPointParameter.java 2011-04-29
21:51:29 UTC (rev 30987)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/InjectionPointParameter.java 2011-04-30
00:39:38 UTC (rev 30988)
@@ -43,9 +43,7 @@
* @see org.jboss.tools.cdi.core.IInjectionPoint#getQualifierDeclarations()
*/
public Set<IQualifierDeclaration> getQualifierDeclarations() {
- Set<IQualifierDeclaration> result = new HashSet<IQualifierDeclaration>();
- //cannot implement
- return result;
+ return super.getQualifierDeclarations();
}
/*
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-04-29
21:51:29 UTC (rev 30987)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/Parameter.java 2011-04-30
00:39:38 UTC (rev 30988)
@@ -1,11 +1,9 @@
package org.jboss.tools.cdi.internal.core.impl;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import org.eclipse.jdt.core.IMember;
-import org.jboss.tools.cdi.core.IAnnotationDeclaration;
import org.jboss.tools.cdi.core.IBeanMethod;
import org.jboss.tools.cdi.core.IClassBean;
import org.jboss.tools.cdi.core.IParametedType;
@@ -14,7 +12,7 @@
import org.jboss.tools.cdi.internal.core.impl.definition.ParameterDefinition;
import org.jboss.tools.common.text.ITextSourceReference;
-public class Parameter extends CDIElement implements IParameter {
+public class Parameter extends AbstractBeanElement implements IParameter {
ParameterDefinition definition;
BeanMethod beanMethod;
@@ -26,13 +24,10 @@
}
public void setDefinition(ParameterDefinition definition) {
+ super.setDefinition(definition);
this.definition = definition;
}
- public Set<IAnnotationDeclaration> getAnnotationDeclarations() {
- throw new RuntimeException("Not implemented because limitations of JDT
model.");
- }
-
public String getName() {
return definition.getName();
}
@@ -66,22 +61,6 @@
return p == null ? 0 : p.getStartPosition();
}
- public IAnnotationDeclaration getAnnotation(String annotationTypeName) {
- throw new RuntimeException("Not implemented because limitations of JDT
model.");
- }
-
- public List<IAnnotationDeclaration> getAnnotations() {
- throw new RuntimeException("Not implemented because limitations of JDT
model.");
- }
-
- public boolean isAnnotationPresent(String annotationTypeName) {
- return definition.isAnnotationPresent(annotationTypeName);
- }
-
- public ITextSourceReference getAnnotationPosition(String annotationTypeName) {
- return definition.getAnnotationPosition(annotationTypeName);
- }
-
public Set<String> getAnnotationTypes() {
return definition.getAnnotationTypes();
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java 2011-04-29
21:51:29 UTC (rev 30987)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java 2011-04-30
00:39:38 UTC (rev 30988)
@@ -17,6 +17,7 @@
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
@@ -28,6 +29,7 @@
import org.jboss.tools.cdi.core.IRootDefinitionContext;
import org.jboss.tools.cdi.core.IStereotypeDeclaration;
import org.jboss.tools.cdi.internal.core.impl.AnnotationDeclaration;
+import org.jboss.tools.cdi.internal.core.impl.AnnotationLiteral;
import org.jboss.tools.cdi.internal.core.impl.ClassBean;
import org.jboss.tools.cdi.internal.core.impl.ParametedType;
import org.jboss.tools.common.model.project.ext.impl.ValueInfo;
@@ -64,15 +66,16 @@
super.init(contextType, context, flags);
isConstructor = method.isConstructor();
//TODO process parameters for disposers and observers
- loadParamDefinitions(contextType, context);
+ loadParamDefinitions(contextType, context, flags);
}
public boolean parametersAreInjectionPoints() {
return getProducesAnnotation() != null || getInjectAnnotation() != null;
}
- void loadParamDefinitions(IType contextType, IRootDefinitionContext context) throws
CoreException {
+ void loadParamDefinitions(IType contextType, IRootDefinitionContext context, int flags)
throws CoreException {
if(method == null) return;
+ boolean loadAll = (flags & FLAG_ALL_MEMBERS) > 0;
boolean parametersAreInjectionPoints = parametersAreInjectionPoints();
String[] parameterNames = method.getParameterNames();
if(parameterNames == null || parameterNames.length == 0) return;
@@ -92,7 +95,7 @@
if(!parametersAreInjectionPoints && paramsString.indexOf("@Observes")
>= 0) {
parametersAreInjectionPoints = true;
}
- if(!parametersAreInjectionPoints && paramsString.indexOf('@') < 0)
return;
+ if(!loadAll && !parametersAreInjectionPoints &&
paramsString.indexOf('@') < 0) return;
String[] params = getParams(paramsString);
String[] ps = method.getParameterTypes();
int start = paramStart + 1;
@@ -103,7 +106,7 @@
// The source code may be broken. Just ignore such errors.
break;
}
- if(!parametersAreInjectionPoints && params[i].indexOf('@') < 0) {
+ if(!loadAll && !parametersAreInjectionPoints &&
params[i].indexOf('@') < 0) {
start += params[i].length() + 1;
continue; //do not need parameters without annotation
}
@@ -129,14 +132,21 @@
String[] tokens = getParamTokens(p);
for (String q: tokens) {
if(!q.startsWith("@")) continue;
- v = new CheckingValueInfo(method);
- v.setValue(q);
- v.valueStartPosition = start + params[i].indexOf(q);
- v.valueLength = q.length();
+ int valueStartPosition = start + params[i].indexOf(q);
+ int valueLength = q.length();
int s = q.indexOf('(');
if(s >= 0) q = q.substring(0, s).trim();
String annotationType = EclipseJavaUtil.resolveType(contextType,
q.substring(1).trim());
- if(annotationType != null) pd.annotationsByTypeName.put(annotationType, v);
+ IType t = context.getProject().getType(annotationType);
+ if(t != null) {
+ String source = content.substring(valueStartPosition, valueStartPosition +
valueLength);
+ IMemberValuePair[] pairs = ParameterDefinition.getMemberValues(source);
+ AnnotationLiteral ja = new AnnotationLiteral(method.getResource(),
valueStartPosition, valueLength, null, IMemberValuePair.K_UNKNOWN, t);
+ if(pairs != null && pairs.length > 0) for (IMemberValuePair pair: pairs)
{
+ ja.addMemberValuePair(pair.getMemberName(), pair.getValue(), pair.getValueKind());
+ }
+ pd.addAnnotation(ja, context);
+ }
}
parameters.add(pd);
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParameterDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParameterDefinition.java 2011-04-29
21:51:29 UTC (rev 30987)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParameterDefinition.java 2011-04-30
00:39:38 UTC (rev 30988)
@@ -10,29 +10,15 @@
******************************************************************************/
package org.jboss.tools.cdi.internal.core.impl.definition;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.eclipse.jdt.core.IMemberValuePair;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.SourceRange;
import org.eclipse.jdt.internal.core.MemberValuePair;
-import org.jboss.tools.cdi.core.CDICoreNature;
-import org.jboss.tools.cdi.core.CDICorePlugin;
-import org.jboss.tools.cdi.core.IAnnotated;
-import org.jboss.tools.cdi.core.IAnnotationDeclaration;
-import org.jboss.tools.cdi.internal.core.impl.AnnotationDeclaration;
-import org.jboss.tools.cdi.internal.core.impl.AnnotationLiteral;
import org.jboss.tools.cdi.internal.core.impl.ParametedType;
import org.jboss.tools.cdi.internal.core.impl.TypeDeclaration;
-import org.jboss.tools.common.model.util.EclipseJavaUtil;
import org.jboss.tools.common.text.ITextSourceReference;
-public class ParameterDefinition implements IAnnotated {
+public class ParameterDefinition extends AbstractMemberDefinition {
protected MethodDefinition methodDefinition;
protected String name;
@@ -41,7 +27,6 @@
protected int index;
protected ITextSourceReference position = null;
- Map<String, ITextSourceReference> annotationsByTypeName = new HashMap<String,
ITextSourceReference>();
public ParameterDefinition() {}
@@ -65,44 +50,9 @@
return methodDefinition;
}
- /**
- * JDT doesn't have API for annotations for method params. So this method will
return a wrapper for ITextSourceReference.
- * Use getAnnotationPosition() instead.
- *
- * @see org.jboss.tools.cdi.core.IAnnotated#getAnnotation(java.lang.String)
- */
- public IAnnotationDeclaration getAnnotation(String annotationTypeName) {
- ITextSourceReference reference = getAnnotationPosition(annotationTypeName);
- if(reference==null) {
- return null;
- }
- // JDT doesn't have API for annotations for method params. So let's wrap
ITextSourceReference into IAnnotationDeclaration.
- AnnotationDeclaration ad = new AnnotationDeclaration();
- IType t = null;
- try {
- t = EclipseJavaUtil.findType(methodDefinition.getMethod().getJavaProject(),
annotationTypeName);
- } catch (JavaModelException e) {
-
- }
- if(t == null) return null;
- int b = reference.getStartPosition();
- int e = reference.getLength() + b;
- if(b < 0 || e < b) return null;
- String source = methodDefinition.getTypeDefinition().getContent().substring(b, e);
-
- //compute member value parameters
- IMemberValuePair[] memberValues = getMemberValues(source);
-
- AnnotationLiteral a = new AnnotationLiteral(methodDefinition.getResource(), source, new
SourceRange(b, e - b), memberValues, t);
- ad.setDeclaration(a);
- CDICoreNature nature =
CDICorePlugin.getCDI(methodDefinition.getResource().getProject(), false);
- ad.setProject(nature);
- return ad;
- }
-
private static IMemberValuePair[] EMPTY_PAIRS = new IMemberValuePair[0];
- private IMemberValuePair[] getMemberValues(String source) {
+ static IMemberValuePair[] getMemberValues(String source) {
int p1 = source.indexOf('(');
int p2 = source.indexOf(')');
if(p1 >= 0 && p2 > p1) {
@@ -127,33 +77,8 @@
return EMPTY_PAIRS;
}
- /**
- * Returns an empty list because JDT doesn't have API for annotations for method
params. Use getAnnotationTypes() instead.
- *
- * @see org.jboss.tools.cdi.core.IAnnotated#getAnnotations()
- */
- public List<IAnnotationDeclaration> getAnnotations() {
- return Collections.emptyList();
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.tools.cdi.core.IAnnotated#isAnnotationPresent(java.lang.String)
- */
- public boolean isAnnotationPresent(String annotationTypeName) {
- return annotationsByTypeName.containsKey(annotationTypeName);
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.tools.cdi.core.IAnnotated#getAnnotationPosition(java.lang.String)
- */
- public ITextSourceReference getAnnotationPosition(String annotationTypeName) {
- return annotationsByTypeName.get(annotationTypeName);
- }
-
public Set<String> getAnnotationTypes() {
- return annotationsByTypeName.keySet();
+ return annotationsByType.keySet();
}
public void setPosition(ITextSourceReference position) {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2011-04-29
21:51:29 UTC (rev 30987)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2011-04-30
00:39:38 UTC (rev 30988)
@@ -21,6 +21,8 @@
import java.util.Set;
import java.util.StringTokenizer;
+import javax.management.ValueExp;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@@ -1310,27 +1312,22 @@
* - injection point other than injected field declares a @Named annotation that does
not specify the value member
*/
if(injection instanceof IInjectionPointParameter) {
- IInjectionPointParameter pinjection = (IInjectionPointParameter)injection;
- if(pinjection.isAnnotationPresent(CDIConstants.NAMED_QUALIFIER_TYPE_NAME)) {
- String value =
((Parameter)pinjection).getValue(CDIConstants.NAMED_QUALIFIER_TYPE_NAME);
- if(value == null || value.length() == 0) {
+// IInjectionPointParameter pinjection = (IInjectionPointParameter)injection;
+ IAnnotationDeclaration named =
injection.getAnnotation(CDIConstants.NAMED_QUALIFIER_TYPE_NAME);
+ if (named != null) {
+ Object value = named.getMemberValue(null);
+ boolean valueExists = value != null && value.toString().trim().length() >
0;
+ if (!valueExists) {
addError(CDIValidationMessages.PARAM_INJECTION_DECLARES_EMPTY_NAME,
CDIPreferences.PARAM_INJECTION_DECLARES_EMPTY_NAME,
- pinjection.getAnnotationPosition(CDIConstants.NAMED_QUALIFIER_TYPE_NAME),
+ named,
injection.getResource());
}
}
} else if (injection instanceof IInjectionPointMethod) {
IAnnotationDeclaration named =
injection.getAnnotation(CDIConstants.NAMED_QUALIFIER_TYPE_NAME);
if (named != null) {
- IMemberValuePair[] values = named.getMemberValuePairs();
- boolean valueExists = false;
- for (IMemberValuePair pair : values) {
- if ("value".equals(pair.getMemberName())) {
- valueExists = true;
- break;
- }
- }
+ boolean valueExists = named.getMemberValue(null) != null;
if (!valueExists) {
addError(CDIValidationMessages.PARAM_INJECTION_DECLARES_EMPTY_NAME,
CDIPreferences.PARAM_INJECTION_DECLARES_EMPTY_NAME, named, injection.getResource());
}