From 4c3e8dceb862b52fc5d12d85cb2012b1f9a9e0ed Mon Sep 17 00:00:00 2001 From: Goktug Gokdogan Date: Thu, 14 Dec 2023 10:41:27 -0800 Subject: [PATCH] [WASM] Remove side effect from j.l.Class name functions. This helps with removal of unused code from common patterns like: Logger.getLogger(Foo.class.getName) PiperOrigin-RevId: 590987324 --- jre/java/super-wasm/java/lang/Class.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jre/java/super-wasm/java/lang/Class.java b/jre/java/super-wasm/java/lang/Class.java index 8dd7bfaa68..0c50202ca1 100644 --- a/jre/java/super-wasm/java/lang/Class.java +++ b/jre/java/super-wasm/java/lang/Class.java @@ -67,6 +67,7 @@ private Class( this.leafType = leafType; } + @HasNoSideEffects public String getName() { if (isArray()) { String className = isPrimitive ? primitiveShortName : "L" + getClassName() + ";"; @@ -77,12 +78,14 @@ public String getName() { // J2CL doesn't follow JLS strictly here and provides an approximation that is good enough for // debugging and testing uses. + @HasNoSideEffects public String getCanonicalName() { return getClassName() + repeatString("[]", dimensionCount); } // J2CL doesn't follow JLS strictly here and provides an approximation that is good enough for // debugging and testing uses. + @HasNoSideEffects public String getSimpleName() { return stripToLastOccurrenceOf(stripToLastOccurrenceOf(getCanonicalName(), "."), "$"); }