package net.sourceforge.javautil.bytecode.api.type;
import net.sourceforge.javautil.bytecode.BytecodeCompiler;
import net.sourceforge.javautil.bytecode.BytecodeException;
import net.sourceforge.javautil.bytecode.api.BytecodeContext;
import net.sourceforge.javautil.bytecode.api.IBytecodeResolvable;
import net.sourceforge.javautil.bytecode.api.MethodDescriptor;
import net.sourceforge.javautil.bytecode.api.TypeDescriptor;
import net.sourceforge.javautil.bytecode.api.TypeMemberAccess;
import net.sourceforge.javautil.bytecode.api.IBytecodeResolvable.ClassType;
import net.sourceforge.javautil.bytecode.api.TypeMemberAccess.Scope;
import net.sourceforge.javautil.bytecode.api.type.method.BytecodeMethodAbstract;
/**
* The base for a java interface type.
*
* @author elponderador
* @author $Author$
* @version $Id$
*/
public class JavaInterface<C extends BytecodeContextType> extends AbstractType<C> {
public JavaInterface(BytecodeCompiler compiler, String name, Scope scope, boolean isStatic, boolean isFinal) {
super(compiler, name, new TypeMemberAccess(scope, true, isStatic, isFinal), ClassType.Interface);
}
/**
* @param iface The interface to extend
*/
public JavaInterface addExtends (IBytecodeResolvable iface) {
if (iface.getClassType() != ClassType.Interface)
throw new BytecodeException("Not an interface: " + iface);
this.interfaces.add(iface);
return this;
}
/**
* @param name The name of the method
* @param returnType The return type, or null if void
* @param parameterTypes The types of parameters the method accepts
* @return The abstract method
*/
public BytecodeMethodAbstract addMethod (String name, boolean varArgs, String returnType, String... parameterTypes) {
this.methods.add(new BytecodeMethodAbstract(this, name, new TypeMemberAccess(Scope.Public, true, false, false),
new MethodDescriptor(varArgs, returnType, null, parameterTypes)));
return (BytecodeMethodAbstract) this.methods.get(methods.size()-1);
}
@Override public AbstractType cloneAs(String name, boolean isStatic, boolean isFinal) {
JavaInterface ji = new JavaInterface(compiler, name, access.getScope(), isStatic, isFinal);
this.internalClone(ji);
return ji;
}
}