mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 00:18:03 +00:00
cleaned a bit and added implementation in CodegeneratorTests which executes all the codeGen tests
This commit is contained in:
parent
6362299de9
commit
fc28ec5f12
6
pom.xml
6
pom.xml
@ -81,6 +81,12 @@
|
|||||||
<version>4.13.1</version>
|
<version>4.13.1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.platform</groupId>
|
||||||
|
<artifactId>junit-platform-launcher</artifactId>
|
||||||
|
<version>1.10.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<!-- JUnit 5 end -->
|
<!-- JUnit 5 end -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-cli</groupId>
|
<groupId>commons-cli</groupId>
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
import de.maishai.Compiler;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.platform.commons.support.HierarchyTraversalMode;
|
||||||
import org.junit.runners.Suite;
|
import org.junit.platform.commons.support.ReflectionSupport;
|
||||||
import testResources.CodeGen.BytecodeTestUtil;
|
|
||||||
import testResources.CodeGen.Features.*;
|
import testResources.CodeGen.Features.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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 {
|
public class CodegeneratorTests {
|
||||||
|
|
||||||
@ -30,21 +29,164 @@ public class CodegeneratorTests {
|
|||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
// public void testBreak() {
|
public void runByteCodeBreakTests() {
|
||||||
// ByteCode_Break ByteCode_Break = new ByteCode_Break();
|
runByteCodeTests(ByteCode_Break.class);
|
||||||
// Assertions.assertTrue(ByteCode_Break.allTestsSuccessful());
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
// public void testClass() {
|
public void runByteCodeClassTests() {
|
||||||
// ByteCode_Class ByteCode_Class = new ByteCode_Class();
|
runByteCodeTests(ByteCode_Class.class);
|
||||||
// Assertions.assertTrue(ByteCode_Class.allTestsSuccessful());
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
// public void testClassObjects() {
|
public void runByteCodeClassObjectsTests() {
|
||||||
// ByteCode_ClassObjects ByteCode_ClassObjects = new ByteCode_ClassObjects();
|
runByteCodeTests(ByteCode_ClassObjects.class);
|
||||||
// Assertions.assertTrue(ByteCode_ClassObjects.allTestsSuccessful());
|
}
|
||||||
// }
|
|
||||||
}
|
@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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
class ScannerParserTests {
|
public class ScannerParserTests {
|
||||||
//
|
//
|
||||||
// @Test
|
// @Test
|
||||||
// public void testPublicClass() {
|
// public void testPublicClass() {
|
||||||
@ -74,146 +74,148 @@ class ScannerParserTests {
|
|||||||
// Feature Tests
|
// Feature Tests
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBreak() {
|
public void testBreak() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Break.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Break.java"));
|
||||||
assertEquals(AST_Break.get(), resultAst);
|
assertEquals(AST_Break.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testClass() {
|
public void testClass() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Class.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Class.java"));
|
||||||
assertEquals(AST_Class.get(), resultAst);
|
assertEquals(AST_Class.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testClassObjects() {
|
public void testClassObjects() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/ClassObjects.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/ClassObjects.java"));
|
||||||
assertEquals(AST_ClassObjects.get(), resultAst);
|
assertEquals(AST_ClassObjects.get(), resultAst);
|
||||||
}
|
}
|
||||||
//TODO: nochmal drüberschauen, nachfragen wegen true/false bei FieldVarAccess
|
//TODO: nochmal drüberschauen, nachfragen wegen true/false bei FieldVarAccess
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testComment() {
|
public void testComment() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Comment.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Comment.java"));
|
||||||
assertEquals(AST_Comment.get(), resultAst);
|
assertEquals(AST_Comment.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCompAssign() {
|
public void testCompAssign() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/CompAssign.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/CompAssign.java"));
|
||||||
assertEquals(AST_CompAssign.get(), resultAst);
|
assertEquals(AST_CompAssign.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testComplexCalls() {
|
public void testComplexCalls() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/ComplexCalls.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/ComplexCalls.java"));
|
||||||
assertEquals(AST_ComplexCalls.get(), resultAst);
|
assertEquals(AST_ComplexCalls.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testConstructor() {
|
public void testConstructor() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Constructor.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Constructor.java"));
|
||||||
assertEquals(AST_Constructor.get(), resultAst);
|
assertEquals(AST_Constructor.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testContinue() {
|
public void testContinue() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Continue.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Continue.java"));
|
||||||
assertEquals(AST_Continue.get(), resultAst);
|
assertEquals(AST_Continue.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDataTypes() {
|
public void testDataTypes() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/DataTypes.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/DataTypes.java"));
|
||||||
assertEquals(AST_DataTypes.get(), resultAst);
|
assertEquals(AST_DataTypes.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testField() {
|
public void testField() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Field.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Field.java"));
|
||||||
assertEquals(AST_Field.get(), resultAst);
|
assertEquals(AST_Field.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFor() {
|
public void testFor() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/For.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/For.java"));
|
||||||
assertEquals(AST_For.get(), resultAst);
|
assertEquals(AST_For.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testIf() {
|
public void testIf() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/If.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/If.java"));
|
||||||
assertEquals(AST_If.get(), resultAst);
|
assertEquals(AST_If.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testLogicExpr() {
|
public void testLogicExpr() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/LogicExpr.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/LogicExpr.java"));
|
||||||
assertEquals(AST_LogicExpr.get(), resultAst);
|
assertEquals(AST_LogicExpr.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMain() {
|
public void testMain() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Main.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Main.java"));
|
||||||
assertEquals(AST_Main.get(), resultAst);
|
assertEquals(AST_Main.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMethod() {
|
public void testMethod() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Method.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Method.java"));
|
||||||
assertEquals(AST_Method.get(), resultAst);
|
assertEquals(AST_Method.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMethodCall() {
|
public void testMethodCall() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/MethodCall.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/MethodCall.java"));
|
||||||
assertEquals(AST_MethodCall.get(), resultAst);
|
assertEquals(AST_MethodCall.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMultipleClasses() {
|
public void testMultipleClasses() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/MultipleClasses.java"));
|
Program resultAst = Compiler.generateASTFromFiles(
|
||||||
|
List.of("src/test/testFiles/ASTandTypedASTFeatures/MultipleClasses1.java",
|
||||||
|
"src/test/testFiles/ASTandTypedASTFeatures/MultipleClasses2.java"));
|
||||||
assertEquals(AST_MultipleClasses.get(), resultAst);
|
assertEquals(AST_MultipleClasses.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOperators() {
|
public void testOperators() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Operators.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Operators.java"));
|
||||||
assertEquals(AST_Operators.get(), resultAst);
|
assertEquals(AST_Operators.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOverloaded() {
|
public void testOverloaded() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Overloaded.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Overloaded.java"));
|
||||||
assertEquals(AST_Overloaded.get(), resultAst);
|
assertEquals(AST_Overloaded.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testPrint() {
|
public void testPrint() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Print.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Print.java"));
|
||||||
assertEquals(AST_Print.get(), resultAst);
|
assertEquals(AST_Print.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testReturn() {
|
public void testReturn() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Return.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Return.java"));
|
||||||
assertEquals(AST_Return.get(), resultAst);
|
assertEquals(AST_Return.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testUnary() {
|
public void testUnary() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Unary.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/Unary.java"));
|
||||||
assertEquals(AST_Unary.get(), resultAst);
|
assertEquals(AST_Unary.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testVariableDefWithDecl() {
|
public void testVariableDefWithDecl() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/VariableDefWithDecl.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/VariableDefWithDecl.java"));
|
||||||
assertEquals(AST_VariableDefWithDecl.get(), resultAst);
|
assertEquals(AST_VariableDefWithDecl.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testWhile() {
|
public void testWhile() {
|
||||||
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/While.java"));
|
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/ASTandTypedASTFeatures/While.java"));
|
||||||
assertEquals(AST_While.get(), resultAst);
|
assertEquals(AST_While.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,8 @@
|
|||||||
import de.maishai.Compiler;
|
import de.maishai.Compiler;
|
||||||
import de.maishai.typedast.typedclass.TypedProgram;
|
import de.maishai.typedast.typedclass.TypedProgram;
|
||||||
import jdk.jshell.spi.ExecutionControl;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import testResources.TypedAST.TypedASTFeatures.*;
|
import testResources.TypedAST.TypedASTFeatures.*;
|
||||||
import testResources.AST.ASTFeatures.*;
|
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;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
@ -121,14 +114,12 @@ public class TypingTests {
|
|||||||
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_LogicExpr.get());
|
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_LogicExpr.get());
|
||||||
assertEquals(TypedAST_LogicExpr.get(), resultTypedAst);
|
assertEquals(TypedAST_LogicExpr.get(), resultTypedAst);
|
||||||
}
|
}
|
||||||
// TODO: mit Operatoren verknüpfte Typen werden nicht korrekt ermittelt
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMain() {
|
public void testMain() {
|
||||||
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Main.get());
|
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Main.get());
|
||||||
assertEquals(TypedAST_Main.get(), resultTypedAst);
|
assertEquals(TypedAST_Main.get(), resultTypedAst);
|
||||||
}
|
}
|
||||||
// TODO: Wie soll das Resultat aussehen? Soll tatsächlich main auch als Methode aufgeführt werden?
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMethod() {
|
public void testMethod() {
|
||||||
@ -177,7 +168,6 @@ public class TypingTests {
|
|||||||
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Unary.get());
|
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Unary.get());
|
||||||
assertEquals(TypedAST_Unary.get(), resultTypedAst);
|
assertEquals(TypedAST_Unary.get(), resultTypedAst);
|
||||||
}
|
}
|
||||||
// TODO: Typ von TypedUnary wird nicht ermittelt
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVariableDefWithDecl() {
|
public void testVariableDefWithDecl() {
|
||||||
@ -191,9 +181,4 @@ public class TypingTests {
|
|||||||
assertEquals(TypedAST_While.get(), resultTypedAst);
|
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
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,18 +11,39 @@ public class AST_MultipleClasses {
|
|||||||
return new Program(
|
return new Program(
|
||||||
List.of(
|
List.of(
|
||||||
new Class(
|
new Class(
|
||||||
"MultipleClasses",
|
"MultipleClasses1",
|
||||||
null,
|
null,
|
||||||
List.of(
|
List.of(
|
||||||
new Declaration(
|
new Declaration(
|
||||||
"anotherClass",
|
"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(
|
List.of(
|
||||||
new Constructor(
|
new Constructor(
|
||||||
"MultipleClasses",
|
"MultipleClasses1",
|
||||||
List.of(),
|
List.of(),
|
||||||
new Block(
|
new Block(
|
||||||
List.of(
|
List.of(
|
||||||
@ -33,7 +54,7 @@ public class AST_MultipleClasses {
|
|||||||
"anotherClass"
|
"anotherClass"
|
||||||
),
|
),
|
||||||
new New(
|
new New(
|
||||||
Type.REFERENCE("AnotherClass"),
|
Type.REFERENCE("MultipleClasses2"),
|
||||||
List.of()
|
List.of()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -43,18 +64,18 @@ public class AST_MultipleClasses {
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
new Class(
|
new Class(
|
||||||
"AnotherClass",
|
"MultipleClasses2",
|
||||||
null,
|
null,
|
||||||
List.of(
|
List.of(
|
||||||
new Declaration(
|
new Declaration(
|
||||||
"multipleClasses",
|
"i",
|
||||||
Type.REFERENCE("MultipleClasses")
|
Type.INT
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
List.of(),
|
List.of(),
|
||||||
List.of(
|
List.of(
|
||||||
new Constructor(
|
new Constructor(
|
||||||
"AnotherClass",
|
"MultipleClasses2",
|
||||||
List.of(),
|
List.of(),
|
||||||
new Block(
|
new Block(
|
||||||
List.of(
|
List.of(
|
||||||
@ -62,12 +83,9 @@ public class AST_MultipleClasses {
|
|||||||
new FieldVarAccess(
|
new FieldVarAccess(
|
||||||
true,
|
true,
|
||||||
null,
|
null,
|
||||||
"multipleClasses"
|
"i"
|
||||||
),
|
),
|
||||||
new New(
|
new IntLiteral(4)
|
||||||
Type.REFERENCE("MultipleClasses"),
|
|
||||||
List.of()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package testResources.CodeGen.Features;
|
package testResources.CodeGen.Features;
|
||||||
|
|
||||||
import de.maishai.typedast.Type;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -7,7 +7,7 @@ import testResources.CodeGen.BytecodeTestUtil;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class ByteCode_ClassObjects {
|
public class ByteCode_ClassObjects {
|
||||||
|
|
||||||
private BytecodeTestUtil util;
|
private BytecodeTestUtil util;
|
||||||
|
|
||||||
@ -20,48 +20,47 @@ class ByteCode_ClassObjects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testConstructorCount() {
|
public void testConstructorCount() {
|
||||||
Assertions.assertEquals(2, util.getConstructorCount());
|
Assertions.assertEquals(2, util.getConstructorCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testConstructor1() {
|
public void testConstructor1() {
|
||||||
Assertions.assertEquals("ClassObjects", util.getConstructorNames().get(0));
|
Assertions.assertEquals("ClassObjects", util.getConstructorNames().get(0));
|
||||||
Assertions.assertEquals(0, util.getConstructorParameterCount(0));
|
Assertions.assertEquals(0, util.getConstructorParameterCount(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testConstructor2() {
|
public void testConstructor2() {
|
||||||
Assertions.assertEquals("ClassObjects", util.getConstructorNames().get(1));
|
Assertions.assertEquals("ClassObjects", util.getConstructorNames().get(1));
|
||||||
Assertions.assertEquals(1, util.getConstructorParameterCount(1));
|
Assertions.assertEquals(1, util.getConstructorParameterCount(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMethodCount() {
|
public void testMethodCount() {
|
||||||
Assertions.assertEquals(1, util.getMethodCount());
|
Assertions.assertEquals(1, util.getMethodCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMethodNames() {
|
public void testMethodNames() {
|
||||||
Assertions.assertEquals("objectsMethod", util.getMethodNames().get(0));
|
Assertions.assertTrue(util.getMethodNames().contains("objectsMethod"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMethodReturnType() {
|
public void testMethodReturnType() {
|
||||||
try {
|
try {
|
||||||
Assertions.assertEquals("void", util.getMethodReturnType("objectsMethod", new Class<?>[]{}));
|
Assertions.assertEquals("void", util.getMethodReturnType("objectsMethod"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Assertions.fail();
|
Assertions.fail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMethodParameters() {
|
public void testMethodParameters() {
|
||||||
try {
|
try {
|
||||||
Assertions.assertEquals(0, util.getMethodParameterCount("objectsMethod", new Class<?>[]{}));
|
Assertions.assertEquals(0, util.getMethodParameterCount("objectsMethod"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Assertions.fail();
|
Assertions.fail();
|
||||||
}
|
}
|
||||||
@ -69,26 +68,26 @@ class ByteCode_ClassObjects {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFieldCount() {
|
public void testFieldCount() {
|
||||||
Assertions.assertEquals(3, util.getFieldCount());
|
Assertions.assertEquals(3, util.getFieldCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFieldNames() {
|
public void testFieldNames() {
|
||||||
Assertions.assertEquals("object", util.getFieldNames().get(0));
|
Assertions.assertEquals("object", util.getFieldNames().get(0));
|
||||||
Assertions.assertEquals("objectWithValue", util.getFieldNames().get(1));
|
Assertions.assertEquals("objectWithValue", util.getFieldNames().get(1));
|
||||||
Assertions.assertEquals("integerValue", util.getFieldNames().get(2));
|
Assertions.assertEquals("integerValue", util.getFieldNames().get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFieldTypes() {
|
public void testFieldTypes() {
|
||||||
Assertions.assertEquals("ClassObjects", util.getFieldTypes().get(0));
|
Assertions.assertEquals("ClassObjects", util.getFieldTypes().get(0));
|
||||||
Assertions.assertEquals("ClassObjects", util.getFieldTypes().get(1));
|
Assertions.assertEquals("ClassObjects", util.getFieldTypes().get(1));
|
||||||
Assertions.assertEquals("int", util.getFieldTypes().get(2));
|
Assertions.assertEquals("int", util.getFieldTypes().get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFieldValues() {
|
public void testFieldValues() {
|
||||||
try {
|
try {
|
||||||
Assertions.assertNull(util.getFieldValue("object"));
|
Assertions.assertNull(util.getFieldValue("object"));
|
||||||
Assertions.assertNull(util.getFieldValue("objectWithValue"));
|
Assertions.assertNull(util.getFieldValue("objectWithValue"));
|
||||||
@ -100,9 +99,9 @@ class ByteCode_ClassObjects {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testInvokeConstructor1() {
|
public void testInvokeConstructor1() {
|
||||||
try {
|
try {
|
||||||
Object constructor1ReturnValue = util.invokeConstructor(new Class<?>[]{}, new Object[]{});
|
Object constructor1ReturnValue = util.invokeConstructor(new Class<?>[]{});
|
||||||
Assertions.assertEquals("ClassObjects", constructor1ReturnValue.getClass().getName());
|
Assertions.assertEquals("ClassObjects", constructor1ReturnValue.getClass().getName());
|
||||||
Assertions.assertNull(util.getFieldValueOfObject(constructor1ReturnValue, "object"));
|
Assertions.assertNull(util.getFieldValueOfObject(constructor1ReturnValue, "object"));
|
||||||
Assertions.assertNull(util.getFieldValueOfObject(constructor1ReturnValue, "objectWithValue"));
|
Assertions.assertNull(util.getFieldValueOfObject(constructor1ReturnValue, "objectWithValue"));
|
||||||
@ -114,9 +113,9 @@ class ByteCode_ClassObjects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testInvokeConstructor2() {
|
public void testInvokeConstructor2() {
|
||||||
try {
|
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.assertEquals("ClassObjects", constructor2ReturnValue.getClass().getName());
|
||||||
Assertions.assertNull(util.getFieldValueOfObject(constructor2ReturnValue, "object"));
|
Assertions.assertNull(util.getFieldValueOfObject(constructor2ReturnValue, "object"));
|
||||||
Assertions.assertNull(util.getFieldValueOfObject(constructor2ReturnValue, "objectWithValue"));
|
Assertions.assertNull(util.getFieldValueOfObject(constructor2ReturnValue, "objectWithValue"));
|
||||||
@ -128,7 +127,7 @@ class ByteCode_ClassObjects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testInvokeMethod() {
|
public void testInvokeMethod() {
|
||||||
try {
|
try {
|
||||||
Object fieldObject = util.getFieldValue("object");
|
Object fieldObject = util.getFieldValue("object");
|
||||||
Object fieldObjectWithValue = util.getFieldValue("objectWithValue");
|
Object fieldObjectWithValue = util.getFieldValue("objectWithValue");
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package testResources.CodeGen.Features;
|
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.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -93,7 +91,7 @@ public class ByteCode_If {
|
|||||||
try {
|
try {
|
||||||
int returnValue = (int) util.invokeMethod("ifMethod",
|
int returnValue = (int) util.invokeMethod("ifMethod",
|
||||||
new Class<?>[]{boolean.class, boolean.class}, true, true);
|
new Class<?>[]{boolean.class, boolean.class}, true, true);
|
||||||
Assertions.assertEquals(1, returnValue);
|
Assertions.assertEquals(6, returnValue);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Assertions.fail();
|
Assertions.fail();
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ public class ByteCode_Operators {
|
|||||||
public void testDotBeforeLine() {
|
public void testDotBeforeLine() {
|
||||||
try {
|
try {
|
||||||
Object result = util.invokeMethod("dotBeforeLine", new Class<?>[]{int.class, int.class}, new Object[]{5, 3});
|
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) {
|
} catch (Exception e) {
|
||||||
Assertions.fail();
|
Assertions.fail();
|
||||||
}
|
}
|
||||||
|
@ -10,33 +10,33 @@ public class TypedAST_MultipleClasses {
|
|||||||
return new TypedProgram(
|
return new TypedProgram(
|
||||||
List.of(
|
List.of(
|
||||||
new TypedClass(
|
new TypedClass(
|
||||||
"MultipleClasses",
|
"MultipleClasses1",
|
||||||
List.of(
|
List.of(
|
||||||
new TypedDeclaration(
|
new TypedDeclaration(
|
||||||
"anotherClass",
|
"anotherClass",
|
||||||
Type.REFERENCE("AnotherClass")
|
Type.REFERENCE("MultipleClasses2")
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
List.of(),
|
List.of(),
|
||||||
List.of(
|
List.of(
|
||||||
new TypedConstructor(
|
new TypedConstructor(
|
||||||
"MultipleClasses",
|
"MultipleClasses1",
|
||||||
List.of(),
|
List.of(),
|
||||||
new TypedBlock(
|
new TypedBlock(
|
||||||
List.of(),
|
List.of(),
|
||||||
List.of(
|
List.of(
|
||||||
new TypedAssignment(
|
new TypedAssignment(
|
||||||
new TypedNew(
|
new TypedNew(
|
||||||
Type.REFERENCE("AnotherClass"),
|
Type.REFERENCE("MultipleClasses2"),
|
||||||
List.of()
|
List.of()
|
||||||
),
|
),
|
||||||
new TypedFieldVarAccess(
|
new TypedFieldVarAccess(
|
||||||
true,
|
true,
|
||||||
null,
|
null,
|
||||||
"anotherClass",
|
"anotherClass",
|
||||||
Type.REFERENCE("AnotherClass")
|
Type.REFERENCE("MultipleClasses2")
|
||||||
),
|
),
|
||||||
Type.REFERENCE("AnotherClass")
|
Type.REFERENCE("MultipleClasses2")
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
Type.VOID
|
Type.VOID
|
||||||
@ -48,36 +48,36 @@ public class TypedAST_MultipleClasses {
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
Type.REFERENCE("MultipleClasses")
|
Type.REFERENCE("MultipleClasses1")
|
||||||
),
|
),
|
||||||
new TypedClass(
|
new TypedClass(
|
||||||
"AnotherClass",
|
"MultipleClasses2",
|
||||||
List.of(
|
List.of(
|
||||||
new TypedDeclaration(
|
new TypedDeclaration(
|
||||||
"multipleClasses",
|
"i",
|
||||||
Type.REFERENCE("MultipleClasses")
|
Type.INT
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
List.of(),
|
List.of(),
|
||||||
List.of(
|
List.of(
|
||||||
new TypedConstructor(
|
new TypedConstructor(
|
||||||
"AnotherClass",
|
"MultipleClasses2",
|
||||||
List.of(),
|
List.of(),
|
||||||
new TypedBlock(
|
new TypedBlock(
|
||||||
List.of(),
|
List.of(),
|
||||||
List.of(
|
List.of(
|
||||||
new TypedAssignment(
|
new TypedAssignment(
|
||||||
new TypedNew(
|
new TypedIntLiteral(
|
||||||
Type.REFERENCE("MultipleClasses"),
|
4,
|
||||||
List.of()
|
Type.INT
|
||||||
),
|
),
|
||||||
new TypedFieldVarAccess(
|
new TypedFieldVarAccess(
|
||||||
true,
|
true,
|
||||||
null,
|
null,
|
||||||
"multipleClasses",
|
"i",
|
||||||
Type.REFERENCE("MultipleClasses")
|
Type.INT
|
||||||
),
|
),
|
||||||
Type.REFERENCE("MultipleClasses")
|
Type.INT
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
Type.VOID
|
Type.VOID
|
||||||
@ -89,7 +89,7 @@ public class TypedAST_MultipleClasses {
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
Type.REFERENCE("AnotherClass")
|
Type.REFERENCE("MultipleClasses2")
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
null
|
null
|
||||||
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,11 @@
|
|||||||
|
public class MultipleClasses1 {
|
||||||
|
MultipleClasses2 anotherClass;
|
||||||
|
|
||||||
|
public MultipleClasses1() {
|
||||||
|
this.anotherClass = new MultipleClasses2();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIFromAnotherClass() {
|
||||||
|
return this.anotherClass.i;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
public class MultipleClasses2 {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
public MultipleClasses2() {
|
||||||
|
this.i = 4;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,11 @@
|
|||||||
public class If {
|
public class If {
|
||||||
public int ifMethod(boolean ifShouldRun, boolean elseIfShouldRun) {
|
public int ifMethod(boolean ifShouldRun, boolean elseIfShouldRun) {
|
||||||
if (ifShouldRun) {
|
if (ifShouldRun) {
|
||||||
return 1;
|
if (ifShouldRun && elseIfShouldRun) {
|
||||||
|
return 6;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
} else if (elseIfShouldRun) {
|
} else if (elseIfShouldRun) {
|
||||||
return 2;
|
return 2;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user