From 6e2355997398923c73756c3ae319c6290977e614 Mon Sep 17 00:00:00 2001 From: zaaarf Date: Fri, 17 Mar 2023 19:24:20 +0100 Subject: fix: support array levels --- .../java/ftbsc/lll/processor/tools/ASTUtils.java | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'src/main/java/ftbsc/lll/processor/tools/ASTUtils.java') diff --git a/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java b/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java index ef50e52..1735b66 100644 --- a/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java +++ b/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java @@ -12,9 +12,7 @@ import ftbsc.lll.processor.tools.obfuscation.ObfuscationMapper; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.*; -import javax.lang.model.type.MirroredTypeException; -import javax.lang.model.type.MirroredTypesException; -import javax.lang.model.type.TypeMirror; +import javax.lang.model.type.*; import javax.lang.model.util.Elements; import java.lang.annotation.Annotation; import java.util.ArrayList; @@ -83,6 +81,33 @@ public class ASTUtils { } } + /** + * Calculates the array nesting level for a {@link TypeMirror}. + * @param t the type mirror to get it for + * @return the array nesting level + * @since 0.3.0 + */ + public static int getArrayLevel(TypeMirror t) { + int arrayLevel = 0; + while(t.getKind() == TypeKind.ARRAY) { + t = ((ArrayType) t).getComponentType(); + arrayLevel++; + } + return arrayLevel; + } + + /** + * Calculates the array nesting level for a {@link TypeMirror}. + * @param t the type mirror to get it for + * @return the array nesting level + * @since 0.3.0 + */ + public static TypeMirror getInnermostComponentType(TypeMirror t) { + while(t.getKind() == TypeKind.ARRAY) + t = ((ArrayType) t).getComponentType(); + return t; + } + /** * Safely extracts a {@link Class} from an annotation and gets its fully qualified name. * @param ann the annotation containing the class -- cgit v1.2.3-56-ga3b1