From 6e770b5ec5dc5cd4b601545e6367ba931654b508 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Mon, 12 Feb 2018 22:32:03 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Java=209:=20Classloader=20=C3=A4ndern=20*?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 8 +++++++ .../environment/CompilationEnvironment.java | 21 +++++++++++-------- src/de/dhbwstuttgart/parser/JavaTXParser.java | 2 +- .../dhbwstuttgart/sat/asp/model/ASPRule.java | 3 ++- .../sat/asp/writer/ASPGenerator.java | 6 +++--- .../sat/asp/writer/model/ASPFCType.java | 17 +++++++++++++++ .../sat/asp/writer/model/ASPPairSmaller.java | 2 +- .../sat/asp/writer/model/ASPRefType.java | 4 ++-- .../typeinference/assumptions/FunNClass.java | 1 - 9 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 src/de/dhbwstuttgart/sat/asp/writer/model/ASPFCType.java diff --git a/pom.xml b/pom.xml index 9cce2d99..ea7be6b3 100644 --- a/pom.xml +++ b/pom.xml @@ -73,6 +73,14 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 9 + 9 + + diff --git a/src/de/dhbwstuttgart/environment/CompilationEnvironment.java b/src/de/dhbwstuttgart/environment/CompilationEnvironment.java index 7044da6b..5f294130 100644 --- a/src/de/dhbwstuttgart/environment/CompilationEnvironment.java +++ b/src/de/dhbwstuttgart/environment/CompilationEnvironment.java @@ -40,15 +40,18 @@ public class CompilationEnvironment { * @param sourceFiles die zu kompilierenden Dateien */ public CompilationEnvironment(List sourceFiles) { - String bootClassPath = System.getProperty("sun.boot.class.path"); - librarys = new ArrayList<>(); - for(String path : bootClassPath.split(File.pathSeparator)) { - try { - librarys.add(new URL("file:"+path)); - } catch (MalformedURLException e) { - new DebugException("Fehler im Classpath auf diesem System"); - } - } + /** + * Java 9 bringt einige Änderungen am Classloader + * So funktioniert der BootClassLoader nicht mehr. + * hier gibts ein paar Quellen zum nachlesen: + * http://java9.wtf/class-loading/ + * https://stackoverflow.com/questions/46494112/classloaders-hierarchy-in-java-9 + * + */ + //String bootClassPath = System.getProperty("sun.boot.class.path"); + ClassLoader cl = ClassLoader.getPlatformClassLoader(); + URLClassLoader loader = new URLClassLoader(new URL[0], cl); + librarys = Arrays.asList(loader.getURLs()); this.sourceFiles = sourceFiles; this.packageCrawler = new PackageCrawler(librarys); } diff --git a/src/de/dhbwstuttgart/parser/JavaTXParser.java b/src/de/dhbwstuttgart/parser/JavaTXParser.java index c860a6a7..aad0a575 100644 --- a/src/de/dhbwstuttgart/parser/JavaTXParser.java +++ b/src/de/dhbwstuttgart/parser/JavaTXParser.java @@ -29,7 +29,7 @@ public class JavaTXParser { */ } - /* Für das Typsystem ist es notwendig, dass sich der Source in einer Datei befindet: + /* Für das Typsystem ist es notwendig, dass sich der Source in einer Datei befindet: public SourceFile parse(String fileContent) throws IOException, java.lang.ClassNotFoundException { return this.parse(new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8))); } diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPRule.java b/src/de/dhbwstuttgart/sat/asp/model/ASPRule.java index 41237547..8d4d73f9 100644 --- a/src/de/dhbwstuttgart/sat/asp/model/ASPRule.java +++ b/src/de/dhbwstuttgart/sat/asp/model/ASPRule.java @@ -8,7 +8,8 @@ public enum ASPRule { ASP_PARAMLIST_NAME("param"), ASP_PARAMLISTNUMERATION_NAME("paramNum"), ASP_PARAMLIST_END_POINTER("null"), - ASP_TYPE("type") + ASP_TYPE("type"), + ASP_FCTYPE("type") ; private final String text; diff --git a/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java b/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java index 002e3c7f..66c206e1 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java @@ -36,8 +36,8 @@ public class ASPGenerator { private String toASP(List constraintSet, Collection fcClasses){ TypeConverter converter = new TypeConverter(); for(ClassOrInterface cl : fcClasses){ - ASPType superClass = cl.getSuperClass().acceptTV(converter); - ASPPairSmaller fcEntry = new ASPPairSmaller(convert(cl), superClass); + ASPRefType superClass = (ASPRefType) cl.getSuperClass().acceptTV(converter); + ASPPairSmaller fcEntry = new ASPPairSmaller(new ASPFCType(convert(cl)), new ASPFCType(superClass)); writer.add(new ASPStatement(fcEntry.toASP())); } for(Pair cons : constraintSet){ @@ -58,7 +58,7 @@ public class ASPGenerator { }else throw new NotImplementedException(); } - private ASPType convert(ClassOrInterface cl){ + private ASPRefType convert(ClassOrInterface cl){ List paramList = new ArrayList<>(); for(GenericTypeVar gtv : cl.getGenerics()){ paramList.add(new ASPGenericType(toConstant(gtv.getName()))); diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPFCType.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPFCType.java new file mode 100644 index 00000000..777a34a7 --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPFCType.java @@ -0,0 +1,17 @@ +package de.dhbwstuttgart.sat.asp.writer.model; + +import de.dhbwstuttgart.sat.asp.model.ASPRule; + +public class ASPFCType extends ASPRefType { + public ASPFCType(String name, ASPParameterList params){ + super(name, params); + } + + public ASPFCType(ASPRefType refType){ + super(refType.name, refType.params); + } + + public String toString(){ + return ASPRule.ASP_FCTYPE + "(" + name +"," + params.name + ")"; + } +} diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmaller.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmaller.java index f57170f6..928acb49 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmaller.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmaller.java @@ -5,7 +5,7 @@ import de.dhbwstuttgart.sat.asp.model.ASPRule; import java.util.Map; public class ASPPairSmaller extends ASPPair{ - public ASPPairSmaller(ASPType ls, ASPType rs){ + public ASPPairSmaller(ASPFCType ls, ASPFCType rs){ super(ls, rs); } diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java index 6491ff33..bfbf27a0 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java @@ -3,8 +3,8 @@ package de.dhbwstuttgart.sat.asp.writer.model; import de.dhbwstuttgart.sat.asp.model.ASPRule; public class ASPRefType implements ASPType { - private final ASPParameterList params; - private final String name; + protected final ASPParameterList params; + protected final String name; public ASPRefType(String name, ASPParameterList params){ this.name = name; diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java b/src/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java index 0eba225d..a04ce9bb 100644 --- a/src/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java @@ -1,6 +1,5 @@ package de.dhbwstuttgart.typeinference.assumptions; -import com.sun.org.apache.regexp.internal.RE; import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext; import de.dhbwstuttgart.parser.scope.GenericTypeName; From 191a1166b9282eeadeaace5f3def6c16e5782432 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 13 Feb 2018 05:25:18 +0100 Subject: [PATCH 2/2] ASP Generator auf neues Format anpassen --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 2 +- .../environment/CompilationEnvironment.java | 16 +++++++++++++--- .../sat/asp/writer/ASPGenerator.java | 6 +++--- .../sat/asp/writer/model/ASPFCType.java | 5 +---- .../sat/asp/writer/model/ASPGenericType.java | 10 ++++++++++ .../sat/asp/writer/model/ASPPair.java | 8 ++++++-- .../sat/asp/writer/model/ASPPairEquals.java | 5 +++-- .../sat/asp/writer/model/ASPPairSmaller.java | 5 +++-- .../sat/asp/writer/model/ASPPairSmallerDot.java | 5 +++-- .../sat/asp/writer/model/ASPRefType.java | 10 ++++++++++ .../sat/asp/writer/model/ASPType.java | 3 +++ .../sat/asp/writer/model/ASPTypeVar.java | 10 ++++++++++ test/javFiles/Vector.jav | 1 + 13 files changed, 67 insertions(+), 19 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 86666a49..e8d74cb6 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -82,7 +82,7 @@ public class JavaTXCompiler { List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC for(SourceFile sf : this.sourceFiles.values()) { - //allClasses.addAll(getAvailableClasses(sf)); + allClasses.addAll(getAvailableClasses(sf)); allClasses.addAll(sf.getClasses()); } diff --git a/src/de/dhbwstuttgart/environment/CompilationEnvironment.java b/src/de/dhbwstuttgart/environment/CompilationEnvironment.java index 5f294130..8a6976d6 100644 --- a/src/de/dhbwstuttgart/environment/CompilationEnvironment.java +++ b/src/de/dhbwstuttgart/environment/CompilationEnvironment.java @@ -49,9 +49,19 @@ public class CompilationEnvironment { * */ //String bootClassPath = System.getProperty("sun.boot.class.path"); - ClassLoader cl = ClassLoader.getPlatformClassLoader(); - URLClassLoader loader = new URLClassLoader(new URL[0], cl); - librarys = Arrays.asList(loader.getURLs()); + // ClassLoader cl = ClassLoader.getPlatformClassLoader(); + ClassLoader cl = ClassLoader.getSystemClassLoader(); + String bootClassPath = System.getProperty("java.class.path"); + librarys = new ArrayList<>(); + for(String path : bootClassPath.split(File.pathSeparator)) { + try { + librarys.add(new URL("file:"+path)); + } catch (MalformedURLException e) { + new DebugException("Fehler im Classpath auf diesem System"); + } + } + //URLClassLoader loader = new URLClassLoader(new URL[0], cl); + //librarys = Arrays.asList(loader.getURLs()); this.sourceFiles = sourceFiles; this.packageCrawler = new PackageCrawler(librarys); } diff --git a/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java b/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java index 66c206e1..ea162c11 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java @@ -37,7 +37,7 @@ public class ASPGenerator { TypeConverter converter = new TypeConverter(); for(ClassOrInterface cl : fcClasses){ ASPRefType superClass = (ASPRefType) cl.getSuperClass().acceptTV(converter); - ASPPairSmaller fcEntry = new ASPPairSmaller(new ASPFCType(convert(cl)), new ASPFCType(superClass)); + ASPPairSmaller fcEntry = new ASPPairSmaller(new ASPFCType(convert(cl)), new ASPFCType(superClass), writer); writer.add(new ASPStatement(fcEntry.toASP())); } for(Pair cons : constraintSet){ @@ -52,9 +52,9 @@ public class ASPGenerator { ASPType ls = pair.TA1.acceptTV(converter); ASPType rs = pair.TA2.acceptTV(converter); if(pair.OperatorEqual()){ - return new ASPPairEquals(ls, rs); + return new ASPPairEquals(ls, rs,writer); }else if(pair.OperatorSmallerDot()){ - return new ASPPairSmallerDot(ls, rs); + return new ASPPairSmallerDot(ls, rs, writer); }else throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPFCType.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPFCType.java index 777a34a7..790fd5af 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPFCType.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPFCType.java @@ -1,12 +1,9 @@ package de.dhbwstuttgart.sat.asp.writer.model; import de.dhbwstuttgart.sat.asp.model.ASPRule; +import de.dhbwstuttgart.sat.asp.writer.ASPWriter; public class ASPFCType extends ASPRefType { - public ASPFCType(String name, ASPParameterList params){ - super(name, params); - } - public ASPFCType(ASPRefType refType){ super(refType.name, refType.params); } diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPGenericType.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPGenericType.java index 57619edf..8e732d64 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPGenericType.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPGenericType.java @@ -12,4 +12,14 @@ public class ASPGenericType implements ASPType{ public String toString(){ return ASPRule.ASP_GENERIC_TYPE_NAME + "(" + name + ")"; } + + @Override + public String toASP() { + return toString(); + } + + @Override + public String getPointer() { + return name; + } } diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPair.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPair.java index 662f995c..19730639 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPair.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPair.java @@ -1,16 +1,20 @@ package de.dhbwstuttgart.sat.asp.writer.model; +import de.dhbwstuttgart.sat.asp.writer.ASPWriter; + public abstract class ASPPair { public final ASPType leftSide; public final ASPType rightSide; - public ASPPair(ASPType ls, ASPType rs){ + 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())); } public String toASP(){ - return this.getRuleName() + "(" + leftSide + ","+ rightSide + ")"; + return this.getRuleName() + "(" + leftSide.getPointer() + ","+ rightSide.getPointer() + ")"; } public String toString(){ diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairEquals.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairEquals.java index 8806f2ce..bf6e2485 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairEquals.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairEquals.java @@ -1,10 +1,11 @@ package de.dhbwstuttgart.sat.asp.writer.model; import de.dhbwstuttgart.sat.asp.model.ASPRule; +import de.dhbwstuttgart.sat.asp.writer.ASPWriter; public class ASPPairEquals extends ASPPair{ - public ASPPairEquals(ASPType ls, ASPType rs){ - super(ls, rs); + public ASPPairEquals(ASPType ls, ASPType rs, ASPWriter writer){ + super(ls, rs, writer); } @Override diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmaller.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmaller.java index 928acb49..610e5c56 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmaller.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmaller.java @@ -1,12 +1,13 @@ package de.dhbwstuttgart.sat.asp.writer.model; import de.dhbwstuttgart.sat.asp.model.ASPRule; +import de.dhbwstuttgart.sat.asp.writer.ASPWriter; import java.util.Map; public class ASPPairSmaller extends ASPPair{ - public ASPPairSmaller(ASPFCType ls, ASPFCType rs){ - super(ls, rs); + public ASPPairSmaller(ASPFCType ls, ASPFCType rs, ASPWriter writer){ + super(ls, rs, writer); } @Override diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmallerDot.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmallerDot.java index e8482bfc..b572ed99 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmallerDot.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmallerDot.java @@ -1,10 +1,11 @@ package de.dhbwstuttgart.sat.asp.writer.model; import de.dhbwstuttgart.sat.asp.model.ASPRule; +import de.dhbwstuttgart.sat.asp.writer.ASPWriter; public class ASPPairSmallerDot extends ASPPair{ - public ASPPairSmallerDot(ASPType ls, ASPType rs){ - super(ls, rs); + public ASPPairSmallerDot(ASPType ls, ASPType rs, ASPWriter writer){ + super(ls, rs, writer); } @Override diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java index bfbf27a0..5eab65be 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java @@ -18,4 +18,14 @@ public class ASPRefType implements ASPType { public String toString(){ 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 da694218..6e715dba 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPType.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPType.java @@ -1,4 +1,7 @@ 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 4b07d30b..8b3c1af6 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPTypeVar.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPTypeVar.java @@ -11,4 +11,14 @@ public class ASPTypeVar implements ASPType{ public String toString() { return "typeVar("+ name +")"; } + + @Override + public String toASP() { + return toString(); + } + + @Override + public String getPointer() { + return name; + } } diff --git a/test/javFiles/Vector.jav b/test/javFiles/Vector.jav index f2a9cdae..1ea1ac41 100644 --- a/test/javFiles/Vector.jav +++ b/test/javFiles/Vector.jav @@ -1,3 +1,4 @@ +import java.util.Vector; class Vector{