This commit is contained in:
Boolean-true 2024-06-29 22:10:44 +02:00
commit 18125531cf
20 changed files with 348 additions and 138 deletions

View File

@ -81,6 +81,12 @@
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.10.2</version>
<scope>test</scope>
</dependency>
<!-- JUnit 5 end -->
<dependency>
<groupId>commons-cli</groupId>

View File

@ -49,12 +49,20 @@ public class TypedFieldVarAccess implements TypedExpression {
private Type checkFieldOrMethodType(TypedProgram typedProgram) {
if (typedProgram.getCurrentClass().isThereField(name)) {
type = typedProgram.getCurrentClass().getFieldType(name);
return type;
return checkTypeField(typedProgram);
} else if (typedProgram.getCurrentClass().isMethodOfCurrentClass(name)) {
type = typedProgram.getCurrentClass().getMethodType(name);
return type;
} else if (recursiveOwnerChain instanceof TypedFieldVarAccess typedFieldVarAccess) {
if (typedProgram.isClassWithNamePresent(recursiveOwnerChain.getType().getReference())) {
Type typeofFieldNameInClass = typedProgram.getTypeOfFieldNameInClass(recursiveOwnerChain.getType().getReference(), name);
if(typeofFieldNameInClass != null){
return typeofFieldNameInClass;
}else{
throw new RuntimeException("Field " + name + " not declared in class " + recursiveOwnerChain.getType().getReference());
}
}
type = typedProgram.getCurrentClass().getFieldType(typedFieldVarAccess.getName());
return type;
} else {
@ -106,7 +114,15 @@ public class TypedFieldVarAccess implements TypedExpression {
}
return type;
}
private Type checkTypeField(TypedProgram typedProgram) {
if (recursiveOwnerChain != null) {
if (recursiveOwnerChain.getType() != null) {
return typedProgram.getTypeOfFieldNameInClass(recursiveOwnerChain.getType().getReference(), name);
}
}
type = typedProgram.getCurrentClass().getFieldType(name);
return type;
}
@Override
public void codeGen(MethodContext ctx) {
if (recursiveOwnerChain != null) {

View File

@ -1,6 +1,7 @@
package de.maishai.typedast.typedclass;
import de.maishai.ast.records.Program;
import de.maishai.typedast.Type;
import lombok.AllArgsConstructor;
import lombok.Getter;
@ -43,6 +44,12 @@ public class TypedProgram {
}
}
public boolean isClassWithNamePresent(String className) {
return typedClasses.stream().anyMatch(clas -> clas.getClassName().equals(className));
}
public Type getTypeOfFieldNameInClass(String className, String fieldName) {
return typedClasses.stream().filter(clas -> clas.getClassName().equals(className)).findFirst().get().getFieldType(fieldName);
}
public TypedClass getTypedClass(String className) {
return typedClasses.stream().filter(clas -> clas.getClassName().equals(className)).findFirst().get();
}

View File

@ -1,15 +1,14 @@
import de.maishai.Compiler;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import testResources.CodeGen.BytecodeTestUtil;
import org.junit.platform.commons.support.HierarchyTraversalMode;
import org.junit.platform.commons.support.ReflectionSupport;
import testResources.CodeGen.Features.*;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class CodegeneratorTests {
@ -30,21 +29,164 @@ public class CodegeneratorTests {
// });
// }
// @Test
// public void testBreak() {
// ByteCode_Break ByteCode_Break = new ByteCode_Break();
// Assertions.assertTrue(ByteCode_Break.allTestsSuccessful());
// }
@Test
public void runByteCodeBreakTests() {
runByteCodeTests(ByteCode_Break.class);
}
// @Test
// public void testClass() {
// ByteCode_Class ByteCode_Class = new ByteCode_Class();
// Assertions.assertTrue(ByteCode_Class.allTestsSuccessful());
// }
@Test
public void runByteCodeClassTests() {
runByteCodeTests(ByteCode_Class.class);
}
// @Test
// public void testClassObjects() {
// ByteCode_ClassObjects ByteCode_ClassObjects = new ByteCode_ClassObjects();
// Assertions.assertTrue(ByteCode_ClassObjects.allTestsSuccessful());
// }
}
@Test
public void runByteCodeClassObjectsTests() {
runByteCodeTests(ByteCode_ClassObjects.class);
}
@Test
public void runByteCodeCommentTests() {
runByteCodeTests(ByteCode_Comment.class);
}
@Test
public void runByteCodeCompAssignTests() {
runByteCodeTests(ByteCode_CompAssign.class);
}
@Test
public void runByteCodeComplexCallsTests() {
runByteCodeTests(ByteCode_ComplexCalls.class);
}
@Test
public void runByteCodeConstructorTests() {
runByteCodeTests(ByteCode_Constructor.class);
}
@Test
public void runByteCodeContinueTests() {
runByteCodeTests(ByteCode_Continue.class);
}
@Test
public void runByteCodeDataTypesTests() {
runByteCodeTests(ByteCode_DataTypes.class);
}
@Test
public void runByteCodeFieldTests() {
runByteCodeTests(ByteCode_Field.class);
}
@Test
public void runByteCodeForTests() {
runByteCodeTests(ByteCode_For.class);
}
@Test
public void runByteCodeIfTests() {
runByteCodeTests(ByteCode_If.class);
}
@Test
public void runByteCodeLogicExprTests() {
runByteCodeTests(ByteCode_LogicExpr.class);
}
@Test
public void runByteCodeMainTests() {
runByteCodeTests(ByteCode_Main.class);
}
@Test
public void runByteCodeMethodTests() {
runByteCodeTests(ByteCode_Method.class);
}
@Test
public void runByteCodeMethodCallTests() {
runByteCodeTests(ByteCode_MethodCall.class);
}
@Test
public void runByteCodeMultipleClassesTests() {
runByteCodeTests(ByteCode_MultipleClasses.class);
}
@Test
public void runByteCodeOperatorsTests() {
runByteCodeTests(ByteCode_Operators.class);
}
@Test
public void runByteCodeOverloadedTests() {
runByteCodeTests(ByteCode_Overloaded.class);
}
@Test
public void runByteCodePrintTests() {
runByteCodeTests(ByteCode_Print.class);
}
@Test
public void runByteCodeReturnTests() {
runByteCodeTests(ByteCode_Return.class);
}
@Test
public void runByteCodeUnaryTests() {
runByteCodeTests(ByteCode_Unary.class);
}
@Test
public void runByteCodeVariableDefWithDeclTests() {
runByteCodeTests(ByteCode_VariableDefWithDecl.class);
}
@Test
public void runByteCodeWhileTests() {
runByteCodeTests(ByteCode_While.class);
}
private void runByteCodeTests(Class<?> testClass) {
List<String> failedTests = new ArrayList<>();
// Finde alle Methoden, die mit @Test annotiert sind
List<Method> testMethods = ReflectionSupport.findMethods(
testClass,
method -> method.isAnnotationPresent(Test.class),
HierarchyTraversalMode.TOP_DOWN
);
for (Method testMethod : testMethods) {
try {
// Erstelle eine Instanz der Testklasse
Object testInstance = ReflectionSupport.newInstance(testClass);
// Führe die Setup-Methode aus (falls vorhanden)
Optional<Method> setUpMethodOptional = ReflectionSupport.findMethod(testClass, "setUp");
if (setUpMethodOptional.isPresent()) {
setUpMethodOptional.get().invoke(testInstance);
}
// Führe die Testmethode aus
testMethod.invoke(testInstance);
} catch (Exception e) {
if (e.getCause() != null) {
failedTests.add(testMethod.getName() + ": " + e.getCause().getMessage());
} else {
failedTests.add(testMethod.getName() + ": " + e.getMessage());
}
}
}
if (!failedTests.isEmpty()) {
failedTests.forEach(System.err::println);
Assertions.fail("Ein oder mehrere Tests sind fehlgeschlagen.");
} else {
System.out.println("Alle Tests sind erfolgreich.");
}
}
}

View File

@ -0,0 +1,23 @@
import de.maishai.Compiler;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.List;
public class NegativeTests {
@Test
public void AddressingFieldWithoutThis() {
try {
Compiler.generateByteCodeFilesFromFiles(List.of("src/test/testFiles/Negative/AddressingFieldWithoutThis.java"));
Assertions.fail();
} catch (Exception e) {
Assertions.assertTrue(true);
}
}
@Test
public void PublicMissingInClass() {
Compiler.generateByteCodeFilesFromFiles(List.of("src/test/testFiles/Negative/PublicMissingInClass.java"));
}
}

View File

@ -75,146 +75,148 @@ public class ScannerParserTests {
@Test
public void testBreak() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/Break.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Break.java"));
assertEquals(AST_Break.get(), resultAst);
}
@Test
public void testClass() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/Class.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Class.java"));
assertEquals(AST_Class.get(), resultAst);
}
@Test
public void testClassObjects() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/ClassObjects.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/ClassObjects.java"));
assertEquals(AST_ClassObjects.get(), resultAst);
}
//TODO: nochmal drüberschauen, nachfragen wegen true/false bei FieldVarAccess
@Test
public void testComment() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/Comment.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Comment.java"));
assertEquals(AST_Comment.get(), resultAst);
}
@Test
public void testCompAssign() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/CompAssign.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/CompAssign.java"));
assertEquals(AST_CompAssign.get(), resultAst);
}
@Test
public void testComplexCalls() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/ComplexCalls.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/ComplexCalls.java"));
assertEquals(AST_ComplexCalls.get(), resultAst);
}
@Test
public void testConstructor() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/Constructor.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Constructor.java"));
assertEquals(AST_Constructor.get(), resultAst);
}
@Test
public void testContinue() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/Continue.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Continue.java"));
assertEquals(AST_Continue.get(), resultAst);
}
@Test
public void testDataTypes() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/DataTypes.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/DataTypes.java"));
assertEquals(AST_DataTypes.get(), resultAst);
}
@Test
public void testField() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/Field.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Field.java"));
assertEquals(AST_Field.get(), resultAst);
}
@Test
public void testFor() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/For.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/For.java"));
assertEquals(AST_For.get(), resultAst);
}
@Test
public void testIf() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/If.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/If.java"));
assertEquals(AST_If.get(), resultAst);
}
@Test
public void testLogicExpr() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/LogicExpr.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/LogicExpr.java"));
assertEquals(AST_LogicExpr.get(), resultAst);
}
@Test
public void testMain() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/Main.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Main.java"));
assertEquals(AST_Main.get(), resultAst);
}
@Test
public void testMethod() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/Method.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Method.java"));
assertEquals(AST_Method.get(), resultAst);
}
@Test
public void testMethodCall() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/MethodCall.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/MethodCall.java"));
assertEquals(AST_MethodCall.get(), resultAst);
}
@Test
public void testMultipleClasses() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/MultipleClasses1.java"));
Program resultAst = Compiler.generateASTFromFiles(
List.of("src/test/testFiles/ASTandTypedASTFeatures/MultipleClasses1.java",
"src/test/testFiles/ASTandTypedASTFeatures/MultipleClasses2.java"));
assertEquals(AST_MultipleClasses.get(), resultAst);
}
@Test
public void testOperators() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/Operators.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Operators.java"));
assertEquals(AST_Operators.get(), resultAst);
}
@Test
public void testOverloaded() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/Overloaded.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Overloaded.java"));
assertEquals(AST_Overloaded.get(), resultAst);
}
@Test
public void testPrint() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/Print.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Print.java"));
assertEquals(AST_Print.get(), resultAst);
}
@Test
public void testReturn() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/Return.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Return.java"));
assertEquals(AST_Return.get(), resultAst);
}
@Test
public void testUnary() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/Unary.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Unary.java"));
assertEquals(AST_Unary.get(), resultAst);
}
@Test
public void testVariableDefWithDecl() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/VariableDefWithDecl.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/VariableDefWithDecl.java"));
assertEquals(AST_VariableDefWithDecl.get(), resultAst);
}
@Test
public void testWhile() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/While.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/While.java"));
assertEquals(AST_While.get(), resultAst);
}
}

View File

@ -1,15 +1,8 @@
import de.maishai.Compiler;
import de.maishai.typedast.typedclass.TypedProgram;
import jdk.jshell.spi.ExecutionControl;
import org.junit.jupiter.api.Test;
import testResources.TypedAST.TypedASTFeatures.*;
import testResources.AST.ASTFeatures.*;
import testResources.AST.ASTMore.AbstractSyntax_ClassWithConstructor;
import testResources.AST.ASTMore.AbstractSyntax_ClassWithField;
import testResources.AST.ASTMore.AbstractSyntax_PublicClass;
import testResources.TypedAST.TypedASTMore.TypedAbstractSyntax_ClassWithConstructor;
import testResources.TypedAST.TypedASTMore.TypedAbstractSyntax_ClassWithField;
import testResources.TypedAST.TypedASTMore.TypedAbstractSyntax_PublicClass;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -121,14 +114,12 @@ public class TypingTests {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_LogicExpr.get());
assertEquals(TypedAST_LogicExpr.get(), resultTypedAst);
}
// TODO: mit Operatoren verknüpfte Typen werden nicht korrekt ermittelt
@Test
public void testMain() {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Main.get());
assertEquals(TypedAST_Main.get(), resultTypedAst);
}
// TODO: Wie soll das Resultat aussehen? Soll tatsächlich main auch als Methode aufgeführt werden?
@Test
public void testMethod() {
@ -177,7 +168,6 @@ public class TypingTests {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Unary.get());
assertEquals(TypedAST_Unary.get(), resultTypedAst);
}
// TODO: Typ von TypedUnary wird nicht ermittelt
@Test
public void testVariableDefWithDecl() {
@ -191,9 +181,4 @@ public class TypingTests {
assertEquals(TypedAST_While.get(), resultTypedAst);
}
//TODO: Anschauen: Konstruktor hat doch immer den Typ der Klasse?
// bei logischen Ausdrücken hat einer keinen boolschen Typ
// In Methoden und Konstruktoren werden Parameter zusätzlich als TypedLocalVariable aufgeführt, warum?
// bei TypedUnary wird nicht der Typ ermittelt
}

View File

@ -11,18 +11,39 @@ public class AST_MultipleClasses {
return new Program(
List.of(
new Class(
"MultipleClasses",
"MultipleClasses1",
null,
List.of(
new Declaration(
"anotherClass",
Type.REFERENCE("AnotherClass")
Type.REFERENCE("MultipleClasses2")
)
),
List.of(
new Method(
Type.INT,
"getIFromAnotherClass",
List.of(),
new Block(
List.of(
new Return(
new FieldVarAccess(
true,
new FieldVarAccess(
true,
null,
"anotherClass"
),
"i"
)
)
)
)
)
),
List.of(),
List.of(
new Constructor(
"MultipleClasses",
"MultipleClasses1",
List.of(),
new Block(
List.of(
@ -33,7 +54,7 @@ public class AST_MultipleClasses {
"anotherClass"
),
new New(
Type.REFERENCE("AnotherClass"),
Type.REFERENCE("MultipleClasses2"),
List.of()
)
)
@ -43,18 +64,18 @@ public class AST_MultipleClasses {
)
),
new Class(
"AnotherClass",
"MultipleClasses2",
null,
List.of(
new Declaration(
"multipleClasses",
Type.REFERENCE("MultipleClasses")
"i",
Type.INT
)
),
List.of(),
List.of(
new Constructor(
"AnotherClass",
"MultipleClasses2",
List.of(),
new Block(
List.of(
@ -62,12 +83,9 @@ public class AST_MultipleClasses {
new FieldVarAccess(
true,
null,
"multipleClasses"
"i"
),
new New(
Type.REFERENCE("MultipleClasses"),
List.of()
)
new IntLiteral(4)
)
)
)

View File

@ -1,6 +1,5 @@
package testResources.CodeGen.Features;
import de.maishai.typedast.Type;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

View File

@ -7,7 +7,7 @@ import testResources.CodeGen.BytecodeTestUtil;
import java.util.List;
class ByteCode_ClassObjects {
public class ByteCode_ClassObjects {
private BytecodeTestUtil util;
@ -20,48 +20,47 @@ class ByteCode_ClassObjects {
}
}
@Test
void testConstructorCount() {
public void testConstructorCount() {
Assertions.assertEquals(2, util.getConstructorCount());
}
@Test
void testConstructor1() {
public void testConstructor1() {
Assertions.assertEquals("ClassObjects", util.getConstructorNames().get(0));
Assertions.assertEquals(0, util.getConstructorParameterCount(0));
}
@Test
void testConstructor2() {
public void testConstructor2() {
Assertions.assertEquals("ClassObjects", util.getConstructorNames().get(1));
Assertions.assertEquals(1, util.getConstructorParameterCount(1));
}
@Test
void testMethodCount() {
public void testMethodCount() {
Assertions.assertEquals(1, util.getMethodCount());
}
@Test
void testMethodNames() {
Assertions.assertEquals("objectsMethod", util.getMethodNames().get(0));
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("objectsMethod"));
}
@Test
void testMethodReturnType() {
public void testMethodReturnType() {
try {
Assertions.assertEquals("void", util.getMethodReturnType("objectsMethod", new Class<?>[]{}));
Assertions.assertEquals("void", util.getMethodReturnType("objectsMethod"));
} catch (Exception e) {
Assertions.fail();
}
}
@Test
void testMethodParameters() {
public void testMethodParameters() {
try {
Assertions.assertEquals(0, util.getMethodParameterCount("objectsMethod", new Class<?>[]{}));
Assertions.assertEquals(0, util.getMethodParameterCount("objectsMethod"));
} catch (Exception e) {
Assertions.fail();
}
@ -69,26 +68,26 @@ class ByteCode_ClassObjects {
@Test
void testFieldCount() {
public void testFieldCount() {
Assertions.assertEquals(3, util.getFieldCount());
}
@Test
void testFieldNames() {
public void testFieldNames() {
Assertions.assertEquals("object", util.getFieldNames().get(0));
Assertions.assertEquals("objectWithValue", util.getFieldNames().get(1));
Assertions.assertEquals("integerValue", util.getFieldNames().get(2));
}
@Test
void testFieldTypes() {
public void testFieldTypes() {
Assertions.assertEquals("ClassObjects", util.getFieldTypes().get(0));
Assertions.assertEquals("ClassObjects", util.getFieldTypes().get(1));
Assertions.assertEquals("int", util.getFieldTypes().get(2));
}
@Test
void testFieldValues() {
public void testFieldValues() {
try {
Assertions.assertNull(util.getFieldValue("object"));
Assertions.assertNull(util.getFieldValue("objectWithValue"));
@ -100,9 +99,9 @@ class ByteCode_ClassObjects {
@Test
void testInvokeConstructor1() {
public void testInvokeConstructor1() {
try {
Object constructor1ReturnValue = util.invokeConstructor(new Class<?>[]{}, new Object[]{});
Object constructor1ReturnValue = util.invokeConstructor(new Class<?>[]{});
Assertions.assertEquals("ClassObjects", constructor1ReturnValue.getClass().getName());
Assertions.assertNull(util.getFieldValueOfObject(constructor1ReturnValue, "object"));
Assertions.assertNull(util.getFieldValueOfObject(constructor1ReturnValue, "objectWithValue"));
@ -114,9 +113,9 @@ class ByteCode_ClassObjects {
}
@Test
void testInvokeConstructor2() {
public void testInvokeConstructor2() {
try {
Object constructor2ReturnValue = util.invokeConstructor(new Class<?>[]{int.class}, new Object[]{2});
Object constructor2ReturnValue = util.invokeConstructor(new Class<?>[]{int.class}, 2);
Assertions.assertEquals("ClassObjects", constructor2ReturnValue.getClass().getName());
Assertions.assertNull(util.getFieldValueOfObject(constructor2ReturnValue, "object"));
Assertions.assertNull(util.getFieldValueOfObject(constructor2ReturnValue, "objectWithValue"));
@ -128,7 +127,7 @@ class ByteCode_ClassObjects {
}
@Test
void testInvokeMethod() {
public void testInvokeMethod() {
try {
Object fieldObject = util.getFieldValue("object");
Object fieldObjectWithValue = util.getFieldValue("objectWithValue");

View File

@ -1,7 +1,5 @@
package testResources.CodeGen.Features;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -93,7 +91,7 @@ public class ByteCode_If {
try {
int returnValue = (int) util.invokeMethod("ifMethod",
new Class<?>[]{boolean.class, boolean.class}, true, true);
Assertions.assertEquals(1, returnValue);
Assertions.assertEquals(6, returnValue);
} catch (Exception e) {
Assertions.fail();
}

View File

@ -172,7 +172,7 @@ public class ByteCode_Operators {
public void testDotBeforeLine() {
try {
Object result = util.invokeMethod("dotBeforeLine", new Class<?>[]{int.class, int.class}, new Object[]{5, 3});
Assertions.assertEquals(20, result);
Assertions.assertEquals(19, result);
} catch (Exception e) {
Assertions.fail();
}

View File

@ -10,33 +10,33 @@ public class TypedAST_MultipleClasses {
return new TypedProgram(
List.of(
new TypedClass(
"MultipleClasses",
"MultipleClasses1",
List.of(
new TypedDeclaration(
"anotherClass",
Type.REFERENCE("AnotherClass")
Type.REFERENCE("MultipleClasses2")
)
),
List.of(),
List.of(
new TypedConstructor(
"MultipleClasses",
"MultipleClasses1",
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedNew(
Type.REFERENCE("AnotherClass"),
Type.REFERENCE("MultipleClasses2"),
List.of()
),
new TypedFieldVarAccess(
true,
null,
"anotherClass",
Type.REFERENCE("AnotherClass")
Type.REFERENCE("MultipleClasses2")
),
Type.REFERENCE("AnotherClass")
Type.REFERENCE("MultipleClasses2")
)
),
Type.VOID
@ -48,36 +48,36 @@ public class TypedAST_MultipleClasses {
null,
null,
null,
Type.REFERENCE("MultipleClasses")
Type.REFERENCE("MultipleClasses1")
),
new TypedClass(
"AnotherClass",
"MultipleClasses2",
List.of(
new TypedDeclaration(
"multipleClasses",
Type.REFERENCE("MultipleClasses")
"i",
Type.INT
)
),
List.of(),
List.of(
new TypedConstructor(
"AnotherClass",
"MultipleClasses2",
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedNew(
Type.REFERENCE("MultipleClasses"),
List.of()
new TypedIntLiteral(
4,
Type.INT
),
new TypedFieldVarAccess(
true,
null,
"multipleClasses",
Type.REFERENCE("MultipleClasses")
"i",
Type.INT
),
Type.REFERENCE("MultipleClasses")
Type.INT
)
),
Type.VOID
@ -89,7 +89,7 @@ public class TypedAST_MultipleClasses {
null,
null,
null,
Type.REFERENCE("AnotherClass")
Type.REFERENCE("MultipleClasses2")
)
),
null

View File

@ -1,15 +0,0 @@
public class MultipleClasses {
AnotherClass anotherClass;
public MultipleClasses() {
this.anotherClass = new AnotherClass();
}
}
public class AnotherClass {
MultipleClasses multipleClasses;
public AnotherClass() {
this.multipleClasses = new MultipleClasses();
}
}

View File

@ -0,0 +1,11 @@
public class MultipleClasses1 {
MultipleClasses2 anotherClass;
public MultipleClasses1() {
this.anotherClass = new MultipleClasses2();
}
public int getIFromAnotherClass() {
return this.anotherClass.i;
}
}

View File

@ -0,0 +1,7 @@
public class MultipleClasses2 {
int i;
public MultipleClasses2() {
this.i = 4;
}
}

View File

@ -1,7 +1,11 @@
public class If {
public int ifMethod(boolean ifShouldRun, boolean elseIfShouldRun) {
if (ifShouldRun) {
return 1;
if (ifShouldRun && elseIfShouldRun) {
return 6;
} else {
return 1;
}
} else if (elseIfShouldRun) {
return 2;
} else {

View File

@ -0,0 +1,6 @@
public class AddressingFieldWithoutThis {
int x;
public AddressingFieldWithoutThis() {
x = 5;
}
}

Binary file not shown.

View File

@ -0,0 +1,2 @@
class PublicMissingInClass {
}