forked from JavaTX/JavaCompilerCore
PackageCrawler wieder einführen. Unvollständig
This commit is contained in:
parent
b1adc4671d
commit
9b960329fc
@ -17,5 +17,6 @@
|
||||
<classpathentry kind="lib" path="lib/reflections-0.9.10-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/reflections-0.9.10.jar" sourcepath="/reflections/src"/>
|
||||
<classpathentry kind="lib" path="lib/guava-22.0.jar" sourcepath="lib/guava-22.0-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/guava-15.0.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
@ -1,11 +0,0 @@
|
||||
package de.dhbwstuttgart.core;
|
||||
|
||||
/**
|
||||
* Stellt die Java-Environment dar
|
||||
* Speichert alle Typen, Klassen aus den benutzen SourceFiles und Librarys
|
||||
*
|
||||
* Ersetzt die JavaClassNameRegistry
|
||||
*/
|
||||
public class CompilationEnvironment {
|
||||
//
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.core;
|
||||
|
||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
|
44
src/de/dhbwstuttgart/environment/CompilationEnvironment.java
Normal file
44
src/de/dhbwstuttgart/environment/CompilationEnvironment.java
Normal file
@ -0,0 +1,44 @@
|
||||
package de.dhbwstuttgart.environment;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.ResourcesScanner;
|
||||
import org.reflections.scanners.SubTypesScanner;
|
||||
import org.reflections.util.ClasspathHelper;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
import org.reflections.util.FilterBuilder;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
|
||||
/**
|
||||
* Stellt die Java-Environment dar und speichert alle Binarys, Librarys und Sourcefiles im zu kompilierenden Projekt
|
||||
* Sie erstellt anhand dieser Informationen die JavaClassNameRegistry
|
||||
*/
|
||||
public class CompilationEnvironment {
|
||||
private final List<URL> librarys;
|
||||
|
||||
/**
|
||||
* Imitiert die Environment beim Aufruf des JavaCompilers auf einer Menge von java-Dateien
|
||||
* Die Environment enthä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(";")) {
|
||||
try {
|
||||
librarys.add(new URL("file:"+path));
|
||||
} catch (MalformedURLException e) {
|
||||
new DebugException("Fehler im Classpath auf diesem System");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.dhbwstuttgart.typecheck;
|
||||
package de.dhbwstuttgart.environment;
|
||||
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
|
||||
//import jdk.nashorn.internal.ir.Node;
|
@ -1,4 +1,4 @@
|
||||
package de.dhbwstuttgart.typecheck;
|
||||
package de.dhbwstuttgart.environment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
@ -1,9 +1,9 @@
|
||||
package de.dhbwstuttgart.typecheck;
|
||||
package de.dhbwstuttgart.environment;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Speichert die Klassen im aktuellen Projektscope
|
||||
* Speichert die Klassen für einen bestimmten Projektscope
|
||||
*/
|
||||
public class JavaClassRegistry {
|
||||
final List<JavaClassName> existingClasses = new ArrayList<>();
|
||||
@ -15,15 +15,6 @@ public class JavaClassRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* F<EFBFBD>gt ein gesamtes Package der ClassRegistry hinzu.
|
||||
* Dies geschieht beispielsweise, wenn der Benutzer ein "import package.*;" statement verwendet
|
||||
* @param packageName
|
||||
*/
|
||||
public void addPackage(String packageName) {
|
||||
importedPackages.add(packageName);
|
||||
}
|
||||
|
||||
public void add(String className){
|
||||
existingClasses.add(new JavaClassName(className));
|
||||
}
|
64
src/de/dhbwstuttgart/environment/PackageCrawler.java
Normal file
64
src/de/dhbwstuttgart/environment/PackageCrawler.java
Normal file
@ -0,0 +1,64 @@
|
||||
package de.dhbwstuttgart.environment;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.ResourcesScanner;
|
||||
import org.reflections.scanners.SubTypesScanner;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
import org.reflections.util.FilterBuilder;
|
||||
|
||||
/**
|
||||
* Hilft beim Durchsuchen von Packages
|
||||
* Benutzt die Reflections-Library (https://github.com/ronmamo/reflections)
|
||||
* Hilfe dazu: http://stackoverflow.com/a/9571146
|
||||
*/
|
||||
public class PackageCrawler {
|
||||
|
||||
final URL[] urls;
|
||||
public PackageCrawler(List<URL> urlList) {
|
||||
urls = urlList.toArray(new URL[0]);
|
||||
}
|
||||
|
||||
public Set<Class<?>> getClassesInPackage(String packageName){
|
||||
/*
|
||||
List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
|
||||
classLoadersList.add(Thread.currentThread().getContextClassLoader());
|
||||
classLoadersList.add(ClasspathHelper.staticClassLoader());
|
||||
classLoadersList.add(Thread.currentThread().getContextClassLoader().getParent());
|
||||
classLoadersList.add(ClassLoader.getSystemClassLoader());
|
||||
String bootClassPath = System.getProperty("sun.boot.class.path");
|
||||
ArrayList<URL> urlList = new ArrayList<>();
|
||||
for(String path : bootClassPath.split(";")) {
|
||||
try {
|
||||
urlList.add(new URL("file:"+path));
|
||||
} catch (MalformedURLException e) {
|
||||
new DebugException("Fehler im Classpath auf diesem System");
|
||||
}
|
||||
}
|
||||
URL[] urls = urlList.toArray(new URL[0]);
|
||||
classLoadersList.add(new URLClassLoader(urls, ClassLoader.getSystemClassLoader()));
|
||||
*/
|
||||
Reflections reflections = new Reflections(new ConfigurationBuilder()
|
||||
.setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
|
||||
.setUrls(urls)
|
||||
.filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(packageName))));
|
||||
|
||||
Set<Class<?>> classes = reflections.getSubTypesOf(Object.class);
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
// Returns a list of JavaClassNames.
|
||||
public List<JavaClassName> getClassNames(String packageName){
|
||||
List<JavaClassName> nameList = new ArrayList();
|
||||
Set<Class<?>> classes = getClassesInPackage(packageName);
|
||||
for(Class c : classes){
|
||||
nameList.add(new JavaClassName(c.getName()));
|
||||
}
|
||||
return nameList;
|
||||
}
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
package de.dhbwstuttgart.parser;
|
||||
|
||||
import de.dhbwstuttgart.core.CompilationEnvironment;
|
||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||
import de.dhbwstuttgart.environment.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Lexer;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassRegistry;
|
||||
|
||||
import org.antlr.v4.runtime.ANTLRInputStream;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import de.dhbwstuttgart.environment.JavaClassName;
|
||||
|
||||
public class GenericContext {
|
||||
public final String parentMethod;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.environment.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||
@ -10,7 +11,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassRegistry;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.environment.JavaClassName;
|
||||
import de.dhbwstuttgart.environment.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import java.lang.ClassNotFoundException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
|
@ -1,5 +1,8 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.environment.GenericTypeName;
|
||||
import de.dhbwstuttgart.environment.JavaClassName;
|
||||
import de.dhbwstuttgart.environment.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
@ -12,9 +15,7 @@ import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typecheck.GenericTypeName;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassRegistry;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
5
src/de/dhbwstuttgart/parser/scope/sad.java
Normal file
5
src/de/dhbwstuttgart/parser/scope/sad.java
Normal file
@ -0,0 +1,5 @@
|
||||
package de.dhbwstuttgart.parser.scope;
|
||||
|
||||
public class sad {
|
||||
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.environment.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
|
@ -1,7 +1,8 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.environment.GenericTypeName;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typecheck.GenericTypeName;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -2,9 +2,8 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.environment.JavaClassName;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
//import sun.security.x509.X509CertInfo;
|
||||
|
@ -5,15 +5,15 @@ import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.environment.GenericTypeName;
|
||||
import de.dhbwstuttgart.environment.JavaClassName;
|
||||
import de.dhbwstuttgart.environment.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typecheck.GenericTypeName;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
|
@ -3,12 +3,12 @@ package de.dhbwstuttgart.syntaxtree.factory;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.environment.JavaClassName;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefType;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.environment.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.environment.JavaClassName;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
import de.dhbwstuttgart.environment.GenericTypeName;
|
||||
import de.dhbwstuttgart.environment.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.typecheck.GenericTypeName;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
import de.dhbwstuttgart.environment.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.environment.JavaClassName;
|
||||
|
||||
|
||||
public class Void extends RefType
|
||||
{
|
||||
|
@ -1,10 +1,10 @@
|
||||
package de.dhbwstuttgart.typeinference.typeAlgo;
|
||||
|
||||
import de.dhbwstuttgart.environment.JavaClassName;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
|
@ -32,7 +32,7 @@ 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 );
|
||||
System.out.println(url);
|
||||
}
|
||||
if(fileToTest != null)filesToTest.add(fileToTest);
|
||||
//filesToTest.add(new File(rootDirectory+"Faculty.jav"));
|
||||
|
Loading…
Reference in New Issue
Block a user