Skip to content

Commit c0fa90c

Browse files
committed
https://github.com/manifold-systems/manifold/issues/611
- addendum. Ensure enum constants are fully qualified in the context of annotation default values
1 parent a66d7b2 commit c0fa90c

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

manifold-core-parent/manifold/src/main/java/manifold/internal/javac/SrcClassUtil.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,9 @@ private void addMethod( IModule module, SrcClass srcClass, Symbol.MethodSymbol m
380380
Type throwType = thrownTypes.get( i );
381381
srcMethod.addThrowType( makeSrcType( throwType, method, TargetType.THROWS, i ) );
382382
}
383-
if( (method.owner.flags_field & Flags.ANNOTATION) != 0 )
384-
{
385-
Attribute defaultValue = method.getDefaultValue();
386-
if( defaultValue != null )
387-
{
388-
srcMethod.setDefaultValue( defaultValue.toString() );
389-
}
390-
}
383+
384+
setAnnotationDefaultValue( method, srcMethod );
385+
391386
String bodyStmt;
392387
if( srcMethod.isConstructor() && !srcClass.isEnum() )
393388
{
@@ -415,6 +410,32 @@ private void addMethod( IModule module, SrcClass srcClass, Symbol.MethodSymbol m
415410
srcClass.addMethod( srcMethod );
416411
}
417412

413+
private void setAnnotationDefaultValue( Symbol.MethodSymbol method, SrcMethod srcMethod )
414+
{
415+
if( (method.owner.flags_field & Flags.ANNOTATION) == 0 )
416+
{
417+
// declaring class is not an annotation
418+
return;
419+
}
420+
421+
Attribute defaultValue = method.getDefaultValue();
422+
if( defaultValue == null )
423+
{
424+
// annotation method does not have a default value
425+
return;
426+
}
427+
428+
String qualifiedValue = defaultValue.toString();
429+
if( defaultValue instanceof Attribute.Enum )
430+
{
431+
// enum constants must be qualified
432+
433+
Symbol.VarSymbol value = ((Attribute.Enum)defaultValue).getValue();
434+
qualifiedValue = value.enclClass() + "." + value;
435+
}
436+
srcMethod.setDefaultValue( qualifiedValue );
437+
}
438+
418439
private static Set<javax.lang.model.element.Modifier> getModifiers( Symbol.MethodSymbol method )
419440
{
420441
long flags = method.flags();

0 commit comments

Comments
 (0)