From 49ea4ee28379d5bd1ceafe2eaa151f8a0030d12a Mon Sep 17 00:00:00 2001 From: Fayez Abu Alia Date: Tue, 8 May 2018 10:19:13 +0200 Subject: [PATCH] Pfad der erzeugten klassendateien angepasst --- src/de/dhbwstuttgart/bytecode/BytecodeGen.java | 6 ++++++ .../bytecode/descriptor/DescriptorToString.java | 6 +++--- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 2 +- test/bytecode/javFiles/Gen.jav | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java index 07bb7308f..52feb6e5f 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java @@ -187,7 +187,11 @@ public class BytecodeGen implements ASTVisitor { // Method getModifiers() ? int acc = isInterface?Opcodes.ACC_ABSTRACT:method.modifier; System.out.println(acc); + + /*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/ boolean hasGenInParameterList = genericsAndBounds.containsKey(resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())); + /*Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature, wenn nicht, + * prüfe, ob einer der Parameter Typ-Variable als Typ hat*/ if(!hasGenInParameterList) { for(String paramName : methodParamsAndTypes.keySet()) { String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor()); @@ -202,6 +206,8 @@ public class BytecodeGen implements ASTVisitor { //then create the descriptor with the new syntax. String sig = null; + /* method.getGenerics: <....> RT method(..) + * */ boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList; /* if method has generics or return type is TPH, create signature */ diff --git a/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java b/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java index 202b647b9..65f48f71d 100644 --- a/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java +++ b/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java @@ -50,9 +50,9 @@ public class DescriptorToString implements DescriptorVisitor{ } } //TODO: generate a class java%% ... %% -// else if(((RefType) fp.getType()).getParaList().size() > 0){ -// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "%").replace("<", "%%").replace(">", "%%")+ ";"; -// } + else if(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()).contains("<")){ + desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "%").replace("<", "%%").replace(">", "%%")+ ";"; + } else { desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";"; } diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 4aaf23dc9..ec74f0dab 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -150,7 +150,7 @@ public class JavaTXCompiler { for(String name : classFiles.keySet()) { byte[] bytecode = classFiles.get(name); System.out.println("generating "+name+ ".class file ..."); - output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/examples/" +name+".class")); + output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" +name+".class")); output.write(bytecode); output.close(); System.out.println(name+".class file generated"); diff --git a/test/bytecode/javFiles/Gen.jav b/test/bytecode/javFiles/Gen.jav index b94ec4459..5d579eb8e 100644 --- a/test/bytecode/javFiles/Gen.jav +++ b/test/bytecode/javFiles/Gen.jav @@ -2,7 +2,7 @@ import java.lang.Integer; import java.util.Vector; public class Gen{ - Vector m(Vector v){ + Vector m(Vector v){ return v; } -} \ No newline at end of file +}