Author: scabanovich
Date: 2011-12-15 20:35:14 -0500 (Thu, 15 Dec 2011)
New Revision: 37384
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/impl/AbstractBeanElement.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
ITypeDeclaration converted to IJavaSourceReference when it is relevant.
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-16
00:37:58 UTC (rev 37383)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2011-12-16
01:35:14 UTC (rev 37384)
@@ -67,6 +67,7 @@
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.java.ITypeDeclaration;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.text.ITextSourceReference;
@@ -944,6 +945,39 @@
}
/**
+ * Converts ITypeDeclaration reference to IJavaSourceReference if
+ * 1) javaElement is not null,
+ * 2) reference and javaElement are declared in the same resource
+ *
+ * @param reference
+ * @param javaElement
+ * @return
+ */
+ public static ITextSourceReference convertToJavaSourceReference(final
ITextSourceReference reference, final IMember javaElement) {
+ if(reference instanceof IJavaSourceReference || javaElement == null
+ || (reference.getResource() != null &&
!(reference.getResource().equals(javaElement.getResource())))) {
+ return reference;
+ }
+ return new IJavaSourceReference() {
+ public IMember getSourceMember() {
+ return javaElement;
+ }
+ public IJavaElement getSourceElement() {
+ return javaElement;
+ }
+ public int getStartPosition() {
+ return reference.getStartPosition();
+ }
+ public IResource getResource() {
+ return reference.getResource();
+ }
+ public int getLength() {
+ return reference.getLength();
+ }
+ };
+ }
+
+ /**
* Returns true if the injection point declares @Default qualifier or doesn't
declare any qualifier at all.
*
* @param point
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-12-16
00:37:58 UTC (rev 37383)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java 2011-12-16
01:35:14 UTC (rev 37384)
@@ -18,6 +18,7 @@
import java.util.Set;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IType;
@@ -57,6 +58,7 @@
import org.jboss.tools.common.java.TypeDeclaration;
import org.jboss.tools.common.model.ui.editor.EditorPartWrapper;
import org.jboss.tools.common.text.ITextSourceReference;
+import org.jboss.tools.common.util.FileUtil;
/**
*
@@ -292,7 +294,13 @@
String txt = null;
if(s >= 0 && typed.getResource() instanceof IFile) {
AbstractTypeDefinition td = getDefinition().getTypeDefinition();
- if(td != null) {
+ if(getDefinition().getOriginalDefinition() != null) {
+ ITextSourceReference r = getDefinition().getOriginalDefinition();
+ String content = FileUtil.readStream((IFile)r.getResource());
+ if(content != null && content.length() > s + l) {
+ txt = content.substring(s);
+ }
+ } else if(td != null) {
String content = td.getContent();
if(content != null && content.length() > s + l) {
txt = content.substring(s, s + l);
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-16
00:37:58 UTC (rev 37383)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2011-12-16
01:35:14 UTC (rev 37384)
@@ -34,6 +34,8 @@
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
@@ -88,9 +90,11 @@
import org.jboss.tools.cdi.internal.core.impl.SessionBean;
import org.jboss.tools.cdi.internal.core.impl.definition.Dependencies;
import org.jboss.tools.common.java.IAnnotationDeclaration;
+import org.jboss.tools.common.java.IJavaReference;
import org.jboss.tools.common.java.IParametedType;
import org.jboss.tools.common.java.ITypeDeclaration;
import org.jboss.tools.common.java.ParametedType;
+import org.jboss.tools.common.java.TypeDeclaration;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.text.INodeReference;
@@ -1224,6 +1228,7 @@
Set<ITypeDeclaration> typeDeclarations = producer.getAllTypeDeclarations();
String[] typeVariables = producer.getBeanClass().getTypeParameterSignatures();
ITypeDeclaration typeDeclaration = null;
+ ITextSourceReference typeDeclarationReference = null;
if (!typeDeclarations.isEmpty()) {
/*
* 3.3. Producer methods
@@ -1236,16 +1241,20 @@
* - producer field type contains a wildcard type parameter
*/
typeDeclaration = typeDeclarations.iterator().next();
+
+ typeDeclarationReference = CDIUtil.convertToJavaSourceReference(typeDeclaration,
producer.getSourceMember());
+
+
String[] paramTypes = Signature.getTypeArguments(typeDeclaration.getSignature());
boolean variable = false;
for (String paramType : paramTypes) {
if (Signature.getTypeSignatureKind(paramType) == Signature.WILDCARD_TYPE_SIGNATURE)
{
if (producer instanceof IProducerField) {
- addError(CDIValidationMessages.PRODUCER_FIELD_TYPE_HAS_WILDCARD,
CDIPreferences.PRODUCER_METHOD_RETURN_TYPE_HAS_WILDCARD_OR_VARIABLE, typeDeclaration,
+ addError(CDIValidationMessages.PRODUCER_FIELD_TYPE_HAS_WILDCARD,
CDIPreferences.PRODUCER_METHOD_RETURN_TYPE_HAS_WILDCARD_OR_VARIABLE,
typeDeclarationReference,
producer.getResource());
} else {
addError(CDIValidationMessages.PRODUCER_METHOD_RETURN_TYPE_HAS_WILDCARD,
CDIPreferences.PRODUCER_METHOD_RETURN_TYPE_HAS_WILDCARD_OR_VARIABLE,
- typeDeclaration, producer.getResource());
+ typeDeclarationReference, producer.getResource());
}
} else if(!variable && isTypeVariable(producer,
Signature.toString(paramType), typeVariables)) {
/*
@@ -1306,7 +1315,7 @@
for (String variableSig : typeVariables) {
String variableName = Signature.getTypeVariable(variableSig);
if (typeString.equals(variableName)) {
- addError(CDIValidationMessages.PRODUCER_FIELD_TYPE_IS_VARIABLE,
CDIPreferences.PRODUCER_METHOD_RETURN_TYPE_HAS_WILDCARD_OR_VARIABLE, typeDeclaration !=
null ? typeDeclaration : producer, producer.getResource());
+ addError(CDIValidationMessages.PRODUCER_FIELD_TYPE_IS_VARIABLE,
CDIPreferences.PRODUCER_METHOD_RETURN_TYPE_HAS_WILDCARD_OR_VARIABLE, typeDeclaration !=
null ? typeDeclarationReference : producer, producer.getResource());
}
}
}
@@ -1372,7 +1381,7 @@
String typeString = Signature.toString(typeSign);
if(isTypeVariable(producerMethod, typeString, typeVariables)) {
addError(CDIValidationMessages.PRODUCER_METHOD_RETURN_TYPE_IS_VARIABLE,
CDIPreferences.PRODUCER_METHOD_RETURN_TYPE_HAS_WILDCARD_OR_VARIABLE,
- typeDeclaration != null ? typeDeclaration : producer, producer.getResource());
+ typeDeclaration != null ? typeDeclarationReference : producer,
producer.getResource());
}
/*
* 3.3.2. Declaring a producer method
@@ -2214,7 +2223,7 @@
} else {
ITextSourceReference declaration = delegate.getDelegateAnnotation();
if(delegateParametedType instanceof ITypeDeclaration) {
- declaration = (ITypeDeclaration)delegateParametedType;
+ declaration =
CDIUtil.convertToJavaSourceReference((ITypeDeclaration)delegateParametedType,
delegate.getSourceMember());
}
String typeName =
Signature.getSignatureSimpleName(decoratedParametedType.getSignature());
addError(MessageFormat.format(CDIValidationMessages.DELEGATE_HAS_ILLEGAL_TYPE,
typeName), CDIPreferences.DELEGATE_HAS_ILLEGAL_TYPE, declaration,
decorator.getResource());
@@ -2270,7 +2279,7 @@
*/
private void validateTyped(IBean bean) {
Set<ITypeDeclaration> typedDeclarations = bean.getRestrictedTypeDeclaratios();
- if (!typedDeclarations.isEmpty()) {
+ if (!typedDeclarations.isEmpty()) {
Set<IParametedType> allTypes = bean.getAllTypes();
for (ITypeDeclaration typedDeclaration : typedDeclarations) {
IType typedType = typedDeclaration.getType();
@@ -2283,8 +2292,11 @@
}
}
if (!typeWasFound) {
+ IMember e = bean instanceof IJavaReference ?
((IJavaReference)bean).getSourceMember() : bean.getBeanClass();
+ ITextSourceReference typedDeclarationReference =
CDIUtil.convertToJavaSourceReference(typedDeclaration, e);
+
String message = CDIValidationMessages.ILLEGAL_TYPE_IN_TYPED_DECLARATION;
- addError(message, CDIPreferences.ILLEGAL_TYPE_IN_TYPED_DECLARATION,
typedDeclaration, bean.getResource());
+ addError(message, CDIPreferences.ILLEGAL_TYPE_IN_TYPED_DECLARATION,
typedDeclarationReference, bean.getResource());
}
}
}