Author: scabanovich
Date: 2011-04-01 19:16:08 -0400 (Fri, 01 Apr 2011)
New Revision: 30238
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/IAnnotationDeclaration.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AnnotationDeclaration.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/ClassBean.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/JavaAnnotation.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/AnnotationValidationDelegate.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
Log:
JBIDE-3120
https://issues.jboss.org/browse/JBIDE-3120
JBIDE-8196
https://issues.jboss.org/browse/JBIDE-8196
JBIDE-8197
https://issues.jboss.org/browse/JBIDE-8197
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-04-01
22:45:02 UTC (rev 30237)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2011-04-01
23:16:08 UTC (rev 30238)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.cdi.core;
+
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
@@ -38,7 +39,6 @@
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.ILocalVariable;
-import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
@@ -1047,24 +1047,20 @@
*/
public static Set<String> getTargetAnnotationValues(IAnnotationDeclaration target)
throws JavaModelException {
Set<String> result = new HashSet<String>();
- IMemberValuePair[] ps = target.getMemberValuePairs();
- for (IMemberValuePair p: ps) {
- if(!"value".equals(p.getMemberName())) continue;
- Object o = p.getValue();
- if(o instanceof Object[]) {
- Object[] os = (Object[])o;
- for (Object q: os) {
- String s = q.toString();
- int i = s.lastIndexOf('.');
- if(i >= 0) s = s.substring(i + 1);
- result.add(s);
- }
- } else if(o != null) {
- String s = o.toString();
+ Object o = target.getMemberValue(null);
+ if(o instanceof Object[]) {
+ Object[] os = (Object[])o;
+ for (Object q: os) {
+ String s = q.toString();
int i = s.lastIndexOf('.');
if(i >= 0) s = s.substring(i + 1);
result.add(s);
}
+ } else if(o != null) {
+ String s = o.toString();
+ int i = s.lastIndexOf('.');
+ if(i >= 0) s = s.substring(i + 1);
+ result.add(s);
}
return result;
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IAnnotationDeclaration.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IAnnotationDeclaration.java 2011-04-01
22:45:02 UTC (rev 30237)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IAnnotationDeclaration.java 2011-04-01
23:16:08 UTC (rev 30238)
@@ -24,15 +24,20 @@
public interface IAnnotationDeclaration extends ITextSourceReference {
/**
- * Return the annotation declaration. May be null.
+ * Returns the member value pairs.
*
- * @return the annotation declaration.
+ * @return the member value pairs
*/
-// IAnnotation getDeclaration();
-
IMemberValuePair[] getMemberValuePairs();
/**
+ * Convenience method that allows to get one member value without enumerating pairs.
+ * @param name
+ * @return
+ */
+ Object getMemberValue(String name);
+
+ /**
* Returns the member which is annotated by this declaration.
*
* @return the member which is annotated by this declaration
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java 2011-04-01
22:45:02 UTC (rev 30237)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java 2011-04-01
23:16:08 UTC (rev 30238)
@@ -21,7 +21,6 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IMember;
-import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.Signature;
import org.jboss.tools.cdi.core.CDIConstants;
@@ -278,11 +277,10 @@
}
}
- IMemberValuePair[] ps = typed.getMemberValuePairs();
- if(ps == null || ps.length == 0) return result;
+ Object value = typed.getMemberValue(null);
+ if(value == null) return result;
IMember member = (IMember)definition.getMember();
IType declaringType = member instanceof IType ? (IType)member :
member.getDeclaringType();
- Object value = ps[0].getValue();
if(value instanceof Object[]) {
Object[] os = (Object[])value;
for (int i = 0; i < os.length; i++) {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AnnotationDeclaration.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AnnotationDeclaration.java 2011-04-01
22:45:02 UTC (rev 30237)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AnnotationDeclaration.java 2011-04-01
23:16:08 UTC (rev 30238)
@@ -51,6 +51,19 @@
return annotation.getMemberValuePairs();
}
+ public Object getMemberValue(String name) {
+ if(name == null) name = "value";
+ IMemberValuePair[] pairs = getMemberValuePairs();
+ if(pairs != null) {
+ for (IMemberValuePair pair: pairs) {
+ if(name.equals(pair.getMemberName())) {
+ return pair.getValue();
+ }
+ }
+ }
+ return null;
+ }
+
public IMember getParentMember() {
return annotation.getParentMember();
}
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-01
22:45:02 UTC (rev 30237)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2011-04-01
23:16:08 UTC (rev 30238)
@@ -732,14 +732,8 @@
if(a instanceof AnnotationDeclaration) {
AnnotationDeclaration aa = (AnnotationDeclaration)a;
if(CDIConstants.NORMAL_SCOPE_ANNOTATION_TYPE_NAME.equals(aa.getTypeName())) {
- IMemberValuePair[] ps = a.getMemberValuePairs();
- if(ps != null) for (IMemberValuePair p: ps) {
- if("passivating".equals(p.getMemberName())) {
- Object o = p.getValue();
- return o != null && "true".equalsIgnoreCase(o.toString());
- }
- }
- return false;
+ Object o = a.getMemberValue("passivating");
+ return o != null && "true".equalsIgnoreCase(o.toString());
}
}
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java 2011-04-01
22:45:02 UTC (rev 30237)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java 2011-04-01
23:16:08 UTC (rev 30238)
@@ -20,7 +20,6 @@
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.jboss.tools.cdi.core.CDIConstants;
@@ -331,12 +330,9 @@
name = name.substring(0, 1).toLowerCase() + name.substring(1);
}
- IMemberValuePair[] vs = named.getMemberValuePairs();
- if(vs != null && vs.length > 0) {
- Object value = vs[0].getValue();
- if(value != null && value.toString().trim().length() > 0) {
- return value.toString().trim();
- }
+ Object value = named.getMemberValue(null);
+ if(value != null && value.toString().trim().length() > 0) {
+ return value.toString().trim();
}
return name;
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/JavaAnnotation.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/JavaAnnotation.java 2011-04-01
22:45:02 UTC (rev 30237)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/JavaAnnotation.java 2011-04-01
23:16:08 UTC (rev 30238)
@@ -89,4 +89,8 @@
return new IMemberValuePair[0];
}
+ public IAnnotation getAnnotation() {
+ return annotation;
+ }
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java 2011-04-01
22:45:02 UTC (rev 30237)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java 2011-04-01
23:16:08 UTC (rev 30238)
@@ -14,7 +14,6 @@
import java.util.HashSet;
import java.util.Set;
-import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IType;
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
@@ -102,17 +101,11 @@
AnnotationDeclaration named = findNamedAnnotation();
if(named == null) return null;
- String name = getField().getElementName();
- IMemberValuePair[] vs = named.getMemberValuePairs();
- if(vs == null || vs.length == 0) {
- return name;
- } else {
- Object value = vs[0].getValue();
- if(value != null && value.toString().trim().length() > 0) {
- return value.toString().trim();
- }
+ Object value = named.getMemberValue(null);
+ if(value != null && value.toString().trim().length() > 0) {
+ return value.toString().trim();
}
- return name;
+ return getField().getElementName();
}
public ITextSourceReference getNameLocation() {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java 2011-04-01
22:45:02 UTC (rev 30237)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java 2011-04-01
23:16:08 UTC (rev 30238)
@@ -14,7 +14,6 @@
import java.util.HashSet;
import java.util.Set;
-import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IType;
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
@@ -131,18 +130,13 @@
AnnotationDeclaration named = findNamedAnnotation();
if(named == null) return null;
+ Object value = named.getMemberValue(null);
+ if(value != null && value.toString().trim().length() > 0) {
+ return value.toString().trim();
+ }
String name = getMethod().getElementName();
-
- IMemberValuePair[] vs = named.getMemberValuePairs();
- if(vs == null || vs.length == 0) {
- if(BeanUtil.isGetter(getMethod())) {
- return BeanUtil.getPropertyName(name);
- }
- } else {
- Object value = vs[0].getValue();
- if(value != null && value.toString().trim().length() > 0) {
- return value.toString().trim();
- }
+ if(BeanUtil.isGetter(getMethod())) {
+ return BeanUtil.getPropertyName(name);
}
return name;
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java 2011-04-01
22:45:02 UTC (rev 30237)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java 2011-04-01
23:16:08 UTC (rev 30238)
@@ -374,6 +374,10 @@
public PackageDefinition getPackageDefinition(String packageName) {
return packageDefinitions.get(packageName);
}
+
+ public TypeDefinition getTypeDefinition(String fullyQualifiedName) {
+ return typeDefinitions.get(fullyQualifiedName);
+ }
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/AnnotationValidationDelegate.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/AnnotationValidationDelegate.java 2011-04-01
22:45:02 UTC (rev 30237)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/AnnotationValidationDelegate.java 2011-04-01
23:16:08 UTC (rev 30238)
@@ -14,7 +14,6 @@
import java.util.Set;
import org.eclipse.core.resources.IResource;
-import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.CDICorePlugin;
@@ -190,18 +189,14 @@
if(retention == null) {
validator.addError(message,
CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE,
CDIUtil.convertToSourceReference(type.getSourceType().getNameRange()), resource);
} else {
- IMemberValuePair[] ps = retention.getMemberValuePairs();
boolean ok = false;
- for (IMemberValuePair p: ps) {
- if(!"value".equals(p.getMemberName())) continue;
- Object o = p.getValue();
- if(o != null) {
- ok = true;
- String s = o.toString();
- int i = s.lastIndexOf('.');
- if(i >= 0) s = s.substring(i + 1);
- if(!"RUNTIME".equals(s)) ok = false;
- }
+ Object o = retention.getMemberValue(null);
+ if(o != null) {
+ ok = true;
+ String s = o.toString();
+ int i = s.lastIndexOf('.');
+ if(i >= 0) s = s.substring(i + 1);
+ if(!"RUNTIME".equals(s)) ok = false;
}
if(!ok) {
validator.addError(message,
CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, retention,
resource);
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-01
22:45:02 UTC (rev 30237)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2011-04-01
23:16:08 UTC (rev 30238)
@@ -1735,14 +1735,7 @@
if(scope!=null && scope.isNorlmalScope()) {
IAnnotationDeclaration normalScopeDeclaration =
scope.getAnnotationDeclaration(CDIConstants.NORMAL_SCOPE_ANNOTATION_TYPE_NAME);
if(normalScopeDeclaration != null) {
- boolean passivatingScope = false;
- IMemberValuePair[] pairs = normalScopeDeclaration.getMemberValuePairs();
- for (IMemberValuePair pair : pairs) {
- if("passivating".equals(pair.getMemberName()) &&
"true".equalsIgnoreCase("" + pair.getValue())) {
- passivatingScope = true;
- break;
- }
- }
+ boolean passivatingScope = "true".equalsIgnoreCase("" +
normalScopeDeclaration.getMemberValue("passivating"));
if(passivatingScope) {
boolean passivatingCapable = false;
Set<IParametedType> supers = bean.getAllTypes();
@@ -1826,24 +1819,20 @@
boolean markedAsWrong = false;
IAnnotationDeclaration target =
binding.getAnnotationDeclaration(CDIConstants.TARGET_ANNOTATION_TYPE_NAME);
if(target!=null) {
- IMemberValuePair[] ps = target.getMemberValuePairs();
- if (ps != null && ps.length==1) {
- IMemberValuePair pair = ps[0];
- Object value = pair.getValue();
- if(value != null && value instanceof Object[]) {
- Object[] values = (Object[]) value;
- if(values.length>1) {
- Set<IBeanMethod> methods = interceptor.getAllMethods();
- for (IBeanMethod method : methods) {
- if(method.isLifeCycleCallbackMethod()) {
- ITextSourceReference declaration =
CDIUtil.getAnnotationDeclaration(interceptor, binding);
- if(declaration==null) {
- declaration = interceptor.getInterceptorAnnotation();
- }
- addError(CDIValidationMessages.ILLEGAL_LIFECYCLE_CALLBACK_INTERCEPTOR_BINDING,
CDIPreferences.ILLEGAL_LIFECYCLE_CALLBACK_INTERCEPTOR_BINDING, declaration,
interceptor.getResource());
- markedAsWrong = true;
- break;
+ Object value = target.getMemberValue(null);
+ if(value != null && value instanceof Object[]) {
+ Object[] values = (Object[]) value;
+ if(values.length>1) {
+ Set<IBeanMethod> methods = interceptor.getAllMethods();
+ for (IBeanMethod method : methods) {
+ if(method.isLifeCycleCallbackMethod()) {
+ ITextSourceReference declaration = CDIUtil.getAnnotationDeclaration(interceptor,
binding);
+ if(declaration==null) {
+ declaration = interceptor.getInterceptorAnnotation();
}
+ addError(CDIValidationMessages.ILLEGAL_LIFECYCLE_CALLBACK_INTERCEPTOR_BINDING,
CDIPreferences.ILLEGAL_LIFECYCLE_CALLBACK_INTERCEPTOR_BINDING, declaration,
interceptor.getResource());
+ markedAsWrong = true;
+ break;
}
}
}
@@ -2156,13 +2145,10 @@
// 1. non-empty name
IAnnotationDeclaration nameDeclaration = stereotype.getNameDeclaration();
if (nameDeclaration != null) {
- IMemberValuePair[] ps = nameDeclaration.getMemberValuePairs();
- if (ps != null && ps.length > 0) {
- Object name = ps[0].getValue();
- if (name != null && name.toString().length() > 0) {
- ITextSourceReference location = nameDeclaration;
- addError(CDIValidationMessages.STEREOTYPE_DECLARES_NON_EMPTY_NAME,
CDIPreferences.STEREOTYPE_DECLARES_NON_EMPTY_NAME, location, resource);
- }
+ Object name = nameDeclaration.getMemberValue(null);
+ if (name != null && name.toString().length() > 0) {
+ ITextSourceReference location = nameDeclaration;
+ addError(CDIValidationMessages.STEREOTYPE_DECLARES_NON_EMPTY_NAME,
CDIPreferences.STEREOTYPE_DECLARES_NON_EMPTY_NAME, location, resource);
}
}