Merge mit bigRefactoring

This commit is contained in:
JanUlrich 2018-06-13 23:54:35 +02:00
commit fe72936737
18 changed files with 253 additions and 54 deletions

View File

@ -7,6 +7,8 @@ import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.TypePrinter;
import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.unify.model.*; import de.dhbwstuttgart.typeinference.unify.model.*;
@ -24,12 +26,16 @@ public class FCGenerator {
return toFC(availableClasses).stream().map(t -> UnifyTypeFactory.convert(t)).collect(Collectors.toSet()); return toFC(availableClasses).stream().map(t -> UnifyTypeFactory.convert(t)).collect(Collectors.toSet());
} }
public static Set<Pair> toFC(Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException { public static Collection<Pair> toFC(Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
HashSet<Pair> pairs = new HashSet<>(); HashMap<String, Pair> pairs = new HashMap<>();
TypePrinter printer = new TypePrinter();
for(ClassOrInterface cly : availableClasses){ for(ClassOrInterface cly : availableClasses){
pairs.addAll(getSuperTypes(cly, availableClasses)); for(Pair p : getSuperTypes(cly, availableClasses)){
String hash = p.TA1.acceptTV(printer)+";"+p.TA2.acceptTV(printer);
pairs.put(hash, p);
} }
return pairs; }
return pairs.values();
} }
/** /**

View File

@ -427,6 +427,9 @@ public class SyntaxTreeGenerator{
GenericsRegistry ret = new GenericsRegistry(this.globalGenerics); GenericsRegistry ret = new GenericsRegistry(this.globalGenerics);
ret.putAll(generics); ret.putAll(generics);
if(ctx == null || ctx.typeParameterList() == null)return ret; if(ctx == null || ctx.typeParameterList() == null)return ret;
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
ret.put(tp.Identifier().getText(), new GenericContext(parentClass, parentMethod));
}
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){ for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
TypeGenerator.convert(tp, parentClass, parentMethod, reg, ret); TypeGenerator.convert(tp, parentClass, parentMethod, reg, ret);
} }

View File

@ -22,18 +22,20 @@ import java.util.List;
public class TypeGenerator { public class TypeGenerator {
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannClassOrInterfaceTypeContext unannClassOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) { public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannClassOrInterfaceTypeContext unannClassOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
String name;
if(unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType() != null){
name = unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().Identifier().getText();
}
Java8Parser.TypeArgumentsContext arguments; Java8Parser.TypeArgumentsContext arguments;
if(unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType() != null){ if(unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType() != null){
name = unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType().Identifier().getText();
arguments = unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType().typeArguments(); arguments = unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType().typeArguments();
}else{// if(unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType() != null){ }else{// if(unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType() != null){
name = unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().getText();
arguments = unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().typeArguments(); arguments = unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().typeArguments();
} }
/**
* Problem sind hier die verschachtelten Typen mit verschachtelten Typargumenten
* Beispiel: Typ<String>.InnererTyp<Integer>
*/
String name = unannClassOrInterfaceTypeContext.getText();
if(name.contains("<")){
name = name.split("<")[0]; //Der Typ ist alles vor den ersten Argumenten
}
return convertTypeName(name, arguments, unannClassOrInterfaceTypeContext.getStart(), reg, generics); return convertTypeName(name, arguments, unannClassOrInterfaceTypeContext.getStart(), reg, generics);
} }
@ -75,7 +77,6 @@ public class TypeGenerator {
List<RefTypeOrTPHOrWildcardOrGeneric> bounds = TypeGenerator.convert(typeParameter.typeBound(),reg, generics); List<RefTypeOrTPHOrWildcardOrGeneric> bounds = TypeGenerator.convert(typeParameter.typeBound(),reg, generics);
GenericTypeVar ret = new GenericTypeVar(name, bounds, typeParameter.getStart(), typeParameter.getStop()); GenericTypeVar ret = new GenericTypeVar(name, bounds, typeParameter.getStart(), typeParameter.getStop());
generics.put(name, new GenericContext(parentClass, parentMethod));
return ret; return ret;
} }
@ -90,7 +91,7 @@ public class TypeGenerator {
return ret; return ret;
} }
if(typeBoundContext.classOrInterfaceType() != null){ if(typeBoundContext.classOrInterfaceType() != null){
ret.add(convert(typeBoundContext.classOrInterfaceType())); ret.add(convert(typeBoundContext.classOrInterfaceType(), reg, generics));
if(typeBoundContext.additionalBound() != null) if(typeBoundContext.additionalBound() != null)
for(Java8Parser.AdditionalBoundContext addCtx : typeBoundContext.additionalBound()){ for(Java8Parser.AdditionalBoundContext addCtx : typeBoundContext.additionalBound()){
ret.add(convert(addCtx.interfaceType())); ret.add(convert(addCtx.interfaceType()));
@ -101,8 +102,9 @@ public class TypeGenerator {
} }
} }
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext) { private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
throw new NotImplementedException(); Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = classOrInterfaceTypeContext.classType_lfno_classOrInterfaceType();
return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),classOrInterfaceTypeContext.getStart(), reg, generics);
} }
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.InterfaceTypeContext interfaceTypeContext) { private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.InterfaceTypeContext interfaceTypeContext) {
@ -112,10 +114,7 @@ public class TypeGenerator {
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ReferenceTypeContext referenceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) { public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ReferenceTypeContext referenceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
if(referenceTypeContext.classOrInterfaceType() != null){ if(referenceTypeContext.classOrInterfaceType() != null){
if(referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType()!= null){ if(referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType()!= null){
Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType(); return convert(referenceTypeContext.classOrInterfaceType(), reg, generics);//return convertTypeName(referenceTypeContext.getText(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
//return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
if(ctx.typeArguments() != null)throw new NotImplementedException();
return convertTypeName(referenceTypeContext.getText(), null,referenceTypeContext.getStart(), reg, generics);
}else{ }else{
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -1,11 +1,13 @@
package de.dhbwstuttgart.sat.asp.model; package de.dhbwstuttgart.sat.asp.model;
import de.dhbwstuttgart.bytecode.signature.Signature;
public enum ASPRule { public enum ASPRule {
ASP_PAIR_EQUALS_NAME("equals"), ASP_PAIR_EQUALS_NAME("equals"),
ASP_PAIR_SMALLER_NAME("smaller"), ASP_PAIR_SMALLER_NAME("smaller"),
ASP_PAIR_SMALLER_DOT_NAME("smallerDot"), ASP_PAIR_SMALLER_DOT_NAME("smallerDot"),
ASP_PARAMLIST_NAME("param"), ASP_PARAMLIST_NAME("param"),
ASP_PARAMLIST_END_POINTER("null"), ASP_FC_PARAMLIST_NAME("paramFC"),
ASP_TYPE("type"), ASP_TYPE("type"),
ASP_FCTYPE("typeFC"), ASP_FCTYPE("typeFC"),
ASP_TYPE_VAR("typeVar"), ASP_ODER("oder"), ASP_TYPE_VAR("typeVar"), ASP_ODER("oder"),

View File

@ -210,7 +210,7 @@ public class ASPParser extends UnifyResultBaseListener {
private List<String> getParams(String pointer) { private List<String> getParams(String pointer) {
List<String> params = new ArrayList<>(); List<String> params = new ArrayList<>();
while(pointer != null){ while(pointer != null){
if(pointer.equals(ASPRule.ASP_PARAMLIST_END_POINTER.toString()))return params; //if(pointer.equals(ASPRule.ASP_PARAMLIST_END_POINTER.toString()))return params;
if(!parameterLists.containsKey(pointer)) if(!parameterLists.containsKey(pointer))
throw new DebugException("Fehler in Ergebnisparsen"); throw new DebugException("Fehler in Ergebnisparsen");
//TODO: Fehler in ASP. Die adapt Regel muss erkennen, wenn die Parameterliste auf der linken Seite kürzer ist und diese Rechtzeitig beenden //TODO: Fehler in ASP. Die adapt Regel muss erkennen, wenn die Parameterliste auf der linken Seite kürzer ist und diese Rechtzeitig beenden

View File

@ -0,0 +1,17 @@
grammar ASPResult;
answer : 'ANSWER' (resultSetRule '.')*;
resultSetRule : NAME parameterList;
parameterList : '(' value (',' value)* ')';
value : NAME
| resultSetRule ;
NAME : [a-zA-Z0-9_]+;
WS : [ \t\r\n\u000C]+ -> skip
;
LINE_COMMENT
: '%' ~[\r\n]* -> skip
;

View File

@ -93,7 +93,7 @@ public class ASPFactory implements TypeVisitor<String>{
boolean isFCType = false; boolean isFCType = false;
protected void convertFC(Collection<ClassOrInterface> classes) throws ClassNotFoundException { protected void convertFC(Collection<ClassOrInterface> classes) throws ClassNotFoundException {
Set<Pair> fc = FCGenerator.toFC(classes); Collection<Pair> fc = FCGenerator.toFC(classes);
isFCType = true; isFCType = true;
for(Pair fcp : fc){ for(Pair fcp : fc){
convertPair(fcp); convertPair(fcp);
@ -132,28 +132,18 @@ public class ASPFactory implements TypeVisitor<String>{
return new ASPStatement(stmt); return new ASPStatement(stmt);
} }
protected String convertParameterlist(List<String> pointers){ protected void convertParameterlist(String pointer, List<String> pointers){
//TODO: Hier an die neue Datenstruktur anpassen
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
Iterator<String> it = pointers.iterator(); Iterator<String> it = pointers.iterator();
String p = pointer; Integer i = 1;
if(!it.hasNext()){ String ruleName = ASPRule.ASP_PARAMLIST_NAME.toString();
return ASPRule.ASP_PARAMLIST_END_POINTER.toString(); if(isFCType) ruleName = ASPRule.ASP_FC_PARAMLIST_NAME.toString();
}
while (it.hasNext()){ while (it.hasNext()){
ASPStatement stmt; ASPStatement stmt;
String type = it.next(); String type = it.next();
String nextP = ASPStringConverter.toConstant(NameGenerator.makeNewName()); stmt = makeStatement(ruleName, pointer, type, i.toString());
if(it.hasNext()){
stmt = makeStatement(ASPRule.ASP_PARAMLIST_NAME.toString(), p, type, nextP);
}else{
stmt = makeStatement(ASPRule.ASP_PARAMLIST_NAME.toString(), p, type,
ASPRule.ASP_PARAMLIST_END_POINTER.toString());
}
p = nextP;
writer.add(stmt); writer.add(stmt);
i++;
} }
return pointer;
} }
@Override @Override
@ -165,7 +155,7 @@ public class ASPFactory implements TypeVisitor<String>{
} }
String typeName = ASPStringConverter.toConstant(refType.getName()); String typeName = ASPStringConverter.toConstant(refType.getName());
String ruleName = isFCType?ASPRule.ASP_FCTYPE.toString():ASPRule.ASP_TYPE.toString(); String ruleName = isFCType?ASPRule.ASP_FCTYPE.toString():ASPRule.ASP_TYPE.toString();
convertParameterlist(params); convertParameterlist(pointer, params);
ASPStatement stmt = makeStatement(ruleName, pointer, typeName, Integer.toString(params.size())); ASPStatement stmt = makeStatement(ruleName, pointer, typeName, Integer.toString(params.size()));
writer.add(stmt); writer.add(stmt);
return pointer; return pointer;
@ -195,7 +185,7 @@ public class ASPFactory implements TypeVisitor<String>{
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName()); String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
String typeName = ASPStringConverter.toConstant(genericRefType.getParsedName()); String typeName = ASPStringConverter.toConstant(genericRefType.getParsedName());
String ruleName = isFCType?ASPRule.ASP_FCTYPE.toString():ASPRule.ASP_TYPE.toString(); String ruleName = isFCType?ASPRule.ASP_FCTYPE.toString():ASPRule.ASP_TYPE.toString();
ASPStatement stmt = makeStatement(ruleName, pointer, typeName, ASPRule.ASP_PARAMLIST_END_POINTER.toString()); ASPStatement stmt = makeStatement(ruleName, pointer, typeName, ASPRule.ASP_LIST_ENDPOINTER.toString());
writer.add(stmt); writer.add(stmt);
return pointer; return pointer;
} }

View File

@ -70,7 +70,7 @@ public class ASPGencayFactory implements TypeVisitor<String> {
} }
private void convertFC(Collection<ClassOrInterface> classes) throws ClassNotFoundException { private void convertFC(Collection<ClassOrInterface> classes) throws ClassNotFoundException {
Set<Pair> fc = FCGenerator.toFC(classes); Collection<Pair> fc = FCGenerator.toFC(classes);
isFCType = true; isFCType = true;
for(Pair fcp : fc){ for(Pair fcp : fc){
generateTheta((RefType) fcp.TA1); generateTheta((RefType) fcp.TA1);

View File

@ -66,10 +66,10 @@ public abstract class AbstractASTWalker implements ASTVisitor{
@Override @Override
public void visit(ParameterList formalParameters) { public void visit(ParameterList formalParameters) {
Iterator<FormalParameter> genericIterator = formalParameters.getFormalparalist().iterator(); Iterator<FormalParameter> it = formalParameters.getFormalparalist().iterator();
if(genericIterator.hasNext()){ if(it.hasNext()){
while(genericIterator.hasNext()){ while(it.hasNext()){
genericIterator.next().accept(this); it.next().accept(this);
} }
} }
} }

View File

@ -12,6 +12,7 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation; import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.Token;
import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -33,6 +34,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters, public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){ RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
super(offset); super(offset);
if(isInterface && !Modifier.isInterface(modifiers))modifiers += Modifier.INTERFACE;
this.modifiers = modifiers; this.modifiers = modifiers;
this.name = name; this.name = name;
this.fields = fielddecl; this.fields = fielddecl;

View File

@ -37,7 +37,7 @@ public class ASTFactory {
methoden.add(createMethod(method, jreClass)); methoden.add(createMethod(method, jreClass));
} }
List<Field> felder = new ArrayList<>(); List<Field> felder = new ArrayList<>();
for(java.lang.reflect.Field field : jreClass.getFields()){ for(java.lang.reflect.Field field : jreClass.getDeclaredFields()){
felder.add(createField(field, name)); felder.add(createField(field, name));
} }
int modifier = jreClass.getModifiers(); int modifier = jreClass.getModifiers();
@ -89,8 +89,7 @@ public class ASTFactory {
} }
private static Field createField(java.lang.reflect.Field field, JavaClassName jreClass) { private static Field createField(java.lang.reflect.Field field, JavaClassName jreClass) {
//TODO: Hier auch GenericRefType generieren: return new Field(field.getName(), createType(field.getGenericType(), jreClass, null), field.getModifiers(), new NullToken());
return new Field(field.getName(), createType(field.getType(), jreClass, null), field.getModifiers(), new NullToken());
} }
//private static RefType createType(Class classType) { //private static RefType createType(Class classType) {

View File

@ -0,0 +1,30 @@
package de.dhbwstuttgart.syntaxtree.visual;
import de.dhbwstuttgart.syntaxtree.type.*;
public class TypePrinter implements TypeVisitor<String> {
@Override
public String visit(RefType refType) {
return refType.toString();
}
@Override
public String visit(SuperWildcardType superWildcardType) {
return "? super " + superWildcardType.getInnerType().acceptTV(this);
}
@Override
public String visit(TypePlaceholder typePlaceholder) {
return "TPH " + typePlaceholder.getName();
}
@Override
public String visit(ExtendsWildcardType extendsWildcardType) {
return "? extends " + extendsWildcardType.getInnerType().acceptTV(this);
}
@Override
public String visit(GenericRefType genericRefType) {
return genericRefType.getParsedName();
}
}

View File

@ -59,13 +59,11 @@ class TypeInsertPlacerClass extends AbstractASTWalker{
} }
@Override @Override
public void visit(ParameterList params) { public void visit(FormalParameter param) {
for(FormalParameter param : params){
if(param.getType() instanceof TypePlaceholder) if(param.getType() instanceof TypePlaceholder)
inserts.add(TypeInsertFactory.createInsertPoints( inserts.add(TypeInsertFactory.createInsertPoints(
param.getType(), param.getType().getOffset(), cl, method, results)); param.getType(), param.getType().getOffset(), cl, method, results));
} super.visit(param);
super.visit(params);
} }
@Override @Override

View File

@ -116,6 +116,16 @@ public class UnifyWithoutWildcards {
assert resultSet.results.size() == 1; assert resultSet.results.size() == 1;
} }
@Test
public void fc() throws ClassNotFoundException {
Collection<ClassOrInterface> fc = new ArrayList<>();
fc.add(ASTFactory.createClass(MatrixTest.class));
fc.add(ASTFactory.createClass(Vector.class));
String content = "";
content = ASPFactory.generateASP(new ConstraintSet<>(), fc);
System.out.println(content);
}
public ResultSet run(ConstraintSet<Pair> toTest, Collection<ClassOrInterface> fc) throws IOException, InterruptedException, ClassNotFoundException { public ResultSet run(ConstraintSet<Pair> toTest, Collection<ClassOrInterface> fc) throws IOException, InterruptedException, ClassNotFoundException {
String content = ""; String content = "";
content = ASPFactory.generateASP(toTest, fc); content = ASPFactory.generateASP(toTest, fc);
@ -184,4 +194,6 @@ public class UnifyWithoutWildcards {
private class Test1<A> extends Object{} private class Test1<A> extends Object{}
private class Test2 extends Object{} private class Test2 extends Object{}
private class MatrixTest extends Vector<Vector<Integer>>{}
} }

View File

@ -0,0 +1,125 @@
package asp.withWildcards;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.syntaxtree.visual.ResultSetPrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class InputGenerator {
public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/";
@Test
public void finiteClosure() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"fc.jav"));
}
@Test
public void lambda() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"Lambda.jav"));
}
@Test
public void lambda2() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"Lambda2.jav"));
}
@Test
public void lambda3() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"Lambda3.jav"));
}
@Test
public void mathStruc() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"mathStruc.jav"));
}
@Test
public void generics() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"Generics.jav"));
}
@Test
public void genericsMethodCall() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"MethodCallGenerics.jav"));
//TODO: Hier sollte der Rückgabetyp der Methode String sein
}
@Test
public void faculty() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"Faculty.jav"));
}
@Test
public void facultyTyped() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"FacultyTyped.jav"));
}
@Test
public void matrix() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"Matrix.jav"));
}
@Test
public void packageTests() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"Package.jav"));
}
@Test
public void vector() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"Vector.jav"));
}
@Test
public void lambdaRunnable() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"LambdaRunnable.jav"));
}
@Test
public void expressions() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"Expressions.jav"));
}
@Test
public void addLong() throws IOException, ClassNotFoundException, InterruptedException {
execute(new File(rootDirectory+"AddLong.jav"));
}
private static class TestResultSet{
}
public void execute(File fileToTest) throws IOException, ClassNotFoundException, InterruptedException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
//List<ResultSet> results = compiler.aspTypeInference();
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
for(SourceFile sf : compiler.sourceFiles.values()) {
allClasses.addAll(compiler.getAvailableClasses(sf));
allClasses.addAll(sf.getClasses());
}
final ConstraintSet<Pair> cons = compiler.getConstraints();
String content = "";
content = ASPFactory.generateASP(cons, allClasses);
System.out.println(content);
}
static String readFile(String path, Charset encoding)
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
}

View File

@ -1,6 +1,9 @@
package astfactory; package astfactory;
//import javafx.collections.ObservableList; //import javafx.collections.ObservableList;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import org.junit.Test; import org.junit.Test;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
@ -19,4 +22,13 @@ public class ASTFactoryTest<A> extends HashMap<String, A>{
System.out.println(Arrays.toString(arguments)); System.out.println(Arrays.toString(arguments));
System.out.println(((TypeVariable)arguments[1]).getGenericDeclaration()); System.out.println(((TypeVariable)arguments[1]).getGenericDeclaration());
} }
public static class GenericFieldTest<G>{
public G testField;
}
@Test
public void genericFieldTest(){
ClassOrInterface test = ASTFactory.createClass(GenericFieldTest.class);
assertTrue(test.getFieldDecl().get(0).getType() instanceof GenericRefType);
}
} }

View File

@ -42,7 +42,7 @@ public class GeneralParserTest{
filenames.add("StructuralTypes.jav"); filenames.add("StructuralTypes.jav");
*/ */
// filenames.add("ExtendsTest.jav"); // filenames.add("ExtendsTest.jav");
filenames.add("OpratorTest.jav"); filenames.add("PackageNameTest.jav");
try{ try{
new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory + s)).collect(Collectors.toList())); new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory + s)).collect(Collectors.toList()));
}catch(Exception exc){ }catch(Exception exc){

View File

@ -1,5 +1,9 @@
import java.lang.Integer;
class ImportTest{ import java.lang.Comparable;
class PackageNameTest{
java.lang.Integer test(a){return a;} java.lang.Integer test(a){return a;}
Comparable<Integer> test2(a){return a;}
} }