package de.dhbwstuttgart.syntaxtree; import de.dhbwstuttgart.typeinference.Menge; import java.util.Iterator; import java.util.List; import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; public class ParameterList extends SyntaxTreeNode implements Iterable { public List formalparameter = new Menge(); public ParameterList(List params){ this.formalparameter = params; } public FormalParameter getParameterAt(int i) { if (i >= formalparameter.size() ) return null; return formalparameter.get(i); } public List sc_get_Formalparalist() { return formalparameter; } /** * Author: J�rg B�uerle
* @return Die Anzahl der Parameter */ public int getParameterCount() { return formalparameter.size(); } public String toString(){ if(formalparameter == null)return "[]"; //"Leere Parameterliste"; //String ret = "ParameterListe, "+formalparameter.size()+" Einträge [ "; String ret = " [ "; for(FormalParameter param : this.formalparameter){ ret += param.toString()+", "; } return ret + "]"; } public JavaCodeResult printJavaCode(ResultSet resultSet) { JavaCodeResult ret = new JavaCodeResult(); Iterator it = this.formalparameter.iterator(); while(it.hasNext()){ FormalParameter param = it.next(); ret.attach(param.printJavaCode(resultSet)); if(it.hasNext())ret.attach(", "); } //if(this.formalparameter.size()>0)ret = ret.substring(0, ret.length() - 2); return ret; } @Override public Iterator iterator() { return this.formalparameter.iterator(); } @Override public boolean equals(Object obj) { if(!(obj instanceof ParameterList))return false; ParameterList equals = (ParameterList)obj; if((this.formalparameter == null )!=(equals.formalparameter==null))return false; if(this.formalparameter!=null)return this.formalparameter.equals(equals.formalparameter); return true; } @Override public int getOffset() { if(formalparameter == null || formalparameter.size()==0)return 0; return formalparameter.get(0).getOffset(); } @Override public List getChildren() { return formalparameter; } public int size() { return this.formalparameter.size(); } public org.apache.bcel.generic.Type[] getBytecodeTypeList(ClassGenerator cg, TypeinferenceResultSet rs){ org.apache.bcel.generic.Type[] ret = new org.apache.bcel.generic.Type[formalparameter.size()]; int i = 0; for(FormalParameter f : formalparameter){ ret[i] = f.getType().getBytecodeType(cg, rs); i++; } return ret; } public String[] getParameterNameArray() { String[] ret = new String[formalparameter.size()]; int i = 0; for(FormalParameter f : formalparameter){ ret[i] = f.getIdentifier(); i++; } return ret; } }