Fehler beheben. PackageCrawler lauffähig
This commit is contained in:
parent
b8a5795bb3
commit
8ce017c2f2
@ -3,16 +3,14 @@ package de.dhbwstuttgart.core;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ConsoleInterface {
|
||||
private static final String directory = System.getProperty("user.dir");
|
||||
|
||||
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
||||
|
||||
JavaTXCompiler compiler = new JavaTXCompiler();
|
||||
for(String arg : Arrays.asList(args)){
|
||||
compiler.parse(new File(arg));
|
||||
}
|
||||
List<File> input = Arrays.asList(args).stream().map((s -> new File(s))).collect(Collectors.toList());
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(input);
|
||||
compiler.typeInference();
|
||||
}
|
||||
}
|
||||
|
@ -24,21 +24,27 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class JavaTXCompiler {
|
||||
|
||||
CompilationEnvironment environment;
|
||||
|
||||
protected List<SourceFile> sourceFiles = new ArrayList<>();
|
||||
/*
|
||||
public JavaTXCompiler(List<File> sourceFiles){
|
||||
final CompilationEnvironment environment;
|
||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||
|
||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||
this(Arrays.asList(sourceFile));
|
||||
}
|
||||
*/
|
||||
|
||||
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
|
||||
environment = new CompilationEnvironment(sources);
|
||||
for(File s : sources){
|
||||
sourceFiles.put(s,parse(s));
|
||||
}
|
||||
}
|
||||
|
||||
public List<ResultSet> typeInference(){
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();
|
||||
for(SourceFile sf : sourceFiles){
|
||||
for(SourceFile sf : sourceFiles.values()){
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||
final ConstraintSet<Pair> cons = new TYPE(sourceFiles).getConstraints();
|
||||
final ConstraintSet<Pair> cons = new TYPE(sourceFiles.values()).getConstraints();
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
|
||||
TypeUnify unify = new TypeUnify();
|
||||
@ -72,11 +78,10 @@ public class JavaTXCompiler {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile));
|
||||
SourceFile ret = generator.convert(tree);
|
||||
sourceFiles.add(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -34,13 +34,13 @@ public class CompilationEnvironment {
|
||||
|
||||
/**
|
||||
* Imitiert die Environment beim Aufruf des JavaCompilers auf einer Menge von java-Dateien
|
||||
* Die Environment enthält automatisch die Java Standard Library
|
||||
* Die Environment enth<EFBFBD>lt automatisch die Java Standard Library
|
||||
* @param sourceFiles die zu kompilierenden Dateien
|
||||
*/
|
||||
public CompilationEnvironment(List<File> sourceFiles) {
|
||||
String bootClassPath = System.getProperty("sun.boot.class.path");
|
||||
librarys = new ArrayList<>();
|
||||
for(String path : bootClassPath.split(";")) {
|
||||
for(String path : bootClassPath.split(File.pathSeparator)) {
|
||||
try {
|
||||
librarys.add(new URL("file:"+path));
|
||||
} catch (MalformedURLException e) {
|
||||
@ -52,6 +52,7 @@ public class CompilationEnvironment {
|
||||
public JavaClassRegistry getRegistry(File forSourceFile) throws ClassNotFoundException, IOException {
|
||||
List<String> allNames = new ArrayList<>();
|
||||
CompilationUnitContext tree = JavaTXParser.parse(forSourceFile);
|
||||
return new JavaClassRegistry(GatherNames.getNames(tree, new PackageCrawler(librarys)));
|
||||
allNames = GatherNames.getNames(tree, new PackageCrawler(librarys));
|
||||
return new JavaClassRegistry(allNames);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typecheck.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
@ -72,6 +72,7 @@ public class GatherNames {
|
||||
|
||||
private static List<String> getImports(Java8Parser.CompilationUnitContext ctx, PackageCrawler packages) throws ClassNotFoundException {
|
||||
List<String> ret = new ArrayList();
|
||||
ret.addAll(packages.getClassNames("java.lang"));
|
||||
for(Java8Parser.ImportDeclarationContext importDeclCtx : ctx.importDeclaration()){
|
||||
if(importDeclCtx.singleTypeImportDeclaration() != null){
|
||||
ret.add(importDeclCtx.singleTypeImportDeclaration().typeName().getText());
|
||||
|
@ -12,9 +12,9 @@ import java.util.*;
|
||||
|
||||
public class TYPE {
|
||||
|
||||
private final List<SourceFile> sfs;
|
||||
private final Collection<SourceFile> sfs;
|
||||
|
||||
public TYPE(List<SourceFile> sourceFiles){
|
||||
public TYPE(Collection<SourceFile> sourceFiles){
|
||||
sfs = sourceFiles;
|
||||
}
|
||||
|
||||
|
@ -1,40 +0,0 @@
|
||||
package parser;
|
||||
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public class FeatherWeightJavaTest {
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/test/parser/";
|
||||
|
||||
@Test
|
||||
public void test() throws IOException, ClassNotFoundException {
|
||||
|
||||
JavaTXParser parser = new JavaTXParser();
|
||||
SourceFile f = parser.parse(new File(rootDirectory + "Methods.jav"));
|
||||
|
||||
String pkgName = f.getPkgName();
|
||||
System.out.println("package: " + pkgName);
|
||||
System.out.println("classes:");
|
||||
for(ClassOrInterface c : f.getClasses()){
|
||||
int mod = c.getModifiers();
|
||||
System.out.println(Modifier.toString(mod));
|
||||
System.out.println(c.getClassName().toString());
|
||||
System.out.println("{");
|
||||
for(Field field : c.getFieldDecl()){
|
||||
System.out.println(field.getName());
|
||||
if(field instanceof Method){
|
||||
System.out.println(((Method) field).getParameterList().getFormalparalist().toString());
|
||||
}
|
||||
}
|
||||
System.out.println("}");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package parser;
|
||||
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public class FieldTest {
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/test/parser/";
|
||||
|
||||
@Test
|
||||
public void test() throws IOException, ClassNotFoundException, ClassNotFoundException {
|
||||
|
||||
JavaTXParser parser = new JavaTXParser();
|
||||
SourceFile f = parser.parse(new File(rootDirectory + "FieldVarTest.jav"));
|
||||
|
||||
String pkgName = f.getPkgName();
|
||||
System.out.println("package: " + pkgName);
|
||||
System.out.println("classes:");
|
||||
for(ClassOrInterface c : f.getClasses()){
|
||||
int mod = c.getModifiers();
|
||||
System.out.println(Modifier.toString(mod));
|
||||
System.out.println(c.getClassName().toString());
|
||||
System.out.println("{");
|
||||
for(Field field : c.getFieldDecl()){
|
||||
System.out.println(field.getName());
|
||||
}
|
||||
System.out.println("}");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package parser;
|
||||
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class RunParserTest {
|
||||
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/test/parser/";
|
||||
|
||||
@Test
|
||||
public void testMain() throws Exception {
|
||||
String[] args = new String[1];
|
||||
args[0] = rootDirectory+"WhileTest.jav";
|
||||
SourceFile sf = new JavaTXParser().parse(new File(args[0]));
|
||||
System.out.println(ASTPrinter.print(sf));
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class JavaTXCompilerTest extends JavaTXCompiler {
|
||||
public class JavaTXCompilerTest {
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/";
|
||||
private static final List<File> filesToTest = new ArrayList<>();
|
||||
@ -31,9 +31,6 @@ public class JavaTXCompilerTest extends JavaTXCompiler {
|
||||
|
||||
@Test
|
||||
public void test() throws IOException, java.lang.ClassNotFoundException {
|
||||
for(URL url : ((URLClassLoader) (Thread.currentThread().getContextClassLoader())).getURLs()){
|
||||
System.out.println(url);
|
||||
}
|
||||
if(fileToTest != null)filesToTest.add(fileToTest);
|
||||
//filesToTest.add(new File(rootDirectory+"Faculty.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
|
||||
@ -46,10 +43,13 @@ public class JavaTXCompilerTest extends JavaTXCompiler {
|
||||
//filesToTest.add(new File(rootDirectory+"MethodsEasy.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Import.jav"));
|
||||
for(File f : filesToTest){
|
||||
SourceFile sf = this.parse(f);
|
||||
System.out.println(ASTTypePrinter.print(this.sourceFiles.get(sourceFiles.size()-1)));
|
||||
for(ResultSet resultSet : this.typeInference()){
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.typeInference();
|
||||
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
System.out.println(ASTTypePrinter.print(sf));
|
||||
for(ResultSet resultSet : compiler.typeInference()){
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
|
||||
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||
for(TypeInsert tip : result){
|
||||
|
Loading…
Reference in New Issue
Block a user