forked from JavaTX/JavaCompilerCore
Construct bis auf Generics fertig, Printausgabe fuer generics angepasst
This commit is contained in:
parent
651c9ee68c
commit
6fc78b9ad3
@ -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,9 +46,14 @@ public class Construct extends DefaultASTVisitor {
|
||||
}
|
||||
|
||||
public List<ClassOrInterface> getConstructedInterfaces() {
|
||||
this.newInterf.forEach(i -> i.accept(this));
|
||||
return constructedInterfaces;
|
||||
}
|
||||
|
||||
public List<SubTypeConstraint> getSubTypeConstraints() {
|
||||
return subTypeConstraints;
|
||||
}
|
||||
|
||||
private void gatherSubTypeConstraints(ConstraintsSet constraintsSet) {
|
||||
this.subTypeConstraints.addAll(constraintsSet.getSubTypeConstraints());
|
||||
constraintsSet.getFieldConstraints().forEach(fc -> this.newInterf.add(fc.getClassType()));
|
||||
@ -58,34 +65,73 @@ public class Construct extends DefaultASTVisitor {
|
||||
|
||||
@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<Field> fielddecl = new ArrayList<>();
|
||||
List<Method> methods = new ArrayList<>();
|
||||
List<Constructor> constructors = new ArrayList<>();
|
||||
List<GenericTypeVar> generics = new ArrayList<>();
|
||||
GenericDeclarationList genericClassParameters = new GenericDeclarationList(generics, i.getOffset());
|
||||
final RefType superClass = this.createSuperClass();
|
||||
final boolean isInterface = true;
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces = new ArrayList<>();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> 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<FormalParameter> 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<Constructor> constructors = new ArrayList<>();
|
||||
final List<RefTypeOrTPHOrWildcardOrGeneric> 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() {
|
||||
|
@ -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<SubTypeConstraint> constraints) {
|
||||
public void printSubTypeConstraints(List<SubTypeConstraint> constraints) {
|
||||
System.out.println("\n SubTypeConstraints:");
|
||||
constraints.forEach(c-> System.out.println(c.getSubtype() + " < " + c.getSupertype()));
|
||||
constraints.forEach(c -> {
|
||||
c.getSubtype().accept(this);
|
||||
System.out.print(" <* ");
|
||||
c.getSupertype().accept(this);
|
||||
System.out.println();
|
||||
});
|
||||
}
|
||||
|
||||
public static void printFieldConstraints(List<FieldConstraint> constraints){
|
||||
public void printFieldConstraints(List<FieldConstraint> constraints) {
|
||||
System.out.println("\n FieldConstraints:");
|
||||
constraints.forEach(c -> System.out.println(String.format("F(%s,%s,%s)", c.getClassType() , c.getFieldName() , c.getFieldType())));
|
||||
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 static void printMethodConstraints(List<MethodConstraint> constraints){
|
||||
public void printMethodConstraints(List<MethodConstraint> 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());
|
||||
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<RefTypeOrTPHOrWildcardOrGeneric> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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,14 +68,32 @@ public class SyntaxTreePrinter implements ASTVisitor {
|
||||
List<Method> methods = classOrInterface.getMethods();
|
||||
RefType superClass = classOrInterface.getSuperClass();
|
||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> 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);
|
||||
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();
|
||||
|
||||
if (!implementedInterfaces.isEmpty()) {
|
||||
System.out.println("\n implemented Interfaces: ");
|
||||
implementedInterfaces.forEach(i -> i.accept(this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -88,6 +103,7 @@ public class SyntaxTreePrinter implements ASTVisitor {
|
||||
RefTypeOrTPHOrWildcardOrGeneric type = field.getType();
|
||||
System.out.print("field: " + name + " : ");
|
||||
type.accept(this);
|
||||
System.out.println();
|
||||
|
||||
}
|
||||
|
||||
@ -98,6 +114,7 @@ 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);
|
||||
|
||||
@ -111,9 +128,11 @@ public class SyntaxTreePrinter implements ASTVisitor {
|
||||
@Override
|
||||
public void visit(ArgumentList argumentList) {
|
||||
List<Expression> arguments = argumentList.getArguments();
|
||||
if (!arguments.isEmpty()) {
|
||||
System.out.println("arguments: ");
|
||||
arguments.forEach(a -> a.accept(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ParameterList formalParameters) {
|
||||
@ -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,6 +158,7 @@ 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);
|
||||
@ -157,6 +178,7 @@ public class SyntaxTreePrinter implements ASTVisitor {
|
||||
RefTypeOrTPHOrWildcardOrGeneric type = localVar.getType();
|
||||
System.out.print("localVar: " + name + " : ");
|
||||
type.accept(this);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@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,6 +206,7 @@ public class SyntaxTreePrinter implements ASTVisitor {
|
||||
expr.accept(this);
|
||||
System.out.print("typeCastExpr: ");
|
||||
type.accept(this);
|
||||
System.out.println();
|
||||
|
||||
}
|
||||
|
||||
@ -193,6 +217,7 @@ public class SyntaxTreePrinter implements ASTVisitor {
|
||||
ArgumentList argumentList = newClass.getArgumentList();
|
||||
System.out.print("new: " + name + " : ");
|
||||
type.accept(this);
|
||||
System.out.println();
|
||||
argumentList.accept(this);
|
||||
|
||||
}
|
||||
@ -203,24 +228,29 @@ 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<RefTypeOrTPHOrWildcardOrGeneric> 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);
|
||||
|
||||
}
|
||||
|
||||
@ -288,7 +318,7 @@ public class SyntaxTreePrinter implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(EmptyStmt emptyStmt) {
|
||||
throw new NotImplementedException();
|
||||
System.out.println("empty statement");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -335,7 +365,7 @@ public class SyntaxTreePrinter implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(GenericTypeVar genericTypeVar) {
|
||||
throw new NotImplementedException();
|
||||
System.out.print(genericTypeVar);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
66
test/strucType/TestConstruct.java
Normal file
66
test/strucType/TestConstruct.java
Normal file
@ -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<File> 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<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||
System.out.println("\nConstructed Interfaces:");
|
||||
constructedInterfaces.forEach(i-> i.accept(new SyntaxTreePrinter()));
|
||||
|
||||
List<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||
printConstraints.printSubTypeConstraints(subTypeConstraints);
|
||||
|
||||
inferredTypes = construct.getInferredTypes();
|
||||
PrintInferredTypes.print(inferredTypes);
|
||||
|
||||
System.out.println("____________________________________________________________________________");
|
||||
}
|
||||
}
|
||||
}
|
66
test/strucType/TestInterface.java
Normal file
66
test/strucType/TestInterface.java
Normal file
@ -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<File> 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<SourceFile> sourceFiles= compiler.sourceFiles.values();
|
||||
// for (SourceFile sourceFile : sourceFiles) {
|
||||
// List<ClassOrInterface> klassenVektor = sourceFile.KlassenVektor;
|
||||
// for (ClassOrInterface classOrInterface : klassenVektor) {
|
||||
// JavaClassName className = classOrInterface.getClassName();
|
||||
// System.out.println("class: "+ className);
|
||||
// List<Field> fields = classOrInterface.getFieldDecl();
|
||||
// List<Method> 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<Statement> blockStatements = method.block.getStatements();
|
||||
// for (Statement statement : blockStatements) {
|
||||
// RefTypeOrTPHOrWildcardOrGeneric statementType = statement.getType();
|
||||
// System.out.println("statementType: " + statementType);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
@ -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<File> 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);
|
||||
|
@ -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<File> 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();
|
||||
|
7
test/strucType/javFiles/testInterface.jav
Normal file
7
test/strucType/javFiles/testInterface.jav
Normal file
@ -0,0 +1,7 @@
|
||||
package strucType.input;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class A implements List
|
||||
{
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package strucType.input;
|
||||
import strucType.typedtestclasses.A;
|
||||
import strucType.typedtestclasses.B;
|
||||
class N
|
||||
class N <T,R>
|
||||
{
|
||||
a;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user