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<>();
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.superClass = superClass;

View File

@ -18,6 +18,12 @@ public class JavaClassName {
public JavaClassName(String name){
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("[.]");
boolean match = true;
if(names.length == 1){

View File

@ -1026,67 +1026,5 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
public boolean isInterface(){
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

View File

@ -53,4 +53,10 @@ public class ASTFactory {
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
String combinedType = getCombinedType(cg);
if(!combinedType.equals(get_Name())){
// TODO bytecode createClass
Class generatedClass = ASTFactory.createClass(getCombinedType(cg), getParentClass());
if(!combinedType.equals(getName().toString())){
// TODO bytecode statt getParentClass die eigene Class?!?!
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());
}
return "L"+getCombinedType(cg)+";";
return "L"+combinedType+";";
}
public String getCombinedType(ClassGenerator cg){
@ -858,14 +859,14 @@ public class RefType extends ObjectType implements IMatchable
StringBuilder sb = new StringBuilder();
if(parameter != null && parameter.size() > 0){
sb.append(this.get_Name().replace(".", "%"));
sb.append(getName().toString().replace(".", "%"));
sb.append("%%");
for(Type type: parameter){
sb.append(((RefType) type).getCombinedType(cg).replace(".", "%"));
sb.append("%");
}
}else{
sb.append(this.get_Name());
sb.append(this.getName().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);
}
}