Author: scabanovich
Date: 2011-12-15 18:15:41 -0500 (Thu, 15 Dec 2011)
New Revision: 37378
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/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-10496
https://issues.jboss.org/browse/JBIDE-10496
CDIUtil.convertToSourceReference should return instance of IJavaSourceReference when Java
element is available.
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-12-15
21:30:08 UTC (rev 37377)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2011-12-15
23:15:41 UTC (rev 37378)
@@ -39,6 +39,7 @@
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.ILocalVariable;
+import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
@@ -64,6 +65,7 @@
import org.jboss.tools.common.java.IAnnotationDeclaration;
import org.jboss.tools.common.java.IAnnotationType;
import org.jboss.tools.common.java.IJavaReference;
+import org.jboss.tools.common.java.IJavaSourceReference;
import org.jboss.tools.common.java.IParametedType;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
@@ -904,8 +906,9 @@
* @param range
* @return
*/
- public static ITextSourceReference convertToSourceReference(final ISourceRange range,
final IResource resource) {
- return new ITextSourceReference() {
+ public static ITextSourceReference convertToSourceReference(final ISourceRange range,
final IResource resource, final IMember javaElement) {
+ if(javaElement == null || javaElement.getResource() == null ||
!javaElement.getResource().equals(resource)) {
+ return new ITextSourceReference() {
public int getStartPosition() {
return range.getOffset();
@@ -918,7 +921,26 @@
public IResource getResource() {
return resource;
}
- };
+ };
+ } else {
+ return new IJavaSourceReference() {
+ public IMember getSourceMember() {
+ return javaElement;
+ }
+ public IJavaElement getSourceElement() {
+ return javaElement;
+ }
+ public int getStartPosition() {
+ return range.getOffset();
+ }
+ public IResource getResource() {
+ return resource;
+ }
+ public int getLength() {
+ return range.getLength();
+ }
+ };
+ }
}
/**
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-12-15
21:30:08 UTC (rev 37377)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/AnnotationValidationDelegate.java 2011-12-15
23:15:41 UTC (rev 37378)
@@ -189,7 +189,7 @@
void validateRetentionAnnotation(ICDIAnnotation type, String message, IResource
resource, int message_id) throws JavaModelException {
IAnnotationDeclaration retention =
type.getAnnotationDeclaration(CDIConstants.RETENTION_ANNOTATION_TYPE_NAME);
if(retention == null) {
- validator.addError(message,
CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE,
CDIUtil.convertToSourceReference(type.getSourceType().getNameRange(), resource), resource,
message_id);
+ validator.addError(message,
CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE,
CDIUtil.convertToSourceReference(type.getSourceType().getNameRange(), resource,
type.getSourceType()), resource, message_id);
} else {
Object o = retention.getMemberValue(null);
if(o == null || !CDIConstants.RETENTION_POLICY_RUNTIME_TYPE_NAME.equals(o.toString()))
{
@@ -214,7 +214,7 @@
private void validateTargetAnnotation(ICDIAnnotation annotationType, String[][]
variants, String message, IResource resource, int message_id) throws JavaModelException {
IAnnotationDeclaration target =
annotationType.getAnnotationDeclaration(CDIConstants.TARGET_ANNOTATION_TYPE_NAME);
if(target==null) {
- validator.addError(message,
CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE,
CDIUtil.convertToSourceReference(annotationType.getSourceType().getNameRange(), resource),
resource, message_id);
+ validator.addError(message,
CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE,
CDIUtil.convertToSourceReference(annotationType.getSourceType().getNameRange(), resource,
annotationType.getSourceType()), resource, message_id);
} else if(!CDIUtil.checkTargetAnnotation(target, variants)) {
validator.addError(message,
CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, target,
resource, message_id);
}
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-12-15
21:30:08 UTC (rev 37377)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2011-12-15
23:15:41 UTC (rev 37378)
@@ -793,14 +793,14 @@
try {
if(hasConflictedInterceptorBindings(bean)) {
//TODO consider putting markers to interceptor bindings/stereotype declarations.
- ITextSourceReference reference =
CDIUtil.convertToSourceReference(bean.getBeanClass().getNameRange(), bean.getResource());
+ ITextSourceReference reference =
CDIUtil.convertToSourceReference(bean.getBeanClass().getNameRange(), bean.getResource(),
bean.getBeanClass());
addError(CDIValidationMessages.CONFLICTING_INTERCEPTOR_BINDINGS,
CDIPreferences.CONFLICTING_INTERCEPTOR_BINDINGS, reference, bean.getResource());
}
Set<IBeanMethod> methods = bean.getAllMethods();
for (IBeanMethod method : methods) {
if(hasConflictedInterceptorBindings(method)) {
//TODO consider putting markers to interceptor bindings/stereotype declarations.
- ITextSourceReference reference =
CDIUtil.convertToSourceReference(method.getMethod().getNameRange(), bean.getResource());
+ ITextSourceReference reference =
CDIUtil.convertToSourceReference(method.getMethod().getNameRange(), bean.getResource(),
method.getMethod());
addError(CDIValidationMessages.CONFLICTING_INTERCEPTOR_BINDINGS,
CDIPreferences.CONFLICTING_INTERCEPTOR_BINDINGS, reference, bean.getResource());
}
}
@@ -1873,7 +1873,7 @@
IField[] fields = type.getFields();
for (IField field : fields) {
if (Flags.isPublic(field.getFlags()) && !Flags.isStatic(field.getFlags()))
{
- ITextSourceReference fieldReference =
CDIUtil.convertToSourceReference(field.getNameRange(), bean.getResource());
+ ITextSourceReference fieldReference =
CDIUtil.convertToSourceReference(field.getNameRange(), bean.getResource(), field);
addError(CDIValidationMessages.ILLEGAL_SCOPE_FOR_MANAGED_BEAN_WITH_PUBLIC_FIELD,
CDIPreferences.ILLEGAL_SCOPE_FOR_BEAN,
fieldReference, bean.getResource(),
ILLEGAL_SCOPE_FOR_MANAGED_BEAN_WITH_PUBLIC_FIELD_ID);
}
@@ -1941,14 +1941,14 @@
Set<IInterceptorBinding> bindings = bean.getInterceptorBindings();
if(!bindings.isEmpty()) {
if(Flags.isFinal(bean.getBeanClass().getFlags())) {
- ITextSourceReference reference =
CDIUtil.convertToSourceReference(bean.getBeanClass().getNameRange(), bean.getResource());
+ ITextSourceReference reference =
CDIUtil.convertToSourceReference(bean.getBeanClass().getNameRange(), bean.getResource(),
bean.getBeanClass());
addError(CDIValidationMessages.ILLEGAL_INTERCEPTOR_BINDING_CLASS,
CDIPreferences.ILLEGAL_INTERCEPTOR_BINDING_METHOD, reference, bean.getResource());
} else {
IMethod[] methods = bean.getBeanClass().getMethods();
for (int i = 0; i < methods.length; i++) {
int flags = methods[i].getFlags();
if(Flags.isFinal(flags) && !Flags.isStatic(flags) &&
!Flags.isPrivate(flags)) {
- ITextSourceReference reference =
CDIUtil.convertToSourceReference(methods[i].getNameRange(), bean.getResource());
+ ITextSourceReference reference =
CDIUtil.convertToSourceReference(methods[i].getNameRange(), bean.getResource(),
methods[i]);
addError(CDIValidationMessages.ILLEGAL_INTERCEPTOR_BINDING_METHOD,
CDIPreferences.ILLEGAL_INTERCEPTOR_BINDING_METHOD, reference, bean.getResource());
}
}
@@ -1958,13 +1958,13 @@
for (IBeanMethod method : beanMethods) {
if(!method.getInterceptorBindings().isEmpty()) {
if(Flags.isFinal(bean.getBeanClass().getFlags())) {
- ITextSourceReference reference =
CDIUtil.convertToSourceReference(bean.getBeanClass().getNameRange(), bean.getResource());
+ ITextSourceReference reference =
CDIUtil.convertToSourceReference(bean.getBeanClass().getNameRange(), bean.getResource(),
bean.getBeanClass());
addError(CDIValidationMessages.ILLEGAL_INTERCEPTOR_BINDING_CLASS,
CDIPreferences.ILLEGAL_INTERCEPTOR_BINDING_METHOD, reference, bean.getResource());
} else {
IMethod sourceMethod = method.getMethod();
int flags = sourceMethod.getFlags();
if(Flags.isFinal(flags) && !Flags.isStatic(flags) &&
!Flags.isPrivate(flags)) {
- ITextSourceReference reference =
CDIUtil.convertToSourceReference(sourceMethod.getNameRange(), bean.getResource());
+ ITextSourceReference reference =
CDIUtil.convertToSourceReference(sourceMethod.getNameRange(), bean.getResource(),
sourceMethod);
addError(CDIValidationMessages.ILLEGAL_INTERCEPTOR_BINDING_METHOD,
CDIPreferences.ILLEGAL_INTERCEPTOR_BINDING_METHOD, reference, bean.getResource());
}
}
@@ -1991,7 +1991,7 @@
}
}
if(!passivatingCapable) {
- ITextSourceReference reference =
CDIUtil.convertToSourceReference(bean.getBeanClass().getNameRange(), bean.getResource());
+ ITextSourceReference reference =
CDIUtil.convertToSourceReference(bean.getBeanClass().getNameRange(), bean.getResource(),
bean.getBeanClass());
addError(MessageFormat.format(CDIValidationMessages.NOT_PASSIVATION_CAPABLE_BEAN,
bean.getElementName(), scope.getSourceType().getElementName()),
CDIPreferences.NOT_PASSIVATION_CAPABLE_BEAN, reference, bean.getResource(),
NOT_PASSIVATION_CAPABLE_BEAN_ID);
}
}
@@ -2492,7 +2492,7 @@
int kind = Signature.getTypeSignatureKind(returnTypeSignature);
if(kind == Signature.ARRAY_TYPE_SIGNATURE) {
if(!annotation.getNonBindingMethods().contains(method)) {
- ITextSourceReference reference =
CDIUtil.convertToSourceReference(method.getNameRange(), annotation.getResource());
+ ITextSourceReference reference =
CDIUtil.convertToSourceReference(method.getNameRange(), annotation.getResource(),
method);
addError(arrayMessageErrorKey, preferencesKey, reference, annotation.getResource(),
arrayMessageId);
}
} else if(kind == Signature.CLASS_TYPE_SIGNATURE) {
@@ -2507,7 +2507,7 @@
IType memberType = type.getJavaProject().findType(typeName);
if(memberType!=null && memberType.isAnnotation()) {
if(!annotation.getNonBindingMethods().contains(method)) {
- ITextSourceReference reference =
CDIUtil.convertToSourceReference(method.getNameRange(), annotation.getResource());
+ ITextSourceReference reference =
CDIUtil.convertToSourceReference(method.getNameRange(), annotation.getResource(),
method);
addError(annotationValueErrorKey, preferencesKey, reference,
annotation.getResource(), annotationValueId);
}
}