forked from JavaTX/JavaCompilerCore
Generierung von Interfaces für Felder und Methode hinzugefügt
This commit is contained in:
parent
a9b9c46d84
commit
ce97cf82fd
@ -3,7 +3,7 @@ package de.dhbwstuttgart.strucTypes3;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
|
||||
class FieldConstraint extends ConstraintAbstract {
|
||||
public class FieldConstraint extends ConstraintAbstract {
|
||||
|
||||
private RefTypeOrTPHOrWildcardOrGeneric reveiver;
|
||||
private String name_of_field;
|
||||
|
@ -4,7 +4,7 @@ import java.util.List;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
|
||||
class MethodConstraint extends ConstraintAbstract {
|
||||
public class MethodConstraint extends ConstraintAbstract {
|
||||
|
||||
/* Der MethodConstraint
|
||||
* constraint( typ_receiver, methodname, arguments_typen ( return_type , typvar von argumenttypen )
|
||||
@ -27,7 +27,78 @@ class MethodConstraint extends ConstraintAbstract {
|
||||
this.argumentTypeVars = argumentTypeVars;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReceiver() {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setReceiver(RefTypeOrTPHOrWildcardOrGeneric receiver) {
|
||||
this.receiver = receiver;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String getMethodName() {
|
||||
return methodName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setMethodName(String methodName) {
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public List<RefTypeOrTPHOrWildcardOrGeneric> getArgumentTypes() {
|
||||
return argumentTypes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setArgumentTypes(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes) {
|
||||
this.argumentTypes = argumentTypes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setReturnType(RefTypeOrTPHOrWildcardOrGeneric returnType) {
|
||||
this.returnType = returnType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public List<MyTypeVar> getArgumentTypeVars() {
|
||||
return argumentTypeVars;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setArgumentTypeVars(List<MyTypeVar> argumentTypeVars) {
|
||||
this.argumentTypeVars = argumentTypeVars;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("MethodConstraint( %s, %s , %s (%s , %s ))" , receiver.toString() , methodName, argumentTypes.toString() , returnType.toString() , argumentTypeVars.toString() );
|
||||
|
||||
}
|
||||
}
|
95
test/strucTypes3/Construct.java
Normal file
95
test/strucTypes3/Construct.java
Normal file
@ -0,0 +1,95 @@
|
||||
package strucTypes3;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.xsltc.runtime.Parameter;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.strucTypes3.ConstraintAbstract;
|
||||
import de.dhbwstuttgart.strucTypes3.FieldConstraint;
|
||||
import de.dhbwstuttgart.strucTypes3.MethodConstraint;
|
||||
import de.dhbwstuttgart.strucTypes3.MyTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
|
||||
public class Construct {
|
||||
|
||||
|
||||
public static ClassOrInterface constructInterfaces(ConstraintAbstract constraint) {
|
||||
|
||||
if (constraint.getClass().equals(FieldConstraint.class)) {
|
||||
FieldConstraint fieldConstraint = (FieldConstraint) constraint;
|
||||
return Construct.constructInterfaceField(fieldConstraint);
|
||||
}
|
||||
else if (constraint.getClass().equals(MethodConstraint.class)) {
|
||||
MethodConstraint methodConstriant = (MethodConstraint) constraint;
|
||||
return Construct.constructInterfaceMethod(methodConstriant);
|
||||
|
||||
}
|
||||
else {
|
||||
// Fehlerfall
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static ClassOrInterface constructInterfaceField(FieldConstraint fieldConstriant) {
|
||||
|
||||
Field field = new Field(fieldConstriant.getName_of_field() , fieldConstriant.getAttribut() , 0 , null);
|
||||
List<Field> fielddecl = new ArrayList<>();
|
||||
fielddecl.add(field);
|
||||
JavaClassName name = new JavaClassName(fieldConstriant.getReveiver().toString());
|
||||
ClassOrInterface face = new ClassOrInterface(0, name, fielddecl, null, null, null, null, null , null);
|
||||
return face;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static ClassOrInterface constructInterfaceMethod(MethodConstraint methodConstraint) {
|
||||
|
||||
System.out.println("Generiere Method-Interface");
|
||||
|
||||
// Erstellen der Argumente der Methode
|
||||
List<FormalParameter> formalParameterList = new ArrayList<>();
|
||||
ParameterList params = new ParameterList(formalParameterList, new NullToken());
|
||||
for (MyTypeVar typeVar : methodConstraint.getArgumentTypeVars()) {
|
||||
params.getFormalparalist().add(new FormalParameter(typeVar.toString() , typeVar.getTypevar(), new NullToken() ));
|
||||
}
|
||||
|
||||
// Erstellen der Methode
|
||||
Method method = new Method(methodConstraint.getMethodName() ,methodConstraint.getReturnType(), 0, params, null, null, null);
|
||||
List<Method> methodlist = new ArrayList<>();
|
||||
methodlist.add(method);
|
||||
|
||||
// Name des neuen Interfaces
|
||||
JavaClassName name = new JavaClassName(methodConstraint.getReceiver().toString());
|
||||
|
||||
//Erstellen der Generics
|
||||
List<GenericTypeVar> genericTypeVarList = new ArrayList<>();
|
||||
GenericDeclarationList genericDeclaraitonList = new GenericDeclarationList(genericTypeVarList, new NullToken());
|
||||
for (MyTypeVar tv : methodConstraint.getArgumentTypeVars()) {
|
||||
genericTypeVarList.add(new GenericTypeVar(tv.toString(), null, new NullToken(), new NullToken()));
|
||||
}
|
||||
|
||||
|
||||
ClassOrInterface face = new ClassOrInterface(0, name, null, methodlist, genericDeclaraitonList, null, true, null, null);
|
||||
return face;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
116
test/strucTypes3/GeneralParserTestConstruct.java
Normal file
116
test/strucTypes3/GeneralParserTestConstruct.java
Normal file
@ -0,0 +1,116 @@
|
||||
package strucTypes3;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Receiver;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. Der
|
||||
* dabei erstellte Syntaxbaum wird nicht kontrolliert.
|
||||
*
|
||||
* @author janulrich
|
||||
*
|
||||
*/
|
||||
public class GeneralParserTestConstruct {
|
||||
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("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;
|
||||
|
||||
|
||||
// Erstellen der Constrinats für die erste Klasse ---------------------------------------
|
||||
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); });
|
||||
|
||||
|
||||
// Erstellen der Interfaces für die erste Klasse
|
||||
List<ClassOrInterface> sf2 = new ArrayList<>();
|
||||
constraints.forEach( (constraint) -> {sf2.add( Construct.constructInterfaces(constraint)); } );
|
||||
|
||||
|
||||
|
||||
System.out.println(sf2.size());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
assertTrue("Tests durchlaufen", filenames.size() > 0);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user