Skip to content

Commit

Permalink
Merge pull request #32529 from Ladicek/jandex-3.1-descriptors-signatures
Browse files Browse the repository at this point in the history
Upgrade to Jandex 3.1.1
  • Loading branch information
gastaldi authored Apr 13, 2023
2 parents 8f21c4e + fa2fac5 commit 5009f7c
Show file tree
Hide file tree
Showing 23 changed files with 153 additions and 845 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<jakarta.el-api.version>5.0.1</jakarta.el-api.version>
<jakarta.json-api.version>2.1.1</jakarta.json-api.version>
<jakarta.ws.rs-api.version>3.1.0</jakarta.ws.rs-api.version>
<jandex.version>3.0.5</jandex.version>
<jandex.version>3.1.1</jandex.version>
<javax.annotation-api.version>1.3.2</javax.annotation-api.version>
<javax.inject.version>1</javax.inject.version>
<parsson.version>1.1.1</parsson.version>
Expand Down
2 changes: 1 addition & 1 deletion build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<failsafe-plugin.version>${version.surefire.plugin}</failsafe-plugin.version>

<!-- Jandex versions -->
<jandex.version>3.0.5</jandex.version>
<jandex.version>3.1.1</jandex.version>
<jandex-gradle-plugin.version>1.0.0</jandex-gradle-plugin.version>

<asciidoctorj.version>2.5.7</asciidoctorj.version>
Expand Down
114 changes: 14 additions & 100 deletions core/deployment/src/main/java/io/quarkus/deployment/util/AsmUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

/**
* A collection of ASM and Jandex utilities.
* NOTE: this has a copy in AsmUtilCopy in arc-processor with some extra methods for knowing if we need a
* signature and getting the signature of a class.
*/
public class AsmUtil {

Expand Down Expand Up @@ -79,69 +77,25 @@ public static org.objectweb.asm.Type autobox(org.objectweb.asm.Type primitive) {
}

/**
* Returns the Java bytecode signature of a given Jandex MethodInfo.
* If the Java compiler doesn't have to emit a signature for the method, {@code null} is returned instead.
*
* @param method the method you want the signature for
* @return a bytecode signature for that method, or {@code null} if signature is not required
* @deprecated use {@link MethodInfo#genericSignatureIfRequired()}
*/
@Deprecated(since = "3.1", forRemoval = true)
public static String getSignatureIfRequired(MethodInfo method) {
return getSignatureIfRequired(method, ignored -> null);
return method.genericSignatureIfRequired();
}

/**
* Returns the Java bytecode signature of a given Jandex MethodInfo using the given type argument mappings.
* If the Java compiler doesn't have to emit a signature for the method, {@code null} is returned instead.
*
* @param method the method you want the signature for
* @param typeArgMapper a mapping between type argument names and their bytecode signatures
* @return a bytecode signature for that method, or {@code null} if signature is not required
* @deprecated use {@link MethodInfo#genericSignatureIfRequired(Function)}
*/
@Deprecated(since = "3.1", forRemoval = true)
public static String getSignatureIfRequired(MethodInfo method, Function<String, String> typeArgMapper) {
if (!hasSignature(method)) {
if (!method.requiresGenericSignature()) {
return null;
}

return getSignature(method, typeArgMapper);
}

private static boolean hasSignature(MethodInfo method) {
// JVMS 16, chapter 4.7.9.1. Signatures:
//
// Java compiler must emit ...
//
// A method signature for any method or constructor declaration which is either generic,
// or has a type variable or parameterized type as the return type or a formal parameter type,
// or has a type variable in a throws clause, or any combination thereof.

if (!method.typeParameters().isEmpty()) {
return true;
}

{
Type type = method.returnType();
if (type.kind() == Kind.TYPE_VARIABLE
|| type.kind() == Kind.UNRESOLVED_TYPE_VARIABLE
|| type.kind() == Kind.PARAMETERIZED_TYPE) {
return true;
}
}

for (Type type : method.parameterTypes()) {
if (type.kind() == Kind.TYPE_VARIABLE
|| type.kind() == Kind.UNRESOLVED_TYPE_VARIABLE
|| type.kind() == Kind.PARAMETERIZED_TYPE) {
return true;
}
}

if (hasThrowsSignature(method)) {
return true;
}

return false;
}

private static boolean hasThrowsSignature(MethodInfo method) {
// JVMS 16, chapter 4.7.9.1. Signatures:
//
Expand All @@ -165,24 +119,9 @@ private static boolean hasThrowsSignature(MethodInfo method) {
}

/**
* Returns the Java bytecode signature of a given Jandex MethodInfo using the given type argument mappings.
* For example, given this method:
*
* <pre>
* {@code
* public class Foo<T> {
* public <R> List<R> method(int a, T t){...}
* }
* }
* </pre>
*
* This will return <tt>&lt;R:Ljava/lang/Object;>(ILjava/lang/Integer;)Ljava/util/List&lt;TR;>;</tt> if
* your {@code typeArgMapper} contains {@code T=Ljava/lang/Integer;}.
*
* @param method the method you want the signature for.
* @param typeArgMapper a mapping between type argument names and their bytecode signature.
* @return a bytecode signature for that method.
* @deprecated use {@link MethodInfo#genericSignature(Function)}
*/
@Deprecated(since = "3.1", forRemoval = true)
public static String getSignature(MethodInfo method, Function<String, String> typeArgMapper) {
// for grammar, see JVMS 16, chapter 4.7.9.1. Signatures

Expand Down Expand Up @@ -241,24 +180,9 @@ private static boolean hasImplicitObjectBound(TypeVariable typeParameter) {
}

/**
* Returns the Java bytecode descriptor of a given Jandex MethodInfo using the given type argument mappings.
* For example, given this method:
*
* <pre>
* {@code
* public class Foo<T> {
* public <R> List<R> method(int a, T t){...}
* }
* }
* </pre>
*
* This will return <tt>(ILjava/lang/Integer;)Ljava/util/List;</tt> if
* your {@code typeArgMapper} contains {@code T=Ljava/lang/Integer;}.
*
* @param method the method you want the descriptor for.
* @param typeArgMapper a mapping between type argument names and their bytecode descriptor.
* @return a bytecode descriptor for that method.
* @deprecated use {@link MethodInfo#descriptor(Function)}
*/
@Deprecated(since = "3.1", forRemoval = true)
public static String getDescriptor(MethodInfo method, Function<String, String> typeArgMapper) {
List<Type> parameters = method.parameterTypes();

Expand All @@ -272,29 +196,19 @@ public static String getDescriptor(MethodInfo method, Function<String, String> t
}

/**
* Returns the Java bytecode descriptor of a given Jandex Type using the given type argument mappings.
* For example, given this type: <tt>List&lt;T></tt>, this will return <tt>Ljava/util/List;</tt> if
* your {@code typeArgMapper} contains {@code T=Ljava/lang/Integer;}.
*
* @param type the type you want the descriptor for.
* @param typeArgMapper a mapping between type argument names and their bytecode descriptor.
* @return a bytecode descriptor for that type.
* @deprecated use {@link Type#descriptor(Function)}
*/
@Deprecated(since = "3.1", forRemoval = true)
public static String getDescriptor(Type type, Function<String, String> typeArgMapper) {
StringBuilder sb = new StringBuilder();
toSignature(sb, type, typeArgMapper, true);
return sb.toString();
}

/**
* Returns the Java bytecode signature of a given Jandex Type using the given type argument mappings.
* For example, given this type: <tt>List&lt;T></tt>, this will return <tt>Ljava/util/List&lt;Ljava/lang/Integer;>;</tt> if
* your {@code typeArgMapper} contains {@code T=Ljava/lang/Integer;}.
*
* @param type the type you want the signature for.
* @param typeArgMapper a mapping between type argument names and their bytecode descriptor.
* @return a bytecode signature for that type.
* @deprecated use {@link org.jboss.jandex.GenericSignature#forType(Type, Function, StringBuilder)}
*/
@Deprecated(since = "3.1", forRemoval = true)
public static String getSignature(Type type, Function<String, String> typeArgMapper) {
StringBuilder sb = new StringBuilder();
toSignature(sb, type, typeArgMapper, false);
Expand Down

This file was deleted.

Loading

0 comments on commit 5009f7c

Please sign in to comment.