Ich habe in dem Ordner StrucTypes5 damit begonnen nochmals eine Version zu schreiben die auf den Erkenntnissen der vorherigen Entwicklungen beruht (auch der eigenen antlr Version) jetzt aber mit dem bereits vorhanden Syntaxbaum arbeitet.

Mit dem aktuellen Commit kann eine Klasse mit Typvariablen versehen werden die auf den TypPlaceholdern des Syntaxbaumes Basieren.
This commit is contained in:
sebastian 2017-04-20 23:17:43 +02:00
parent 22bc53cde9
commit 3bb14b82a0
37 changed files with 2801 additions and 233 deletions

124
.idea/uiDesigner.xml Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

File diff suppressed because it is too large Load Diff

View File

@ -42,4 +42,3 @@ public class Main {
}
}

View File

@ -0,0 +1,16 @@
package de.dhbwstuttgart.strucTypes5;
/**
* Created by sebastian on 20.04.17.
*/
public class Main {
public static void main(String[] args) {
}
}

View File

@ -0,0 +1,7 @@
package de.dhbwstuttgart.strucTypes5;
/**
* Created by sebastian on 20.04.17.
*/
public class Start {
}

View File

@ -0,0 +1,46 @@
package de.dhbwstuttgart.strucTypes5;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
/**
* Created by sebastian on 20.04.17.
*/
public class ToCode implements Walk<String> {
public String eval_SourceFile () {
String x = "";
return String.format( "Sourcefile %s " , x );
}
@Override
public String eval_class(ClassOrInterface classOrInterface) {
return null;
}
@Override
public String eval_field() {
return null;
}
@Override
public String eval_method() {
return null;
}
@Override
public String eval_methodCall() {
return null;
}
@Override
public String eval_receiver() {
return null;
}
}

View File

@ -0,0 +1,21 @@
package de.dhbwstuttgart.strucTypes5;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
/**
* Created by sebastian on 20.04.17.
*/
public interface Walk<T> {
T eval_class(ClassOrInterface classOrInterface);
T eval_field();
T eval_method();
T eval_methodCall();
T eval_receiver();
}

View File

@ -0,0 +1,44 @@
package de.dhbwstuttgart.strucTypes5;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Field;
/**
* Created by sebastian on 20.04.17.
*/
public class WalkTrough<T> {
Walk<T> walk;
public WalkTrough(ClassOrInterface classOrInterface , Walk<T> walk) {
}
// Wenn dann geht es nur wenn ich klassisches Java Schreibe
// 1. Durch alle Felder laufen
public Object walk_Fields(ClassOrInterface classOrInterface) {
T result = walk.eval_class(classOrInterface);
return "";
}
//. Durch ein Feld laufen;
public Object walk_Field(Field field) {
return "";
}
}

View File

@ -0,0 +1,17 @@
package de.dhbwstuttgart.strucTypes5.algo;
/**
* Created by sebastian on 20.04.17.
*/
public class TI {
// Start TypeInference Algorithm, need Assumptions and a Class
public TI() {
}
}

View File

@ -0,0 +1,38 @@
package de.dhbwstuttgart.strucTypes5.algo;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionAbstract;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMakerLocal;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Method;
import java.util.ArrayList;
import java.util.List;
/**
* Created by sebastian on 20.04.17.
*/
public class Type {
// Start Type Algorithm, need Assumption and class , and Typeinformations
public Type(List<AssumptionAbstract> assumptions, ClassOrInterface cl , TypeVarStore typeVarStore) {
for (Method m : cl.getMethods()) {
// Erstelle Lokale Assumptions
AssumptionMakerLocal assumptionMakerLocal = new AssumptionMakerLocal(m, typeVarStore);
List<AssumptionAbstract> newAssumptions = new ArrayList<>();
newAssumptions.addAll(assumptions);
newAssumptions.addAll(assumptionMakerLocal.getResultAssumptionList());
// Führe TypeExpression aus
//TypeExpr typeExpr = new TypeExpr();
}
}
}

View File

@ -0,0 +1,108 @@
package de.dhbwstuttgart.strucTypes5.algo;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionAbstract;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMakerLocal;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMap;
import de.dhbwstuttgart.strucTypes5.constraints.ConstraintAbstract;
import de.dhbwstuttgart.strucTypes5.constraints.ConstraintFactory;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.statement.*;
import java.util.ArrayList;
import java.util.List;
/**
* Created by sebastian on 20.04.17.
*/
public class TypeExpr {
private TypeVarStore typeVarStore;
private AssumptionMap assumptionMap;
private List<ConstraintAbstract> resultConstraints;
public TypeExpr(List<AssumptionAbstract> assumptionAbstractList , Method method, TypeVarStore typeVarStore) {
this.typeVarStore = typeVarStore;
this.assumptionMap = makeAllAssumptions(assumptionAbstractList,method);
if (method.get_Block().getStatements().get(0) instanceof Return) {
Return rt = (Return) method.get_Block().getStatements().get(0);
this.resultConstraints = typeExpression(rt.get_Expression());
}
else {
System.err.println("Fehler???");
}
}
private AssumptionMap makeAllAssumptions(List<AssumptionAbstract> assumptionAbstractList , Method method) {
// Globale Assumptions
AssumptionMap assumptionMap = new AssumptionMap();
assumptionMap.addAll(assumptionAbstractList);
//Lokale Assumptions
AssumptionMakerLocal assumptionMakerLocal = new AssumptionMakerLocal(method,typeVarStore);
assumptionMap.addAll(assumptionMakerLocal.getResultAssumptionList());
return assumptionMap;
}
private List<ConstraintAbstract> typeExpression(Expression expression) {
if (expression instanceof LocalVar) {
LocalVar localVar = (LocalVar) expression;
// Erstellung keines Constriants
// Lediglich eintrag in TypeVarStore
// ToDo wie sieht es mit einem MethodCall aus?
TypeVarAbstract typeVar = assumptionMap.getVarAssumption(localVar.get_expression());
typeVarStore.addTuple(typeVar,localVar.getType());
List<ConstraintAbstract> result = new ArrayList<>();
return result;
}
else if (expression instanceof FieldVar) {
FieldVar fieldVar = (FieldVar) expression;
List<ConstraintAbstract> result = typeExpression(fieldVar.getReceiver());
result.add(ConstraintFactory.generateConstriantField(fieldVar,typeVarStore));
return result;
}
else if (expression instanceof MethodCall) {
MethodCall methodCall = (MethodCall) expression;
List<ConstraintAbstract> result = typeExpression(methodCall.get_Receiver());
// TypeExpr für die Argumente
for (Expression arg : methodCall.get_ArgList().getArguments()) {
result.addAll(typeExpression(arg));
}
result.addAll(ConstraintFactory.generateConstraintMethod(methodCall,typeVarStore));
return result;
}
else if (expression instanceof Receiver) {
Receiver receiver = (Receiver) expression;
List<ConstraintAbstract> result = typeExpression(receiver.get_Expression());
return result;
}
else {
System.err.println("Fehler unbekannt");
System.out.println(expression);
List<ConstraintAbstract> noResult = new ArrayList<>();
return noResult;
}
}
public List<ConstraintAbstract> getResultConstraints() {
return resultConstraints;
}
public TypeVarStore getTypeVarStore() {
return typeVarStore;
}
}

View File

@ -0,0 +1,7 @@
package de.dhbwstuttgart.strucTypes5.assumptions;
/**
* Created by sebastian on 20.04.17.
*/
public class AssumptionAbstract {
}

View File

@ -0,0 +1,42 @@
package de.dhbwstuttgart.strucTypes5.assumptions;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
/**
* Created by sebastian on 20.04.17. *
*
* Assumption is only nessasarry in an local Method Context.
*
*/
public class AssumptionArgument extends AssumptionAbstract {
private String nameOfArgument;
private TypeVarAbstract typeOfArgument;
public AssumptionArgument(String nameOfArgument, TypeVarAbstract typeOfArgument) {
this.nameOfArgument = nameOfArgument;
this.typeOfArgument = typeOfArgument;
}
public String getNameOfArgument() {
return nameOfArgument;
}
public void setNameOfArgument(String nameOfArgument) {
this.nameOfArgument = nameOfArgument;
}
public TypeVarAbstract getTypeOfArgument() {
return typeOfArgument;
}
public void setTypeOfArgument(TypeVarAbstract typeOfArgument) {
this.typeOfArgument = typeOfArgument;
}
@Override
public String toString() {
return String.format("AssArgument( %s : %s) " , nameOfArgument , typeOfArgument);
}
}

View File

@ -0,0 +1,65 @@
package de.dhbwstuttgart.strucTypes5.assumptions;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarFactory;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.Method;
import java.util.ArrayList;
import java.util.List;
/**
* Created by sebastian on 20.04.17.
*
* The main Task of AssumptionFactory is to create a new Assumption and save The new TypVar in the Typevarstore with the
* relatet TypePlaceHolder of the Syntaxtree.
*/
public class AssumptionFactory {
public static AssumptionField makeFieldAssumption(Field feld, TypeVarStore typeVarStore) {
TypeVar typeVar = TypeVarFactory.makeTypeVar();
typeVarStore.addTuple(typeVar, feld.getType());
return new AssumptionField(feld.getName(), typeVar);
}
public static AssumptionMethod makeMethodAssumption(Method method, TypeVarStore typeVarStore) {
// TypeVar for Returntype
TypeVar rType = TypeVarFactory.makeTypeVar();
typeVarStore.addTuple(rType,method.getType());
// TypeVar for ArgumentTypes
List<TypeVar> typeVars = new ArrayList<>();
for (FormalParameter fp : method.getParameterList().getFormalparalist()) {
TypeVar typeVarFp = TypeVarFactory.makeTypeVar();
typeVarStore.addTuple(typeVarFp,fp.getType());
typeVars.add(typeVarFp);
}
AssumptionMethod assumptionMethod = new AssumptionMethod(method.getName(), typeVars, rType);
return assumptionMethod;
}
public static AssumptionArgument makeArgumentAssumption(FormalParameter formalParameter , TypeVarStore typeVarStore) {
TypeVarAbstract typeVar = typeVarStore.storeTPH(formalParameter.getType());
return new AssumptionArgument(formalParameter.getName(), typeVar);
}
}

View File

@ -0,0 +1,43 @@
package de.dhbwstuttgart.strucTypes5.assumptions;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
/**
* Created by sebastian on 20.04.17.
*
* Enhält Name des Feldes und die Typvariable des Feldes
*/
public class AssumptionField extends AssumptionAbstract{
private String name;
private TypeVar typeVar;
public AssumptionField(String name, TypeVar typeVar) {
this.name = name;
this.typeVar = typeVar;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public TypeVar getTypeVar() {
return typeVar;
}
public void setTypeVar(TypeVar typeVar) {
this.typeVar = typeVar;
}
@Override
public String toString() {
return String.format("AssField( %s : %s) " , name , typeVar);
}
}

View File

@ -0,0 +1,44 @@
package de.dhbwstuttgart.strucTypes5.assumptions;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.Method;
import java.util.ArrayList;
import java.util.List;
/**
* Created by sebastian on 20.04.17.
*/
public class AssumptionMakerGlobal {
List<AssumptionAbstract> assumptionAbstractList = new ArrayList<>();
public AssumptionMakerGlobal(ClassOrInterface classOrInterface, TypeVarStore typeVarStore) {
makeFieldAssumptions(classOrInterface.getFieldDecl() , typeVarStore);
makeMethodAssumptions(classOrInterface.getMethods() , typeVarStore);
}
// Erstelle Feld Assumptions
private void makeFieldAssumptions(List<Field> fieldList, TypeVarStore typeVarStore) {
for (Field f : fieldList) {
assumptionAbstractList.add(AssumptionFactory.makeFieldAssumption(f,typeVarStore));
}
}
// Erstelle MethodenAussumptions
private void makeMethodAssumptions(List<Method> methodList, TypeVarStore typeVarStore) {
for (Method m : methodList) {
assumptionAbstractList.add(AssumptionFactory.makeMethodAssumption(m,typeVarStore));
}
}
public List<AssumptionAbstract> getAssumptionAbstractList() {
return assumptionAbstractList;
}
}

View File

@ -0,0 +1,28 @@
package de.dhbwstuttgart.strucTypes5.assumptions;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.Method;
import java.util.ArrayList;
import java.util.List;
/**
* Created by sebastian on 20.04.17.
* Generates Lokal Assumption there are only valid in one Method
*/
public class AssumptionMakerLocal {
List<AssumptionAbstract> resultAssumptionList = new ArrayList<>();
public AssumptionMakerLocal(Method method, TypeVarStore typeVarStore) {
for (FormalParameter formalParameter : method.getParameterList().getFormalparalist()) {
resultAssumptionList.add(AssumptionFactory.makeArgumentAssumption(formalParameter,typeVarStore));
}
}
public List<AssumptionAbstract> getResultAssumptionList() {
return resultAssumptionList;
}
}

View File

@ -0,0 +1,78 @@
package de.dhbwstuttgart.strucTypes5.assumptions;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by sebastian on 20.04.17.
*/
public class AssumptionMap {
private Map<String, AssumptionMethod> mAss = new HashMap<>();
private Map<String, AssumptionField> fass = new HashMap<>();
private Map<String, AssumptionArgument> argAss = new HashMap<>();
public void addAssumption(AssumptionAbstract ass) {
if (ass instanceof AssumptionMethod) {
AssumptionMethod assMethod = (AssumptionMethod) ass;
mAss.put(assMethod.getName() , assMethod);
}
else if (ass instanceof AssumptionField) {
AssumptionField assumptionField = (AssumptionField) ass;
fass.put(assumptionField.getName(), assumptionField);
}
else if (ass instanceof AssumptionArgument) {
AssumptionArgument assumptionArgument = (AssumptionArgument) ass;
argAss.put(assumptionArgument.getNameOfArgument(), assumptionArgument);
}
else {
System.err.println("Fehler Ass nicht bekannt");
}
}
public void addAll(List<AssumptionAbstract> assumptionAbstractList) {
for (AssumptionAbstract ass : assumptionAbstractList) {
addAssumption(ass);
}
}
public TypeVar getReturnTypeMethod(String name) {
return mAss.get(name).getReturnType();
}
public TypeVarAbstract getVarAssumption(String name) {
// gibt lokale Var zurück. wenn nicht vorhanden gloable. wenn nicht vorhanden null
if (argAss.containsKey(name)) {
return argAss.get(name).getTypeOfArgument();
}
else if (fass.containsKey(name)) {
return fass.get(name).getTypeVar();
}
else {
System.err.println("Kein Wert gespeichert");
return null;
}
}
public TypeVarAbstract getThisVar(String name) {
return fass.get(name).getTypeVar();
}
@Override
public String toString() {
return String.format("AssMethod \n AssField: %s \n AssArgument %s " , mAss.toString() , fass.toString() , argAss.toString());
}
}

View File

@ -0,0 +1,53 @@
package de.dhbwstuttgart.strucTypes5.assumptions;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import java.util.List;
/**
* Created by sebastian on 20.04.17. *
* Contains Method Name, Method Arguments and Return Type of Method
*/
public class AssumptionMethod extends AssumptionAbstract {
private String name;
private List<TypeVar> arguments;
private TypeVar returnType;
public AssumptionMethod(String name, List<TypeVar> arguments, TypeVar returnType) {
this.name = name;
this.arguments = arguments;
this.returnType = returnType;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<TypeVar> getArguments() {
return arguments;
}
public void setArguments(List<TypeVar> arguments) {
this.arguments = arguments;
}
public TypeVar getReturnType() {
return returnType;
}
public void setReturnType(TypeVar returnType) {
this.returnType = returnType;
}
@Override
public String toString() {
return String.format("AssMethod( %s : %s --> %s) " , name , arguments.toString() , returnType);
}
}

View File

@ -0,0 +1,181 @@
package de.dhbwstuttgart.strucTypes5.ausgabe;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.List;
/**
* Created by sebastian on 20.04.17.
*/
public class Class2String {
// Select Mode
public static final Integer WITH_BLANK = 1;
public static final Integer WITH_TPH = 2;
public static final Integer WITH_TYPEVARS = 3;
//
private Integer aktMode;
private TypeVarStore typeVarStore;
public String generateStringBlank(ClassOrInterface cl) {
aktMode = WITH_BLANK;
return generateString(cl);
}
public String generateStringTPH(ClassOrInterface cl) {
aktMode = WITH_TPH;
return generateString(cl);
}
public String generateStringTypeVars(ClassOrInterface cl , TypeVarStore typeVarStore) {
aktMode = WITH_TYPEVARS;
this.typeVarStore = typeVarStore;
return generateString(cl);
}
private String generateString(ClassOrInterface cl) {
String name = cl.getClassName().toString();
String fieldsString = generateFieldsString(cl.getFieldDecl());
String methodsString = generateMethodsString(cl.getMethods());
return String.format( "class %s { \n %s \n %s }" , name, fieldsString, methodsString);
}
private String generateFieldsString(List<Field> fieldList) {
String fieldString = "";
for (Field f : fieldList ) {
fieldString = fieldString.concat(generateFieldString(f) + "\n" );
}
return fieldString;
}
private String generateFieldString(Field f) {
return String.format("%s : %s; " , f.getName() , tS(f.getType()) );
}
private String generateMethodsString(List<Method> methods) {
String resultMethodsString = "";
for (Method m : methods) {
resultMethodsString = resultMethodsString.concat(generateMethodString(m) + "\n");
}
return resultMethodsString;
}
private String generateMethodString(Method m) {
String mName = m.getName();
String argsString = generateFormalParameters(m.getParameterList().getFormalparalist());
String returnString = generateReturnString(m.get_Block().getStatements());
//String returnString = "";
return String.format( "%s %s ( %s ) { return %s } " , tS(m.getType()) , mName , argsString , returnString);
}
private String generateFormalParameters(List<FormalParameter> formalParameterList) {
String result = "";
for (FormalParameter formalParameter : formalParameterList) {
result = result.concat(generateFormalParameter(formalParameter));
}
return result;
}
private String generateFormalParameter(FormalParameter fp) {
return String.format(" %s : %s " , fp.getName() , tS(fp.getType()));
}
// Erstellt String für Return Statement
private String generateReturnString(List<Statement> statements) {
if (statements.get(0) instanceof Return) {
Return returnStatement = (Return) statements.get(0);
Expression expression = returnStatement.get_Expression();
return generateExpressionString(expression);
}
else {
return "Fehler ???";
}
}
// Erstellt rekursiv Strings für die auftauchenden Expressions
private String generateExpressionString(Expression expression) {
if (expression instanceof LocalVar) {
LocalVar localVar = (LocalVar) expression;
return String.format( " [%s : %s ] " , localVar.get_expression() , tS(localVar.getType()) );
}
else if (expression instanceof FieldVar ) {
FieldVar fieldVar = (FieldVar) expression;
String receiverString = generateExpressionString(fieldVar.getReceiver());
return String.format(" [%s.%s : %s ] " , receiverString , tS(fieldVar.getType()));
}
else if (expression instanceof MethodCall) {
MethodCall methodCall = (MethodCall) expression;
String receiverString = generateExpressionString(methodCall.get_Receiver());
String arguments = "";
for (Expression arg : methodCall.get_ArgList().getArguments()) {
String expArg = generateExpressionString(arg);
arguments = arguments.concat(expArg + ",");
}
return String.format( "[%s.%s(%s) : %s ] " , receiverString, methodCall.get_Name() , arguments , tS(methodCall.getType()));
}
else if (expression instanceof Receiver){
Receiver receiver = (Receiver) expression;
return generateExpressionString(receiver.get_Expression());
}
else {
return "Expression nicht bekannt";
}
}
private String tS(RefTypeOrTPHOrWildcardOrGeneric ref) {
String resultString = "";
if (aktMode.equals(WITH_TPH)) {
resultString = ref.toString();
}
else if (aktMode.equals(WITH_TYPEVARS)) {
resultString = typeVarStore.getTypeVarByTPH(ref).toString();
if (resultString == null) {
System.err.println("Fehler bei " +ref);
return "";
}
}
else if (aktMode.equals(WITH_BLANK)) {
resultString = "";
}
return resultString;
}
}

View File

@ -0,0 +1,7 @@
package de.dhbwstuttgart.strucTypes5.constraints;
/**
* Created by sebastian on 20.04.17.
*/
public class ConstraintAbstract {
}

View File

@ -0,0 +1,50 @@
package de.dhbwstuttgart.strucTypes5.constraints;
import de.dhbwstuttgart.strucTypes5.algo.Type;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
import java.util.ArrayList;
import java.util.List;
/**
* Created by sebastian on 20.04.17.
*/
public class ConstraintFactory {
public static ConstraintField generateConstriantField(FieldVar fieldVar, TypeVarStore typeVarStore) {
TypeVar revceiver = (TypeVar) typeVarStore.storeTPH(fieldVar.getReceiver().getType());
TypeVar caller = (TypeVar) typeVarStore.storeTPH(fieldVar.getType());
return new ConstraintField(revceiver , fieldVar.getFieldVarName() , caller);
}
// Methode muss constraint für methode sowie Subtype Constrainsts erstellen
public static List<ConstraintAbstract> generateConstraintMethod(MethodCall methodCall , TypeVarStore typeVarStore) {
TypeVar receiver = (TypeVar) typeVarStore.storeTPH(methodCall.get_Receiver().getType());
TypeVar caller = (TypeVar) typeVarStore.storeTPH(methodCall.getType());
List<ConstraintAbstract> resultConstraints = new ArrayList<>();
List<TypeVar> typeVarsArg = new ArrayList<>();
List<TypeVar> neueTypeVars = new ArrayList<>();
for (Expression arg : methodCall.get_ArgList().getArguments()) {
TypeVar newVar = typeVarStore.makeFreshTypeVar();
TypeVar oldVar = (TypeVar) typeVarStore.storeTPH(arg.getType());
neueTypeVars.add(newVar);
typeVarsArg.add(oldVar);
ConstraintSubTypeGeneric<TypeVar,TypeVar> subTypeGeneric = new ConstraintSubTypeGeneric<>(newVar,oldVar);
resultConstraints.add(subTypeGeneric);
}
resultConstraints.add(new ConstraintMethod(receiver, methodCall.get_Name(), typeVarsArg, caller , neueTypeVars ));
return resultConstraints;
}
}

View File

@ -0,0 +1,52 @@
package de.dhbwstuttgart.strucTypes5.constraints;
import de.dhbwstuttgart.strucTypes5.algo.Type;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
/**
* Created by sebastian on 20.04.17.
*/
public class ConstraintField extends ConstraintAbstract{
private TypeVar receiver;
private String nameOfField;
private TypeVar returnType;
public ConstraintField(TypeVar receiver, String nameOfField, TypeVar returnType) {
this.receiver = receiver;
this.nameOfField = nameOfField;
this.returnType = returnType;
}
public TypeVar getReceiver() {
return receiver;
}
public void setReceiver(TypeVar receiver) {
this.receiver = receiver;
}
public String getNameOfField() {
return nameOfField;
}
public void setNameOfField(String nameOfField) {
this.nameOfField = nameOfField;
}
public TypeVar getReturnType() {
return returnType;
}
public void setReturnType(TypeVar returnType) {
this.returnType = returnType;
}
@Override
public String toString() {
return String.format("ConstraintField( %s , %s , %s ) " , receiver, nameOfField, returnType);
}
}

View File

@ -0,0 +1,78 @@
package de.dhbwstuttgart.strucTypes5.constraints;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import java.util.List;
/**
* Created by sebastian on 20.04.17.
*/
public class ConstraintMethod extends ConstraintAbstract {
private TypeVar receiver;
private String methodName;
private List<TypeVar> argumentTypes;
private TypeVar returnType;
private List<TypeVar> argumentTypesBeta;
public ConstraintMethod(TypeVar receiver, String methodName, List<TypeVar> argumentTypes, TypeVar returnType, List<TypeVar> argumentTypesBeta) {
this.receiver = receiver;
this.methodName = methodName;
this.argumentTypes = argumentTypes;
this.returnType = returnType;
this.argumentTypesBeta = argumentTypesBeta;
}
public TypeVar getReceiver() {
return receiver;
}
public void setReceiver(TypeVar receiver) {
this.receiver = receiver;
}
public String getMethodName() {
return methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public List<TypeVar> getArgumentTypes() {
return argumentTypes;
}
public void setArgumentTypes(List<TypeVar> argumentTypes) {
this.argumentTypes = argumentTypes;
}
public TypeVar getReturnType() {
return returnType;
}
public void setReturnType(TypeVar returnType) {
this.returnType = returnType;
}
public List<TypeVar> getArgumentTypesBeta() {
return argumentTypesBeta;
}
public void setArgumentTypesBeta(List<TypeVar> argumentTypesBeta) {
this.argumentTypesBeta = argumentTypesBeta;
}
@Override
public String toString() {
return String.format("ConstraintMethod( %s , %s , %s , ( %s , %s )) " , receiver, methodName , argumentTypes , returnType , argumentTypesBeta);
}
}

View File

@ -0,0 +1,39 @@
package de.dhbwstuttgart.strucTypes5.constraints;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
/**
* Created by sebastian on 20.04.17.
*/
public class ConstraintSubType extends ConstraintAbstract{
// TODO Der SubtypeConstraint muss entweder eine Typvariable einen Typen oder ein Interface enthalten
// TODO Hier muss ich mir das noch überlegen wie es geht. Evtl ist eine TypeVarType nicht notwenidg
// Eine Typvariable kann TypVar sein, ein Typ kann auch eine TypVar sein , ein Interface kann was sein ?
private TypeVar subtype;
private TypeVar superType;
public TypeVar getSubtype() {
return subtype;
}
public void setSubtype(TypeVar subtype) {
this.subtype = subtype;
}
public TypeVar getSuperType() {
return superType;
}
public void setSuperType(TypeVar superType) {
this.superType = superType;
}
@Override
public String toString() {
return String.format("ConstraintSubType( %s <* %s )" , subtype , superType);
}
}

View File

@ -0,0 +1,40 @@
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("ConstraintSubType( %s <* %s )" , subType , superType);
}
}

View File

@ -0,0 +1,35 @@
package de.dhbwstuttgart.strucTypes5.typeVars;
/**
* Created by sebastian on 14.04.17.
*/
public class TypeVar extends TypeVarAbstract {
private String id;
public TypeVar(String id) {
this.id = id;
}
@Override
public String toString() {
return String.format("TVar: %s" , id);
}
@Override
public boolean equals(Object obj) {
if (obj.getClass().equals(TypeVar.class)) {
TypeVar t = (TypeVar) obj;
if (t.id.equals(id)) {
return true;
}
else {
return false;
}
}
else {
return false;
}
}
}

View File

@ -0,0 +1,11 @@
package de.dhbwstuttgart.strucTypes5.typeVars;
/**
* Created by sebastian on 14.04.17.
*/
public abstract class TypeVarAbstract {
}

View File

@ -0,0 +1,20 @@
package de.dhbwstuttgart.strucTypes5.typeVars;
/**
* Created by sebastian on 14.04.17.
*/
public class TypeVarFactory {
private static Integer zaehler = 0;
public static TypeVar makeTypeVar() {
zaehler = zaehler +1;
return new TypeVar(zaehler.toString());
}
}

View File

@ -0,0 +1,153 @@
package de.dhbwstuttgart.strucTypes5.typeVars;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* Created by sebastian on 14.04.17.
*/
public class TypeVarStore {
private HashMap<TypeVarAbstract, List<RefTypeOrTPHOrWildcardOrGeneric>> map = new HashMap<>();
public TypeVarAbstract storeTPH(RefTypeOrTPHOrWildcardOrGeneric tph) {
if (getTypeVarByTPH(tph) == null) {
TypeVar tvNeu = TypeVarFactory.makeTypeVar();
addTuple(tvNeu, tph);
return tvNeu;
}
else {
return getTypeVarByTPH(tph);
}
}
public TypeVar makeFreshTypeVar() {
TypeVar neu = TypeVarFactory.makeTypeVar();
List<RefTypeOrTPHOrWildcardOrGeneric> tphList = new ArrayList<>();
map.put(neu,tphList);
return neu;
}
public void addTuple(TypeVarAbstract tv, RefTypeOrTPHOrWildcardOrGeneric tph) {
// TypVar bereits vorhandne
if (map.containsKey(tv)) {
if (map.get(tv) != null ) {
map.get(tv).add(tph);
}
else {
List<RefTypeOrTPHOrWildcardOrGeneric> tphl = new ArrayList<>();
tphl.add(tph);
map.put(tv,tphl);
}
}
// TypVar noch nicht vorhanden
else if (! map.containsKey(tv)) {
List<RefTypeOrTPHOrWildcardOrGeneric> tphl = new ArrayList<>();
tphl.add(tph);
map.put(tv,tphl);
}
}
public List<RefTypeOrTPHOrWildcardOrGeneric> getTPHByTypeVar(TypeVarAbstract tv) {
return map.get(tv);
}
public TypeVarAbstract getTypeVarByTPH(RefTypeOrTPHOrWildcardOrGeneric tph) {
// TPH ist bereits einer TypVar zugeordnet
for (TypeVarAbstract typeVar : map.keySet()) {
if (map.get(typeVar).contains(tph)) {
return typeVar;
}
}
// TPH ist noch keiner TypVar zugerodent
return null;
}
// Erstellt neue Typvariablen für bestehenden Syntax
// -> nicht mehr benötigt
public TypeVarStore freshVariables() {
TypeVarStore typeVarStore = new TypeVarStore();
for (TypeVarAbstract tvarOld : map.keySet()) {
TypeVar tvNew = TypeVarFactory.makeTypeVar();
typeVarStore.map.put(tvNew,map.get(tvarOld));
}
return typeVarStore;
}
/*
public ResultTuple freshVariableAndMapping() {
MappingAltNeu mappingAltNeu = new MappingAltNeu();
TypeVarStore typeVarStore = new TypeVarStore();
for (TypeVarAbstract tvarOld : map.keySet()) {
// Wenn der Typ bereits bekannt ist, wird dieser nicht ersetzt.
if (tvarOld instanceof TypeVarType) {
TypeVarAbstract tvNew = tvarOld;
typeVarStore.map.put(tvNew,map.get(tvarOld));
mappingAltNeu.addTypeVar(tvarOld,tvNew);
}
else {
TypeVar tvNew = TypeVarFactory.makeTypeVar();
typeVarStore.map.put(tvNew,map.get(tvarOld));
mappingAltNeu.addTypeVar(tvarOld,tvNew);
}
}
return new ResultTuple(mappingAltNeu,typeVarStore);
}
public boolean replaceTypeVar(TypeVarAbstract old, TypeVarAbstract neu) {
if (map.containsKey(old)) {
List<RefTypeOrTPHOrWildcardOrGeneric> tphList = map.get(old);
map.remove(old);
map.put(neu, tphList);
return true;
}
else {
return false;
}
}
*/
@Override
public String toString() {
String res = "--- TypeVarStore ---\n";
for (TypeVarAbstract tvar : map.keySet() ) {
res = res + tvar.toString() + " : " + map.get(tvar).toString() + "\n";
}
return String.format(res);
}
}

View File

@ -0,0 +1,47 @@
package de.dhbwstuttgart.strucTypes5.typeVars;
import de.dhbwstuttgart.strucTypes4.syntaxtree.Class;
/**
* Created by sebastian on 14.04.17.
*/
public class TypeVarType extends TypeVarAbstract {
private Class typeClass;
public TypeVarType(Class typeClass) {
this.typeClass = typeClass;
}
public Class getTypeClass() {
return typeClass;
}
public void setTypeClass(Class typeClass) {
this.typeClass = typeClass;
}
@Override
public String toString() {
return String.format("TVarType: %s ", typeClass.getName() );
}
@Override
public boolean equals(Object obj) {
if (obj.getClass().equals(TypeVarType.class)) {
TypeVarType tv = (TypeVarType) obj;
if (tv.toString().equals(this.toString())) {
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,87 @@
package strucTypes3;
import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.strucTypes3.AssTuple;
import de.dhbwstuttgart.strucTypes3.AssumptionGenerator;
import de.dhbwstuttgart.strucTypes3.ConstraintAbstract;
import de.dhbwstuttgart.strucTypes3.HelpMethoden;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
import de.dhbwstuttgart.syntaxtree.statement.Return;
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;
/**
* Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. Der
* dabei erstellte Syntaxbaum wird nicht kontrolliert.
*
* @author janulrich
*
*/
public class GeneralParserTestNeuX {
private static final String rootDirectory = System.getProperty("user.dir") + "/test/strucTypes3/";
@Test
public void run() {
/*
* Auflistung aller Files die getestet werden sollen
*/
List<String> filenames = new ArrayList<String>();
// filenames.add("FieldInitializationTest.jav");
// filenames.add("ImportTest.jav");
// filenames.add("StatementsTest.jav");
// filenames.add("ImportTestGeneric.jav");
// filenames.add("BoundedParameter.jav");
// filenames.add("GenericFieldVarTest.jav");
// filenames.add("FieldVarTest.jav");
//filenames.add("Main.jav");
filenames.add("StructuralTypesSimpleSkript.jav");
// filenames.add("StructuralTypesField.jav");
// filenames.add("Main.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 aktClass = sf.getClasses().get(0);
AssTuple ass = AssumptionGenerator.generateAssumptions(aktClass);
List<ConstraintAbstract> constraints = new ArrayList<>();
for (Method m : aktClass.getMethods()) {
Return rt = (Return) m.get_Block().statements.get(0);
Expression ex = (Expression) rt.get_Expression();
constraints.addAll(HelpMethoden.TypeExpr(ass, ex, m, aktClass));
}
constraints.forEach( (x) -> {System.out.println(x); });
*/
}
} catch (Exception exc) {
exc.printStackTrace();
fail();
}
assertTrue("Tests durchlaufen", filenames.size() > 0);
}
}

View File

@ -1,7 +1,27 @@
// eigentlich sollten noch die beiden Interfaces Alpha und Gamma implementiert sein.
// warum funktioniert new i nicht?
class MyInteger {
Integer i;
MyInteger sub(MyInteger x) { return new MyInteger(x); }
MyInteger add(MyInteger x) { return new MyInteger(x); }
}
class A {
mt(x,y,z) { return x.sub(y).add(z); }
}
class Main {
main() { return new A<>().mt(new MyInteger(), new MyInteger() , new MyInteger() ); }
}

View File

@ -0,0 +1,13 @@
class A {
Integer i;
mt(x,y,z) { return x.sub(y).add(z); }
}

View File

@ -0,0 +1,63 @@
package strucTypes5;
import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMakerGlobal;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMakerLocal;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
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;
/**
* Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. Der
* dabei erstellte Syntaxbaum wird nicht kontrolliert.
*
* @author janulrich
*
*/
public class AssumptionTest {
private static final String rootDirectory = System.getProperty("user.dir") + "/test/strucTypes5/";
@Test
public void run() {
List<String> filenames = new ArrayList<String>();
filenames.add("AssumptionTest.jav");
JavaTXParser parser = new JavaTXParser();
try {
for (String filename : filenames) {
System.out.println("Teste: " + filename);
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 );
System.out.println(typeVarStore.toString());
System.out.println(makerGlobal.getAssumptionAbstractList().toString()) ;
// Test of the Local AssumptionMaker who only makes the Assumption for an Local Method;
AssumptionMakerLocal assumptionMakerLocal = new AssumptionMakerLocal(sf.getClasses().get(0).getMethods().get(0) , typeVarStore);
System.out.println(assumptionMakerLocal.getResultAssumptionList());
}
} catch (Exception exc) {
exc.printStackTrace();
fail();
}
assertTrue("Tests durchlaufen", filenames.size() > 0);
}
}

View File

@ -0,0 +1,92 @@
package strucTypes5;
import com.sun.org.apache.xpath.internal.SourceTree;
import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.strucTypes5.algo.TypeExpr;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionAbstract;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMakerGlobal;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMakerLocal;
import de.dhbwstuttgart.strucTypes5.ausgabe.Class2String;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
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;
/**
* Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. Der
* dabei erstellte Syntaxbaum wird nicht kontrolliert.
*
* @author janulrich
*
*/
public class Class2StringTest {
private static final String rootDirectory = System.getProperty("user.dir") + "/test/strucTypes5/";
@Test
public void run() {
List<String> filenames = new ArrayList<String>();
filenames.add("AssumptionTest.jav");
JavaTXParser parser = new JavaTXParser();
try {
for (String filename : filenames) {
System.out.println("Teste: " + filename);
SourceFile sf = parser.parse(new File(rootDirectory + filename));
ClassOrInterface classA = sf.getClasses().get(0);
// Test of the Global Assumption Maker who make mass und fass;
TypeVarStore typeVarStore = new TypeVarStore();
AssumptionMakerGlobal makerGlobal = new AssumptionMakerGlobal(sf.getClasses().get(0), typeVarStore );
//System.out.println(typeVarStore.toString());
//System.out.println(makerGlobal.getAssumptionAbstractList().toString()) ;
// Test of the Local AssumptionMaker who only makes the Assumption for an Local Method;
AssumptionMakerLocal assumptionMakerLocal = new AssumptionMakerLocal(sf.getClasses().get(0).getMethods().get(0) , typeVarStore);
//System.out.println(assumptionMakerLocal.getResultAssumptionList());
System.out.println(typeVarStore.toString());
// Teste Blank
Class2String class2String1 = new Class2String();
System.out.println("Blank");
System.out.println(class2String1.generateStringBlank(classA));
//Teste TPH
Class2String class2String2 = new Class2String();
System.out.println("TPH");
System.out.println(class2String2.generateStringTPH(classA));
ArrayList<AssumptionAbstract> assAll = new ArrayList<>();
assAll.addAll(assumptionMakerLocal.getResultAssumptionList());
assAll.addAll(makerGlobal.getAssumptionAbstractList());
TypeExpr typeExpr = new TypeExpr(assAll , sf.getClasses().get(0).getMethods().get(0) , typeVarStore );
// Teste TypeVars Problem Typevars werden benötigt
Class2String class2String3 = new Class2String();
System.out.println("TypeVars");
System.out.println(class2String3.generateStringTypeVars(classA ,typeVarStore ));
}
} catch (Exception exc) {
exc.printStackTrace();
fail();
}
assertTrue("Tests durchlaufen", filenames.size() > 0);
}
}

View File

@ -0,0 +1,78 @@
package strucTypes5;
import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.strucTypes5.algo.TypeExpr;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionAbstract;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMakerGlobal;
import de.dhbwstuttgart.strucTypes5.assumptions.AssumptionMakerLocal;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
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;
/**
* Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. Der
* dabei erstellte Syntaxbaum wird nicht kontrolliert.
*
* @author janulrich
*
*/
public class TypeExprTest {
private static final String rootDirectory = System.getProperty("user.dir") + "/test/strucTypes5/";
@Test
public void run() {
List<String> filenames = new ArrayList<String>();
filenames.add("AssumptionTest.jav");
JavaTXParser parser = new JavaTXParser();
try {
for (String filename : filenames) {
System.out.println("Teste: " + filename);
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 );
System.out.println(typeVarStore.toString());
System.out.println(makerGlobal.getAssumptionAbstractList().toString()) ;
// Test of the Local AssumptionMaker who only makes the Assumption for an Local Method;
AssumptionMakerLocal assumptionMakerLocal = new AssumptionMakerLocal(sf.getClasses().get(0).getMethods().get(0) , typeVarStore);
System.out.println(assumptionMakerLocal.getResultAssumptionList());
List<AssumptionAbstract> assAll = new ArrayList<>();
assAll.addAll(assumptionMakerLocal.getResultAssumptionList());
assAll.addAll(makerGlobal.getAssumptionAbstractList());
TypeExpr typeExpr = new TypeExpr(assAll , sf.getClasses().get(0).getMethods().get(0) , typeVarStore );
System.out.println(typeExpr.getResultConstraints());
System.out.println(typeExpr.getTypeVarStore());
}
} catch (Exception exc) {
exc.printStackTrace();
fail();
}
assertTrue("Tests durchlaufen", filenames.size() > 0);
}
}