Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public interface CDIConstants {
public String NEW_QUALIFIER_TYPE_NAME = "javax.enterprise.inject.New";

public String VETOED_ANNOTATION_TYPE_NAME = "javax.enterprise.inject.Vetoed";
public String PRIORITY_ANNOTATION_TYPE_NAME = "javax.annotation.Priority";

public String STEREOTYPE_ANNOTATION_TYPE_NAME = "javax.enterprise.inject.Stereotype";
public String MODEL_STEREOTYPE_TYPE_NAME = "javax.enterprise.inject.Model";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,11 @@ public interface IClassBean extends IBean, IInterceptorBinded, IJavaReference {
* @return
*/
Collection<IInjectionPoint> getInjectionPoints(boolean all);

/**
* Returns value of annotation @Priority(int) if it is present for CDI 1.1.
* Otherwise, returns null.
* @return
*/
Integer getPriority();
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ public Collection<IBean> getResolvedBeans(Collection<IBean> result, boolean atte
return result;
}

boolean containsAlternatives = false;
Iterator<IBean> it = result.iterator();
Set<IBean> disabled = null;
Set<IBean> alternatives = null;
while(it.hasNext()) {
IBean b = it.next();
if(!b.isEnabled() || b instanceof IDecorator || b instanceof IInterceptor) {
Expand All @@ -245,15 +245,21 @@ public Collection<IBean> getResolvedBeans(Collection<IBean> result, boolean atte
}
if(b.isAlternative()) {
if(b.isSelectedAlternative()) {
containsAlternatives = true;
if(alternatives == null) {
alternatives = new HashSet<IBean>();
}
alternatives.add(b);
} else {
it.remove();
}
}
if(b instanceof IProducer && b instanceof IBeanMember) {
IBeanMember p = (IBeanMember)b;
if(p.getClassBean() != null && p.getClassBean().isAlternative()) {
containsAlternatives = true;
if(alternatives == null) {
alternatives = new HashSet<IBean>();
}
alternatives.add(b);
}
}
IBean bean = b.getSpecializedBean();
Expand All @@ -273,16 +279,38 @@ public Collection<IBean> getResolvedBeans(Collection<IBean> result, boolean atte
return result;
}

if(containsAlternatives) {
it = result.iterator();
while(it.hasNext()) {
IBean bean = it.next();
if(bean.isAlternative()) continue;
if(bean instanceof IProducer && bean instanceof IBeanMember) {
IBeanMember p = (IBeanMember)bean;
if(p.getClassBean() != null && p.getClassBean().isAlternative()) continue;
if(alternatives != null) {
result = alternatives;
if(result.size() < 2) {
return result;
}
alternatives = new HashSet<IBean>();
Integer maxPriority = null;
for (IBean b: result) {
Integer priority = null;
if(b instanceof IClassBean) {
priority = ((IClassBean)b).getPriority();
} else if(b instanceof IProducer && b instanceof IBeanMember) {
priority = ((IBeanMember)b).getClassBean().getPriority();
}
it.remove();
if(priority == null) {
maxPriority = null;
break;
} else {
if(maxPriority == null) {
maxPriority = priority;
alternatives.add(b);
} else if(priority.intValue() > maxPriority.intValue()) {
maxPriority = priority;
alternatives.clear();
alternatives.add(b);
} else if(priority.intValue() == maxPriority.intValue()) {
alternatives.add(b);
}
}
}
if(maxPriority != null) {
result = alternatives;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ public boolean isEnabled() {
return false;
}
if(isAlternative()) {
if(getAnnotation(CDIConstants.PRIORITY_ANNOTATION_TYPE_NAME) != null) {
return true;
}
if(getCDIProject().isClassAlternativeActivated(getDefinition().getQualifiedName())) {
return true;
}
Expand Down Expand Up @@ -568,8 +571,13 @@ public boolean isNullable() {
* @see org.jboss.tools.cdi.core.IBean#isSelectedAlternative()
*/
public boolean isSelectedAlternative() {
if(getDefinition().getAlternativeAnnotation() != null && getCDIProject().isTypeAlternative(getBeanClass().getFullyQualifiedName())) {
return true;
if(getDefinition().getAlternativeAnnotation() != null) {
if(getCDIProject().isTypeAlternative(getBeanClass().getFullyQualifiedName())) {
return true;
}
if(getAnnotation(CDIConstants.PRIORITY_ANNOTATION_TYPE_NAME) != null) {
return true;
}
}
for (IStereotypeDeclaration d: getStereotypeDeclarations(true)) {
IStereotype s = d.getStereotype();
Expand Down Expand Up @@ -637,4 +645,19 @@ public synchronized void cleanCache() {
f.setField(f.getField()); // type update
}
}

@Override
public Integer getPriority() {
IAnnotationDeclaration d = getAnnotation(CDIConstants.PRIORITY_ANNOTATION_TYPE_NAME);
if(d instanceof AnnotationDeclaration) {
Object o = ((AnnotationDeclaration)d).getMemberConstantValue(null);
if(o == null) {
o = d.getMemberValue(null);
}
if(o instanceof Integer) {
return (Integer)o;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

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.IDecorator;
import org.jboss.tools.common.java.IAnnotationDeclaration;
Expand Down Expand Up @@ -65,6 +66,7 @@ public IAnnotationDeclaration getDecoratorAnnotation() {
*/
@Override
public boolean isEnabled() {
return !getCDIProject().getDecoratorClasses(getBeanClass().getFullyQualifiedName()).isEmpty();
return !getCDIProject().getDecoratorClasses(getBeanClass().getFullyQualifiedName()).isEmpty()
|| getAnnotation(CDIConstants.PRIORITY_ANNOTATION_TYPE_NAME) != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.cdi.internal.core.impl;

import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.IInterceptor;
import org.jboss.tools.common.java.IAnnotationDeclaration;

Expand All @@ -27,7 +28,8 @@ public IAnnotationDeclaration getInterceptorAnnotation() {
}

public boolean isEnabled() {
return !getCDIProject().getInterceptorClasses(getBeanClass().getFullyQualifiedName()).isEmpty();
return !getCDIProject().getInterceptorClasses(getBeanClass().getFullyQualifiedName()).isEmpty()
|| getAnnotation(CDIConstants.PRIORITY_ANNOTATION_TYPE_NAME) != null;
}

}
5 changes: 0 additions & 5 deletions cdi/tests/org.jboss.tools.cdi.core.test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,6 @@
<artifactId>cdi-api</artifactId>
<version>1.1</version>
</artifactItem>
<artifactItem>
<groupId>org.jboss.spec.javax.interceptor</groupId>
<artifactId>jboss-interceptors-api_1.1_spec</artifactId>
<version>1.0.0.Beta1</version>
</artifactItem>
<artifactItem>
<groupId>org.jboss.spec.javax.jms</groupId>
<artifactId>jboss-jms-api_1.1_spec</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.jboss.jsr299.tck.tests.jbt.resolution.priority;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Alternative;
import javax.enterprise.inject.Produces;

@Alternative
@ApplicationScoped
public class IllegalTableFactory {

@Produces @TableQualifier(0)
MarbleTable modelY = new MarbleTable();

@Produces @TableQualifier(1)
MarbleTable modelA = new MarbleTable();

@Produces @TableQualifier(2)
MarbleTable modelB = new MarbleTable();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.jboss.jsr299.tck.tests.jbt.resolution.priority;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Alternative;
import javax.annotation.Priority;

import static javax.interceptor.Interceptor.Priority.APPLICATION;

@ApplicationScoped
@Alternative
@Priority(APPLICATION + 100)
public class IronTable {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jboss.jsr299.tck.tests.jbt.resolution.priority;
package test.a;

import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Alternative;
import javax.enterprise.inject.Produces;

import static javax.interceptor.Interceptor.Priority.APPLICATION;

@Alternative
@ApplicationScoped
@Priority(APPLICATION + 100)
public class LuxuryTableFactory {

@Produces @TableQualifier(1)
MarbleTable modelA = new MarbleTable();

@Produces @TableQualifier(2)
MarbleTable modelB = new MarbleTable();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.jboss.jsr299.tck.tests.jbt.resolution.priority;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Alternative;
import javax.annotation.Priority;

import static javax.interceptor.Interceptor.Priority.APPLICATION;

@ApplicationScoped
@Alternative
@Priority(APPLICATION)
public class MarbleTable {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.jboss.jsr299.tck.tests.jbt.resolution.priority;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

@ApplicationScoped
public class Office {

/**
* Eligible beans with priorities 2000, 2001, 2100
* Resolved to bean with maximum priority.
*/
@Inject MarbleTable marbleTable;

/**
* Assignable non-eligible bean without priority.
* Eligible bean with priority.
* Resolved.
*/
@Inject @TableQualifier(0) MarbleTable marbleTableY;

/**
* Eligible beans with priorities 2001, 2100
* Resolved to bean with maximum priority.
*/
@Inject @TableQualifier(1) MarbleTable marbleTableA;

/**
* Eligible beans with priorities 2001, 2100, 2100
* Ambiguous dependency.
*/
@Inject @TableQualifier(2) MarbleTable marbleTableB;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.jboss.jsr299.tck.tests.jbt.resolution.priority;

import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Alternative;
import javax.enterprise.inject.Produces;

import static javax.interceptor.Interceptor.Priority.APPLICATION;

@Alternative
@ApplicationScoped
@Priority(APPLICATION + 100)
public class RivalLuxuryTableFactory {

@Produces @TableQualifier(2)
MarbleTable modelB = new MarbleTable();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.jboss.jsr299.tck.tests.jbt.resolution.priority;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Alternative;
import javax.annotation.Priority;

import static javax.interceptor.Interceptor.Priority.APPLICATION;

@ApplicationScoped
@Alternative
@Priority(APPLICATION)
public class StrawTable {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.jboss.jsr299.tck.tests.jbt.resolution.priority;

import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Alternative;
import javax.enterprise.inject.Produces;

import static javax.interceptor.Interceptor.Priority.APPLICATION;

@Alternative
@ApplicationScoped
@Priority(APPLICATION + 1)
public class TableFactory {

@Produces MarbleTable modelX = new MarbleTable();

@Produces @TableQualifier(0)
MarbleTable modelY = new MarbleTable();

@Produces @TableQualifier(1)
MarbleTable modelA = new MarbleTable();

@Produces @TableQualifier(2)
MarbleTable modelB = new MarbleTable();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jboss.jsr299.tck.tests.jbt.resolution.priority;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.inject.Qualifier;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Qualifier
@Target({ TYPE, METHOD, PARAMETER, FIELD })
@Retention(RUNTIME)
@Documented
public @interface TableQualifier {
int value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jboss.jsr299.tck.tests.jbt.resolution.priority;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Alternative;
import javax.annotation.Priority;

@ApplicationScoped
@Alternative
@Priority(300)
public class WoodenTable {

}
Loading