Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #994 from Tim203/fix/correct-long-interpretation
Browse files Browse the repository at this point in the history
Add L to long values to prevent them from being interpreted as int
  • Loading branch information
JakeWharton authored Jan 16, 2024
2 parents aaebc48 + fa579e1 commit c9925e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/squareup/javapoet/AnnotationSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ Builder addMemberForValue(String memberName, Object value) {
if (value instanceof Float) {
return addMember(memberName, "$Lf", value);
}
if (value instanceof Long) {
return addMember(memberName, "$LL", value);
}
if (value instanceof Character) {
return addMember(memberName, "'$L'", characterLiteralWithoutSingleQuotes((char) value));
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/squareup/javapoet/AnnotationSpecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public enum Breakfast {

int c() default 7;

long d() default 8;
long d() default 12345678910L;

float e() default 9.0f;

Expand Down Expand Up @@ -313,7 +313,7 @@ public class IsAnnotated {
+ " a = 5,\n"
+ " b = 6,\n"
+ " c = 7,\n"
+ " d = 8,\n"
+ " d = 12345678910L,\n"
+ " e = 9.0f,\n"
+ " f = 11.1,\n"
+ " g = {\n"
Expand Down

0 comments on commit c9925e4

Please sign in to comment.