summaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-25 17:42:17 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-25 17:42:17 +0100
commitb219b7a24fbece0256b15d408e0f65d8136e671a (patch)
treea10dd73ebf1dabfc76501c9d357d33243125ef93 /src/main/java/org/zwobble
parentf19321fcc099fdcb22c30bcca5bdad04c7396876 (diff)
Avoid variable name collisions in java-transient-0
Diffstat (limited to 'src/main/java/org/zwobble')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatransient0/JavaTransient0Generator.java88
1 files changed, 45 insertions, 43 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatransient0/JavaTransient0Generator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatransient0/JavaTransient0Generator.java
index ca654e3..f1d4957 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatransient0/JavaTransient0Generator.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatransient0/JavaTransient0Generator.java
@@ -905,50 +905,52 @@ public class JavaTransient0Generator implements Generator {
var existingId = JavaIdentifier.of("existingId");
return List.of(
- new JavaLocalVariableDeclaration(
- Optional.empty(),
- existingId,
- Optional.of(new JavaMethodCall(
- new JavaRef(SHARED_VALUES_NAME),
- JavaIdentifier.of("get"),
- List.of(value)
- ))
- ),
- new JavaIfStatement(
- new JavaBinaryOperation(
- JavaBinaryOperator.NOT_EQUAL_TO,
- new JavaRef(existingId),
- new JavaNullLiteral()
- ),
- new JavaBlock(
- generateEncode(new JavaRef(existingId), NativeTypes.INT_64)
+ new JavaBlock(List.of(
+ new JavaLocalVariableDeclaration(
+ Optional.empty(),
+ existingId,
+ Optional.of(new JavaMethodCall(
+ new JavaRef(SHARED_VALUES_NAME),
+ JavaIdentifier.of("get"),
+ List.of(value)
+ ))
),
- new JavaBlock(Lists.concat(List.of(
- generateEncode(
- new JavaMethodCall(
- new JavaRef(SHARED_VALUES_NAME),
- JavaIdentifier.of("size"),
- List.of()
- ),
- NativeTypes.INT_64
+ new JavaIfStatement(
+ new JavaBinaryOperation(
+ JavaBinaryOperator.NOT_EQUAL_TO,
+ new JavaRef(existingId),
+ new JavaNullLiteral()
),
- List.of(
- new JavaExpressionStatement(new JavaMethodCall(
- new JavaRef(SHARED_VALUES_NAME),
- JavaIdentifier.of("put"),
- List.of(
- value,
- new JavaCast(JavaTypeRef.LONG, new JavaMethodCall(
- new JavaRef(SHARED_VALUES_NAME),
- JavaIdentifier.of("size"),
- List.of()
- ))
- )
- ))
+ new JavaBlock(
+ generateEncode(new JavaRef(existingId), NativeTypes.INT_64)
),
- generateEncode(value, type)
- )))
- )
+ new JavaBlock(Lists.concat(List.of(
+ generateEncode(
+ new JavaMethodCall(
+ new JavaRef(SHARED_VALUES_NAME),
+ JavaIdentifier.of("size"),
+ List.of()
+ ),
+ NativeTypes.INT_64
+ ),
+ List.of(
+ new JavaExpressionStatement(new JavaMethodCall(
+ new JavaRef(SHARED_VALUES_NAME),
+ JavaIdentifier.of("put"),
+ List.of(
+ value,
+ new JavaCast(JavaTypeRef.LONG, new JavaMethodCall(
+ new JavaRef(SHARED_VALUES_NAME),
+ JavaIdentifier.of("size"),
+ List.of()
+ ))
+ )
+ ))
+ ),
+ generateEncode(value, type)
+ )))
+ )
+ ))
);
}
@@ -956,8 +958,8 @@ public class JavaTransient0Generator implements Generator {
JavaIdentifier target,
Type type
) {
- var id = JavaIdentifier.of("id");
- var decodedValue = JavaIdentifier.of("decodedValue");
+ var id = JavaIdentifier.of(target.value() + "$id");
+ var decodedValue = JavaIdentifier.of(target.value() + "$decodedValue");
return Lists.concat(List.of(
generateDecode(id, NativeTypes.INT_64),