Construct bis auf Generics fertig, Printausgabe fuer generics angepasst

This commit is contained in:
Aldaron7 2018-03-20 21:24:48 +01:00
parent 651c9ee68c
commit 6fc78b9ad3
9 changed files with 370 additions and 111 deletions

View File

@ -9,15 +9,17 @@ import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet; import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
import de.dhbwstuttgart.strucTypes.constraint.FieldConstraint;
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint; import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException; import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor; import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.Field; import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList; import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.Method; 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.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
@ -44,8 +46,13 @@ public class Construct extends DefaultASTVisitor {
} }
public List<ClassOrInterface> getConstructedInterfaces() { public List<ClassOrInterface> getConstructedInterfaces() {
this.newInterf.forEach(i -> i.accept(this));
return constructedInterfaces; return constructedInterfaces;
} }
public List<SubTypeConstraint> getSubTypeConstraints() {
return subTypeConstraints;
}
private void gatherSubTypeConstraints(ConstraintsSet constraintsSet) { private void gatherSubTypeConstraints(ConstraintsSet constraintsSet) {
this.subTypeConstraints.addAll(constraintsSet.getSubTypeConstraints()); this.subTypeConstraints.addAll(constraintsSet.getSubTypeConstraints());
@ -55,40 +62,79 @@ public class Construct extends DefaultASTVisitor {
this.newInterf.add(mc.getClassType()); this.newInterf.add(mc.getClassType());
}); });
} }
@Override @Override
public void visit(TypePlaceholder typePlaceholder) { public void visit(TypePlaceholder typePlaceholder) {
JavaClassName name = new JavaClassName("de.dhbw.constructedinterface." + typePlaceholder.getName()); JavaClassName name = new JavaClassName("constructedinterface." + typePlaceholder.getName());
this.constructInterface(typePlaceholder, name); this.constructedInterfaces.add(this.constructInterface(typePlaceholder, name));
} }
// TODO check nur TPH in newInterf
@Override @Override
public void visit(RefType refType) { public void visit(RefType refType) {
JavaClassName name = refType.getName(); // JavaClassName name = refType.getName();
this.constructInterface(refType, name); // this.constructedInterfaces.add(this.constructInterface(refType,
// name));
} }
private ClassOrInterface constructInterface(RefTypeOrTPHOrWildcardOrGeneric i, JavaClassName name) { private ClassOrInterface constructInterface(TypePlaceholder i, JavaClassName name) {
final int modifiers = Modifier.interfaceModifiers();
List<Field> fielddecl = new ArrayList<>(); List<Field> fielddecl = new ArrayList<>();
List<Method> methods = new ArrayList<>(); List<Method> methods = new ArrayList<>();
List<Constructor> constructors = new ArrayList<>();
List<GenericTypeVar> generics = new ArrayList<>(); List<GenericTypeVar> generics = new ArrayList<>();
GenericDeclarationList genericClassParameters = new GenericDeclarationList(generics, i.getOffset()); List<RefTypeOrTPHOrWildcardOrGeneric> parameterInhTyterm = new ArrayList<>();
final RefType superClass = this.createSuperClass();
final boolean isInterface = true;
List<RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces = new ArrayList<>();
final Token offset = i.getOffset(); final Token offset = i.getOffset();
// For über alle FieldConstraints mit ClassType i
this.constraintsSet.getFieldConstraints().stream().filter(fc -> fc.getClassType().equals(i)).forEach(fc -> { this.constraintsSet.getFieldConstraints().stream().filter(fc -> fc.getClassType().equals(i)).forEach(fc -> {
TypePlaceholder type = TypePlaceholder.fresh(i.getOffset()); 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(){ private RefType createSuperClass() {
JavaClassName name = new JavaClassName(Object.class.getName()); JavaClassName name = new JavaClassName(Object.class.getName());
GenericDeclarationList genericsOfClass = new GenericDeclarationList(new ArrayList<>(), new NullToken()); GenericDeclarationList genericsOfClass = new GenericDeclarationList(new ArrayList<>(), new NullToken());
return ClassOrInterface.generateTypeOfClass(name, genericsOfClass, new NullToken()); return ClassOrInterface.generateTypeOfClass(name, genericsOfClass, new NullToken());

View File

@ -2,41 +2,86 @@ package de.dhbwstuttgart.strucTypes.printutils;
import java.util.List; import java.util.List;
import de.dhbwstuttgart.strucTypes.DefaultASTVisitor;
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet; import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
import de.dhbwstuttgart.strucTypes.constraint.FieldConstraint; import de.dhbwstuttgart.strucTypes.constraint.FieldConstraint;
import de.dhbwstuttgart.strucTypes.constraint.MethodConstraint; import de.dhbwstuttgart.strucTypes.constraint.MethodConstraint;
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint; 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()); printSubTypeConstraints(constraintsSet.getSubTypeConstraints());
printFieldConstraints(constraintsSet.getFieldConstraints()); printFieldConstraints(constraintsSet.getFieldConstraints());
printMethodConstraints(constraintsSet.getMethodConstraints()); printMethodConstraints(constraintsSet.getMethodConstraints());
} }
public static void printSubTypeConstraints(List<SubTypeConstraint> constraints) { public void printSubTypeConstraints(List<SubTypeConstraint> constraints) {
System.out.println("\n SubTypeConstraints:"); 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(" <* ");
public static void printFieldConstraints(List<FieldConstraint> constraints){ c.getSupertype().accept(this);
System.out.println("\n FieldConstraints:"); System.out.println();
constraints.forEach(c -> System.out.println(String.format("F(%s,%s,%s)", c.getClassType() , c.getFieldName() , c.getFieldType())));
}
public static 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());
}); });
}
public void printFieldConstraints(List<FieldConstraint> 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<MethodConstraint> 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<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);
} }
} }

View File

@ -55,9 +55,6 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
public class SyntaxTreePrinter implements ASTVisitor { public class SyntaxTreePrinter implements ASTVisitor {
@Override @Override
public void visit(SourceFile sourceFile) { public void visit(SourceFile sourceFile) {
sourceFile.KlassenVektor.forEach(cl -> cl.accept(this)); sourceFile.KlassenVektor.forEach(cl -> cl.accept(this));
@ -71,15 +68,33 @@ public class SyntaxTreePrinter implements ASTVisitor {
List<Method> methods = classOrInterface.getMethods(); List<Method> methods = classOrInterface.getMethods();
RefType superClass = classOrInterface.getSuperClass(); RefType superClass = classOrInterface.getSuperClass();
List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces = classOrInterface.implementedInterfaces; 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); type.accept(this);
fields.forEach(f->f.accept(this)); System.out.println();
methods.forEach(m->m.accept(this));
fields.forEach(f -> f.accept(this));
methods.forEach(m -> m.accept(this));
System.out.print("\n superClass: "); System.out.print("\n superClass: ");
superClass.accept(this); superClass.accept(this);
System.out.println("\n implemented Interfaces: "); System.out.println();
implementedInterfaces.forEach(i -> i.accept(this));
if (!implementedInterfaces.isEmpty()) {
System.out.println("\n implemented Interfaces: ");
implementedInterfaces.forEach(i -> i.accept(this));
}
} }
@Override @Override
@ -88,7 +103,8 @@ public class SyntaxTreePrinter implements ASTVisitor {
RefTypeOrTPHOrWildcardOrGeneric type = field.getType(); RefTypeOrTPHOrWildcardOrGeneric type = field.getType();
System.out.print("field: " + name + " : "); System.out.print("field: " + name + " : ");
type.accept(this); type.accept(this);
System.out.println();
} }
@Override @Override
@ -98,28 +114,31 @@ public class SyntaxTreePrinter implements ASTVisitor {
ParameterList parameterList = method.getParameterList(); ParameterList parameterList = method.getParameterList();
System.out.print("\n method: " + name + " : "); System.out.print("\n method: " + name + " : ");
returnType.accept(this); returnType.accept(this);
System.out.println();
parameterList.accept(this); parameterList.accept(this);
method.block.accept(this); method.block.accept(this);
} }
@Override @Override
public void visit(Block block) { public void visit(Block block) {
block.statements.forEach(s->s.accept(this)); block.statements.forEach(s -> s.accept(this));
} }
@Override @Override
public void visit(ArgumentList argumentList) { public void visit(ArgumentList argumentList) {
List<Expression> arguments = argumentList.getArguments(); List<Expression> arguments = argumentList.getArguments();
System.out.println("arguments: "); if (!arguments.isEmpty()) {
arguments.forEach(a->a.accept(this)); System.out.println("arguments: ");
arguments.forEach(a -> a.accept(this));
}
} }
@Override @Override
public void visit(ParameterList formalParameters) { public void visit(ParameterList formalParameters) {
List<FormalParameter> formalparalist = formalParameters.getFormalparalist(); List<FormalParameter> formalparalist = formalParameters.getFormalparalist();
formalparalist.forEach(p->p.accept(this)); formalparalist.forEach(p -> p.accept(this));
} }
@Override @Override
@ -128,6 +147,7 @@ public class SyntaxTreePrinter implements ASTVisitor {
RefTypeOrTPHOrWildcardOrGeneric type = formalParameter.getType(); RefTypeOrTPHOrWildcardOrGeneric type = formalParameter.getType();
System.out.print("parameter: " + name + " : "); System.out.print("parameter: " + name + " : ");
type.accept(this); type.accept(this);
System.out.println();
} }
@Override @Override
@ -138,10 +158,11 @@ public class SyntaxTreePrinter implements ASTVisitor {
Receiver receiver = methodCall.receiver; Receiver receiver = methodCall.receiver;
System.out.print("methodCall: " + name + " : "); System.out.print("methodCall: " + name + " : ");
type.accept(this); type.accept(this);
System.out.println();
argumentList.accept(this); argumentList.accept(this);
System.out.print("receiver: "); System.out.print("receiver: ");
receiver.accept(this); receiver.accept(this);
} }
@Override @Override
@ -157,11 +178,12 @@ public class SyntaxTreePrinter implements ASTVisitor {
RefTypeOrTPHOrWildcardOrGeneric type = localVar.getType(); RefTypeOrTPHOrWildcardOrGeneric type = localVar.getType();
System.out.print("localVar: " + name + " : "); System.out.print("localVar: " + name + " : ");
type.accept(this); type.accept(this);
System.out.println();
} }
@Override @Override
public void visit(LocalVarDecl localVarDecl) { public void visit(LocalVarDecl localVarDecl) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
@ -171,6 +193,7 @@ public class SyntaxTreePrinter implements ASTVisitor {
Expression receiver = fieldVar.receiver; Expression receiver = fieldVar.receiver;
System.out.print("fieldVar: " + name + " : "); System.out.print("fieldVar: " + name + " : ");
type.accept(this); type.accept(this);
System.out.println();
System.out.println("receiver: "); System.out.println("receiver: ");
receiver.accept(this); receiver.accept(this);
} }
@ -183,7 +206,8 @@ public class SyntaxTreePrinter implements ASTVisitor {
expr.accept(this); expr.accept(this);
System.out.print("typeCastExpr: "); System.out.print("typeCastExpr: ");
type.accept(this); type.accept(this);
System.out.println();
} }
@Override @Override
@ -193,8 +217,9 @@ public class SyntaxTreePrinter implements ASTVisitor {
ArgumentList argumentList = newClass.getArgumentList(); ArgumentList argumentList = newClass.getArgumentList();
System.out.print("new: " + name + " : "); System.out.print("new: " + name + " : ");
type.accept(this); type.accept(this);
System.out.println();
argumentList.accept(this); argumentList.accept(this);
} }
@Override @Override
@ -203,97 +228,102 @@ public class SyntaxTreePrinter implements ASTVisitor {
RefTypeOrTPHOrWildcardOrGeneric type = aThis.getType(); RefTypeOrTPHOrWildcardOrGeneric type = aThis.getType();
System.out.print("this : "); System.out.print("this : ");
type.accept(this); type.accept(this);
if( arglist != null) arglist.accept(this); if (arglist != null)
arglist.accept(this);
System.out.println();
} }
@Override @Override
public void visit(RefType refType) { public void visit(RefType refType) {
JavaClassName name = refType.getName(); List<RefTypeOrTPHOrWildcardOrGeneric> paraList = refType.getParaList();
System.out.println(name); System.out.print(refType.getName());
if(!refType.getParaList().isEmpty()){ if (!paraList.isEmpty()) {
System.out.println(" generics: "); System.out.print(" <");
refType.getParaList().forEach(p->p.accept(this)); paraList.forEach(p -> {
p.accept(this);
System.out.print(", ");
});
System.out.print(">");
} }
} }
@Override @Override
public void visit(TypePlaceholder typePlaceholder) { public void visit(TypePlaceholder typePlaceholder) {
String name = typePlaceholder.getName(); String name = typePlaceholder.getName();
System.out.println("TPH " + name); System.out.print("TPH " + name);
} }
@Override @Override
public void visit(NewArray newArray) { public void visit(NewArray newArray) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(ReturnVoid aReturn) { public void visit(ReturnVoid aReturn) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(StaticClassName staticClassName) { public void visit(StaticClassName staticClassName) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(Super aSuper) { public void visit(Super aSuper) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(UnaryPlus unaryPlus) { public void visit(UnaryPlus unaryPlus) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(LambdaExpression lambdaExpression) { public void visit(LambdaExpression lambdaExpression) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(WhileStmt whileStmt) { public void visit(WhileStmt whileStmt) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(DoStmt whileStmt) { public void visit(DoStmt whileStmt) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(Assign assign) { public void visit(Assign assign) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(ForStmt forStmt) { public void visit(ForStmt forStmt) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(Binary binary) { public void visit(Binary binary) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(IfStmt ifStmt) { public void visit(IfStmt ifStmt) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(EmptyStmt emptyStmt) { public void visit(EmptyStmt emptyStmt) {
throw new NotImplementedException(); System.out.println("empty statement");
} }
@Override @Override
public void visit(Null aNull) { public void visit(Null aNull) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
@ -305,22 +335,22 @@ public class SyntaxTreePrinter implements ASTVisitor {
@Override @Override
public void visit(InstanceOf instanceOf) { public void visit(InstanceOf instanceOf) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(AssignToField assignLeftSide) { public void visit(AssignToField assignLeftSide) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(AssignToLocal assignLeftSide) { public void visit(AssignToLocal assignLeftSide) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(SuperCall superCall) { public void visit(SuperCall superCall) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
@ -330,37 +360,37 @@ public class SyntaxTreePrinter implements ASTVisitor {
System.out.print("expressionReceiverType: " + type); System.out.print("expressionReceiverType: " + type);
System.out.print(" expressionReceiver: "); System.out.print(" expressionReceiver: ");
expr.accept(this); expr.accept(this);
} }
@Override @Override
public void visit(GenericTypeVar genericTypeVar) { public void visit(GenericTypeVar genericTypeVar) {
throw new NotImplementedException(); System.out.print(genericTypeVar);
} }
@Override @Override
public void visit(GenericDeclarationList genericTypeVars) { public void visit(GenericDeclarationList genericTypeVars) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(Constructor field) { public void visit(Constructor field) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(SuperWildcardType superWildcardType) { public void visit(SuperWildcardType superWildcardType) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(ExtendsWildcardType extendsWildcardType) { public void visit(ExtendsWildcardType extendsWildcardType) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override @Override
public void visit(GenericRefType genericRefType) { public void visit(GenericRefType genericRefType) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }

View 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("____________________________________________________________________________");
}
}
}

View 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);
// }
// }
// }
// }
// }
}

View File

@ -15,17 +15,18 @@ import de.dhbwstuttgart.syntaxtree.SourceFile;
public class TestStrucType { public class TestStrucType {
public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/javFiles/"; public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/javFiles/";
private final PrintConstraints printConstraints = new PrintConstraints();
@org.junit.Test @org.junit.Test
public void test() throws ClassNotFoundException, IOException { public void test() throws ClassNotFoundException, IOException {
ArrayList<File> files = new ArrayList<>(); ArrayList<File> files = new ArrayList<>();
// files.add(new File(rootDirectory + "testLocalVar.jav")); files.add(new File(rootDirectory + "testLocalVar.jav"));
// files.add(new File(rootDirectory + "testCast.jav")); files.add(new File(rootDirectory + "testCast.jav"));
// files.add(new File(rootDirectory + "testNew.jav")); files.add(new File(rootDirectory + "testNew.jav"));
// files.add(new File(rootDirectory + "testFieldVar.jav")); files.add(new File(rootDirectory + "testFieldVar.jav"));
// files.add(new File(rootDirectory + "testFieldMethod.jav")); files.add(new File(rootDirectory + "testFieldMethod.jav"));
files.add(new File(rootDirectory + "testMethod.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); JavaTXCompiler compiler = new JavaTXCompiler(files);
for (File f : compiler.sourceFiles.keySet()) { for (File f : compiler.sourceFiles.keySet()) {
String name = f.getName(); String name = f.getName();
@ -37,7 +38,7 @@ public class TestStrucType {
StrucTYPE strucTYPE = new StrucTYPE(sourceFile); StrucTYPE strucTYPE = new StrucTYPE(sourceFile);
ConstraintsSet constraints = strucTYPE.getConstraints(); ConstraintsSet constraints = strucTYPE.getConstraints();
PrintConstraints.print(constraints); printConstraints.print(constraints);
InferredTypes inferredTypes = strucTYPE.getInferredTypes(); InferredTypes inferredTypes = strucTYPE.getInferredTypes();
PrintInferredTypes.print(inferredTypes); PrintInferredTypes.print(inferredTypes);

View File

@ -3,10 +3,8 @@ package strucType;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter; import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
@ -17,12 +15,12 @@ public class TestSyntaxTreePrinter {
@org.junit.Test @org.junit.Test
public void test() throws ClassNotFoundException, IOException { public void test() throws ClassNotFoundException, IOException {
ArrayList<File> files = new ArrayList<>(); ArrayList<File> files = new ArrayList<>();
files.add(new File(rootDirectory + "testLocalVar.jav")); // files.add(new File(rootDirectory + "testLocalVar.jav"));
files.add(new File(rootDirectory + "testCast.jav")); // files.add(new File(rootDirectory + "testCast.jav"));
files.add(new File(rootDirectory + "testNew.jav")); files.add(new File(rootDirectory + "testNew.jav"));
files.add(new File(rootDirectory + "testFieldVar.jav")); // files.add(new File(rootDirectory + "testFieldVar.jav"));
files.add(new File(rootDirectory + "testFieldMethod.jav")); // files.add(new File(rootDirectory + "testFieldMethod.jav"));
files.add(new File(rootDirectory + "testPaperExample.jav")); // files.add(new File(rootDirectory + "testPaperExample.jav"));
JavaTXCompiler compiler = new JavaTXCompiler(files); JavaTXCompiler compiler = new JavaTXCompiler(files);
compiler.sourceFiles.keySet().forEach(f->{ compiler.sourceFiles.keySet().forEach(f->{
String name = f.getName(); String name = f.getName();

View File

@ -0,0 +1,7 @@
package strucType.input;
import java.util.List;
class A implements List
{
}

View File

@ -1,7 +1,7 @@
package strucType.input; package strucType.input;
import strucType.typedtestclasses.A; import strucType.typedtestclasses.A;
import strucType.typedtestclasses.B; import strucType.typedtestclasses.B;
class N class N <T,R>
{ {
a; a;