Author: scabanovich
Date: 2011-10-18 18:56:52 -0400 (Tue, 18 Oct 2011)
New Revision: 35775
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/CDISeamSolderDefaultBeanExtension.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/CDISeamSolderPreferences.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/validation/SeamSolderValidationMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/validation/messages.properties
Log:
JBIDE-9244
https://issues.jboss.org/browse/JBIDE-9244
Implemented validation of default beans (Solder).
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/CDISeamSolderDefaultBeanExtension.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/CDISeamSolderDefaultBeanExtension.java 2011-10-18
20:52:33 UTC (rev 35774)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/CDISeamSolderDefaultBeanExtension.java 2011-10-18
22:56:52 UTC (rev 35775)
@@ -14,23 +14,38 @@
import java.util.List;
import java.util.Set;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IType;
+import org.eclipse.osgi.util.NLS;
import org.jboss.tools.cdi.core.CDIConstants;
+import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.cdi.core.IClassBean;
import org.jboss.tools.cdi.core.IProducer;
+import org.jboss.tools.cdi.core.IProducerField;
+import org.jboss.tools.cdi.core.IQualifierDeclaration;
import org.jboss.tools.cdi.core.IRootDefinitionContext;
+import org.jboss.tools.cdi.core.IScope;
import org.jboss.tools.cdi.core.extension.ICDIExtension;
import org.jboss.tools.cdi.core.extension.feature.IAmbiguousBeanResolverFeature;
import org.jboss.tools.cdi.core.extension.feature.IProcessAnnotatedTypeFeature;
+import org.jboss.tools.cdi.core.extension.feature.IValidatorFeature;
+import org.jboss.tools.cdi.internal.core.impl.CDIProject;
import org.jboss.tools.cdi.internal.core.impl.definition.AbstractMemberDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.FieldDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.MethodDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.TypeDefinition;
+import org.jboss.tools.cdi.internal.core.validation.CDICoreValidator;
+import org.jboss.tools.cdi.seam.solder.core.validation.SeamSolderValidationMessages;
import org.jboss.tools.common.java.IAnnotationDeclaration;
import org.jboss.tools.common.java.IJavaAnnotation;
+import org.jboss.tools.common.java.IParametedType;
+import org.jboss.tools.common.java.ParametedTypeFactory;
import org.jboss.tools.common.java.impl.AnnotationLiteral;
+import org.jboss.tools.common.preferences.SeverityPreferences;
/**
* Implements support for org.jboss.seam.solder.bean.defaultbean.DefaultBeanExtension.
@@ -44,7 +59,7 @@
* @author Viacheslav Kabanovich
*
*/
-public class CDISeamSolderDefaultBeanExtension implements ICDIExtension,
IProcessAnnotatedTypeFeature, IAmbiguousBeanResolverFeature {
+public class CDISeamSolderDefaultBeanExtension implements ICDIExtension,
IProcessAnnotatedTypeFeature, IAmbiguousBeanResolverFeature, IValidatorFeature {
protected Version getVersion() {
return Version.instance;
@@ -119,4 +134,58 @@
return result;
}
+ public void validateResource(IFile file, CDICoreValidator validator) {
+ String defaultBeanAnnotationTypeName =
getVersion().getDefaultBeanAnnotationTypeName();
+ ICDIProject cdiProject = CDICorePlugin.getCDIProject(file.getProject(), true);
+ Set<IBean> bs = cdiProject.getBeans(file.getFullPath());
+ for (IBean bean: bs) {
+ IAnnotationDeclaration a = bean.getAnnotation(defaultBeanAnnotationTypeName);
+ if(a != null) {
+ if(bean instanceof IProducerField) {
+ IClassBean cb = ((IProducerField) bean).getClassBean();
+ IScope scope = cb.getScope();
+ if(scope != null && scope.isNorlmalScope()) {
+ validator.addError(SeamSolderValidationMessages.DEFAULT_PRODUCER_FIELD_ON_NORMAL_SCOPED_BEAN,
+ CDISeamSolderPreferences.DEFAULT_PRODUCER_FIELD_ON_NORMAL_SCOPED_BEAN, new
String[]{}, a, file);
+ }
+ }
+ IQualifierDeclaration[] qs = bean.getQualifierDeclarations().toArray(new
IQualifierDeclaration[0]);
+ Set<IParametedType> ts = bean.getLegalTypes();
+ if(ts.size() < 3) {
+ IParametedType type = null;
+ for (IParametedType t: ts) {
+ if(!"java.lang.Object".equals(t.getType().getFullyQualifiedName())) {
+ type = t;
+ }
+ }
+ if(type != null) {
+ Set<IBean> bs2 = cdiProject.getBeans(false, type, qs);
+ StringBuilder otherDefaultBeans = new StringBuilder();
+ for (IBean b: bs2) {
+ try {
+ if(b != bean && b.isAnnotationPresent(defaultBeanAnnotationTypeName)
+ && CDIProject.areMatchingQualifiers(bean.getQualifierDeclarations(),
b.getQualifierDeclarations(true))) {
+ if(otherDefaultBeans.length() > 0) {
+ otherDefaultBeans.append(", ");
+ }
+ otherDefaultBeans.append(b.getElementName());
+ }
+ } catch (CoreException e) {
+ CDISeamSolderCorePlugin.getDefault().logError(e);
+ }
+ }
+ if(otherDefaultBeans.length() > 0) {
+ String message = NLS.bind(SeamSolderValidationMessages.IDENTICAL_DEFAULT_BEANS,
otherDefaultBeans);
+ validator.addError(message, CDISeamSolderPreferences.IDENTICAL_DEFAULT_BEANS, new
String[]{}, a, file);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public SeverityPreferences getSeverityPreferences() {
+ return CDISeamSolderPreferences.getInstance();
+ }
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/CDISeamSolderPreferences.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/CDISeamSolderPreferences.java 2011-10-18
20:52:33 UTC (rev 35774)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/CDISeamSolderPreferences.java 2011-10-18
22:56:52 UTC (rev 35775)
@@ -29,6 +29,9 @@
public static final String WRONG_TYPE_OF_GENERIC_CONFIGURATION_POINT =
INSTANCE.createSeverityOption("wrongTypeOfGenericConfigurationPoint");
public static final String WRONG_GENERIC_CONFIGURATION_ANNOTATION_REFERENCE =
INSTANCE.createSeverityOption("wrongGenericConfigurationAnnotationReference");
public static final String GENERIC_CONFIGURATION_TYPE_IS_A_GENERIC_BEAN =
INSTANCE.createSeverityOption("genericConfigurationTypeIsGenericBean");
+
+ public static final String DEFAULT_PRODUCER_FIELD_ON_NORMAL_SCOPED_BEAN =
INSTANCE.createSeverityOption("defaultProducerFieldOnNormalScopedBean");
+ public static final String IDENTICAL_DEFAULT_BEANS =
INSTANCE.createSeverityOption("identicalDefaultBeans");
public static CDISeamSolderPreferences getInstance() {
return INSTANCE;
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/validation/SeamSolderValidationMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/validation/SeamSolderValidationMessages.java 2011-10-18
20:52:33 UTC (rev 35774)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/validation/SeamSolderValidationMessages.java 2011-10-18
22:56:52 UTC (rev 35775)
@@ -26,6 +26,9 @@
public static String WRONG_GENERIC_CONFIGURATION_ANNOTATION_REFERENCE;
public static String GENERIC_CONFIGURATION_TYPE_IS_A_GENERIC_BEAN;
+ public static String DEFAULT_PRODUCER_FIELD_ON_NORMAL_SCOPED_BEAN;
+ public static String IDENTICAL_DEFAULT_BEANS;
+
static {
NLS.initializeMessages(BUNDLE_NAME, SeamSolderValidationMessages.class);
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/validation/messages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/validation/messages.properties 2011-10-18
20:52:33 UTC (rev 35774)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.solder.core/src/org/jboss/tools/cdi/seam/solder/core/validation/messages.properties 2011-10-18
22:56:52 UTC (rev 35775)
@@ -2,3 +2,6 @@
WRONG_TYPE_OF_GENERIC_CONFIGURATION_POINT=Type of generic configuration point must be
assignable to the generic configuration type.
WRONG_GENERIC_CONFIGURATION_ANNOTATION_REFERENCE=Annotation type mismatch: {0} is not a
generic configuration annotation.
GENERIC_CONFIGURATION_TYPE_IS_A_GENERIC_BEAN=Generic configuration types may not be
generic beans.
+
+DEFAULT_PRODUCER_FIELD_ON_NORMAL_SCOPED_BEAN=Default producer fields are not allowed on
normal scoped beans.
+IDENTICAL_DEFAULT_BEANS=Other default beans have the same type and qualifiers: {0}