Skip to content

Commit

Permalink
Extract shared constants for the javaemul annotation types
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 585808420
  • Loading branch information
kevinoconnor7 authored and copybara-github committed Nov 28, 2023
1 parent 37c2fad commit 11160d1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -949,14 +952,14 @@ private ImmutableList<TypeDescriptor> 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");
}

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 11160d1

Please sign in to comment.