Package net.sourceforge.javautil.bytecode.api

Examples of net.sourceforge.javautil.bytecode.api.MethodDescriptor


   
    final BytecodeEmbedded cinit = this.getClassInitializer();
   
    if (cinit != null || this.defaultStaticValues.size() > 0) {
      BytecodeMethodConcrete clinit = new BytecodeMethodConcrete(this, "<clinit>", new TypeMemberAccess(Scope.Private, false, true, true),
        new MethodDescriptor(false, void.class, new Class[0], new Class[0]));
     
      clinit.setMethodBody(new BytecodeBlock() {
       
        @Override protected void writeInstructions(BytecodeContextMethod context) {
          for (String name : defaultStaticValues.keySet()) {
View Full Code Here


   * @param parameterTypes The types of parameters the method accepts
   * @return The abstract method
   */
  public BytecodeMethodAbstract addMethod (String name, boolean varArgs, Scope scope, String returnType, String... parameterTypes) {
    this.methods.add(new BytecodeMethodAbstract(this, name, new TypeMemberAccess(scope, true, false, false),
      new MethodDescriptor(varArgs, returnType, parameterTypes)));
    return (BytecodeMethodAbstract) this.methods.get(methods.size()-1);
  }
View Full Code Here

   * @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);
  }
View Full Code Here

    final BytecodeFieldDeclaration field = this.fields.get(fieldName);
    final boolean isStatic = field.getAccess().isStatic();
   
    BytecodeMethodConcrete getter = this.addMethod(getterName,
      new TypeMemberAccess(Scope.Public, false, isStatic, false),
      new MethodDescriptor(false, field.getType(), new TypeDescriptor[0])).setMethodBody(new BytecodeBlock() {
       
        @Override protected void writeInstructions(BytecodeContextMethod context) {
          context.returnValue(isStatic ? context.getStaticField(fieldName) : context.getThisField(fieldName));
        }
       
      });
   
    if (setterName != null) {
      this.addMethod(setterName,
        new TypeMemberAccess(Scope.Public, false, isStatic, false),
        new MethodDescriptor(false, TypeDescriptor.VOID, new TypeDescriptor[0], field.getType())).setMethodBody(new BytecodeBlock() {
         
          @Override protected void writeInstructions(BytecodeContextMethod context) {
            context.setArrayIndexValue(isStatic ? context.getStaticField(fieldName) : context.getThisField(fieldName), context.getDeclaredParameter(0));
          }
         
View Full Code Here

* @version $Id$
*/
public class BytecodeConstructorBase extends BytecodeMethodConcrete implements IBytecodeConstructor {
 
  public BytecodeConstructorBase(AbstractType type, TypeMemberAccess access, boolean varArgs, TypeDescriptor... parameterTypes) {
    super(type, "<init>", access, new MethodDescriptor(varArgs, TypeDescriptor.VOID, null, parameterTypes));
  }
View Full Code Here

   
    context.getClassWriter().visitSource(null, null);
  }
 
  public void writeMethod(BytecodeContextTypeASM context, IBytecodeMethod method) {
    MethodDescriptor md = method.getDescriptor();
   
    String[] exceptions = new String[md.getExceptionTypes() == null ? 0 : md.getExceptionTypes().length];
    for (int i=0; i<exceptions.length; i++) {
      exceptions[i] = md.getExceptionTypes()[i].getName();
    }
   
    int access = getAccess(method);
    String desc = md.toDescriptorString();
   
    MethodVisitor mv = context.getClassWriter().visitMethod(access, method.getName(), desc, null, exceptions);
    for (IBytecodeAnnotation ba : method.getDeclaredAnnotations()) {
      this.declareAnnotation(context, ba, mv.visitAnnotation(ba.getType().getType().toDescriptorString(), true));
    }
View Full Code Here

    if (abilities != null && abilities.size() > 0) {
      this.addInstanceField(ABILITIES_FIELD_NAME, Map.class, Scope.Private, true);
      this.abilities = abilities;
    }
   
    this.addMethod("set$Interceptor", Scope.Private, false, true, new MethodDescriptor(false, null, null, IInterceptorManager.class))
      .setMethodBody(new BytecodeBlock() {
       
        @Override protected void writeInstructions(BytecodeContextMethod context) {
          context.set("this", INTERCEPTOR_FIELD_NAME, context.getDeclaredParameter(0));
        }
View Full Code Here

    }
   
    try {
      Method toString = type.getMethod("toString");
      if (toString.getDeclaringClass() == Object.class) {
        this.addMethod("toString", Scope.Public, false, true, new MethodDescriptor(toString))
          .setMethodBody(new BytecodeBlock() {
           
            @Override protected void writeInstructions(BytecodeContextMethod context) {
              context.returnValue(context.createConcat(context.translate(
                context.createInvocation(context.resolve("this"), "getClass")
View Full Code Here

    }
   
    try {
      Method toString = type.getMethod("toString");
      if (toString.getDeclaringClass() == Object.class) {
        this.addMethod("toString", Scope.Public, false, true, new MethodDescriptor(toString))
          .setMethodBody(new BytecodeBlock() {
           
            @Override protected void writeInstructions(BytecodeContextMethod context) {
              context.returnValue(context.createInvocation(
                context.getThisField(TARGET_FIELD_NAME).createInvocation(context, "get", context.resolve("this")), "toString")
View Full Code Here

TOP

Related Classes of net.sourceforge.javautil.bytecode.api.MethodDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.