mirror of
https://github.com/zaaarf/lillero-processor.git
synced 2024-11-13 02:29:22 +01:00
fix: support array levels
This commit is contained in:
parent
5fd954a118
commit
6e23559973
2 changed files with 31 additions and 6 deletions
|
@ -332,12 +332,12 @@ public class LilleroProcessor extends AbstractProcessor {
|
|||
for(VariableElement p : targetMethod.getParameters()) {
|
||||
if(p.asType().getKind().isPrimitive())
|
||||
b.addStatement("bd.addParameter($T.class)", p.asType());
|
||||
else b.addStatement("bd.addParameter($S)", p.asType().toString());
|
||||
else b.addStatement("bd.addParameter($S, %L)", getInnermostComponentType(p.asType()), getArrayLevel(p.asType()));
|
||||
}
|
||||
|
||||
if(targetMethod.getReturnType().getKind().isPrimitive())
|
||||
b.addStatement("bd.setReturnType($T.class)", targetMethod.getReturnType());
|
||||
else b.addStatement("bd.setReturnType($S)", targetMethod.getReturnType().toString());
|
||||
else b.addStatement("bd.setReturnType($S, %L)", getInnermostComponentType(targetMethod.getReturnType()), getArrayLevel(targetMethod.getReturnType()));
|
||||
|
||||
b.addStatement("return bd.build()");
|
||||
|
||||
|
@ -366,7 +366,7 @@ public class LilleroProcessor extends AbstractProcessor {
|
|||
|
||||
if(targetField.asType().getKind().isPrimitive())
|
||||
b.addStatement("bd.setType($T.class)", targetField.asType());
|
||||
else b.addStatement("bd.setType($S)", targetField.asType().toString());
|
||||
else b.addStatement("bd.setType($S, %L)", getInnermostComponentType(targetField.asType()), getArrayLevel(targetField.asType()));
|
||||
|
||||
b.addStatement("return bd.build()");
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue