diff --git a/transpiler/java/com/google/j2cl/transpiler/frontend/common/FrontendConstants.java b/transpiler/java/com/google/j2cl/transpiler/frontend/common/FrontendConstants.java index 9d81ca7dce..e4c1f42b0d 100644 --- a/transpiler/java/com/google/j2cl/transpiler/frontend/common/FrontendConstants.java +++ b/transpiler/java/com/google/j2cl/transpiler/frontend/common/FrontendConstants.java @@ -47,5 +47,13 @@ public final class FrontendConstants { public static final String DO_NOT_AUTOBOX_ANNOTATION_NAME = "javaemul.internal.annotations.DoNotAutobox"; + public static final String UNCHECKED_CAST_ANNOTATION_NAME = + "javaemul.internal.annotations.UncheckedCast"; + + public static final String HAS_NO_SIDE_EFFECTS_ANNOTATION_NAME = + "javaemul.internal.annotations.HasNoSideEffects"; + + public static final String WASM_ANNOTATION_NAME = "javaemul.internal.annotations.Wasm"; + private FrontendConstants() {} } diff --git a/transpiler/java/com/google/j2cl/transpiler/frontend/javac/JavaEnvironment.java b/transpiler/java/com/google/j2cl/transpiler/frontend/javac/JavaEnvironment.java index 096569ed90..79711dec50 100644 --- a/transpiler/java/com/google/j2cl/transpiler/frontend/javac/JavaEnvironment.java +++ b/transpiler/java/com/google/j2cl/transpiler/frontend/javac/JavaEnvironment.java @@ -17,6 +17,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.ImmutableList.toImmutableList; +import static com.google.j2cl.transpiler.frontend.common.FrontendConstants.HAS_NO_SIDE_EFFECTS_ANNOTATION_NAME; +import static com.google.j2cl.transpiler.frontend.common.FrontendConstants.UNCHECKED_CAST_ANNOTATION_NAME; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; @@ -880,12 +882,12 @@ private MethodDescriptor createDeclaredMethodDescriptor( /** Returns true if the element is annotated with @UncheckedCast. */ private static boolean hasUncheckedCastAnnotation(Element element) { - return AnnotationUtils.hasAnnotation(element, "javaemul.internal.annotations.UncheckedCast"); + return AnnotationUtils.hasAnnotation(element, UNCHECKED_CAST_ANNOTATION_NAME); } /** Returns true if the element is annotated with @HasNoSideEffects. */ private static boolean isAnnotatedWithHasNoSideEffects(Element element) { - return AnnotationUtils.hasAnnotation(element, "javaemul.internal.annotations.HasNoSideEffects"); + return AnnotationUtils.hasAnnotation(element, HAS_NO_SIDE_EFFECTS_ANNOTATION_NAME); } private boolean isJavaLangObjectOverride(MethodSymbol method) { diff --git a/transpiler/java/com/google/j2cl/transpiler/frontend/jdt/JdtEnvironment.java b/transpiler/java/com/google/j2cl/transpiler/frontend/jdt/JdtEnvironment.java index c0fda35a73..80e959a823 100644 --- a/transpiler/java/com/google/j2cl/transpiler/frontend/jdt/JdtEnvironment.java +++ b/transpiler/java/com/google/j2cl/transpiler/frontend/jdt/JdtEnvironment.java @@ -18,6 +18,9 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static com.google.common.collect.ImmutableList.toImmutableList; +import static com.google.j2cl.transpiler.frontend.common.FrontendConstants.HAS_NO_SIDE_EFFECTS_ANNOTATION_NAME; +import static com.google.j2cl.transpiler.frontend.common.FrontendConstants.UNCHECKED_CAST_ANNOTATION_NAME; +import static com.google.j2cl.transpiler.frontend.common.FrontendConstants.WASM_ANNOTATION_NAME; import com.google.common.base.Splitter; import com.google.common.collect.FluentIterable; @@ -249,7 +252,7 @@ private static boolean isArrayLengthBinding(IVariableBinding variableBinding) { /** Returns true if the binding is annotated with @UncheckedCast. */ public static boolean hasUncheckedCastAnnotation(IBinding binding) { - return JdtAnnotationUtils.hasAnnotation(binding, "javaemul.internal.annotations.UncheckedCast"); + return JdtAnnotationUtils.hasAnnotation(binding, UNCHECKED_CAST_ANNOTATION_NAME); } /** Helper method to work around JDT habit of returning raw collections. */ @@ -949,14 +952,14 @@ private ImmutableList convertTypeArguments( private static String getWasmInfo(ITypeBinding binding) { return JdtAnnotationUtils.getStringAttribute( JdtAnnotationUtils.findAnnotationBindingByName( - binding.getAnnotations(), "javaemul.internal.annotations.Wasm"), + binding.getAnnotations(), WASM_ANNOTATION_NAME), "value"); } private static String getWasmInfo(IMethodBinding binding) { return JdtAnnotationUtils.getStringAttribute( JdtAnnotationUtils.findAnnotationBindingByName( - binding.getAnnotations(), "javaemul.internal.annotations.Wasm"), + binding.getAnnotations(), WASM_ANNOTATION_NAME), "value"); } @@ -1272,7 +1275,6 @@ private static boolean isAnnotatedWithJUnitRunWith(ITypeBinding typeBinding) { } private static boolean isAnnotatedWithHasNoSideEffects(IMethodBinding methodBinding) { - return JdtAnnotationUtils.hasAnnotation( - methodBinding, "javaemul.internal.annotations.HasNoSideEffects"); + return JdtAnnotationUtils.hasAnnotation(methodBinding, HAS_NO_SIDE_EFFECTS_ANNOTATION_NAME); } }