forked from JavaTX/JavaCompilerCore
Merge branch 'bigRefactoring' into strucTypesNew
This commit is contained in:
commit
52dd0e6276
@ -81,7 +81,7 @@ public class FCGenerator {
|
|||||||
//Hier vermerken, welche Typen im der Superklasse ausgetauscht werden müssen
|
//Hier vermerken, welche Typen im der Superklasse ausgetauscht werden müssen
|
||||||
Iterator<GenericTypeVar> itGenParams = superClass.getGenerics().iterator();
|
Iterator<GenericTypeVar> itGenParams = superClass.getGenerics().iterator();
|
||||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itSetParams = superType.getParaList().iterator();
|
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itSetParams = superType.getParaList().iterator();
|
||||||
while(itGenParams.hasNext()){
|
while(itSetParams.hasNext()){
|
||||||
RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next();
|
RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next();
|
||||||
//In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen:
|
//In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen:
|
||||||
RefTypeOrTPHOrWildcardOrGeneric setSetType = setType.acceptTV(new TypeExchanger(gtvs));
|
RefTypeOrTPHOrWildcardOrGeneric setSetType = setType.acceptTV(new TypeExchanger(gtvs));
|
||||||
|
@ -73,6 +73,7 @@ public class SyntaxTreeGenerator{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SourceFile convert(Java8Parser.CompilationUnitContext ctx, PackageCrawler packageCrawler) throws ClassNotFoundException{
|
public SourceFile convert(Java8Parser.CompilationUnitContext ctx, PackageCrawler packageCrawler) throws ClassNotFoundException{
|
||||||
|
if(ctx.packageDeclaration()!=null)this.pkgName = convert(ctx.packageDeclaration());
|
||||||
List<ClassOrInterface> classes = new ArrayList<>();
|
List<ClassOrInterface> classes = new ArrayList<>();
|
||||||
Map<String, Integer> imports = GatherNames.getImports(ctx, packageCrawler);
|
Map<String, Integer> imports = GatherNames.getImports(ctx, packageCrawler);
|
||||||
this.imports = imports.keySet().stream().map(name -> reg.getName(name)).collect(Collectors.toSet());
|
this.imports = imports.keySet().stream().map(name -> reg.getName(name)).collect(Collectors.toSet());
|
||||||
@ -89,6 +90,15 @@ public class SyntaxTreeGenerator{
|
|||||||
return new SourceFile(this.pkgName, classes, this.imports);
|
return new SourceFile(this.pkgName, classes, this.imports);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String convert(Java8Parser.PackageDeclarationContext packageDeclarationContext) {
|
||||||
|
String ret = "";
|
||||||
|
for(TerminalNode identifier : packageDeclarationContext.Identifier()){
|
||||||
|
ret += identifier.getText()+".";
|
||||||
|
}
|
||||||
|
ret = ret.substring(0, ret.length()-1);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
public Method convert(Java8Parser.MethodDeclarationContext methodDeclarationContext, JavaClassName parentClass, RefType superClass, GenericsRegistry generics) {
|
public Method convert(Java8Parser.MethodDeclarationContext methodDeclarationContext, JavaClassName parentClass, RefType superClass, GenericsRegistry generics) {
|
||||||
Java8Parser.MethodHeaderContext header = methodDeclarationContext.methodHeader();
|
Java8Parser.MethodHeaderContext header = methodDeclarationContext.methodHeader();
|
||||||
int modifiers = SyntaxTreeGenerator.convert(methodDeclarationContext.methodModifier());
|
int modifiers = SyntaxTreeGenerator.convert(methodDeclarationContext.methodModifier());
|
||||||
@ -165,8 +175,8 @@ public class SyntaxTreeGenerator{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
String className = this.pkgName + (this.pkgName.length()>0?".":"") + ctx.Identifier().getText();
|
String className = this.pkgName + (this.pkgName.length()>0?".":"") + ctx.Identifier().getText();
|
||||||
JavaClassName name = reg.getName(className);
|
JavaClassName name = reg.getName(className); //Holt den Package Namen mit dazu
|
||||||
if(! name.toString().equals(className)){
|
if(! name.toString().equals(className)){ //Kommt die Klasse schon in einem anderen Package vor?
|
||||||
throw new TypeinferenceException("Name " + className + " bereits vorhanden in " + reg.getName(className).toString()
|
throw new TypeinferenceException("Name " + className + " bereits vorhanden in " + reg.getName(className).toString()
|
||||||
,ctx.getStart());
|
,ctx.getStart());
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ public class ASTFactory {
|
|||||||
superClass = (RefType) createType(java.lang.Object.class, name, "");
|
superClass = (RefType) createType(java.lang.Object.class, name, "");
|
||||||
}
|
}
|
||||||
List<RefType> implementedInterfaces = new ArrayList<>();
|
List<RefType> implementedInterfaces = new ArrayList<>();
|
||||||
for(java.lang.Class jreInterface : jreClass.getInterfaces()){
|
for(Type jreInterface : jreClass.getGenericInterfaces()){
|
||||||
implementedInterfaces.add((RefType) createType(jreInterface, name, ""));
|
implementedInterfaces.add((RefType) createType(jreInterface, name, ""));
|
||||||
}
|
}
|
||||||
GenericDeclarationList genericDeclarationList = createGenerics(jreClass.getTypeParameters(), jreClass, null);
|
GenericDeclarationList genericDeclarationList = createGenerics(jreClass.getTypeParameters(), jreClass, null);
|
||||||
@ -193,7 +193,12 @@ public class ASTFactory {
|
|||||||
params.add(createType(t, parentClass, parentMethod));
|
params.add(createType(t, parentClass, parentMethod));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RefType ret = new RefType(new JavaClassName(type.getTypeName()), params, new NullToken());
|
String name = type.getTypeName();
|
||||||
|
if(name.contains("<")){ //Komischer fix. Type von Generischen Typen kann die Generics im Namen enthalten Type<A>
|
||||||
|
//Diese entfernen:
|
||||||
|
name = name.split("<")[0];
|
||||||
|
}
|
||||||
|
RefType ret = new RefType(new JavaClassName(name), params, new NullToken());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,23 @@ public class SuperInterfacesTest {
|
|||||||
classes.add(ASTFactory.createClass(TestClass.class));
|
classes.add(ASTFactory.createClass(TestClass.class));
|
||||||
System.out.println(FCGenerator.toFC(classes));
|
System.out.println(FCGenerator.toFC(classes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGeneric() throws ClassNotFoundException {
|
||||||
|
Collection<ClassOrInterface> classes = new ArrayList<>();
|
||||||
|
classes.add(ASTFactory.createClass(TestClassGeneric.class));
|
||||||
|
System.out.println(FCGenerator.toFC(classes));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestClass implements Test2, Test3{
|
class TestClass implements Test2, Test3{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestClassGeneric<A,B> implements Test4<A>{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
interface Test2 {
|
interface Test2 {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -29,3 +40,7 @@ interface Test2 {
|
|||||||
interface Test3{
|
interface Test3{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Test4<A>{
|
||||||
|
|
||||||
|
}
|
14
test/javFiles/MethodCallGenerics.jav
Normal file
14
test/javFiles/MethodCallGenerics.jav
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import java.lang.String;
|
||||||
|
|
||||||
|
class Generics<B> {
|
||||||
|
//<A extends B> A mt1(A a, B b){
|
||||||
|
B mt1(B a, B b){
|
||||||
|
return mt1(a, a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
methode(String s){
|
||||||
|
return new Generics<String>().mt1(s,s);
|
||||||
|
}
|
||||||
|
}
|
5
test/javFiles/Package.jav
Normal file
5
test/javFiles/Package.jav
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package strucType.input;
|
||||||
|
|
||||||
|
class Neu
|
||||||
|
{
|
||||||
|
}
|
@ -50,7 +50,8 @@ public class JavaTXCompilerTest {
|
|||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void genericsMethodCall() throws IOException, ClassNotFoundException {
|
public void genericsMethodCall() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"MethodCallGenerics.jav"));
|
TestResultSet result = execute(new File(rootDirectory+"MethodCallGenerics.jav"));
|
||||||
|
//TODO: Hier sollte der Rückgabetyp der Methode String sein
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void faculty() throws IOException, ClassNotFoundException {
|
public void faculty() throws IOException, ClassNotFoundException {
|
||||||
@ -65,6 +66,10 @@ public class JavaTXCompilerTest {
|
|||||||
execute(new File(rootDirectory+"Matrix.jav"));
|
execute(new File(rootDirectory+"Matrix.jav"));
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
|
public void packageTests() throws IOException, ClassNotFoundException {
|
||||||
|
execute(new File(rootDirectory+"Package.jav"));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
public void vector() throws IOException, ClassNotFoundException {
|
public void vector() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"Vector.jav"));
|
execute(new File(rootDirectory+"Vector.jav"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user