Author: scabanovich
Date: 2010-12-02 10:16:30 -0500 (Thu, 02 Dec 2010)
New Revision: 27102
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/ImplementationCollector.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.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/validation/CDICoreValidator.java
Log:
JBIDE-7721
https://jira.jboss.org/browse/JBIDE-7721
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2010-12-02
15:09:46 UTC (rev 27101)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2010-12-02
15:16:30 UTC (rev 27102)
@@ -70,6 +70,11 @@
public String INJECTIONPOINT_TYPE_NAME =
"javax.enterprise.inject.spi.InjectionPoint";
+ public String DECORATOR_SIMPLE_NAME = "Decorator";
+ public String DECORATOR_TYPE_NAME = "javax.enterprise.inject.spi.Decorator";
+ public String INTERCEPTOR_SIMPLE_NAME = "Interceptor";
+ public String INTERCEPTOR_TYPE_NAME =
"javax.enterprise.inject.spi.Interceptor";
+
public String INSTANCE_TYPE_NAME = "javax.enterprise.inject.Instance";
public String PRE_DESTROY_TYPE_NAME = "javax.annotation.PreDestroy";
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 2010-12-02
15:09:46 UTC (rev 27101)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2010-12-02
15:16:30 UTC (rev 27102)
@@ -59,6 +59,7 @@
import org.jboss.tools.cdi.internal.core.impl.definition.BeansXMLDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.DefinitionContext;
import org.jboss.tools.cdi.internal.core.impl.definition.TypeDefinition;
+import org.jboss.tools.cdi.internal.core.scanner.ImplementationCollector;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
@@ -1129,12 +1130,14 @@
List<TypeDefinition> typeDefinitions = getAllTypeDefinitions();
List<IBean> beans = new ArrayList<IBean>();
Map<IType, ClassBean> newClassBeans = new HashMap<IType, ClassBean>();
+
+ ImplementationCollector ic = new ImplementationCollector(typeDefinitions);
for (TypeDefinition typeDefinition : typeDefinitions) {
ClassBean bean = null;
- if(typeDefinition.getInterceptorAnnotation() != null) {
+ if(typeDefinition.getInterceptorAnnotation() != null ||
ic.isInterceptor(typeDefinition.getType())) {
bean = new InterceptorBean();
- } else if(typeDefinition.getDecoratorAnnotation() != null) {
+ } else if(typeDefinition.getDecoratorAnnotation() != null ||
ic.isDecorator(typeDefinition.getType())) {
bean = new DecoratorBean();
} else if(typeDefinition.getStatefulAnnotation() != null ||
typeDefinition.getStatelessAnnotation() != null || typeDefinition.getSingletonAnnotation()
!= null) {
bean = new SessionBean();
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/ImplementationCollector.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/ImplementationCollector.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/ImplementationCollector.java 2010-12-02
15:16:30 UTC (rev 27102)
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.internal.core.scanner;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.jboss.tools.cdi.core.CDIConstants;
+import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.core.IParametedType;
+import org.jboss.tools.cdi.internal.core.impl.definition.TypeDefinition;
+
+public class ImplementationCollector {
+ List<TypeDefinition> typeDefinitions;
+ Set<IType> decorators = new HashSet<IType>();
+ Set<IType> interceptors = new HashSet<IType>();
+
+ public ImplementationCollector(List<TypeDefinition> typeDefinitions) {
+ this.typeDefinitions = typeDefinitions;
+// long t = System.currentTimeMillis();
+ try {
+ process();
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+// long dt = System.currentTimeMillis() - t;
+// System.out.println("ImplementationCollector: " + dt + " ms for "
+ typeDefinitions.size() + " types.");
+ }
+
+ void process() throws JavaModelException {
+ for (TypeDefinition typeDef: typeDefinitions) {
+ IType type = typeDef.getType();
+ if(type == null || type.isInterface()) continue;
+ if(!mayBeRelevant(type)) continue;
+ Set<IParametedType> types = typeDef.getInheritedTypes();
+ for (IParametedType t: types) {
+ IType q = t.getType();
+ if(q == null) continue;
+ String cn = q.getFullyQualifiedName();
+ boolean isDecorator = CDIConstants.DECORATOR_TYPE_NAME.equals(cn);
+ boolean isInterceptor = CDIConstants.INTERCEPTOR_TYPE_NAME.equals(cn);
+ if(isDecorator || isInterceptor) {
+ List<? extends IParametedType> ps = t.getParameters();
+ if( ps != null) for (IParametedType p: ps) {
+ IType pt = p.getType();
+ if(pt != null) {
+ if(isDecorator) {
+ decorators.add(pt);
+ }
+ if(isInterceptor) {
+ interceptors.add(pt);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ boolean mayBeRelevant(IType type) throws JavaModelException {
+ String[] is = type.getSuperInterfaceNames();
+ if(is != null) for (String s: is) {
+ if(s.indexOf(CDIConstants.DECORATOR_SIMPLE_NAME) >= 0) return true;
+ if(s.indexOf(CDIConstants.INTERCEPTOR_SIMPLE_NAME) >= 0) return true;
+ }
+ return false;
+ }
+
+ public boolean isDecorator(IType type) {
+ return decorators.contains(type);
+ }
+
+ public boolean isInterceptor(IType type) {
+ return interceptors.contains(type);
+ }
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/ImplementationCollector.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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 2010-12-02
15:09:46 UTC (rev 27101)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-12-02
15:16:30 UTC (rev 27102)
@@ -939,7 +939,11 @@
*/
if (bean instanceof IDecorator) {
IDecorator decorator = (IDecorator) bean;
- IAnnotationDeclaration decoratorDeclaration = decorator.getDecoratorAnnotation();
+ ITextSourceReference decoratorDeclaration = decorator.getDecoratorAnnotation();
+ if(decoratorDeclaration == null) {
+ //for custom implementations
+ decoratorDeclaration = decorator.getNameLocation();
+ }
addError(CDIValidationMessages.DISPOSER_IN_DECORATOR,
CDIPreferences.DISPOSER_IN_INTERCEPTOR_OR_DECORATOR, decoratorDeclaration, bean
.getResource());
for (ITextSourceReference declaration : disposerDeclarations) {
@@ -953,7 +957,11 @@
*/
if (bean instanceof IInterceptor) {
IInterceptor interceptor = (IInterceptor) bean;
- IAnnotationDeclaration interceptorDeclaration =
interceptor.getInterceptorAnnotation();
+ ITextSourceReference interceptorDeclaration =
interceptor.getInterceptorAnnotation();
+ if(interceptorDeclaration == null) {
+ //for custom implementations
+ interceptorDeclaration = interceptor.getNameLocation();
+ }
addError(CDIValidationMessages.DISPOSER_IN_INTERCEPTOR,
CDIPreferences.DISPOSER_IN_INTERCEPTOR_OR_DECORATOR, interceptorDeclaration, bean
.getResource());
for (ITextSourceReference declaration : disposerDeclarations) {
@@ -1695,6 +1703,10 @@
if (declaration == null) {
declaration = interceptor.getInterceptorAnnotation();
}
+ if(declaration == null) {
+ //for custom implementations
+ declaration = interceptor.getNameLocation();
+ }
addError(CDIValidationMessages.INTERCEPTOR_IS_ALTERNATIVE,
CDIPreferences.INTERCEPTOR_OR_DECORATOR_IS_ALTERNATIVE, declaration, interceptor
.getResource());
}
@@ -1787,6 +1799,10 @@
if (declaration == null) {
declaration = decorator.getDecoratorAnnotation();
}
+ if(declaration == null) {
+ //for custom implementations
+ declaration = decorator.getNameLocation();
+ }
addError(CDIValidationMessages.DECORATOR_IS_ALTERNATIVE,
CDIPreferences.INTERCEPTOR_OR_DECORATOR_IS_ALTERNATIVE, declaration,
decorator.getResource());
}