- Method refactored

This commit is contained in:
Enrico Schrödter 2016-04-25 14:58:52 +02:00
parent 8bad95f774
commit 8bda352bc9

View File

@ -613,45 +613,41 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
DHBWInstructionFactory _factory = cg.getInstructionFactory();
for(TypeinferenceResultSet t: typeInterferenceResults){
DHBWConstantPoolGen _cp = cg.getConstantPool();
InstructionList il = new InstructionList();
Class parentClass = this.getParentClass();
//Die Argumentliste generieren:
org.apache.commons.bcel6.generic.Type[] argumentTypes = org.apache.commons.bcel6.generic.Type.NO_ARGS;
String[] argumentNames = new String[]{};
if(this.parameterlist != null && this.parameterlist.size() > 0){
argumentTypes = new org.apache.commons.bcel6.generic.Type[this.parameterlist.size()];
argumentNames = new String[this.parameterlist.size()];
int i = 0;
for(FormalParameter parameter : this.parameterlist){
argumentTypes[i] = parameter.getType().getBytecodeType(cg, t);
argumentNames[i] = parameter.getIdentifier();
_factory.getStoreIndex(parameter.getIdentifier());
i++;
}
}
String nameAndSignature = get_Method_Name()+Arrays.toString(argumentTypes);
Logger.getLogger("nameAndSignature").error(nameAndSignature, Section.CODEGEN);
addMethodToClassGenerator(cg, _factory, t);
}
}
short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public
if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC;
Type returnType = this.getType();
private void addMethodToClassGenerator(ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) {
DHBWConstantPoolGen _cp = cg.getConstantPool();
InstructionList il = new InstructionList();
org.apache.commons.bcel6.generic.Type[] argumentTypes = org.apache.commons.bcel6.generic.Type.NO_ARGS;
String[] argumentNames = new String[]{};
if(this.parameterlist != null && this.parameterlist.size() > 0){
generateArgumentList(argumentTypes, argumentNames, cg, _factory, t);
}
short constants = Constants.ACC_PUBLIC;
if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC;
Type returnType = this.getType();
MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes , argumentNames, this.get_Method_Name(), getParentClass().name, il, _cp);
cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t));
}
private void generateArgumentList(org.apache.commons.bcel6.generic.Type[] argumentTypes, String[] argumentNames, ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) {
argumentTypes = new org.apache.commons.bcel6.generic.Type[this.parameterlist.size()];
argumentNames = new String[this.parameterlist.size()];
int i = 0;
for(FormalParameter parameter : this.parameterlist){
argumentTypes[i] = parameter.getType().getBytecodeType(cg, t);
argumentNames[i] = parameter.getIdentifier();
//Methode generieren:
MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp);
_factory.getStoreIndex(parameter.getIdentifier());
//Methode generieren und anfügen:
cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t));
Logger.getLogger("createMethod").debug(this.toString(), Section.CODEGEN);
i++;
}
}
}