diff --git a/resources/bytecode/javFiles/Literal.jav b/resources/bytecode/javFiles/Literal.jav index 1d081e27..52e1c8c9 100644 --- a/resources/bytecode/javFiles/Literal.jav +++ b/resources/bytecode/javFiles/Literal.jav @@ -1,3 +1,6 @@ +import java.lang.Character; + public class Literal { m() { return null; } + m2() { return 'C'; } } \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java index aef180d3..7c06ee8d 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java @@ -136,7 +136,7 @@ public class Codegen { } else if (type.equals(TargetType.Short) || type.equals(TargetType.short_)) { mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;", false); } else if (type.equals(TargetType.Char) || type.equals(TargetType.char_)) { - mv.visitMethodInsn(INVOKESTATIC, "java/lang/Char", "valueOf", "(C)Ljava/lang/Char;", false); + mv.visitMethodInsn(INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;", false); } } @@ -157,7 +157,7 @@ public class Codegen { } else if (type.equals(TargetType.Short)) { mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Short", "shortValue", "()S", false); } else if (type.equals(TargetType.Char)) { - mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Char", "charValue", "()C", false); + mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Character", "charValue", "()C", false); } } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index 48c4830d..308cf9a2 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -361,7 +361,7 @@ public class ASTFactory { } else if (type.getTypeName().equals("boolean")) { return new RefType(new JavaClassName("java.lang.Boolean"), new ArrayList<>(), new NullToken(), true); } else if (type.getTypeName().equals("char")) { - return new RefType(new JavaClassName("java.lang.Char"), new ArrayList<>(), new NullToken(), true); + return new RefType(new JavaClassName("java.lang.Character"), new ArrayList<>(), new NullToken(), true); } else if (type.getTypeName().equals("short")) { return new RefType(new JavaClassName("java.lang.Short"), new ArrayList<>(), new NullToken(), true); } else if (type.getTypeName().equals("double")) { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index c49eceaf..3e0012f1 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -226,6 +226,8 @@ public class TYPEStmt implements StatementVisitor { private final RefType doublee = new RefType(ASTFactory.createClass(Double.class).getClassName(), new NullToken()); private final RefType string = new RefType(ASTFactory.createClass(String.class).getClassName(), new NullToken()); private final RefType bool = new RefType(ASTFactory.createClass(Boolean.class).getClassName(), new NullToken()); + + private final RefType charr = new RefType(ASTFactory.createClass(Character.class).getClassName(), new NullToken()); @Override public void visit(UnaryExpr unaryExpr) { @@ -452,6 +454,10 @@ public class TYPEStmt implements StatementVisitor { constraintsSet.addUndConstraint(new Pair(literal.getType(), bool, PairOperator.EQUALSDOT)); return; } + if (literal.value instanceof Character) { + constraintsSet.addUndConstraint(new Pair(literal.getType(), charr, PairOperator.EQUALSDOT)); + return; + } if (literal.value != null) { throw new NotImplementedException(); } diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index cd396155..ff857464 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -824,6 +824,7 @@ public class TestComplete { var instance = clazz.getDeclaredConstructor().newInstance(); assertNull(clazz.getDeclaredMethod("m").invoke(instance)); + assertEquals(clazz.getDeclaredMethod("m2").invoke(instance), 'C'); } @Test