Package net.sourceforge.javautil.bytecode.api.type.method

Examples of net.sourceforge.javautil.bytecode.api.type.method.BytecodeBlock


   
    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()) {
            context.set(context.getStaticField(name), defaultStaticValues.get(name));
          }
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

  public class DefaultConstructor extends BytecodeConstructorBase {

    public DefaultConstructor() {
      super(JavaClass.this, new TypeMemberAccess(Scope.Public, false, false, false), false);
     
      this.setMethodBody(new BytecodeBlock() {
       
        @Override protected void writeInstructions(BytecodeContextMethod context) {
          context.createSuperConstructorInvocation().load(context);
          context.returnVoid();
        }
View Full Code Here

      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

    }
  }
 
  @Override public void addProxyMethods() {
    final InterceptorProxyMethod apm = new InterceptorProxyMethod();
    BytecodeBlock apmb = new BytecodeBlock() {
     
      @Override protected void writeInstructions(BytecodeContextMethod context) {
        apm.write(context);
      }
     
    };
   
    IBytecodeResolvable st = getSuperType();
    while (st != null && !"java.lang.Object".equals( st.getType().getClassName() )) {
      for (IBytecodeMethod method : st.getDeclaredMethods()) {
        if (method.getAccess().isStatic() || method.getAccess().getScope() != Scope.Public) continue;
        this.addMethod(method.getName() + "$$", Scope.Private, false, true, method.getDescriptor()).setMethodBody(
          new BytecodeBlock() {
            @Override protected void writeInstructions(BytecodeContextMethod context) {
              context.returnValue(
                context.createSuperInvocation(context.getMethod().getName().split("\\$")[0], context.getMethodArguments())
              );
            }
          }
        );
       
        BytecodeMethodConcrete bmc = this.addMethod(method.getName(), Scope.Public, false, true, method.getDescriptor());
        bmc.copyAnnotations(method);
        bmc.setMethodBody(apmb);
      }
     
      st = st.getSuperType();
    }
   
    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")
                  .createInvocation(context, "getSuperclass")
View Full Code Here

    }
  }
 
  @Override public void addProxyMethods() {
    final InterceptorProxyMethod apm = new InterceptorProxyMethod();
    BytecodeBlock apmb = new BytecodeBlock() {
     
      @Override protected void writeInstructions(BytecodeContextMethod context) {
        apm.write(context);
      }
     
    };
   
    IBytecodeResolvable st = getSuperType();
    while (st != null && !"java.lang.Object".equals( st.getType().getClassName() )) {
      for (IBytecodeMethod method : st.getDeclaredMethods()) {
        if (method.getAccess().isStatic() || method.getAccess().getScope() != Scope.Public) continue;
       
        BytecodeMethodConcrete bmc = this.addMethod(method.getName(), Scope.Public, false, true, method.getDescriptor());
        bmc.copyAnnotations(method);
        bmc.setMethodBody(apmb);
      }
     
      st = st.getSuperType();
    }
   
    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.type.method.BytecodeBlock

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.