Skip to content

Commit

Permalink
https://github.com/manifold-systems/manifold/issues/611
Browse files Browse the repository at this point in the history
- addendum. Ensure enum constants are fully qualified in the context of annotation default values
  • Loading branch information
rsmckinney committed Jul 27, 2024
1 parent a66d7b2 commit c0fa90c
Showing 1 changed file with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,9 @@ 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() );
}
}

setAnnotationDefaultValue( method, srcMethod );

String bodyStmt;
if( srcMethod.isConstructor() && !srcClass.isEnum() )
{
Expand Down Expand Up @@ -415,6 +410,32 @@ private void addMethod( IModule module, SrcClass srcClass, Symbol.MethodSymbol m
srcClass.addMethod( srcMethod );
}

private void setAnnotationDefaultValue( Symbol.MethodSymbol method, SrcMethod srcMethod )
{
if( (method.owner.flags_field & Flags.ANNOTATION) == 0 )
{
// declaring class is not an annotation
return;
}

Attribute defaultValue = method.getDefaultValue();
if( defaultValue == null )
{
// annotation method does not have a default value
return;
}

String qualifiedValue = defaultValue.toString();
if( defaultValue instanceof Attribute.Enum )
{
// enum constants must be qualified

Symbol.VarSymbol value = ((Attribute.Enum)defaultValue).getValue();
qualifiedValue = value.enclClass() + "." + value;
}
srcMethod.setDefaultValue( qualifiedValue );
}

private static Set<javax.lang.model.element.Modifier> getModifiers( Symbol.MethodSymbol method )
{
long flags = method.flags();
Expand Down

0 comments on commit c0fa90c

Please sign in to comment.