Skip to content

Commit

Permalink
Merge pull request #20386 from yrodiere/i20375-valueextractor-applica…
Browse files Browse the repository at this point in the history
…tionscoped

Fix @ApplicationScoped ValueExtractors
  • Loading branch information
gsmet authored Oct 14, 2021
2 parents 85fb4f1 + 30f382e commit 2e5b57c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

@Disabled("Reproduces https://github.com/quarkusio/quarkus/issues/20375, not yet fixed")
public class ApplicationScopedCustomValueExtractorTest {

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,48 +164,35 @@ else if (erased)

/**
* Returns the Java bytecode signature of a given Jandex Class using the given type argument mappings.
* For example, given this class:
*
*
* For example, given this superclass:
*
* <pre>
* {@code
* public class Foo<R> extends Bar<R> implements List<String> {
* }
* </pre>
*
* This will return <tt>&lt;R:Ljava/lang/Object;>LBar&lt;TR;>;Ljava/util/List&lt;Ljava/lang/String;>;</tt>.
*
* @param klass the class you want the signature for.
*
* @return a bytecode signature for that class.
*/
public static String getSignature(ClassInfo klass) {
return getSignature(klass, NO_ARG_MAPPER);
}

/**
* Returns the Java bytecode signature of a given Jandex Class using the given type argument mappings.
* For example, given this class:
*
*
* This will return <tt>&lt;R:Ljava/lang/Object;>LFoo&lt;TR;>;</tt>.
* {@code Bar} and {@code List} will be ignored, as they won't be part of the signature of the generated subclass.
*
* All will be as if the generated subclass was declared like this:
*
* <pre>
* {@code
* public class Foo<R> extends Bar<R> implements List<String> {
* public class MyGeneratedClass<R> extends Foo<R> {
* }
* </pre>
*
* @param superClass the superclass of the type you want to generate the signature for.
*
* This will return <tt>&lt;R:Ljava/lang/Object;>LBar&lt;TR;>;Ljava/util/List&lt;Ljava/lang/String;>;</tt>.
*
* @param klass the class you want the signature for.
*
* @param typeArgMapper a mapping between type variables and their resolved type.
* @param superClassAsType the superclass as a Jandex Type.
* @return a bytecode signature for that class.
*/
public static String getSignature(ClassInfo klass, Function<TypeVariable, Type> typeArgMapper) {
StringBuilder signature = new StringBuilder("");
toSignature(signature, klass.typeParameters(), typeArgMapper, false);
toSignature(signature, klass.superClassType(), typeArgMapper, false);
for (Type superinterface : klass.interfaceTypes()) {
toSignature(signature, superinterface, typeArgMapper, false);
}
public static String getGeneratedSubClassSignature(ClassInfo superClass, Type superClassAsType) {
StringBuilder signature = new StringBuilder();
toSignature(signature, superClass.typeParameters(), NO_ARG_MAPPER, false);
toSignature(signature, superClassAsType, NO_ARG_MAPPER, false);
return signature.toString();
}

Expand All @@ -224,21 +211,6 @@ private static void toSignature(StringBuilder sb, List<TypeVariable> typeParamet
sb.append(">");
}

/**
* Returns true if the given class has type parameters or if its superclass or superinterfaces require a signature
*/
public static boolean needsSignature(ClassInfo klass) {
if (!klass.typeParameters().isEmpty()
|| needsSignature(klass.superClassType())) {
return true;
}
for (Type type : klass.interfaceTypes()) {
if (needsSignature(type))
return true;
}
return false;
}

/**
* Returns true if the given method has type parameters or if its return type or parameter types require a signature
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,16 @@ Collection<Resource> generate(BeanInfo bean, String beanClassName,
ClassCreator clientProxy = ClassCreator.builder().classOutput(classOutput).className(generatedName)
.superClass(superClass)
.interfaces(interfaces.toArray(new String[0])).build();
if (AsmUtilCopy.needsSignature(providerClass)) {
clientProxy.setSignature(AsmUtilCopy.getSignature(providerClass));
// See https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.9.1
// Essentially a signature is needed if a class has type parameters or extends/implements parameterized type.
// We're generating a subtype (subclass or subinterface) of "providerClass".
// The only way for that generated subtype to have type parameters or to extend/implement a parameterized type
// is if providerClass has type parameters.
// Whether supertypes or superinterfaces of providerClass have type parameters is irrelevant:
// as long as those type parameters are bound in providerClass,
// they won't affect the need for a signature in the generated subtype.
if (!providerClass.typeParameters().isEmpty()) {
clientProxy.setSignature(AsmUtilCopy.getGeneratedSubClassSignature(providerClass, bean.getProviderType()));
}
Map<ClassInfo, Map<TypeVariable, Type>> resolvedTypeVariables = Types.resolvedTypeVariables(providerClass,
bean.getDeployment());
Expand Down

This file was deleted.

0 comments on commit 2e5b57c

Please sign in to comment.