Skip to content
Open
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 @@ -25,7 +25,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
Expand Down Expand Up @@ -747,19 +746,10 @@ private boolean checkEventTypeParameterForExtensions(Type beanClass, Type observ
{
if(ClassUtil.isTypeVariable(observerTypeActualArg))
{
TypeVariable<?> tv = (TypeVariable<?>)observerTypeActualArg;
Type tvBound = tv.getBounds()[0];

if(tvBound instanceof Class)
if (Class.class.isInstance(beanClass) && GenericsUtil.isAssignableFrom(false, true, observerTypeActualArg, beanClass, new HashMap<>()))
{
Class<?> clazzTvBound = (Class<?>)tvBound;

if(Class.class.isInstance(beanClass) && clazzTvBound.isAssignableFrom(Class.class.cast(beanClass)))
{
return true;
}
}

return true;
}
}
else if(ClassUtil.isWildCardType(observerTypeActualArg))
{
Expand All @@ -773,9 +763,9 @@ else if(observerTypeActualArg instanceof Class)
return true;
}
}
else if (observerTypeActualArg instanceof ParameterizedType)
else if(observerTypeActualArg instanceof ParameterizedType)
{
return GenericsUtil.isAssignableFrom(false, true, observerTypeActualArg, beanClass, new HashMap<>());
return GenericsUtil.isAssignableFrom(true, true, observerTypeActualArg, beanClass, new HashMap<>());
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ public void testWithAnnotation()

Assert.assertEquals(4, WithAnnotationExtension.scannedClasses);
Assert.assertEquals(1, WithAnnotationExtension.one);
Assert.assertEquals(1, WithAnnotationExtension.extend);
}


public static class WithAnnotationExtension implements Extension
{
public static int scannedClasses = 0;
public static int one = 0;
public static int extend = 0;

public void processClassess(@Observes @WithAnnotations(MyAnnoation.class) ProcessAnnotatedType pat)
{
Expand All @@ -73,6 +75,12 @@ public void noIssueWithGenericsOWB997(@Observes @WithAnnotations(MyAnnoation.cla
{
one++;
}

<T extends WithAnnotatedClass> void noIssueWithExtendGenericsOWB997(@Observes @WithAnnotations(MyAnnoation.class) ProcessAnnotatedType<T> pat)
{
extend++;
}

}

@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,28 @@
import java.util.ArrayList;
import java.util.Collection;

import org.junit.Assert;

import org.apache.webbeans.test.AbstractUnitTest;
import org.apache.webbeans.test.portable.events.beans.Apple;
import org.apache.webbeans.test.portable.events.beans.AppleTree;
import org.apache.webbeans.test.portable.events.beans.Cherry;
import org.apache.webbeans.test.portable.events.beans.CherryTree;
import org.apache.webbeans.test.portable.events.beans.Tree;
import org.apache.webbeans.test.portable.events.extensions.AppleExtension;
import org.apache.webbeans.test.portable.events.extensions.AppleExtension1;
import org.apache.webbeans.test.portable.events.extensions.MessageReceiverExtension;
import org.apache.webbeans.test.portable.events.extensions.MessageSenderExtension;
import org.apache.webbeans.test.portable.events.extensions.NotAppleExtnsion;
import org.apache.webbeans.test.portable.events.extensions.ParameterizedTypeWithTypeVariableExtension;
import org.apache.webbeans.test.portable.events.extensions.RawTypeExtension;
import org.apache.webbeans.test.portable.events.extensions.ThreeParameterMixedVarianceExtension;
import org.apache.webbeans.test.portable.events.extensions.TreeExtension;
import org.apache.webbeans.test.portable.events.extensions.TwoParameterTypeWithTypeVariableExtension;
import org.apache.webbeans.test.portable.events.extensions.TypeVariableExtension;
import org.apache.webbeans.test.portable.events.extensions.WildcardExtension;
import org.apache.webbeans.test.portable.events.extensions.WrongTypeVariableExtension;
import org.apache.webbeans.test.portable.events.extensions.WrongWildcardExtension;
import org.junit.Assert;

import org.apache.webbeans.test.AbstractUnitTest;
import org.apache.webbeans.test.portable.events.beans.Apple;
import org.apache.webbeans.test.portable.events.beans.AppleTree;
import org.apache.webbeans.test.portable.events.beans.Cherry;
import org.apache.webbeans.test.portable.events.beans.CherryTree;
import org.apache.webbeans.test.portable.events.beans.Tree;
import org.junit.Test;

public class PortableEventTest extends AbstractUnitTest
Expand Down Expand Up @@ -260,4 +263,68 @@ public void testNumberCallsGenerics()

shutDownContainer();
}

@Test
public void testParameterizedTypeWithTypeVariableExtension()
{
Collection<String> beanXmls = new ArrayList<String>();

Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
beanClasses.add(ParameterizedTypeWithTypeVariableExtension.PaintToolFactoryImpl.class);
addExtension(new ParameterizedTypeWithTypeVariableExtension());
startContainer(beanClasses, beanXmls);

Assert.assertTrue(ParameterizedTypeWithTypeVariableExtension.CALLED);

shutDownContainer();
}

@Test
public void testTwoParameterTypeWithTypeVariableExtension()
{
Collection<String> beanXmls = new ArrayList<String>();

Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
beanClasses.add(TwoParameterTypeWithTypeVariableExtension.KeyValueStoreImpl.class);
addExtension(new TwoParameterTypeWithTypeVariableExtension());
startContainer(beanClasses, beanXmls);

Assert.assertTrue(TwoParameterTypeWithTypeVariableExtension.CALLED);

shutDownContainer();
}

@Test
public void testThreeParameterMixedVarianceExtension_positive()
{
ThreeParameterMixedVarianceExtension.CALLED = false;

Collection<String> beanXmls = new ArrayList<String>();

Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
beanClasses.add(ThreeParameterMixedVarianceExtension.TripleStoreImpl.class);
addExtension(new ThreeParameterMixedVarianceExtension());
startContainer(beanClasses, beanXmls);

Assert.assertTrue(ThreeParameterMixedVarianceExtension.CALLED);

shutDownContainer();
}

@Test
public void testThreeParameterMixedVarianceExtension_negative()
{
ThreeParameterMixedVarianceExtension.CALLED = false;

Collection<String> beanXmls = new ArrayList<String>();

Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
beanClasses.add(ThreeParameterMixedVarianceExtension.TripleStoreWrongImpl.class);
addExtension(new ThreeParameterMixedVarianceExtension());
startContainer(beanClasses, beanXmls);

Assert.assertFalse(ThreeParameterMixedVarianceExtension.CALLED);

shutDownContainer();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.webbeans.test.portable.events.extensions;

import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.spi.Extension;
import jakarta.enterprise.inject.spi.ProcessAnnotatedType;

public class ParameterizedTypeWithTypeVariableExtension implements Extension
{

public static boolean CALLED = false;

<T extends PaintToolFactory<?>> void processClasses(@Observes ProcessAnnotatedType<T> event)
{
CALLED = true;
}

public static class PaintToolFactoryImpl implements PaintToolFactory<PaintBrush<Red>>
{
@Override
public PaintBrush<Red> createPaintTool()
{
return new PaintBrush<Red>();
}
}

public static class PaintBrush<T extends Color> implements PaintTool<T>
{
@Override
public void paint(T color)
{
// no-op
}
}

public interface PaintTool<T extends Color>
{
void paint(T color);
}

public interface PaintToolFactory<T extends PaintTool<?>>
{
T createPaintTool();
}

public interface Color
{
void getColor();
}

public static class Red implements Color {

@Override
public void getColor() {

}
}

public static class Green implements Color {

@Override
public void getColor() {

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.webbeans.test.portable.events.extensions;

import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.spi.Extension;
import jakarta.enterprise.inject.spi.ProcessAnnotatedType;

/**
* Three-parameter generic with mixed variance:
* {@code TripleStore<? extends HeadlineFoo, ?, ? extends HeadlineBar>}.
*/
public class ThreeParameterMixedVarianceExtension implements Extension
{
public static boolean CALLED = false;

void processClasses(@Observes ProcessAnnotatedType<TripleStore<? extends HeadlineFoo, ?, ? extends HeadlineBar>> event)
{
CALLED = true;
}

public interface Baz3
{
}

public static class BazImpl3 implements Baz3
{
}

public static class OtherBazImpl3 implements Baz3
{
}

public interface Bar3<T extends Baz3>
{
}

public static class HeadlineBar implements Bar3<BazImpl3>
{
}

public static class OtherBar implements Bar3<OtherBazImpl3>
{
}

public interface Foo3
{
}

public static class HeadlineFoo implements Foo3
{
}

public static class OtherFoo implements Foo3
{
}

public interface TripleStore<A extends Foo3, B, C extends Bar3<?>>
{
void store(A a, B b, C c);
}

/**
* Matches the observer: uses HeadlineFoo and HeadlineBar.
*/
public static class TripleStoreImpl implements TripleStore<HeadlineFoo, String, HeadlineBar>
{
@Override
public void store(HeadlineFoo a, String b, HeadlineBar c)
{
// no-op
}
}

/**
* Does not match the observer: uses OtherBar instead of HeadlineBar.
*/
public static class TripleStoreWrongImpl implements TripleStore<HeadlineFoo, String, OtherBar>
{
@Override
public void store(HeadlineFoo a, String b, OtherBar c)
{
// no-op
}
}
}

Loading