JavaTXCompilerInJavaTX/src/de/dhbwstuttgart/syntaxtree/ParameterList.java

121 lines
3.1 KiB
Java
Raw Normal View History

2014-09-02 08:33:54 +00:00
package de.dhbwstuttgart.syntaxtree;
2016-12-07 13:32:48 +00:00
import de.dhbwstuttgart.typeinference.Menge;
2014-04-09 12:12:55 +00:00
2013-10-18 11:33:46 +00:00
import java.util.Iterator;
2016-09-13 15:32:22 +00:00
import java.util.List;
2013-10-18 11:33:46 +00:00
import de.dhbwstuttgart.bytecode.ClassGenerator;
2014-09-02 08:33:54 +00:00
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
2014-09-02 08:33:54 +00:00
2013-10-18 11:33:46 +00:00
public class ParameterList extends SyntaxTreeNode implements Iterable<FormalParameter>
2013-10-18 11:33:46 +00:00
{
2016-09-13 15:32:22 +00:00
public List<FormalParameter> formalparameter = new Menge<FormalParameter>();
2013-10-18 11:33:46 +00:00
2016-09-13 15:32:22 +00:00
public ParameterList(List<FormalParameter> params){
this.formalparameter = params;
2013-10-18 11:33:46 +00:00
}
2016-12-07 13:32:48 +00:00
2013-10-18 11:33:46 +00:00
public FormalParameter getParameterAt(int i)
{
if (i >= formalparameter.size() ) return null;
2016-09-13 15:32:22 +00:00
return formalparameter.get(i);
2013-10-18 11:33:46 +00:00
}
2016-09-13 15:32:22 +00:00
public List<FormalParameter> sc_get_Formalparalist()
2013-10-18 11:33:46 +00:00
{
return formalparameter;
}
/**
* Author: ¯Â¿Â½rg ¯Â¿Â½uerle<br/>
2013-10-18 11:33:46 +00:00
* @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 [ ";
2013-10-18 11:33:46 +00:00
String ret = " [ ";
for(FormalParameter param : this.formalparameter){
ret += param.toString()+", ";
}
return ret + "]";
}
public JavaCodeResult printJavaCode(ResultSet resultSet) {
JavaCodeResult ret = new JavaCodeResult();
Iterator<FormalParameter> 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;
}
2014-02-19 16:32:43 +00:00
@Override
public Iterator<FormalParameter> iterator() {
return this.formalparameter.iterator();
}
2014-04-09 12:12:55 +00:00
@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;
2016-09-13 15:32:22 +00:00
return formalparameter.get(0).getOffset();
}
@Override
2016-09-13 15:32:22 +00:00
public List<? extends SyntaxTreeNode> getChildren() {
return formalparameter;
}
2015-08-27 11:36:14 +00:00
public int size() {
return this.formalparameter.size();
}
2016-07-21 14:36:33 +00:00
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;
}
2013-10-18 11:33:46 +00:00
}