JavaClassName: Hack damit Object zu java.lang.Object wird. Muss unbedingt anders gelöst werden

This commit is contained in:
Enrico Schrödter 2015-10-23 16:23:20 +02:00
parent 77c06225a6
commit b99f1bc3c9
6 changed files with 32 additions and 69 deletions

View File

@ -35,7 +35,7 @@ public class ClassGenerator extends ClassGen{
private Map<String, ClassGenerator> extraClasses = new HashMap<>(); private Map<String, ClassGenerator> extraClasses = new HashMap<>();
public ClassGenerator(String name, Type superClass, String string, short accPublic, String[] strings, TypeinferenceResultSet resultSet) { public ClassGenerator(String name, Type superClass, String string, short accPublic, String[] strings, TypeinferenceResultSet resultSet) {
super(name,superClass.get_Name(),string,accPublic,strings, new DHBWConstantPoolGen()); super(name,superClass.getName().toString(),string,accPublic,strings, new DHBWConstantPoolGen());
this.tiResult = resultSet; this.tiResult = resultSet;
this.superClass = superClass; this.superClass = superClass;

View File

@ -18,6 +18,12 @@ public class JavaClassName {
public JavaClassName(String name){ public JavaClassName(String name){
if(name == null)throw new NullPointerException(); if(name == null)throw new NullPointerException();
//TODO bytecode hack, muss unbedingt anders gelöst werden
if(name.equals("Object")){
name = "java.lang.Object";
}
String[] names = name.split("[.]"); String[] names = name.split("[.]");
boolean match = true; boolean match = true;
if(names.length == 1){ if(names.length == 1){

View File

@ -1026,67 +1026,5 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
public boolean isInterface(){ public boolean isInterface(){
return false; return false;
} }
/*
private Collection<? extends ByteCodeResult> getGenericClasses() {
Collection<ByteCodeResult> results = new Menge<>();
for(Field field : this.fielddecl){
Type type = field.getType();
//Der Type des Feldes
if(type instanceof RefType){
RefType refType = (RefType) type;
if(!refType.getCombinedType(null).equals(refType.get_Name().replace(".", "%"))){
results.addAll(generateGenericClass(refType.getCombinedType(null), new Class("java/util/Vector",-1)));
}
}
if(field instanceof Method){
Method method = (Method) field;
ParameterList parameterList = method.getParameterList();
//Die Typen der Methodenparameter
for(FormalParameter parameter: parameterList){
Type parameterType = parameter.getType();
if(parameterType instanceof RefType){
RefType refType = (RefType) parameterType;
if(!refType.getCombinedType(null).equals(refType.get_Name().replace(".", "%"))){
results.addAll(generateGenericClass(refType.getCombinedType(null), new Class("java/util/Vector",-1)));
}
}
}
}
}
return results;
}
*/
/*
private Menge<ByteCodeResult> generateGenericClass(String name, Class superClass){
//TODO: bytecode -- Generics hinzufügen
//Type superClassType = superClass.getType();
//TODO: bytecode
//ClassGenerator genericClassGenerator = new ClassGenerator(name, superClassType, name + ".java", Constants.ACC_PUBLIC , new String[] { }, new TypeinferenceResultSet(null, null, null));
//TODO: bytecode -- Namen der neuen Klasse
Class generatedClass = new Class(name, 0);
//TODO: bytecode -- alle Konstruktoren generieren
Block konstruktorBlock = new Block();
konstruktorBlock.setType(new de.dhbwstuttgart.syntaxtree.type.Void(konstruktorBlock, 0));
konstruktorBlock.statements.add(new SuperCall(konstruktorBlock));
Constructor standardKonstruktor = new Constructor(Method.createEmptyMethod(konstruktorBlock, name, superClass), superClass);
standardKonstruktor.parserPostProcessing(generatedClass);
generatedClass.addField(standardKonstruktor);
return generatedClass.genByteCode(new TypeinferenceResultSet(generatedClass, new Menge<>(), new ResultSet()));
}
*/
} }
// ino.end // ino.end

View File

@ -53,4 +53,10 @@ public class ASTFactory {
return generatedClass; return generatedClass;
} }
public static Class createObjectClass() {
Class generatedClass = new Class("java.lang.Object", 0);
return generatedClass;
}
} }

View File

@ -843,14 +843,15 @@ public class RefType extends ObjectType implements IMatchable
//TODO: bytecode woher bekommt ich die parent klasse //TODO: bytecode woher bekommt ich die parent klasse
String combinedType = getCombinedType(cg); String combinedType = getCombinedType(cg);
if(!combinedType.equals(get_Name())){ if(!combinedType.equals(getName().toString())){
// TODO bytecode createClass // TODO bytecode statt getParentClass die eigene Class?!?!
Class generatedClass = ASTFactory.createClass(getCombinedType(cg), getParentClass()); Class classObject = ASTFactory.createClass(getName().toString(), ASTFactory.createObjectClass());
Class generatedClass = ASTFactory.createClass(getCombinedType(cg), classObject);
cg.addExtraClass(generatedClass.genByteCode(new TypeinferenceResultSet(generatedClass, new Menge<>(), new ResultSet())).getByteCode()); cg.addExtraClass(generatedClass.genByteCode(new TypeinferenceResultSet(generatedClass, new Menge<>(), new ResultSet())).getByteCode());
} }
return "L"+getCombinedType(cg)+";"; return "L"+combinedType+";";
} }
public String getCombinedType(ClassGenerator cg){ public String getCombinedType(ClassGenerator cg){
@ -858,14 +859,14 @@ public class RefType extends ObjectType implements IMatchable
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if(parameter != null && parameter.size() > 0){ if(parameter != null && parameter.size() > 0){
sb.append(this.get_Name().replace(".", "%")); sb.append(getName().toString().replace(".", "%"));
sb.append("%%"); sb.append("%%");
for(Type type: parameter){ for(Type type: parameter){
sb.append(((RefType) type).getCombinedType(cg).replace(".", "%")); sb.append(((RefType) type).getCombinedType(cg).replace(".", "%"));
sb.append("%"); sb.append("%");
} }
}else{ }else{
sb.append(this.get_Name()); sb.append(this.getName().toString());
} }
return sb.toString(); return sb.toString();

View File

@ -0,0 +1,12 @@
import java.util.Vector;
public class Test {
public static void main(String[] args) {
Overloading o = new Overloading();
Vector<String> stringVector = new Vector<String>();
o.method(stringVector);
}
}