From 6fc78b9ad3a8039e0800381841febb3279d5febd Mon Sep 17 00:00:00 2001 From: Aldaron7 Date: Tue, 20 Mar 2018 21:24:48 +0100 Subject: [PATCH] Construct bis auf Generics fertig, Printausgabe fuer generics angepasst --- .../dhbwstuttgart/strucTypes/Construct.java | 84 ++++++++--- .../printutils/PrintConstraints.java | 91 +++++++++--- .../printutils/SyntaxTreePrinter.java | 138 +++++++++++------- test/strucType/TestConstruct.java | 66 +++++++++ test/strucType/TestInterface.java | 66 +++++++++ test/strucType/TestStrucType.java | 15 +- test/strucType/TestSyntaxTreePrinter.java | 12 +- test/strucType/javFiles/testInterface.jav | 7 + test/strucType/javFiles/testNew.jav | 2 +- 9 files changed, 370 insertions(+), 111 deletions(-) create mode 100644 test/strucType/TestConstruct.java create mode 100644 test/strucType/TestInterface.java create mode 100644 test/strucType/javFiles/testInterface.jav diff --git a/src/de/dhbwstuttgart/strucTypes/Construct.java b/src/de/dhbwstuttgart/strucTypes/Construct.java index cbb79f61..3535ce80 100644 --- a/src/de/dhbwstuttgart/strucTypes/Construct.java +++ b/src/de/dhbwstuttgart/strucTypes/Construct.java @@ -9,15 +9,17 @@ import org.antlr.v4.runtime.Token; import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet; -import de.dhbwstuttgart.strucTypes.constraint.FieldConstraint; import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint; import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.Constructor; import de.dhbwstuttgart.syntaxtree.Field; +import de.dhbwstuttgart.syntaxtree.FormalParameter; import de.dhbwstuttgart.syntaxtree.GenericDeclarationList; import de.dhbwstuttgart.syntaxtree.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.Method; +import de.dhbwstuttgart.syntaxtree.ParameterList; +import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; @@ -44,8 +46,13 @@ public class Construct extends DefaultASTVisitor { } public List getConstructedInterfaces() { + this.newInterf.forEach(i -> i.accept(this)); return constructedInterfaces; } + + public List getSubTypeConstraints() { + return subTypeConstraints; + } private void gatherSubTypeConstraints(ConstraintsSet constraintsSet) { this.subTypeConstraints.addAll(constraintsSet.getSubTypeConstraints()); @@ -55,40 +62,79 @@ public class Construct extends DefaultASTVisitor { this.newInterf.add(mc.getClassType()); }); } - + @Override public void visit(TypePlaceholder typePlaceholder) { - JavaClassName name = new JavaClassName("de.dhbw.constructedinterface." + typePlaceholder.getName()); - this.constructInterface(typePlaceholder, name); + JavaClassName name = new JavaClassName("constructedinterface." + typePlaceholder.getName()); + this.constructedInterfaces.add(this.constructInterface(typePlaceholder, name)); } - + + // TODO check nur TPH in newInterf @Override public void visit(RefType refType) { - JavaClassName name = refType.getName(); - this.constructInterface(refType, name); + // JavaClassName name = refType.getName(); + // this.constructedInterfaces.add(this.constructInterface(refType, + // name)); } - private ClassOrInterface constructInterface(RefTypeOrTPHOrWildcardOrGeneric i, JavaClassName name) { - final int modifiers = Modifier.interfaceModifiers(); + private ClassOrInterface constructInterface(TypePlaceholder i, JavaClassName name) { List fielddecl = new ArrayList<>(); List methods = new ArrayList<>(); - List constructors = new ArrayList<>(); List generics = new ArrayList<>(); - GenericDeclarationList genericClassParameters = new GenericDeclarationList(generics, i.getOffset()); - final RefType superClass = this.createSuperClass(); - final boolean isInterface = true; - List implementedInterfaces = new ArrayList<>(); + List parameterInhTyterm = new ArrayList<>(); final Token offset = i.getOffset(); - + + // For über alle FieldConstraints mit ClassType i this.constraintsSet.getFieldConstraints().stream().filter(fc -> fc.getClassType().equals(i)).forEach(fc -> { TypePlaceholder type = TypePlaceholder.fresh(i.getOffset()); - new Field(fc.getFieldName(), type, Modifier.fieldModifiers(), i.getOffset()); + parameterInhTyterm.add(fc.getFieldType()); + // TODO generics.add(new GenericTypeVar(s, bounds, offset, + // endOffset)); mit type + Field field = new Field(fc.getFieldName(), type, Modifier.fieldModifiers(), i.getOffset()); + fielddecl.add(field); }); - return new ClassOrInterface(modifiers, name, fielddecl, methods, constructors, genericClassParameters, superClass, isInterface, implementedInterfaces, offset); + // For über alle MethodConstraints mit ClassType i + this.constraintsSet.getMethodConstraints().stream().filter(mc -> mc.getClassType().equals(i)).forEach(mc -> { + TypePlaceholder returnType = TypePlaceholder.fresh(i.getOffset()); + parameterInhTyterm.add(mc.getReturnType()); + // TODO generics.add(new GenericTypeVar(s, bounds, offset, + // endOffset)); mit retrunType + Block block = new Block(new ArrayList<>(), offset); + GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), offset); + List params = new ArrayList<>(); + mc.getArguments().stream().map(a -> a.getSupertype()).forEach(supertype -> { + TypePlaceholder tph = TypePlaceholder.fresh(offset); + params.add(new FormalParameter(tph.getName(), tph, offset)); + parameterInhTyterm.add(supertype); + // TODO generics.add(new GenericTypeVar(s, bounds, offset, + // endOffset)); mit tph + }); + ParameterList parameterList = new ParameterList(params, offset); + Method method = new Method(Modifier.PUBLIC, mc.getMethodName(), returnType, Modifier.methodModifiers(), + parameterList, block, gtvDeclarations, offset); + methods.add(method); + }); + + RefType inh_tyterm = new RefType(name, parameterInhTyterm, offset); + TypePlaceholder x = TypePlaceholder.fresh(offset); + this.subTypeConstraints.add(new SubTypeConstraint(x, inh_tyterm)); + this.inferredTypes.put(i, x); + this.subTypeConstraints.forEach(sc -> sc.inferTypes(this.inferredTypes)); + + + final int modifiers = Modifier.interfaceModifiers(); + final RefType superClass = this.createSuperClass(); + final boolean isInterface = true; + final List constructors = new ArrayList<>(); + final List implementedInterfaces = new ArrayList<>(); + GenericDeclarationList genericClassParameters = new GenericDeclarationList(generics, i.getOffset()); + ClassOrInterface constructedInterface = new ClassOrInterface(modifiers, name, fielddecl, methods, constructors, genericClassParameters, + superClass, isInterface, implementedInterfaces, offset); + return constructedInterface; } - - private RefType createSuperClass(){ + + private RefType createSuperClass() { JavaClassName name = new JavaClassName(Object.class.getName()); GenericDeclarationList genericsOfClass = new GenericDeclarationList(new ArrayList<>(), new NullToken()); return ClassOrInterface.generateTypeOfClass(name, genericsOfClass, new NullToken()); diff --git a/src/de/dhbwstuttgart/strucTypes/printutils/PrintConstraints.java b/src/de/dhbwstuttgart/strucTypes/printutils/PrintConstraints.java index e12eed43..ae9399b7 100644 --- a/src/de/dhbwstuttgart/strucTypes/printutils/PrintConstraints.java +++ b/src/de/dhbwstuttgart/strucTypes/printutils/PrintConstraints.java @@ -2,41 +2,86 @@ package de.dhbwstuttgart.strucTypes.printutils; import java.util.List; +import de.dhbwstuttgart.strucTypes.DefaultASTVisitor; import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet; import de.dhbwstuttgart.strucTypes.constraint.FieldConstraint; import de.dhbwstuttgart.strucTypes.constraint.MethodConstraint; import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint; +import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -public class PrintConstraints { +public class PrintConstraints extends DefaultASTVisitor { - public static void print(ConstraintsSet constraintsSet){ + public void print(ConstraintsSet constraintsSet) { printSubTypeConstraints(constraintsSet.getSubTypeConstraints()); printFieldConstraints(constraintsSet.getFieldConstraints()); printMethodConstraints(constraintsSet.getMethodConstraints()); } - public static void printSubTypeConstraints(List constraints) { + public void printSubTypeConstraints(List constraints) { System.out.println("\n SubTypeConstraints:"); - constraints.forEach(c-> System.out.println(c.getSubtype() + " < " + c.getSupertype())); - } - - public static void printFieldConstraints(List constraints){ - System.out.println("\n FieldConstraints:"); - constraints.forEach(c -> System.out.println(String.format("F(%s,%s,%s)", c.getClassType() , c.getFieldName() , c.getFieldType()))); - } - - public static void printMethodConstraints(List constraints){ - System.out.println("\n MethodConstraints:"); - constraints.forEach(c-> { - StringBuilder sb = new StringBuilder("M("); - sb.append(c.getClassType() + ","); - sb.append(c.getMethodName() + ",["); - c.getArguments().forEach(a -> sb.append(a.getSubtype() + ",")); - sb.append("],(" + c.getReturnType() + ",["); - c.getArguments().forEach(a-> sb.append(a.getSupertype() + ",")); - sb.append("]))"); - System.out.println(sb.toString()); + constraints.forEach(c -> { + c.getSubtype().accept(this); + System.out.print(" <* "); + c.getSupertype().accept(this); + System.out.println(); }); - + } + + public void printFieldConstraints(List constraints) { + System.out.println("\n FieldConstraints:"); + constraints.forEach(c -> { + System.out.print("F("); + c.getClassType().accept(this); + System.out.print(", "); + System.out.print(c.getFieldName()); + System.out.print(", "); + c.getFieldType().accept(this); + System.out.println(")"); + }); + } + + public void printMethodConstraints(List constraints) { + System.out.println("\n MethodConstraints:"); + constraints.forEach(c -> { + System.out.print("M("); + c.getClassType().accept(this); + System.out.print(", "); + System.out.print(c.getMethodName() + ", ["); + c.getArguments().forEach(a -> { + a.getSubtype().accept(this); + System.out.print(", "); + }); + System.out.print("],("); + c.getReturnType().accept(this); + System.out.print(", ["); + c.getArguments().forEach(a -> { + a.getSupertype().accept(this); + System.out.print(", "); + }); + System.out.print("]))"); + System.out.println(); + }); + + } + + @Override + public void visit(RefType refType) { + List paraList = refType.getParaList(); + System.out.print(refType.getName()); + if (!paraList.isEmpty()) { + System.out.print(" <"); + paraList.forEach(p -> { + p.accept(this); + System.out.print(", "); + }); + System.out.print(">"); + } + } + + @Override + public void visit(TypePlaceholder typePlaceholder) { + System.out.print(typePlaceholder); } } diff --git a/src/de/dhbwstuttgart/strucTypes/printutils/SyntaxTreePrinter.java b/src/de/dhbwstuttgart/strucTypes/printutils/SyntaxTreePrinter.java index e1728747..19a2d233 100644 --- a/src/de/dhbwstuttgart/strucTypes/printutils/SyntaxTreePrinter.java +++ b/src/de/dhbwstuttgart/strucTypes/printutils/SyntaxTreePrinter.java @@ -55,9 +55,6 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; public class SyntaxTreePrinter implements ASTVisitor { - - - @Override public void visit(SourceFile sourceFile) { sourceFile.KlassenVektor.forEach(cl -> cl.accept(this)); @@ -71,15 +68,33 @@ public class SyntaxTreePrinter implements ASTVisitor { List methods = classOrInterface.getMethods(); RefType superClass = classOrInterface.getSuperClass(); List implementedInterfaces = classOrInterface.implementedInterfaces; - System.out.print("class: " + className + " : "); + GenericDeclarationList generics = classOrInterface.getGenerics(); + + System.out.print("class: " + className); + if (generics.iterator().hasNext()) { + System.out.print(" <"); + generics.forEach(g -> { + g.accept(this); + System.out.print(", "); + }); + System.out.print(">"); + } + System.out.print(" : "); type.accept(this); - fields.forEach(f->f.accept(this)); - methods.forEach(m->m.accept(this)); + System.out.println(); + + fields.forEach(f -> f.accept(this)); + methods.forEach(m -> m.accept(this)); + System.out.print("\n superClass: "); superClass.accept(this); - System.out.println("\n implemented Interfaces: "); - implementedInterfaces.forEach(i -> i.accept(this)); - + System.out.println(); + + if (!implementedInterfaces.isEmpty()) { + System.out.println("\n implemented Interfaces: "); + implementedInterfaces.forEach(i -> i.accept(this)); + } + } @Override @@ -88,7 +103,8 @@ public class SyntaxTreePrinter implements ASTVisitor { RefTypeOrTPHOrWildcardOrGeneric type = field.getType(); System.out.print("field: " + name + " : "); type.accept(this); - + System.out.println(); + } @Override @@ -98,28 +114,31 @@ public class SyntaxTreePrinter implements ASTVisitor { ParameterList parameterList = method.getParameterList(); System.out.print("\n method: " + name + " : "); returnType.accept(this); + System.out.println(); parameterList.accept(this); method.block.accept(this); - + } @Override public void visit(Block block) { - block.statements.forEach(s->s.accept(this)); + block.statements.forEach(s -> s.accept(this)); } @Override public void visit(ArgumentList argumentList) { List arguments = argumentList.getArguments(); - System.out.println("arguments: "); - arguments.forEach(a->a.accept(this)); + if (!arguments.isEmpty()) { + System.out.println("arguments: "); + arguments.forEach(a -> a.accept(this)); + } } @Override public void visit(ParameterList formalParameters) { List formalparalist = formalParameters.getFormalparalist(); - formalparalist.forEach(p->p.accept(this)); - + formalparalist.forEach(p -> p.accept(this)); + } @Override @@ -128,6 +147,7 @@ public class SyntaxTreePrinter implements ASTVisitor { RefTypeOrTPHOrWildcardOrGeneric type = formalParameter.getType(); System.out.print("parameter: " + name + " : "); type.accept(this); + System.out.println(); } @Override @@ -138,10 +158,11 @@ public class SyntaxTreePrinter implements ASTVisitor { Receiver receiver = methodCall.receiver; System.out.print("methodCall: " + name + " : "); type.accept(this); + System.out.println(); argumentList.accept(this); System.out.print("receiver: "); receiver.accept(this); - + } @Override @@ -157,11 +178,12 @@ public class SyntaxTreePrinter implements ASTVisitor { RefTypeOrTPHOrWildcardOrGeneric type = localVar.getType(); System.out.print("localVar: " + name + " : "); type.accept(this); + System.out.println(); } @Override public void visit(LocalVarDecl localVarDecl) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override @@ -171,6 +193,7 @@ public class SyntaxTreePrinter implements ASTVisitor { Expression receiver = fieldVar.receiver; System.out.print("fieldVar: " + name + " : "); type.accept(this); + System.out.println(); System.out.println("receiver: "); receiver.accept(this); } @@ -183,7 +206,8 @@ public class SyntaxTreePrinter implements ASTVisitor { expr.accept(this); System.out.print("typeCastExpr: "); type.accept(this); - + System.out.println(); + } @Override @@ -193,8 +217,9 @@ public class SyntaxTreePrinter implements ASTVisitor { ArgumentList argumentList = newClass.getArgumentList(); System.out.print("new: " + name + " : "); type.accept(this); + System.out.println(); argumentList.accept(this); - + } @Override @@ -203,97 +228,102 @@ public class SyntaxTreePrinter implements ASTVisitor { RefTypeOrTPHOrWildcardOrGeneric type = aThis.getType(); System.out.print("this : "); type.accept(this); - if( arglist != null) arglist.accept(this); + if (arglist != null) + arglist.accept(this); + System.out.println(); } @Override public void visit(RefType refType) { - JavaClassName name = refType.getName(); - System.out.println(name); - if(!refType.getParaList().isEmpty()){ - System.out.println(" generics: "); - refType.getParaList().forEach(p->p.accept(this)); + List paraList = refType.getParaList(); + System.out.print(refType.getName()); + if (!paraList.isEmpty()) { + System.out.print(" <"); + paraList.forEach(p -> { + p.accept(this); + System.out.print(", "); + }); + System.out.print(">"); } } @Override public void visit(TypePlaceholder typePlaceholder) { String name = typePlaceholder.getName(); - System.out.println("TPH " + name); - - + System.out.print("TPH " + name); + } @Override public void visit(NewArray newArray) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(ReturnVoid aReturn) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(StaticClassName staticClassName) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(Super aSuper) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(UnaryPlus unaryPlus) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(LambdaExpression lambdaExpression) { throw new NotImplementedException(); - + } @Override public void visit(WhileStmt whileStmt) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(DoStmt whileStmt) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(Assign assign) { throw new NotImplementedException(); - + } @Override public void visit(ForStmt forStmt) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(Binary binary) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(IfStmt ifStmt) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(EmptyStmt emptyStmt) { - throw new NotImplementedException(); + System.out.println("empty statement"); } @Override public void visit(Null aNull) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override @@ -305,22 +335,22 @@ public class SyntaxTreePrinter implements ASTVisitor { @Override public void visit(InstanceOf instanceOf) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(AssignToField assignLeftSide) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(AssignToLocal assignLeftSide) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(SuperCall superCall) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override @@ -330,37 +360,37 @@ public class SyntaxTreePrinter implements ASTVisitor { System.out.print("expressionReceiverType: " + type); System.out.print(" expressionReceiver: "); expr.accept(this); - + } @Override public void visit(GenericTypeVar genericTypeVar) { - throw new NotImplementedException(); + System.out.print(genericTypeVar); } @Override public void visit(GenericDeclarationList genericTypeVars) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(Constructor field) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(SuperWildcardType superWildcardType) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(ExtendsWildcardType extendsWildcardType) { - throw new NotImplementedException(); + throw new NotImplementedException(); } @Override public void visit(GenericRefType genericRefType) { - throw new NotImplementedException(); + throw new NotImplementedException(); } } diff --git a/test/strucType/TestConstruct.java b/test/strucType/TestConstruct.java new file mode 100644 index 00000000..f5222c71 --- /dev/null +++ b/test/strucType/TestConstruct.java @@ -0,0 +1,66 @@ +package strucType; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.strucTypes.Construct; +import de.dhbwstuttgart.strucTypes.InferredTypes; +import de.dhbwstuttgart.strucTypes.StrucTYPE; +import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet; +import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint; +import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException; +import de.dhbwstuttgart.strucTypes.printutils.PrintConstraints; +import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes; +import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter; +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.SourceFile; + +public class TestConstruct { + public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/javFiles/"; + public final PrintConstraints printConstraints = new PrintConstraints(); + + @org.junit.Test + public void test() throws ClassNotFoundException, IOException, ImpossibleSubTypeException { + ArrayList files = new ArrayList<>(); + files.add(new File(rootDirectory + "testLocalVar.jav")); + files.add(new File(rootDirectory + "testCast.jav")); + files.add(new File(rootDirectory + "testNew.jav")); + files.add(new File(rootDirectory + "testFieldVar.jav")); + files.add(new File(rootDirectory + "testFieldMethod.jav")); + files.add(new File(rootDirectory + "testMethod.jav")); + files.add(new File(rootDirectory + "testPaperExample.jav")); + JavaTXCompiler compiler = new JavaTXCompiler(files); + for (File f : compiler.sourceFiles.keySet()) { + String name = f.getName(); + System.out.println("Filename: " + name); + SourceFile sourceFile = compiler.sourceFiles.get(f); + //Print SourceFile Infos + sourceFile.accept(new SyntaxTreePrinter()); + + StrucTYPE strucTYPE = new StrucTYPE(sourceFile); + + ConstraintsSet constraints = strucTYPE.getConstraints(); + printConstraints.print(constraints); + + InferredTypes inferredTypes = strucTYPE.getInferredTypes(); + PrintInferredTypes.print(inferredTypes); + + Construct construct = new Construct(constraints, inferredTypes); + + List constructedInterfaces = construct.getConstructedInterfaces(); + System.out.println("\nConstructed Interfaces:"); + constructedInterfaces.forEach(i-> i.accept(new SyntaxTreePrinter())); + + List subTypeConstraints = construct.getSubTypeConstraints(); + printConstraints.printSubTypeConstraints(subTypeConstraints); + + inferredTypes = construct.getInferredTypes(); + PrintInferredTypes.print(inferredTypes); + + System.out.println("____________________________________________________________________________"); + } + } +} diff --git a/test/strucType/TestInterface.java b/test/strucType/TestInterface.java new file mode 100644 index 00000000..dcbef4e9 --- /dev/null +++ b/test/strucType/TestInterface.java @@ -0,0 +1,66 @@ +package strucType; + + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.strucTypes.TypeExtract; + +public class TestInterface { + public static final String rootDirectory = System.getProperty("user.dir")+"/test/strucType/javFiles/"; + + + @org.junit.Test + public void test() throws ClassNotFoundException, IOException { + ArrayList files = new ArrayList<>(); + files.add(new File(rootDirectory + "testInterface.jav")); + JavaTXCompiler compiler = new JavaTXCompiler(files); + compiler.sourceFiles.keySet().forEach(f->{ + String name = f.getName(); + System.out.println("Filename: " + name); + compiler.sourceFiles.get(f).getClasses().forEach(c-> c.accept(new TypeExtract())); + System.out.println(); + }); +// this.printSyntaxTree(compiler); + System.out.println("test end"); + } + +// private void printSyntaxTree(JavaTXCompiler compiler){ +// Collection sourceFiles= compiler.sourceFiles.values(); +// for (SourceFile sourceFile : sourceFiles) { +// List klassenVektor = sourceFile.KlassenVektor; +// for (ClassOrInterface classOrInterface : klassenVektor) { +// JavaClassName className = classOrInterface.getClassName(); +// System.out.println("class: "+ className); +// List fields = classOrInterface.getFieldDecl(); +// List methods = classOrInterface.getMethods(); +// for (Field field : fields) { +// String fName = field.getName(); +// RefTypeOrTPHOrWildcardOrGeneric fType = field.getType(); +// System.out.println("field: "+ fName + " : " + fType); +// } +// for (Method method : methods) { +// String mName = method.getName(); +// RefTypeOrTPHOrWildcardOrGeneric mReturnType = method.getReturnType(); +// System.out.println("method: " + mName + " : " + mReturnType); +// ParameterList mParameterList = method.getParameterList(); +// for (FormalParameter formalParameter : mParameterList) { +// String paraName = formalParameter.getName(); +// RefTypeOrTPHOrWildcardOrGeneric paraType = formalParameter.getType(); +// System.out.println("parameter: " + paraName + " : " + paraType); +// } +// RefTypeOrTPHOrWildcardOrGeneric blockType = method.block.getType(); +// System.out.println("blockType: " + blockType); +// List blockStatements = method.block.getStatements(); +// for (Statement statement : blockStatements) { +// RefTypeOrTPHOrWildcardOrGeneric statementType = statement.getType(); +// System.out.println("statementType: " + statementType); +// } +// } +// } +// } +// } + +} diff --git a/test/strucType/TestStrucType.java b/test/strucType/TestStrucType.java index 388485e3..ae41b796 100644 --- a/test/strucType/TestStrucType.java +++ b/test/strucType/TestStrucType.java @@ -15,17 +15,18 @@ import de.dhbwstuttgart.syntaxtree.SourceFile; public class TestStrucType { public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/javFiles/"; + private final PrintConstraints printConstraints = new PrintConstraints(); @org.junit.Test public void test() throws ClassNotFoundException, IOException { ArrayList files = new ArrayList<>(); -// files.add(new File(rootDirectory + "testLocalVar.jav")); -// files.add(new File(rootDirectory + "testCast.jav")); -// files.add(new File(rootDirectory + "testNew.jav")); -// files.add(new File(rootDirectory + "testFieldVar.jav")); -// files.add(new File(rootDirectory + "testFieldMethod.jav")); + files.add(new File(rootDirectory + "testLocalVar.jav")); + files.add(new File(rootDirectory + "testCast.jav")); + files.add(new File(rootDirectory + "testNew.jav")); + files.add(new File(rootDirectory + "testFieldVar.jav")); + files.add(new File(rootDirectory + "testFieldMethod.jav")); files.add(new File(rootDirectory + "testMethod.jav")); -// files.add(new File(rootDirectory + "testPaperExample.jav")); + files.add(new File(rootDirectory + "testPaperExample.jav")); JavaTXCompiler compiler = new JavaTXCompiler(files); for (File f : compiler.sourceFiles.keySet()) { String name = f.getName(); @@ -37,7 +38,7 @@ public class TestStrucType { StrucTYPE strucTYPE = new StrucTYPE(sourceFile); ConstraintsSet constraints = strucTYPE.getConstraints(); - PrintConstraints.print(constraints); + printConstraints.print(constraints); InferredTypes inferredTypes = strucTYPE.getInferredTypes(); PrintInferredTypes.print(inferredTypes); diff --git a/test/strucType/TestSyntaxTreePrinter.java b/test/strucType/TestSyntaxTreePrinter.java index 2819fdcb..c1b5d04f 100644 --- a/test/strucType/TestSyntaxTreePrinter.java +++ b/test/strucType/TestSyntaxTreePrinter.java @@ -3,10 +3,8 @@ package strucType; import java.io.File; import java.io.IOException; -import java.io.Serializable; import java.util.ArrayList; - import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter; @@ -17,12 +15,12 @@ public class TestSyntaxTreePrinter { @org.junit.Test public void test() throws ClassNotFoundException, IOException { ArrayList files = new ArrayList<>(); - files.add(new File(rootDirectory + "testLocalVar.jav")); - files.add(new File(rootDirectory + "testCast.jav")); +// files.add(new File(rootDirectory + "testLocalVar.jav")); +// files.add(new File(rootDirectory + "testCast.jav")); files.add(new File(rootDirectory + "testNew.jav")); - files.add(new File(rootDirectory + "testFieldVar.jav")); - files.add(new File(rootDirectory + "testFieldMethod.jav")); - files.add(new File(rootDirectory + "testPaperExample.jav")); +// files.add(new File(rootDirectory + "testFieldVar.jav")); +// files.add(new File(rootDirectory + "testFieldMethod.jav")); +// files.add(new File(rootDirectory + "testPaperExample.jav")); JavaTXCompiler compiler = new JavaTXCompiler(files); compiler.sourceFiles.keySet().forEach(f->{ String name = f.getName(); diff --git a/test/strucType/javFiles/testInterface.jav b/test/strucType/javFiles/testInterface.jav new file mode 100644 index 00000000..c0b1968d --- /dev/null +++ b/test/strucType/javFiles/testInterface.jav @@ -0,0 +1,7 @@ +package strucType.input; + +import java.util.List; + +class A implements List +{ +} \ No newline at end of file diff --git a/test/strucType/javFiles/testNew.jav b/test/strucType/javFiles/testNew.jav index 9f877591..fd2bf3b3 100644 --- a/test/strucType/javFiles/testNew.jav +++ b/test/strucType/javFiles/testNew.jav @@ -1,7 +1,7 @@ package strucType.input; import strucType.typedtestclasses.A; import strucType.typedtestclasses.B; -class N +class N { a;