Fix #303
All checks were successful
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 2m37s
All checks were successful
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 2m37s
This commit is contained in:
parent
43da2ffbdc
commit
7f3c1686ec
@ -3,4 +3,6 @@ import java.lang.Character;
|
|||||||
public class Literal {
|
public class Literal {
|
||||||
public m() { return null; }
|
public m() { return null; }
|
||||||
public m2() { return 'C'; }
|
public m2() { return 'C'; }
|
||||||
|
public m3() { return 10L; }
|
||||||
|
public m4() { return 10.5F; }
|
||||||
}
|
}
|
@ -1044,10 +1044,17 @@ public class StatementGenerator {
|
|||||||
private Expression convert(Java17Parser.LiteralContext literal) {
|
private Expression convert(Java17Parser.LiteralContext literal) {
|
||||||
switch (literal) {
|
switch (literal) {
|
||||||
case IntLiteralContext intliteral:
|
case IntLiteralContext intliteral:
|
||||||
Number value = Integer.parseInt(intliteral.getText());
|
Number value;
|
||||||
|
if (intliteral.getText().endsWith("l") || intliteral.getText().endsWith("L"))
|
||||||
|
value = Long.parseLong(intliteral.getText().substring(0, intliteral.getText().length() - 1));
|
||||||
|
else value = Integer.parseInt(intliteral.getText());
|
||||||
return new Literal(TypePlaceholder.fresh(literal.getStart()), value, intliteral.getStart());
|
return new Literal(TypePlaceholder.fresh(literal.getStart()), value, intliteral.getStart());
|
||||||
case FltLiteralContext floatliteral:
|
case FltLiteralContext floatliteral:
|
||||||
value = Double.parseDouble(floatliteral.getText());
|
if (floatliteral.getText().endsWith("f") || floatliteral.getText().endsWith("F"))
|
||||||
|
value = Float.parseFloat(floatliteral.getText().substring(0, floatliteral.getText().length() - 1));
|
||||||
|
else if (floatliteral.getText().endsWith("d") || floatliteral.getText().endsWith("D"))
|
||||||
|
value = Double.parseDouble(floatliteral.getText().substring(0, floatliteral.getText().length() - 1));
|
||||||
|
else value = Double.parseDouble(floatliteral.getText());
|
||||||
return new Literal(TypePlaceholder.fresh(literal.getStart()), value, floatliteral.getStart());
|
return new Literal(TypePlaceholder.fresh(literal.getStart()), value, floatliteral.getStart());
|
||||||
case CharLiteralContext charliteral:
|
case CharLiteralContext charliteral:
|
||||||
RefType type = new RefType(reg.getName("java.lang.Character"), charliteral.getStart());
|
RefType type = new RefType(reg.getName("java.lang.Character"), charliteral.getStart());
|
||||||
|
@ -825,6 +825,8 @@ public class TestComplete {
|
|||||||
|
|
||||||
assertNull(clazz.getDeclaredMethod("m").invoke(instance));
|
assertNull(clazz.getDeclaredMethod("m").invoke(instance));
|
||||||
assertEquals(clazz.getDeclaredMethod("m2").invoke(instance), 'C');
|
assertEquals(clazz.getDeclaredMethod("m2").invoke(instance), 'C');
|
||||||
|
assertEquals(clazz.getDeclaredMethod("m3").invoke(instance), 10L);
|
||||||
|
assertEquals(clazz.getDeclaredMethod("m4").invoke(instance), 10.5F);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user