Skip to content

Commit 9e064f6

Browse files
cushonJavac Team
authored and
Javac Team
committed
Support sealed and non-sealed modifiers in getModifiers
Startblock: * unknown commit is submitted PiperOrigin-RevId: 664849597
1 parent 7dafb70 commit 9e064f6

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

java/com/google/turbine/processing/TurbineElement.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,12 @@ private static ImmutableSet<Modifier> asModifierSet(ModifierOwner modifierOwner,
10381038
if ((access & TurbineFlag.ACC_STRICT) == TurbineFlag.ACC_STRICT) {
10391039
modifiers.add(Modifier.STRICTFP);
10401040
}
1041-
1041+
if ((access & TurbineFlag.ACC_SEALED) == TurbineFlag.ACC_SEALED) {
1042+
modifiers.add(Modifier.SEALED);
1043+
}
1044+
if ((access & TurbineFlag.ACC_NON_SEALED) == TurbineFlag.ACC_NON_SEALED) {
1045+
modifiers.add(Modifier.NON_SEALED);
1046+
}
10421047
return Sets.immutableEnumSet(modifiers);
10431048
}
10441049

javatests/com/google/turbine/processing/ProcessingIntegrationTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,36 @@ public void recordComponents() {
869869
"enclosing: R, name: y, accessor: y() [@java.lang.Deprecated]");
870870
}
871871

872+
@SupportedAnnotationTypes("*")
873+
public static class ModifiersProcessor extends AbstractProcessor {
874+
@Override
875+
public SourceVersion getSupportedSourceVersion() {
876+
return SourceVersion.latestSupported();
877+
}
878+
879+
@Override
880+
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
881+
for (Element e : roundEnv.getRootElements()) {
882+
processingEnv
883+
.getMessager()
884+
.printMessage(Diagnostic.Kind.ERROR, String.format("%s %s", e, e.getModifiers()), e);
885+
}
886+
return false;
887+
}
888+
}
889+
890+
@Test
891+
public void modifiers() {
892+
ImmutableList<Tree.CompUnit> units =
893+
parseUnit(
894+
"=== I.java ===", //
895+
"sealed interface I {}",
896+
"non-sealed interface J {}");
897+
TurbineError e = runProcessors(units, new ModifiersProcessor());
898+
assertThat(e.diagnostics().stream().map(d -> d.message()))
899+
.containsExactly("I [abstract, sealed]", "J [abstract, non-sealed]");
900+
}
901+
872902
private TurbineError runProcessors(ImmutableList<Tree.CompUnit> units, Processor... processors) {
873903
return assertThrows(
874904
TurbineError.class,

0 commit comments

Comments
 (0)