expression NewClass kann nach bigRefactoring wieder verarbeitet werden

This commit is contained in:
sebastian 2017-05-07 02:41:22 +02:00
parent 7dbc2bbd4c
commit 13330e4fd6
17 changed files with 272 additions and 1948 deletions

1823
.idea/workspace.xml generated

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.ClassNotFoundException;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.PackageCrawler;
import de.dhbwstuttgart.parser.antlr.Java8Parser;
import de.dhbwstuttgart.syntaxtree.*;

View File

@ -0,0 +1,101 @@
package de.dhbwstuttgart.strucTypes5.NeueKlassen;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.typecheck.GenericTypeName;
import de.dhbwstuttgart.typecheck.JavaClassName;
import org.antlr.v4.runtime.Token;
import java.util.ArrayList;
import java.util.List;
/**
* Created by sebastian on 06.05.17.
*/
public class ConstructInterfaces {
public static void main(String[] args) {
//ClassOrInterface cl = makeInterface( );
//System.out.println(cl);
List<String> nameArguments = new ArrayList<>();
nameArguments.add("x");
nameArguments.add("y");
Method m = makeMethodForInterface("mt" , nameArguments);
makeMethodForInterface("add" , nameArguments );
}
public static ClassOrInterface makeInterface(String nameInterface, List<String> arguments) {
// Initialisierie alles
int modifiers = 0;
JavaClassName name = new JavaClassName(nameInterface);
List< Field > fielddecl = new ArrayList<>();
List< Method > methods = new ArrayList<>();
List< Constructor > constructors = new ArrayList<>();
List<GenericTypeVar> genericTypeVars = new ArrayList<>();
GenericDeclarationList genericClassParameters = new GenericDeclarationList(genericTypeVars, new NullToken());
RefTypeOrTPHOrWildcardOrGeneric superClass = null;
Boolean isInterface = true;
List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces = new ArrayList<>();
ClassOrInterface newInterface = new ClassOrInterface(modifiers, name, fielddecl,methods,constructors,
genericClassParameters, superClass , isInterface , implementedInterfaces, new NullToken());
// Füge noch die benötigten Infos ein
List<String> nameArguments = new ArrayList<>();
nameArguments.add("x");
nameArguments.add("y");
Method m = makeMethodForInterface("mt" , nameArguments);
makeMethodForInterface("add" , nameArguments );
methods.add( makeMethodForInterface("add" , nameArguments));
return newInterface;
}
public static Method makeMethodForInterface(String name , List<String> namesArgruments ) {
String methodName = name;
RefTypeOrTPHOrWildcardOrGeneric returnType = null;
int modifiers = 0;
List<FormalParameter> formalParameters = new ArrayList<>();
// Generate Formalparameter
for (String nameArgument : namesArgruments ) {
// bounds
// Todo parent Class
GenericContext context = new GenericContext(new JavaClassName("xx") , "xx");
GenericTypeName typeName = new GenericTypeName( context,name);
GenericRefType typeVar = new GenericRefType(typeName, new NullToken());
formalParameters.add(new FormalParameter(name,typeVar , new NullToken() ));
}
ParameterList parameterList = new ParameterList(formalParameters,new NullToken());
Block block = null;
List<GenericTypeVar> genericDeclarations = new ArrayList<>();
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(genericDeclarations ,new NullToken());
Token offset = new NullToken();
return new Method(methodName ,returnType , 0 , parameterList ,block , gtvDeclarations, offset);
}
}

View File

@ -155,7 +155,6 @@ public class Construct {
}
}
//Konstruktor:
// public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, GenericDeclarationList genericClassParameters,
// RefTypeOrTPHOrWildcardOrGeneric superClass, Boolean isInterface, List<? extends RefTypeOrTPHOrWildca
@ -167,8 +166,10 @@ public class Construct {
Boolean isInterface = true;
List<RefTypeOrTPHOrWildcardOrGeneric> implementetInterfaces = new ArrayList<>();
ClassOrInterface newInterface = new ClassOrInterface(modifers, name, fields,methods, genericClassParameters, superClass , isInterface, implementetInterfaces ,new NullToken());
return newInterface;
// return newInterface = new ClassOrInterface(modifers, name, fields,methods, genericClassParameters, superClass , isInterface, implementetInterfaces ,new NullToken());
return null;
}

View File

@ -54,8 +54,16 @@ public class TI {
ConstructInterfaceTemplates constructInterfaceTemplates = new ConstructInterfaceTemplates(cl, tp.getTypeVarStore(), type.constraintList , tp.getMappingAltNeu());
System.out.println("Generierte Interfaces");
System.out.println(constructInterfaceTemplates.interfaceList);
//ToDo -> Interfaces umwandeln
System.out.println("Generierte Constraints");
System.out.println(constructInterfaceTemplates.remainingConstraints);
// ToDo -> constraints umwandeln
// Generiere Generics für die Klasse
@ -97,8 +105,6 @@ public class TI {
// -------- Das Ergebnis aus Solve wird in die Assumptions gespeichert zu weiteren Verwendung ------------------------
@ -121,9 +127,6 @@ public class TI {
System.out.println(newResultConstraints);
this.resultConstraints = newResultConstraints;
}
@ -144,6 +147,8 @@ public class TI {
public List<ConstraintAbstract> bearbeiteConstraints(List<ConstraintAbstract> constraints , TypeVarStore typeVarStore) {
List<ConstraintAbstract> newResultConstraints = new ArrayList<>();

View File

@ -16,7 +16,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import javax.swing.plaf.nimbus.State;
import java.util.ArrayList;
import java.util.List;
@ -69,6 +69,8 @@ public class TypeExpr {
LocalVar localVar = (LocalVar) expression;
// Erstellung keines Constriants
// Lediglich eintrag in TypeVarStore
// Todo Problem TypeVar Expression != TypeVar Methode.
RefTypeOrTPHOrWildcardOrGeneric typeVar = assumptionMap.getVarAssumption(localVar.get_expression());
typeVarStore.addTuple(typeVar,localVar.getType());
@ -85,6 +87,12 @@ public class TypeExpr {
else if (expression instanceof MethodCall) {
MethodCall methodCall = (MethodCall) expression;
// Return aufgrund von Refactoring
if (expression instanceof NewClass) {
return walkNewClass((NewClass) expression);
}
// Call of non-Abstract Field do not add constraints
if (methodCall.get_Receiver().getType() instanceof RefType) {
List<ConstraintAbstract> result = typeExpression(methodCall.get_Receiver());
@ -131,19 +139,34 @@ public class TypeExpr {
List<ConstraintAbstract> result = typeExpression(receiver.get_Expression());
return result;
}
else if (expression instanceof NewClass) {
NewClass newClass = (NewClass) expression;
/*
@ veraltet -> kann seit big refactoring so nicht mehr geparst werden
Stattdessen wird dies jetzt in Method Call verarbeitet, weil dort die new Methode aufläuft
*/
return null;
// Argumente
List<ConstraintAbstract> result = new ArrayList<>();
// TypeExpr für die Argumente
for (Expression arg : newClass.getArgumentList().getArguments()) {
result.addAll(typeExpression(arg));
}
;
}
else {
System.err.println("Fehler unbekannt");
System.out.println(expression);
List<ConstraintAbstract> noResult = new ArrayList<>();
return noResult;
}
}
public List<ConstraintAbstract> walkNewClass(NewClass newClass) {
// Argumente
List<ConstraintAbstract> result = new ArrayList<>();
// TypeExpr für die Argumente
for (Expression arg : newClass.getArgumentList().getArguments()) {
result.addAll(typeExpression(arg));
}
/*
Information:
@ -152,35 +175,30 @@ public class TypeExpr {
Diese können dann verwendet werden.
*/
//Versuche Informationen zu laden
AssumptionClass assumptionClass = assumptionMap.getClassAssumption(newClass.getType().toString());
if (assumptionClass != null) {
//Versuche Informationen zu laden
AssumptionClass assumptionClass = assumptionMap.getClassAssumption(newClass.getType().toString());
if (assumptionClass != null) {
ChangeTypeVars changeTypeVars = new ChangeTypeVars();
assumptionClass = changeTypeVars.change(assumptionClass);
assumptionMap.putClass(assumptionClass);
OldConstraints oldConstraints= new OldConstraints(assumptionClass.getConstraints());
result.add(oldConstraints);
System.out.println("-----------------KlassenAssumption ------");
System.out.println(assumptionClass.getTypeVarStore().toString());
Class2String class2String = new Class2String();
System.out.println(class2String.generateStringTypeVars(assumptionClass.getCl(), assumptionClass.getTypeVarStore()));
System.out.println("-----------------------");
//ChangeTypeVars changeTypeVars = new ChangeTypeVars();
//AssumptionClass assumptionClass1 = changeTypeVars.change(assumptionClass);
// ToDO Problem mit den neuen Typvariablen da die infos nochmals geladen werden beim Method call !!!
// (Das einige logische wäre bereits davor die TypVariablen zu tauschen -> So steht es ja eigentlich auf im Skript
//assumptionMap.putClass(assumptionClass1);
}
ChangeTypeVars changeTypeVars = new ChangeTypeVars();
assumptionClass = changeTypeVars.change(assumptionClass);
assumptionMap.putClass(assumptionClass);
OldConstraints oldConstraints= new OldConstraints(assumptionClass.getConstraints());
result.add(oldConstraints);
System.out.println("-----------------KlassenAssumption ------");
System.out.println(assumptionClass.getTypeVarStore().toString());
Class2String class2String = new Class2String();
System.out.println(class2String.generateStringTypeVars(assumptionClass.getCl(), assumptionClass.getTypeVarStore()));
System.out.println("-----------------------");
//ChangeTypeVars changeTypeVars = new ChangeTypeVars();
//AssumptionClass assumptionClass1 = changeTypeVars.change(assumptionClass);
// ToDO Problem mit den neuen Typvariablen da die infos nochmals geladen werden beim Method call !!!
// (Das einige logische wäre bereits davor die TypVariablen zu tauschen -> So steht es ja eigentlich auf im Skript
//assumptionMap.putClass(assumptionClass1);
}
/*
//Versuche Informationen zu laden
@ -202,19 +220,13 @@ public class TypeExpr {
}
*/
typeVarStore.addTuple(TypeVarFactory.makeTypeVar() , newClass.getType());
return result;
}
else {
System.err.println("Fehler unbekannt");
System.out.println(expression);
List<ConstraintAbstract> noResult = new ArrayList<>();
return noResult;
}
typeVarStore.addTuple(TypeVarFactory.makeTypeVar() , newClass.getType());
return result;
}
public List<ConstraintAbstract> getResultConstraints() {
return resultConstraints;
}

View File

@ -133,6 +133,13 @@ public class Class2String {
}
else if (expression instanceof MethodCall) {
MethodCall methodCall = (MethodCall) expression;
if (methodCall instanceof NewClass) {
return generateExpressionNewClass((NewClass) methodCall);
}
String receiverString = generateExpressionString(methodCall.get_Receiver());
String arguments = "";
@ -147,14 +154,8 @@ public class Class2String {
return generateExpressionString(receiver.get_Expression());
}
else if (expression instanceof NewClass) {
NewClass newClass = (NewClass) expression;
String arguments = "";
for (Expression arg : newClass.getArgumentList().getArguments()) {
String expArg = generateExpressionString(arg);
arguments = arguments.concat(expArg + ",");
}
return String.format("[new %s( %s ): %s ]" , newClass.getType() , arguments , newClass.getType() );
return "XXX";
}
else {
return "Expression nicht bekannt";
@ -196,6 +197,16 @@ public class Class2String {
}
private String generateExpressionNewClass( NewClass newClass ) {
String arguments = "";
for (Expression arg : newClass.getArgumentList().getArguments()) {
String expArg = generateExpressionString(arg);
arguments = arguments.concat(expArg + ",");
}
return String.format("[new %s( %s ): %s ]" , newClass.getType() , arguments , newClass.getType() );
}

View File

@ -1,40 +0,0 @@
package de.dhbwstuttgart.strucTypes5.constraints;
/**
* Created by sebastian on 20.04.17.
*/
public class ConstraintSubTypeGeneric<T1, T2> extends ConstraintAbstract {
private T1 subType;
private T2 superType;
public ConstraintSubTypeGeneric(T1 subType, T2 superType) {
this.subType = subType;
this.superType = superType;
}
public T1 getSubType() {
return subType;
}
public void setSubType(T1 subType) {
this.subType = subType;
}
public T2 getSuperType() {
return superType;
}
public void setSuperType(T2 superType) {
this.superType = superType;
}
@Override
public String toString() {
return String.format("ConstraintSubTypeG( %s <* %s )" , subType , superType);
}
}

View File

@ -34,7 +34,6 @@ public class InterfaceForConstraint {
genericsneu.add(tv);
}
}
generics = genericsneu;
return true;
}

View File

@ -33,12 +33,4 @@ public class FactoryForElementes {
GenericRefType genericRefType = new GenericRefType( genericTypeName , new NullToken());
return genericRefType;
}
}

View File

@ -155,7 +155,7 @@ public class Rules {
/*
// Todo wer sagt dass man nicht irgendwo in der mitte anfängt
//
public void reflect(List<ConstraintAbstract> constriants) {
for (ConstraintAbstract cs : constriants) {
if (cs instanceof ConstraintSubType) {
@ -389,7 +389,7 @@ public class Rules {
}
if (nameStart != null && nameStartIF != null && nameVglStart != null && nameVglStart != null ) {
if (nameStart != null && nameStartIF != null && nameVglStart != null && nameVglIf != null ) {
if (nameStart.equals(nameVglStart) && nameStartIF.equals(nameVglIf)) {
return cs;
}
@ -477,10 +477,7 @@ public class Rules {
}
}
}
constraintsToRemove.add(css);
return constraintsToRemove;
}

View File

@ -60,9 +60,9 @@ public class Construct {
List<Method> methods = new ArrayList<Method>();
ClassOrInterface face = new ClassOrInterface(0, name, fielddecl, methods, genericDeclaraitonList, null, true, null , null);
return face;
// return new ClassOrInterface(0, name, fielddecl, methods, genericDeclaraitonList, null, true, null , null);
return null;
}
@ -95,8 +95,9 @@ public class Construct {
}
ClassOrInterface face = new ClassOrInterface(0, name, null, methodlist, genericDeclaraitonList, null, true, null, null);
return face;
// return ClassOrInterface(0, name, null, methodlist, genericDeclaraitonList, null, true, null, null);
return null;
}

View File

@ -0,0 +1,60 @@
package strucTypes5;
import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.strucTypes5.algo.TI;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMap;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import org.junit.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
*
* Test soll prüfen ob bei einem Aufruf von zwei mal der gleichen Klasse unterschiedlich neue Typvariablen vergeben werden
*
*
*/
public class InterfaceTest {
private static final String rootDirectory = System.getProperty("user.dir") + "/test/strucTypes5/";
@Test
public void run() {
List<String> filenames = new ArrayList<String>();
filenames.add("TestInterfaces.jav");
JavaTXParser parser = new JavaTXParser();
try {
for (String filename : filenames) {
System.out.println("Teste: " + filename);
SourceFile sf = parser.parse(new File(rootDirectory + filename));
SourceFile sfdebug = sf;
ClassOrInterface mainClass = sf.getClasses().get(0);
ClassOrInterface aClass = sf.getClasses().get(1);
AssumptionMap assumptionMap = new AssumptionMap();
TI ti = new TI(assumptionMap, aClass);
TI ti1 = new TI(ti.assresult, mainClass);
}
} catch (Exception exc) {
exc.printStackTrace();
fail();
}
assertTrue("Tests durchlaufen", filenames.size() > 0);
}
}

View File

@ -2,12 +2,12 @@
class Main {
main () { return new A().mt( new MyInteger() ); }
main () { return new A().mt( new A.mt( new MyInteger() ) ); }
}
class A{
mt(x) { return x; }
mt(x) { return new A().mt(new MyInteger()); }
}

View File

@ -67,9 +67,9 @@ public class SolveTest_Rek {
TypeVarRefType myInteger = (TypeVarRefType) getTypeVar(ti1.resultConstraints , "TVar_MyInteger");
RefTypeOrTPHOrWildcardOrGeneric v2 = getTypeVar(ti1.resultConstraints , "TVar_2");
RefTypeOrTPHOrWildcardOrGeneric v5 = getTypeVar(ti1.resultConstraints , "TVar_5");
System.out.println(myInteger.toString());
System.out.println(v2.toString());
System.out.println(v5.toString());
System.out.println(myInteger);
// System.out.println(v2.toString());
// System.out.println(v5.toString());
// Generiere Interface 1
List<RefTypeOrTPHOrWildcardOrGeneric> generics = new ArrayList<>();
@ -110,7 +110,7 @@ public class SolveTest_Rek {
} catch (Exception exc) {
exc.printStackTrace();
fail();
fail();
}
assertTrue("Tests durchlaufen", filenames.size() > 0);
}

View File

@ -0,0 +1,9 @@
interface s1<R,A> {
R add(A x);
}

View File

@ -42,7 +42,6 @@ public class TypeExprTest {
SourceFile sf = parser.parse(new File(rootDirectory + filename));
// Test of the Global Assumption Maker who make mass und fass;
TypeVarStore typeVarStore = new TypeVarStore();
AssumptionMakerGlobal makerGlobal = new AssumptionMakerGlobal(sf.getClasses().get(0), typeVarStore );
@ -66,7 +65,6 @@ public class TypeExprTest {
TypeExpr typeExpr = new TypeExpr(assumptionMap , sf.getClasses().get(0).getMethods().get(0) , typeVarStore );
System.out.println(typeExpr.getResultConstraints());
System.out.println(typeExpr.getTypeVarStore());
}
} catch (Exception exc) {