55 lines
1.5 KiB
Java
55 lines
1.5 KiB
Java
package de.dhbwstuttgart.bytecode;
|
|
|
|
import java.awt.List;
|
|
import java.util.Iterator;
|
|
|
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
|
import de.dhbwstuttgart.syntaxtree.Method;
|
|
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
|
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|
|
|
public class Descriptor {
|
|
String desc;
|
|
|
|
public Descriptor(Method method) {
|
|
desc = "(";
|
|
Iterator<FormalParameter> itr = method.getParameterList().iterator();
|
|
while(itr.hasNext()) {
|
|
FormalParameter fp = itr.next();
|
|
desc = desc + "L"+fp.getType().toString().replace(".", "/") + ";";
|
|
}
|
|
if(method.getReturnType().toString().equals("void")){
|
|
desc = desc + ")V";
|
|
}else {
|
|
desc = desc + ")" + "L"+method.getReturnType().toString().replace(".", "/")+";";
|
|
}
|
|
|
|
}
|
|
|
|
public Descriptor(Constructor constructor) {
|
|
desc = "(";
|
|
Iterator<FormalParameter> itr = constructor.getParameterList().iterator();
|
|
while(itr.hasNext()) {
|
|
FormalParameter fp = itr.next();
|
|
desc = desc + "L"+fp.getType().toString().replace(".", "/") + ";";
|
|
}
|
|
desc = desc + ")V";
|
|
}
|
|
|
|
public Descriptor(ArgumentList argList, RefTypeOrTPHOrWildcardOrGeneric returnType) {
|
|
desc = "(";
|
|
for(Expression e : argList.getArguments()) {
|
|
desc = desc + "L"+e.getType().toString().replace(".", "/") + ";";
|
|
}
|
|
desc = desc + ")"+returnType.toString();
|
|
|
|
}
|
|
|
|
public String getDesc() {
|
|
return this.desc;
|
|
}
|
|
|
|
}
|