diff --git a/src/de/dhbwstuttgart/sat/asp/ASPStringConverter.java b/src/de/dhbwstuttgart/sat/asp/ASPStringConverter.java index 0497b09a..5235ab1a 100644 --- a/src/de/dhbwstuttgart/sat/asp/ASPStringConverter.java +++ b/src/de/dhbwstuttgart/sat/asp/ASPStringConverter.java @@ -2,16 +2,39 @@ package de.dhbwstuttgart.sat.asp; import de.dhbwstuttgart.parser.scope.JavaClassName; +import java.util.HashMap; +import java.util.Map; + public class ASPStringConverter { + private static final Map replacements = new HashMap<>(); + static{ + replacements.put(".", "_DOT_"); + replacements.put("$", "_DOLLAR_"); + } + public static String toConstant(JavaClassName name){ - return toConstant(name.toString().replace(".", "_")); + return toConstant(name.toString()); } public static String toConstant(String name){ - return "c" + name.toString().replace(".", "_"); + return "c" + replace(name); } public static String fromConstant(String s){ - return s.replace("_", ".").substring(1); + return unReplace(s).substring(1); + } + + private static String replace(String input){ + for(String toReplace : replacements.keySet()){ + input = input.replace(toReplace, replacements.get(toReplace)); + } + return input; + } + + private static String unReplace(String input){ + for(String toReplace : replacements.keySet()){ + input = input.replace(replacements.get(toReplace), toReplace); + } + return input; } } diff --git a/src/de/dhbwstuttgart/sat/asp/Clingo.java b/src/de/dhbwstuttgart/sat/asp/Clingo.java index ed1e9f40..e0f29cb1 100644 --- a/src/de/dhbwstuttgart/sat/asp/Clingo.java +++ b/src/de/dhbwstuttgart/sat/asp/Clingo.java @@ -41,6 +41,7 @@ public class Clingo { commands.add(file.getPath()); } commands.addAll(programFiles.stream().map(f->f.getPath()).collect(Collectors.toList())); + Process clingo = new ProcessBuilder( commands.toArray(new String[0])).start(); InputStream output = clingo.getInputStream(); clingo.waitFor(); diff --git a/src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java b/src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java new file mode 100644 index 00000000..46c047d5 --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java @@ -0,0 +1,16 @@ +package de.dhbwstuttgart.sat.asp.writer; + +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.type.RefType; + +import java.util.Collection; + +public class ASPFactory { + public static String convertFC(Collection classes){ + return null; //TODO + } + + public static String convert(RefType t){ + return null; //TODO + } +} diff --git a/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java b/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java index 676aa33f..3f999a41 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java @@ -36,11 +36,10 @@ public class ASPGenerator { TypeConverter converter = new TypeConverter(); for(Pair fcp : fc){ //Wenn dieser Cast fehlschlägt stimmt etwas nicht. Alle Paare in der FC müssen smaller Operatoren haen - ASPPairSmaller fcEntry = (ASPPairSmaller) convert(fcp); - writer.add(new ASPStatement(fcEntry.toASP())); + convert(fcp); } for(Pair cons : constraintSet){ - writer.add(new ASPStatement(convert(cons).toASP())); + convert(cons); } return writer.getASPFile(); @@ -88,7 +87,7 @@ public class ASPGenerator { @Override public ASPType visit(TypePlaceholder typePlaceholder) { - return new ASPTypeVar(ASPStringConverter.toConstant(typePlaceholder.getName())); + return new ASPTypeVar(ASPStringConverter.toConstant(typePlaceholder.getName()),writer); } @Override diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPGenericType.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPGenericType.java index 8e732d64..327ce04a 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPGenericType.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPGenericType.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.sat.asp.writer.model; import de.dhbwstuttgart.sat.asp.model.ASPRule; +import de.dhbwstuttgart.sat.asp.writer.ASPWriter; public class ASPGenericType implements ASPType{ private final String name; @@ -13,9 +14,8 @@ public class ASPGenericType implements ASPType{ return ASPRule.ASP_GENERIC_TYPE_NAME + "(" + name + ")"; } - @Override - public String toASP() { - return toString(); + private String toASP() { + return ASPRule.ASP_GENERIC_TYPE_NAME + "(" + name + ")"; } @Override diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPair.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPair.java index 19730639..e881f346 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPair.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPair.java @@ -9,11 +9,10 @@ public abstract class ASPPair { public ASPPair(ASPType ls, ASPType rs, ASPWriter writer){ this.leftSide = ls; this.rightSide = rs; - writer.add(new ASPStatement(ls.toASP())); - writer.add(new ASPStatement(rs.toASP())); + writer.add(new ASPStatement(toASP())); } - public String toASP(){ + private String toASP(){ return this.getRuleName() + "(" + leftSide.getPointer() + ","+ rightSide.getPointer() + ")"; } diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPParameterList.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPParameterList.java index 178bb8fa..fafa50f5 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPParameterList.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPParameterList.java @@ -29,7 +29,7 @@ public class ASPParameterList { if(! it.hasNext())nextPointer = ASPRule.ASP_PARAMLIST_END_POINTER.toString(); param += nextPointer; writer.add(new ASPStatement(ASPRule.ASP_PARAMLIST_NAME + "(" + param + ")")); - writer.add(new ASPStatement(ASPRule.ASP_PARAMLISTNUMERATION_NAME + "(" + name + "," +t + "," + paramNum + ")")); + writer.add(new ASPStatement(ASPRule.ASP_PARAMLISTNUMERATION_NAME + "(" + name + "," + t.getPointer() + "," + paramNum + ")")); paramNum++; } } diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java index 5eab65be..46a4d1c7 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java @@ -19,11 +19,6 @@ public class ASPRefType implements ASPType { return ASPRule.ASP_TYPE + "(" + name +"," + params.name + ")"; } - @Override - public String toASP() { - return toString(); - } - @Override public String getPointer() { return name; diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPType.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPType.java index 6e715dba..201e36ad 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPType.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPType.java @@ -1,7 +1,5 @@ package de.dhbwstuttgart.sat.asp.writer.model; public interface ASPType { - String toASP(); - String getPointer(); } diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPTypeVar.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPTypeVar.java index 24b33eaf..e10a88bf 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPTypeVar.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPTypeVar.java @@ -1,22 +1,23 @@ package de.dhbwstuttgart.sat.asp.writer.model; import de.dhbwstuttgart.sat.asp.model.ASPRule; +import de.dhbwstuttgart.sat.asp.writer.ASPWriter; public class ASPTypeVar implements ASPType{ private final String name; - public ASPTypeVar(String name){ + public ASPTypeVar(String name, ASPWriter writer){ this.name = name; + writer.add(new ASPStatement(this.toASP())); } @Override public String toString() { - return ASPRule.ASP_TYPE_VAR+"("+ name +")"; + return toASP(); } - @Override - public String toASP() { - return toString(); + private String toASP() { + return ASPRule.ASP_TYPE_VAR+"("+ name +")"; } @Override diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index fa930f58..de1bec99 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -49,12 +49,10 @@ public class ASTFactory { parameterSuperClass = (ParameterizedType) tempSuperClass; java.lang.Class superjreClass = jreClass.getSuperclass(); RefType superClass; - if(superjreClass != null){ - List params = new ArrayList<>(); - for(TypeVariable tv : superjreClass.getTypeParameters()){ - params.add(new GenericRefType(tv.getName(), new NullToken())); - } - superClass = new RefType(new JavaClassName(superjreClass.getName()), params, new NullToken()); + if(parameterSuperClass != null){ + superClass = (RefType) convertType(parameterSuperClass); + }else if(superjreClass != null){ + superClass = (RefType) convertType(superjreClass); }else{//Jede Klasse und jedes Interface erbt von Object: (auch Object selbst!) superClass = (RefType) createType(java.lang.Object.class, name, ""); } @@ -70,19 +68,24 @@ public class ASTFactory { } private static RefTypeOrTPHOrWildcardOrGeneric convertType(Type type){ - JavaClassName name = null; - List params = new ArrayList<>(); if(type instanceof ParameterizedType){ + List params = new ArrayList<>(); for(Type paramType : ((ParameterizedType)type).getActualTypeArguments()){ params.add(convertType(paramType)); } + JavaClassName name = new JavaClassName(((ParameterizedType) type).getRawType().getTypeName()); + return new RefType(name, params, new NullToken()); }else if(type instanceof TypeVariable){ - + return new GenericRefType(((TypeVariable) type).getName(), new NullToken()); }else if(type instanceof Class){ + List params = new ArrayList<>(); Class paramClass = (Class) type; - //params.add(new RefType(paramClass.getName()) + for(TypeVariable tv : paramClass.getTypeParameters()){ + params.add(new GenericRefType(tv.getName(), new NullToken())); + } + JavaClassName name = new JavaClassName(paramClass.getName()); + return new RefType(name, params, new NullToken()); }else throw new NotImplementedException(); - return new RefType(name, params, new NullToken()); } private static Field createField(java.lang.reflect.Field field, JavaClassName jreClass) { diff --git a/test/asp/UnifyWithoutWildcards.java b/test/asp/UnifyWithoutWildcards.java index db697312..998ec56c 100644 --- a/test/asp/UnifyWithoutWildcards.java +++ b/test/asp/UnifyWithoutWildcards.java @@ -28,10 +28,11 @@ public class UnifyWithoutWildcards { public void adapt() throws InterruptedException, IOException, ClassNotFoundException { ConstraintSet testSet = new ConstraintSet<>(); List list = Arrays.asList(TypePlaceholder.fresh(new NullToken())); - RefType t1 = new RefType(new JavaClassName("Matrix"), new NullToken()); + RefType t1 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Matrix"), new NullToken()); RefType t2 = new RefType(new JavaClassName("Vector"), list, new NullToken()); testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT)); - run(testSet); + ResultSet resultSet = run(testSet); + System.out.println(resultSet); } public ResultSet run(ConstraintSet toTest) throws IOException, InterruptedException, ClassNotFoundException { diff --git a/test/javFiles/LambdaRunnable.jav b/test/javFiles/LambdaRunnable.jav index 982680c3..37924ea2 100644 --- a/test/javFiles/LambdaRunnable.jav +++ b/test/javFiles/LambdaRunnable.jav @@ -1,3 +1,6 @@ +import java.lang.Runnable; +import java.lang.String; +import java.lang.System; public class LamRunnable{