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

Source Code of net.sourceforge.javautil.bytecode.api.type.BytecodeFieldDeclaration

package net.sourceforge.javautil.bytecode.api.type;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

import net.sourceforge.javautil.bytecode.api.IBytecodeAssignable;
import net.sourceforge.javautil.bytecode.api.IBytecodeField;
import net.sourceforge.javautil.bytecode.api.IBytecodeMember;
import net.sourceforge.javautil.bytecode.api.IBytecodeReferenceable;
import net.sourceforge.javautil.bytecode.api.BytecodeReferenceableAbstract;
import net.sourceforge.javautil.bytecode.api.IBytecodeResolvable;
import net.sourceforge.javautil.bytecode.api.TypeDescriptor;
import net.sourceforge.javautil.bytecode.api.TypeMemberAccess;
import net.sourceforge.javautil.bytecode.api.type.method.BytecodeContextMethod;
import net.sourceforge.javautil.bytecode.api.type.method.invocation.MethodInvocation;

/**
* The declaration of a field in for {@link AbstractType}'s.
*
* @author elponderador
* @author $Author$
* @version $Id$
*/
public class BytecodeFieldDeclaration extends BytecodeAnnotatedMember implements IBytecodeAssignable<BytecodeContextMethod>, IBytecodeMember, IBytecodeField {
 
  protected final String name;
  protected final TypeMemberAccess access;
  protected final TypeDescriptor type;

  public BytecodeFieldDeclaration(String name, TypeMemberAccess access, AbstractType declaringType, TypeDescriptor type) {
    super(declaringType);
    this.name = name;
    this.access = access;
    this.type = type;
  }
 
  public String getName() { return name; }

  public TypeMemberAccess getAccess() { return this.access; }

  public MethodInvocation createInvocation(BytecodeContextMethod context, String name, IBytecodeReferenceable... parameters) {
    return new MethodInvocation(this, getType(context).findMethod(context.getResolutionPool(), name, context.getTypes(parameters)), parameters);
  }

  public TypeDescriptor getType() {
    return type;
  }

  public IBytecodeResolvable getType(BytecodeContextMethod ctx) {
    return ctx.getResolutionPool().resolve(type.getClassName());
  }

  public void load(BytecodeContextMethod context) {
    if (this.access.isStatic()) {
      context.getWriter().loadStaticField(context, this.declaringType, name);
    } else {
      context.getWriter().loadField(context, this.declaringType, name);
    }
  }

  public void store(BytecodeContextMethod context) {
    if (this.access.isStatic()) {
      context.getWriter().storeStaticField(context, this.declaringType, name);
    } else {
      context.getWriter().storeField(context, this.declaringType, name);
    }
  }

}
TOP

Related Classes of net.sourceforge.javautil.bytecode.api.type.BytecodeFieldDeclaration

TOP
Copyright © 2018 www.massapi.com. 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.