/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package peaconnector;

import java.util.ArrayList;

/**
 *
 * @author Csubák Péter
 */
public class SchemaMethodElement extends SchemaElement {

    private ArrayList<SchemaElement> parameters = new ArrayList<SchemaElement>();
    private SchemaElement returnType = null;

    public SchemaMethodElement(SEMethod annot) {
        super(annot.schemaName(), annot.name());
        this.parameters = getParameters(annot.parameters());
        this.returnType = annot.returnType().name().equals("void") ? null : SchemaElement.getByAnnot(annot.returnType());

    }

    public SchemaMethodElement(String schemaName, String name) {
        super(schemaName, name);
        this.parameters = null;
    }

    public SchemaMethodElement(String schemaName, String name, SchemaElement[] parameters) {
        super(schemaName, name);
        this.parameters = getParameters(parameters);
    }

    public SchemaMethodElement(String schemaName, String name, SchemaElement returnType) {
        super(schemaName, name);
        this.parameters = null;
        this.returnType = returnType;
    }

    public SchemaMethodElement(String schemaName, String name, SchemaElement returnType, SchemaElement[] parameters) {
        super(schemaName, name);
        this.parameters = getParameters(parameters);
        this.returnType = returnType;
    }

    private ArrayList<SchemaElement> getParameters(SchemaElement[] parameters){
        ArrayList<SchemaElement> res = new ArrayList<SchemaElement>();
        for (SchemaElement s : parameters){
            res.add(s);
        }
        return res;
    }

    private ArrayList<SchemaElement> getParameters(SEAnnot[] parameters){
        ArrayList<SchemaElement> res = new ArrayList<SchemaElement>();
        for (SEAnnot s : parameters){
            res.add(SchemaElement.getByAnnot(s));
        }
        return res;
    }

    public ArrayList<SchemaElement> getParameters() {
        return parameters;
    }

    public SchemaElement getReturnType() {
        return returnType;
    }

}
