Test update
This commit is contained in:
parent
d4f98693d6
commit
a3000d0ba1
BIN
classWithMain.class
Normal file
BIN
classWithMain.class
Normal file
Binary file not shown.
BIN
emptyClass.class
Normal file
BIN
emptyClass.class
Normal file
Binary file not shown.
@ -8,5 +8,17 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.antlr:antlr4-runtime:4.13.1" level="project" />
|
||||
<orderEntry type="module" module-name="NichtHaskell" scope="TEST" />
|
||||
<orderEntry type="module-library" scope="TEST">
|
||||
<library name="JUnit4">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
@ -18,7 +18,7 @@ public class Compiler {
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
|
||||
Path filePath = Paths.get("src/main/java/Input.java");
|
||||
Path filePath = Paths.get("src/main/java/TestClass.java");
|
||||
|
||||
|
||||
// todo remove this debug info
|
||||
|
@ -1,6 +1,5 @@
|
||||
public class TestClass {
|
||||
public static void main(String[] args){
|
||||
// new Example();
|
||||
// new Example2();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,10 @@ public class FieldDecl extends AbstractType implements Node {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
FieldDecl fieldDecl = (FieldDecl) o;
|
||||
return ( Objects.equals(type, fieldDecl.type)
|
||||
&& Objects.equals(identifier, fieldDecl.identifier));
|
||||
boolean result = Objects.equals(type, fieldDecl.type)
|
||||
&& Objects.equals(identifier, fieldDecl.identifier);
|
||||
|
||||
System.out.println("In FieldDecl: " + result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -173,10 +173,12 @@ public class MethodDecl implements Node {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MethodDecl methodDecl = (MethodDecl) o;
|
||||
return (Objects.equals(name, methodDecl.name)
|
||||
boolean result = (Objects.equals(name, methodDecl.name)
|
||||
&& Objects.equals(parameters, methodDecl.parameters)
|
||||
&& Objects.equals(returnType, methodDecl.returnType)
|
||||
&& Objects.equals(codeBlock, methodDecl.codeBlock));
|
||||
System.out.println("In MethodDecl: " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -96,14 +96,16 @@ public class RefType extends AbstractType implements Node {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
System.out.println("Dont forget me ;)");
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
RefType refType = (RefType) o;
|
||||
return ( Objects.equals(name, refType.name)
|
||||
boolean result = ( Objects.equals(name, refType.name)
|
||||
&& Objects.equals(fieldDecls, refType.fieldDecls)
|
||||
&& Objects.equals(methodDecls, refType.methodDecls)
|
||||
&& Objects.equals(hasMain, refType.hasMain));
|
||||
System.out.println("In RefType: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,10 @@ public class BoolDatatype extends AbstractType implements IDatatype{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
BoolDatatype boolDatatype = (BoolDatatype) o;
|
||||
return (Objects.equals(value, boolDatatype.value));
|
||||
boolean result = Objects.equals(value, boolDatatype.value);
|
||||
System.out.println("In BoolDataType: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public TypeCheckResult typeCheck() {
|
||||
@ -39,4 +42,6 @@ public class BoolDatatype extends AbstractType implements IDatatype{
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,10 @@ public class CharDatatype extends AbstractType implements IDatatype{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CharDatatype charDatatype = (CharDatatype) o;
|
||||
return (Objects.equals(value, charDatatype.value));
|
||||
boolean result = Objects.equals(value, charDatatype.value);
|
||||
System.out.println("In CharDataType: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,7 +36,10 @@ public class IntDatatype extends AbstractType implements IDatatype{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
IntDatatype intDatatype = (IntDatatype) o;
|
||||
return (Objects.equals(value, intDatatype.value));
|
||||
boolean result = (Objects.equals(value, intDatatype.value));
|
||||
System.out.println("In IntDataType: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -181,10 +181,13 @@ public class BinaryExpression extends AbstractType implements IExpression{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
BinaryExpression binaryExpression = (BinaryExpression) o;
|
||||
return (Objects.equals(operator, binaryExpression.operator)
|
||||
boolean result = (Objects.equals(operator, binaryExpression.operator)
|
||||
&& Objects.equals(left, binaryExpression.left)
|
||||
&& Objects.equals(right, binaryExpression.right)
|
||||
);
|
||||
System.out.println("In BinaryExpression: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
|
@ -3,12 +3,14 @@ package abstractSyntaxTree.Expression;
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Datatype.BoolDatatype;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public class BooleanConstantExpression extends AbstractType implements IExpression{
|
||||
public boolean value;
|
||||
@ -37,4 +39,15 @@ public class BooleanConstantExpression extends AbstractType implements IExpressi
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
BooleanConstantExpression boolDatatype = (BooleanConstantExpression) o;
|
||||
boolean result = Objects.equals(value, boolDatatype.value);
|
||||
System.out.println("In BooleanConstantExpression: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CharConstantExpression extends AbstractType implements IExpression{
|
||||
public char value;
|
||||
@ -33,4 +34,15 @@ public class CharConstantExpression extends AbstractType implements IExpression{
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CharConstantExpression boolDatatype = (CharConstantExpression) o;
|
||||
boolean result = Objects.equals(value, boolDatatype.value);
|
||||
System.out.println("In CharConstantExpression: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -80,9 +80,12 @@ public class InstVarExpression extends AbstractType implements IExpression{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
InstVarExpression instVarExpression = (InstVarExpression) o;
|
||||
return (Objects.equals(thisClass, instVarExpression.thisClass)
|
||||
boolean result = (Objects.equals(thisClass, instVarExpression.thisClass)
|
||||
&& Objects.equals(fieldName, instVarExpression.fieldName)
|
||||
);
|
||||
System.out.println("In InstVarExpression: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,8 +37,11 @@ public class IntConstantExpression extends AbstractType implements IExpression{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
IntConstantExpression intConstantExpression = (IntConstantExpression) o;
|
||||
return (Objects.equals(value, intConstantExpression.value)
|
||||
boolean result = (Objects.equals(value, intConstantExpression.value)
|
||||
);
|
||||
System.out.println("In intConstantExpression: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,7 +93,10 @@ public class LocalVarIdentifier extends AbstractType implements IExpression{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
LocalVarIdentifier localVarIdentifier = (LocalVarIdentifier) o;
|
||||
return (Objects.equals(identifier, localVarIdentifier.identifier)
|
||||
boolean result = (Objects.equals(identifier, localVarIdentifier.identifier)
|
||||
);
|
||||
System.out.println("In localVarIdentifier: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -120,8 +120,7 @@ public class Program implements Node {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Program program = (Program) o;
|
||||
System.out.println(classes);
|
||||
System.out.println(program.classes);
|
||||
System.out.println("In program: " + Objects.equals(classes, program.classes));
|
||||
return (Objects.equals(classes, program.classes));
|
||||
}
|
||||
}
|
@ -8,15 +8,22 @@ public class testAll {
|
||||
AstComparer astComparer;
|
||||
public testAll()
|
||||
{
|
||||
this.astComparer = new AstComparer("test/resources");
|
||||
this.astComparer = new AstComparer("src/test/resources");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestEmptyClass(){
|
||||
public void testEmptyClass(){
|
||||
Program ast = emptyClassAST.getEmptyProgramm();
|
||||
String pathToCode = "basicClasses/emptyClass.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyClassWithConstructor(){
|
||||
Program ast = emptyClassAST.getEmptyProgramm();
|
||||
String pathToCode = "basicClasses/emptyClassWithConstructor.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
public void testAst(Program ast, String pathToCode)
|
||||
{
|
||||
|
||||
|
@ -3,21 +3,24 @@ package ASTs;
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
import abstractSyntaxTree.Expression.InstVarExpression;
|
||||
import abstractSyntaxTree.Expression.*;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
import abstractSyntaxTree.Statement.LocalVarDecl;
|
||||
import abstractSyntaxTree.Statement.ReturnStatement;
|
||||
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
|
||||
import abstractSyntaxTree.StatementExpression.NewStatementExpression;
|
||||
import abstractSyntaxTree.StatementExpression.ReceivingMethod;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
|
||||
public class fourClassesAST extends Program {
|
||||
|
||||
public fourClassesAST()
|
||||
@ -26,55 +29,174 @@ public class fourClassesAST extends Program {
|
||||
}
|
||||
private static List<RefType> staticClasses() {
|
||||
|
||||
/////////// Classes ///////////
|
||||
|
||||
///////// Class: FourClasses /////////
|
||||
|
||||
/////// Fields ///////
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
|
||||
ParameterList emptyParameterList = new ParameterList(new ArrayList<>());
|
||||
|
||||
/////// Methods ///////
|
||||
|
||||
// Main //
|
||||
|
||||
List<IStatement> emptyIStatementList = new ArrayList<>();
|
||||
BlockStatement emptyBlockStatement = new BlockStatement(emptyIStatementList, "void");
|
||||
MethodDecl constructor = new MethodDecl("emptyClassWithConstructor", "null", "emptyClassWithConstructor", emptyParameterList, emptyBlockStatement);
|
||||
|
||||
//IStatement
|
||||
List<IStatement> fourClassesMainBlockIstatements = new ArrayList<>();
|
||||
|
||||
IExpression atntiLeft = new InstVarExpression("Test", "t");
|
||||
IExpression atntiRight = new NewStatementExpression();
|
||||
AssignStatementExpression atnti = new AssignStatementExpression(atntiLeft, "=", );
|
||||
|
||||
|
||||
ReturnStatement fcmbiReturn = new ReturnStatement();
|
||||
|
||||
fourClassesMainBlockIstatements.add(atnti);
|
||||
//BlockStatement
|
||||
BlockStatement fourClassesMainBlock = new BlockStatement(fourClassesMainBlockIstatements, "int");
|
||||
|
||||
//Parameter
|
||||
Parameter intI = new Parameter("int", "i");
|
||||
List<Parameter> fourClassesMainParameterList = new ArrayList<>();
|
||||
|
||||
ParameterList fourClassesMainParameters = new ParameterList(fourClassesMainParameterList);
|
||||
|
||||
MethodDecl fourClassesMain = new MethodDecl("fourClasses", "int", "main", fourClassesMainParameters, fourClassesMainBlock);
|
||||
List<MethodDecl> MethodDeclList = new ArrayList<>();
|
||||
|
||||
RefType emptyClass = new RefType("emptyClass", fieldDeclList, MethodDeclList, false);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
List<RefType> classes = new ArrayList<>();
|
||||
classes.add(emptyClass);
|
||||
return classes;
|
||||
return program;
|
||||
}
|
||||
}*/
|
||||
|
||||
public RefType Test() {
|
||||
|
||||
|
||||
// Class Test
|
||||
|
||||
//public int x
|
||||
FieldDecl publicIntX = new FieldDecl("int","x");
|
||||
|
||||
//public int y
|
||||
FieldDecl publicIntY = new FieldDecl("int", "y");
|
||||
|
||||
//public Test3 test3
|
||||
FieldDecl Test3test3 = new FieldDecl("Test3", "test3");
|
||||
|
||||
// FieldDeclList
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
fieldDeclList.add(publicIntX);
|
||||
fieldDeclList.add(publicIntY);
|
||||
fieldDeclList.add(Test3test3);
|
||||
|
||||
// (int i)
|
||||
List<Parameter> par11 = new ArrayList<>();
|
||||
Parameter inti = new Parameter("int", "i");
|
||||
par11.add(inti);
|
||||
ParameterList par1 = new ParameterList(par11);
|
||||
|
||||
//this.x
|
||||
InstVarExpression thisX = new InstVarExpression("X");
|
||||
|
||||
// i
|
||||
LocalVarIdentifier i = new LocalVarIdentifier("i");
|
||||
|
||||
//this.x = i
|
||||
AssignStatementExpression thisXeqI = new AssignStatementExpression("=", thisX, i);
|
||||
|
||||
//this.test3
|
||||
LocalVarIdentifier thisTest3 = new LocalVarIdentifier("test3");
|
||||
|
||||
// 2
|
||||
IntConstantExpression two = new IntConstantExpression(2);
|
||||
//(i * 2)
|
||||
BinaryExpression iTimes2 = new BinaryExpression("*", i, two);
|
||||
|
||||
//new Test3(i*2)
|
||||
List<IExpression> exprNewTest3 = new ArrayList<>();
|
||||
exprNewTest3.add(iTimes2);
|
||||
NewStatementExpression newTest3 = new NewStatementExpression("Test3",exprNewTest3 );
|
||||
|
||||
//this.test3 = new Test3(i * 2);
|
||||
AssignStatementExpression thisTesteqNewTest3 = new AssignStatementExpression("=", thisTest3, newTest3);
|
||||
|
||||
// {}
|
||||
List<IStatement> ilistTest = new ArrayList<>();
|
||||
ilistTest.add(thisTesteqNewTest3);
|
||||
BlockStatement blockTest = new BlockStatement(ilistTest,"void");
|
||||
|
||||
//public Test (int i)
|
||||
MethodDecl Test = new MethodDecl("Test", "void",
|
||||
"Test", par1, blockTest);
|
||||
|
||||
|
||||
// public Test3 getTest3() {return this.test3;}
|
||||
|
||||
//this.test3
|
||||
//LocalVarIdentifier thisTest3 = new LocalVarIdentifier("test3")
|
||||
|
||||
// return this.test3
|
||||
ReturnStatement returnThisTest3 = new ReturnStatement(thisTest3);
|
||||
|
||||
// {return this.test3}
|
||||
List<IStatement> getTest3Stmts = new ArrayList<>();
|
||||
getTest3Stmts.add(returnThisTest3);
|
||||
BlockStatement blockReturnThisTest3 = new BlockStatement(getTest3Stmts, "Test3");
|
||||
|
||||
ParameterList emptyParamList = new ParameterList(null);
|
||||
MethodDecl getTest3 = new MethodDecl("Test", "Test3",
|
||||
"gettest3", emptyParamList, blockReturnThisTest3);
|
||||
|
||||
|
||||
//this.x
|
||||
//LocalVarIdentifier thisX = new LocalVarIdentifier("x");
|
||||
|
||||
//return this.x
|
||||
ReturnStatement returnThisX = new ReturnStatement(thisX);
|
||||
|
||||
// {return this.x}
|
||||
List<IStatement> stmtsBlockReturnX = new ArrayList<>();
|
||||
stmtsBlockReturnX.add(returnThisX);
|
||||
BlockStatement blockReturnX = new BlockStatement(stmtsBlockReturnX,"int");
|
||||
|
||||
//public int getX() {
|
||||
// return this.x;
|
||||
// }
|
||||
MethodDecl getX = new MethodDecl("Test", "int",
|
||||
"getX", emptyParamList, blockReturnX);
|
||||
|
||||
//MethodDeclList
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(Test);
|
||||
methodDeclList.add(getTest3);
|
||||
methodDeclList.add(getX);
|
||||
|
||||
// Class Test
|
||||
RefType ClassTest = new RefType("Test", fieldDeclList,
|
||||
methodDeclList, false);
|
||||
|
||||
return ClassTest;
|
||||
}
|
||||
|
||||
public RefType FourClasses() {
|
||||
|
||||
LocalVarDecl localVarDecl1 = () -> {
|
||||
String type = Test2;
|
||||
String identifier = "t2";
|
||||
NewStatementExpression expression = () -> {
|
||||
String className = "Test2";
|
||||
List<IExpression> arguments = () -> {
|
||||
InstVarExpression arg0 = () -> {
|
||||
List<SubReceiver> receivers = () -> {
|
||||
ArrayList subReceiverList = new ArrayList<>();
|
||||
SubReceiver subreceiver1 = new SubReceiver();
|
||||
|
||||
subReceiverList.add(subreceiver1);
|
||||
|
||||
return subReceiverList;
|
||||
};
|
||||
List<ReceivingMethod> = () -> {
|
||||
ArrayList receivingMethodList = new ArrayList<>();
|
||||
ReceivingMethod receivingMethod01 = () -> {
|
||||
new ReceivingMethod();
|
||||
}
|
||||
return receivingMethodList
|
||||
};
|
||||
|
||||
return new InstVarExpression();
|
||||
};
|
||||
};
|
||||
return new NewStatementExpression();
|
||||
};
|
||||
|
||||
return new LocalVarDecl();
|
||||
};
|
||||
|
||||
LocalVarIdentifier localVarIdentifier01 = new LocalVarIdentifier("i");
|
||||
List<IExpression> localargumentList01 = new ArrayList<>();
|
||||
localargumentList01.add(localVarIdentifier01);
|
||||
NewStatementExpression newstmtexpr01 = new NewStatementExpression("Test", localargumentList01);
|
||||
LocalVarDecl statement01 = new LocalVarDecl("Test", "t", newstmtexpr01);
|
||||
List<IStatement> statements01 = new ArrayList<>();
|
||||
statements01.add(statement01);
|
||||
BlockStatement blockStatement0 = new BlockStatement(statements01, "int");
|
||||
|
||||
Parameter parameter01 = new Parameter("int", "i");
|
||||
List<Parameter> parameterList0x = new ArrayList<>();
|
||||
parameterList0x.add(parameter01);
|
||||
ParameterList parameterList0 = new ParameterList(parameterList0x);
|
||||
MethodDecl methodDecl0 = new MethodDecl("FourClasses", "int", "main", parameterList0, blockStatement0);
|
||||
|
||||
List<FieldDecl> fieldDeclsList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(methodDecl0);
|
||||
RefType FourClassesClass = new RefType("FourClasses", fieldDeclsList, methodDeclList, true);
|
||||
|
||||
return FourClassesClass;
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
@ -4,18 +4,23 @@ import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CompareByteCodeSyntax {
|
||||
|
||||
public static boolean haveSameBehavior(Class<?> class1, Class<?> class2) {
|
||||
System.out.println("Comparing class signatures of " + class1.getName() + " and " + class2.getName());
|
||||
if (!compareClassSignatures(class1, class2)) {
|
||||
return false;
|
||||
}
|
||||
System.out.println("Comparing methods of " + class1.getName() + " and " + class2.getName());
|
||||
if (!compareMethods(class1, class2)) {
|
||||
return false;
|
||||
}
|
||||
System.out.println("Comparing fields of " + class1.getName() + " and " + class2.getName());
|
||||
if (!compareFields(class1, class2)) {
|
||||
return false;
|
||||
}
|
||||
System.out.println("Comparing annotations of " + class1.getName() + " and " + class2.getName());
|
||||
if (!compareAnnotations(class1.getAnnotations(), class2.getAnnotations())) {
|
||||
return false;
|
||||
}
|
||||
@ -24,9 +29,11 @@ public class CompareByteCodeSyntax {
|
||||
|
||||
public static boolean compareClassSignatures(Class<?> class1, Class<?> class2) {
|
||||
if (!Arrays.equals(class1.getInterfaces(), class2.getInterfaces())) {
|
||||
System.out.println("Interfaces do not match");
|
||||
return false;
|
||||
}
|
||||
if (class1.getSuperclass() != class2.getSuperclass()) {
|
||||
System.out.println("Superclasses do not match");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -36,6 +43,7 @@ public class CompareByteCodeSyntax {
|
||||
Method[] methods1 = class1.getDeclaredMethods();
|
||||
Method[] methods2 = class2.getDeclaredMethods();
|
||||
if (methods1.length != methods2.length) {
|
||||
System.out.println("Method counts do not match");
|
||||
return false;
|
||||
}
|
||||
for (Method method1 : methods1) {
|
||||
@ -49,6 +57,7 @@ public class CompareByteCodeSyntax {
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
System.out.println("No matching method found for: " + method1.getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -57,15 +66,19 @@ public class CompareByteCodeSyntax {
|
||||
|
||||
public static boolean compareMethod(Method method1, Method method2) {
|
||||
if (!method1.getReturnType().equals(method2.getReturnType())) {
|
||||
System.out.println("Return types do not match for methods " + method1.getName() + " and " + method2.getName());
|
||||
return false;
|
||||
}
|
||||
if (!Arrays.equals(method1.getParameterTypes(), method2.getParameterTypes())) {
|
||||
System.out.println("Parameter types do not match for methods " + method1.getName() + " and " + method2.getName());
|
||||
return false;
|
||||
}
|
||||
if (!Arrays.equals(method1.getExceptionTypes(), method2.getExceptionTypes())) {
|
||||
System.out.println("Exception types do not match for methods " + method1.getName() + " and " + method2.getName());
|
||||
return false;
|
||||
}
|
||||
if (!compareAnnotations(method1.getAnnotations(), method2.getAnnotations())) {
|
||||
System.out.println("Annotations do not match for methods " + method1.getName() + " and " + method2.getName());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -75,6 +88,7 @@ public class CompareByteCodeSyntax {
|
||||
Field[] fields1 = class1.getDeclaredFields();
|
||||
Field[] fields2 = class2.getDeclaredFields();
|
||||
if (fields1.length != fields2.length) {
|
||||
System.out.println("Field counts do not match");
|
||||
return false;
|
||||
}
|
||||
for (Field field1 : fields1) {
|
||||
@ -88,6 +102,7 @@ public class CompareByteCodeSyntax {
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
System.out.println("No matching field found for: " + field1.getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -96,9 +111,11 @@ public class CompareByteCodeSyntax {
|
||||
|
||||
public static boolean compareField(Field field1, Field field2) {
|
||||
if (!field1.getType().equals(field2.getType())) {
|
||||
System.out.println("Field types do not match for fields " + field1.getName() + " and " + field2.getName());
|
||||
return false;
|
||||
}
|
||||
if (!compareAnnotations(field1.getAnnotations(), field2.getAnnotations())) {
|
||||
System.out.println("Annotations do not match for fields " + field1.getName() + " and " + field2.getName());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -106,6 +123,7 @@ public class CompareByteCodeSyntax {
|
||||
|
||||
public static boolean compareAnnotations(Annotation[] annotations1, Annotation[] annotations2) {
|
||||
if (annotations1.length != annotations2.length) {
|
||||
System.out.println("Annotation counts do not match");
|
||||
return false;
|
||||
}
|
||||
for (Annotation annotation1 : annotations1) {
|
||||
@ -117,10 +135,10 @@ public class CompareByteCodeSyntax {
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
System.out.println("No matching annotation found for: " + annotation1.annotationType().getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,17 +79,19 @@ public class TestAll {
|
||||
abstractSyntaxTree.typeCheck();
|
||||
} catch (Exception e){
|
||||
System.out.println("Le Exception in le type-check");
|
||||
//fail();
|
||||
}
|
||||
|
||||
try {
|
||||
abstractSyntaxTree.codeGen();
|
||||
} catch (Exception e){
|
||||
System.out.println("Le Exception in le codegen");
|
||||
fail();
|
||||
}
|
||||
|
||||
try {
|
||||
ClassFileLoader classLoader1 = new ClassFileLoader(correctClassFilePath);
|
||||
ClassFileLoader classLoader2 = new ClassFileLoader(className + ".class");
|
||||
ClassFileLoader classLoader2 = new ClassFileLoader(className+ ".class");
|
||||
|
||||
Class<?> class1 = classLoader1.findClass(className);
|
||||
Class<?> class2 = classLoader2.findClass(className);
|
||||
@ -112,5 +114,35 @@ public class TestAll {
|
||||
//testByteCodeFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFourClasses() {
|
||||
String classPath = "src/test/resources/basicClasses/FourClasses.class";
|
||||
Program ast = emptyClassAST.getEmptyProgramm();
|
||||
String className = "emptyClass";
|
||||
String javacode = "src/test/resources/basicClasses/FourClasses.java";
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
testByteCodeFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFakultaet() {
|
||||
String classPath = "src/test/resources/basicClasses/Fakultaet.class";
|
||||
Program ast = emptyClassAST.getEmptyProgramm();
|
||||
String className = "Fakultät";
|
||||
String javacode = "src/test/resources/basicClasses/Fakultaet.java";
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
testByteCodeFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassWithMain() {
|
||||
String classPath = "src/test/resources/basicClasses/classWithMain.class";
|
||||
Program ast = emptyClassAST.getEmptyProgramm();
|
||||
String className = "classWithMain";
|
||||
String javacode = "src/test/resources/basicClasses/classWithMain.java";
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
testByteCodeFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
BIN
src/test/resources/basicClasses/Fakultaet.class
Normal file
BIN
src/test/resources/basicClasses/Fakultaet.class
Normal file
Binary file not shown.
19
src/test/resources/basicClasses/Fakultaet.java
Normal file
19
src/test/resources/basicClasses/Fakultaet.java
Normal file
@ -0,0 +1,19 @@
|
||||
class Fakultaet {
|
||||
public int fak(int number) {
|
||||
if (number < 0) {
|
||||
return 1;
|
||||
}
|
||||
int factorial = 1;
|
||||
int i = 0;
|
||||
while(i < number){
|
||||
factorial = factorial * i;
|
||||
}
|
||||
|
||||
return factorial;
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -19,11 +19,11 @@ class Test {
|
||||
this.test3 = new Test3(i * 2);
|
||||
}
|
||||
|
||||
public Test3 getTest3() {
|
||||
public Test3 getTest3(int not) {
|
||||
return this.test3;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
public int getX(int not) {
|
||||
return this.x;
|
||||
}
|
||||
}
|
||||
@ -46,11 +46,11 @@ class Test3 {
|
||||
this.x = i;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
public int getX(int not) {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
public int getY(int not) {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
|
BIN
src/test/resources/basicClasses/Test.class
Normal file
BIN
src/test/resources/basicClasses/Test.class
Normal file
Binary file not shown.
BIN
src/test/resources/basicClasses/Test2.class
Normal file
BIN
src/test/resources/basicClasses/Test2.class
Normal file
Binary file not shown.
BIN
src/test/resources/basicClasses/Test3.class
Normal file
BIN
src/test/resources/basicClasses/Test3.class
Normal file
Binary file not shown.
BIN
src/test/resources/basicClasses/classWithMain.class
Normal file
BIN
src/test/resources/basicClasses/classWithMain.class
Normal file
Binary file not shown.
6
src/test/resources/basicClasses/classWithMain.java
Normal file
6
src/test/resources/basicClasses/classWithMain.java
Normal file
@ -0,0 +1,6 @@
|
||||
class classWithMain {
|
||||
public static void main(String[] args){
|
||||
|
||||
}
|
||||
|
||||
}
|
BIN
src/test/resources/basicClasses/emptyClass.class
Normal file
BIN
src/test/resources/basicClasses/emptyClass.class
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user