Skip to content

Commit

Permalink
Support sealed and non-sealed modifiers in getModifiers
Browse files Browse the repository at this point in the history
Startblock:
  * unknown commit is submitted
PiperOrigin-RevId: 673984224
  • Loading branch information
cushon authored and Javac Team committed Sep 12, 2024
1 parent 7dafb70 commit 6574ba5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion java/com/google/turbine/processing/TurbineElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,12 @@ private static ImmutableSet<Modifier> asModifierSet(ModifierOwner modifierOwner,
if ((access & TurbineFlag.ACC_STRICT) == TurbineFlag.ACC_STRICT) {
modifiers.add(Modifier.STRICTFP);
}

if ((access & TurbineFlag.ACC_SEALED) == TurbineFlag.ACC_SEALED) {
modifiers.add(Modifier.SEALED);
}
if ((access & TurbineFlag.ACC_NON_SEALED) == TurbineFlag.ACC_NON_SEALED) {
modifiers.add(Modifier.NON_SEALED);
}
return Sets.immutableEnumSet(modifiers);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,36 @@ public void recordComponents() {
"enclosing: R, name: y, accessor: y() [@java.lang.Deprecated]");
}

@SupportedAnnotationTypes("*")
public static class ModifiersProcessor extends AbstractProcessor {
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (Element e : roundEnv.getRootElements()) {
processingEnv
.getMessager()
.printMessage(Diagnostic.Kind.ERROR, String.format("%s %s", e, e.getModifiers()), e);
}
return false;
}
}

@Test
public void modifiers() {
ImmutableList<Tree.CompUnit> units =
parseUnit(
"=== I.java ===", //
"sealed interface I {}",
"non-sealed interface J {}");
TurbineError e = runProcessors(units, new ModifiersProcessor());
assertThat(e.diagnostics().stream().map(d -> d.message()))
.containsExactly("I [abstract, sealed]", "J [abstract, non-sealed]");
}

private TurbineError runProcessors(ImmutableList<Tree.CompUnit> units, Processor... processors) {
return assertThrows(
TurbineError.class,
Expand Down

0 comments on commit 6574ba5

Please sign in to comment.