Add parameter annotation support

This commit is contained in:
Alexey Andreev 2015-08-01 23:48:19 +03:00
parent 1d45cd4d2b
commit dd00dd4c78
5 changed files with 51 additions and 0 deletions

View File

@ -24,10 +24,15 @@ public class MethodHolder extends MemberHolder implements MethodReader {
private ClassHolder owner; private ClassHolder owner;
private Program program; private Program program;
private AnnotationValue annotationDefault; private AnnotationValue annotationDefault;
private AnnotationContainer[] parameterAnnotations;
public MethodHolder(MethodDescriptor descriptor) { public MethodHolder(MethodDescriptor descriptor) {
super(descriptor.getName()); super(descriptor.getName());
this.descriptor = descriptor; this.descriptor = descriptor;
parameterAnnotations = new AnnotationContainer[descriptor.parameterCount()];
for (int i = 0; i < parameterAnnotations.length; ++i) {
parameterAnnotations[i] = new AnnotationContainer();
}
} }
public MethodHolder(String name, ValueType... signature) { public MethodHolder(String name, ValueType... signature) {
@ -59,6 +64,16 @@ public class MethodHolder extends MemberHolder implements MethodReader {
return descriptor.getParameterTypes(); return descriptor.getParameterTypes();
} }
@Override
public AnnotationContainer parameterAnnotation(int index) {
return parameterAnnotations[index];
}
@Override
public AnnotationContainer[] getParameterAnnotations() {
return parameterAnnotations.clone();
}
@Override @Override
public String getOwnerName() { public String getOwnerName() {
return owner != null ? owner.getName() : null; return owner != null ? owner.getName() : null;

View File

@ -30,6 +30,10 @@ public interface MethodReader extends MemberReader {
ValueType[] getParameterTypes(); ValueType[] getParameterTypes();
AnnotationContainerReader parameterAnnotation(int index);
AnnotationContainerReader[] getParameterAnnotations();
MethodDescriptor getDescriptor(); MethodDescriptor getDescriptor();
MethodReference getReference(); MethodReference getReference();

View File

@ -146,6 +146,30 @@ public final class ProgramEmitter {
return var(var, type); return var(var, type);
} }
public ValueEmitter defaultValue(ValueType type) {
if (type instanceof ValueType.Primitive) {
switch (((ValueType.Primitive) type).getKind()) {
case BOOLEAN:
return constant(0).cast(boolean.class);
case BYTE:
return constant(0).cast(byte.class);
case SHORT:
return constant(0).cast(short.class);
case CHARACTER:
return constant(0).cast(char.class);
case INTEGER:
return constant(0);
case LONG:
return constant(0L);
case FLOAT:
return constant(0F);
case DOUBLE:
return constant(0.0);
}
}
return constantNull(type);
}
public ValueEmitter getField(FieldReference field, ValueType type) { public ValueEmitter getField(FieldReference field, ValueType type) {
FieldReader resolvedField = classSource.resolve(field); FieldReader resolvedField = classSource.resolve(field);
if (resolvedField != null) { if (resolvedField != null) {

View File

@ -55,6 +55,9 @@ public final class ModelUtils {
if (method.getAnnotationDefault() != null) { if (method.getAnnotationDefault() != null) {
copy.setAnnotationDefault(copyAnnotationValue(method.getAnnotationDefault())); copy.setAnnotationDefault(copyAnnotationValue(method.getAnnotationDefault()));
} }
for (int i = 0; i < method.parameterCount(); ++i) {
copyAnnotations(method.parameterAnnotation(i), copy.parameterAnnotation(i));
}
return copy; return copy;
} }

View File

@ -57,6 +57,11 @@ public final class Parser {
if (node.annotationDefault != null) { if (node.annotationDefault != null) {
method.setAnnotationDefault(parseAnnotationValue(node.annotationDefault)); method.setAnnotationDefault(parseAnnotationValue(node.annotationDefault));
} }
for (int i = 0; i < method.parameterCount(); ++i) {
parseAnnotations(method.parameterAnnotation(i),
node.visibleParameterAnnotations != null ? node.visibleParameterAnnotations[i] : null,
node.invisibleParameterAnnotations != null ? node.invisibleParameterAnnotations[i] : null);
}
return method; return method;
} }