diff --git a/teavm-core/src/main/java/org/teavm/model/MethodHolder.java b/teavm-core/src/main/java/org/teavm/model/MethodHolder.java index d55ad57c6..6d89e09a2 100644 --- a/teavm-core/src/main/java/org/teavm/model/MethodHolder.java +++ b/teavm-core/src/main/java/org/teavm/model/MethodHolder.java @@ -24,10 +24,15 @@ public class MethodHolder extends MemberHolder implements MethodReader { private ClassHolder owner; private Program program; private AnnotationValue annotationDefault; + private AnnotationContainer[] parameterAnnotations; public MethodHolder(MethodDescriptor descriptor) { super(descriptor.getName()); 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) { @@ -59,6 +64,16 @@ public class MethodHolder extends MemberHolder implements MethodReader { return descriptor.getParameterTypes(); } + @Override + public AnnotationContainer parameterAnnotation(int index) { + return parameterAnnotations[index]; + } + + @Override + public AnnotationContainer[] getParameterAnnotations() { + return parameterAnnotations.clone(); + } + @Override public String getOwnerName() { return owner != null ? owner.getName() : null; diff --git a/teavm-core/src/main/java/org/teavm/model/MethodReader.java b/teavm-core/src/main/java/org/teavm/model/MethodReader.java index edceb3d90..bb5e263b8 100644 --- a/teavm-core/src/main/java/org/teavm/model/MethodReader.java +++ b/teavm-core/src/main/java/org/teavm/model/MethodReader.java @@ -30,6 +30,10 @@ public interface MethodReader extends MemberReader { ValueType[] getParameterTypes(); + AnnotationContainerReader parameterAnnotation(int index); + + AnnotationContainerReader[] getParameterAnnotations(); + MethodDescriptor getDescriptor(); MethodReference getReference(); diff --git a/teavm-core/src/main/java/org/teavm/model/emit/ProgramEmitter.java b/teavm-core/src/main/java/org/teavm/model/emit/ProgramEmitter.java index 02d595e76..0765b8a4d 100644 --- a/teavm-core/src/main/java/org/teavm/model/emit/ProgramEmitter.java +++ b/teavm-core/src/main/java/org/teavm/model/emit/ProgramEmitter.java @@ -146,6 +146,30 @@ public final class ProgramEmitter { 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) { FieldReader resolvedField = classSource.resolve(field); if (resolvedField != null) { diff --git a/teavm-core/src/main/java/org/teavm/model/util/ModelUtils.java b/teavm-core/src/main/java/org/teavm/model/util/ModelUtils.java index cfde95dde..7be844a16 100644 --- a/teavm-core/src/main/java/org/teavm/model/util/ModelUtils.java +++ b/teavm-core/src/main/java/org/teavm/model/util/ModelUtils.java @@ -55,6 +55,9 @@ public final class ModelUtils { if (method.getAnnotationDefault() != null) { copy.setAnnotationDefault(copyAnnotationValue(method.getAnnotationDefault())); } + for (int i = 0; i < method.parameterCount(); ++i) { + copyAnnotations(method.parameterAnnotation(i), copy.parameterAnnotation(i)); + } return copy; } diff --git a/teavm-core/src/main/java/org/teavm/parsing/Parser.java b/teavm-core/src/main/java/org/teavm/parsing/Parser.java index 70df7b2ee..7df874bd2 100644 --- a/teavm-core/src/main/java/org/teavm/parsing/Parser.java +++ b/teavm-core/src/main/java/org/teavm/parsing/Parser.java @@ -57,6 +57,11 @@ public final class Parser { if (node.annotationDefault != null) { 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; }