Skip to content

Commit

Permalink
[WASM] Remove side effect from j.l.Class name functions.
Browse files Browse the repository at this point in the history
This helps with removal of unused code from common patterns like:
Logger.getLogger(Foo.class.getName)

PiperOrigin-RevId: 590987324
  • Loading branch information
gkdn authored and copybara-github committed Dec 14, 2023
1 parent 71f2c81 commit 4c3e8dc
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions jre/java/super-wasm/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private Class(
this.leafType = leafType;
}

@HasNoSideEffects
public String getName() {
if (isArray()) {
String className = isPrimitive ? primitiveShortName : "L" + getClassName() + ";";
Expand All @@ -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(), "."), "$");
}
Expand Down

0 comments on commit 4c3e8dc

Please sign in to comment.