diff --git a/manifold-core-parent/manifold/src/main/java/manifold/api/gen/AbstractSrcMethod.java b/manifold-core-parent/manifold/src/main/java/manifold/api/gen/AbstractSrcMethod.java index e9ec81daf..e97a89f1a 100644 --- a/manifold-core-parent/manifold/src/main/java/manifold/api/gen/AbstractSrcMethod.java +++ b/manifold-core-parent/manifold/src/main/java/manifold/api/gen/AbstractSrcMethod.java @@ -32,6 +32,7 @@ public class AbstractSrcMethod> extends SrcStatem private List _throwTypes; private boolean _isConstructor; private boolean _isPrimaryConstructor; + private String _defaultValue; public AbstractSrcMethod( AbstractSrcClass srcClass ) { @@ -132,6 +133,15 @@ public T body( String rawText ) return (T)this; } + public String getDefaultValue() + { + return _defaultValue; + } + public void setDefaultValue( String defaultValue ) + { + _defaultValue = defaultValue; + } + public SrcType getReturnType() { return _returns; @@ -191,6 +201,11 @@ else if( isConstructor() ) } if( isAbstractMethod() ) { + String defaultValue = getDefaultValue(); + if( defaultValue != null ) + { + sb.append( " default " ).append( defaultValue ); + } sb.append( ";\n" ); } else diff --git a/manifold-core-parent/manifold/src/main/java/manifold/internal/javac/SrcClassUtil.java b/manifold-core-parent/manifold/src/main/java/manifold/internal/javac/SrcClassUtil.java index d67ad7a12..92977f41b 100644 --- a/manifold-core-parent/manifold/src/main/java/manifold/internal/javac/SrcClassUtil.java +++ b/manifold-core-parent/manifold/src/main/java/manifold/internal/javac/SrcClassUtil.java @@ -380,6 +380,14 @@ private void addMethod( IModule module, SrcClass srcClass, Symbol.MethodSymbol m Type throwType = thrownTypes.get( i ); srcMethod.addThrowType( makeSrcType( throwType, method, TargetType.THROWS, i ) ); } + if( (method.owner.flags_field & Flags.ANNOTATION) != 0 ) + { + Attribute defaultValue = method.getDefaultValue(); + if( defaultValue != null ) + { + srcMethod.setDefaultValue( defaultValue.toString() ); + } + } String bodyStmt; if( srcMethod.isConstructor() && !srcClass.isEnum() ) { diff --git a/manifold-deps-parent/manifold-ext-middle-test/src/main/java/xyz/OtherAnno.java b/manifold-deps-parent/manifold-ext-middle-test/src/main/java/xyz/OtherAnno.java new file mode 100644 index 000000000..8080ef3cd --- /dev/null +++ b/manifold-deps-parent/manifold-ext-middle-test/src/main/java/xyz/OtherAnno.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2019 - Manifold Systems LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package xyz; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import static xyz.OtherAnno.Local.*; + +@Retention( RetentionPolicy.CLASS ) +public @interface OtherAnno +{ + String value() default "foo"; + boolean booleanValue() default true; + int intValue() default 9; + double doubleValue() default 9.9; + String stringValue() default "hi"; + Class classValue() default Local.class; + Local enumValue() default B; + InnerAnno annoValue() default @InnerAnno(stringValue = "abc"); + boolean[] booleanArrayValue() default {true,false}; + int[] intArrayValue() default {1,2}; + double[] doubleArrayValue() default {1.2,2.1}; + String[] stringArrayValue() default {"a", "b"}; + Class[] classArrayValue() default {String.class, int.class}; + Local[] enumArrayValue() default {A, B}; + InnerAnno[] annoArrayValue() default {@InnerAnno, @InnerAnno(value=7)}; + + + enum Local {A, B, C} + + @Retention( RetentionPolicy.CLASS ) + @interface InnerAnno + { + int value() default 0; + String stringValue() default "bar"; + } +} diff --git a/manifold-deps-parent/manifold-ext-test/src/test/java/abc/ClassThatUsesOtherAnno.java b/manifold-deps-parent/manifold-ext-test/src/test/java/abc/ClassThatUsesOtherAnno.java new file mode 100644 index 000000000..db0a06a21 --- /dev/null +++ b/manifold-deps-parent/manifold-ext-test/src/test/java/abc/ClassThatUsesOtherAnno.java @@ -0,0 +1,10 @@ +package abc; + +import xyz.OtherAnno; + +public class ClassThatUsesOtherAnno +{ + // tests that default values exist in generated stub for extended annotation OtherAnno, see MyOtherAnnoExt + @OtherAnno + public void myMethod() {} +} diff --git a/manifold-deps-parent/manifold-ext-test/src/test/java/manifold/extensions/xyz/OtherAnno/MyOtherAnnoExt.java b/manifold-deps-parent/manifold-ext-test/src/test/java/manifold/extensions/xyz/OtherAnno/MyOtherAnnoExt.java new file mode 100644 index 000000000..774bec4c6 --- /dev/null +++ b/manifold-deps-parent/manifold-ext-test/src/test/java/manifold/extensions/xyz/OtherAnno/MyOtherAnnoExt.java @@ -0,0 +1,9 @@ +package manifold.extensions.xyz.OtherAnno; + +import manifold.ext.rt.api.Extension; + +// tests extending annotation classes with annotations +@Extension +@Deprecated +public class MyOtherAnnoExt { +} \ No newline at end of file