Example usage for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding getField

List of usage examples for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding getField

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding getField.

Prototype

@Override
    public FieldBinding getField(char[] fieldName, boolean needResolve) 

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.RoleMigrationImplementor.java

License:Open Source License

static void genMigrateToBaseInstructions(CodeStream codeStream, SourceTypeBinding roleBinding, Scope scope,
        char[] cacheName) {
    FieldBinding baseField = roleBinding.getField(IOTConstants._OT_BASE, true);
    // accessing the cache (using remove() and put()):
    ReferenceBinding cacheTypeBinding = (ReferenceBinding) scope.getType(IOTConstants.WEAK_HASH_MAP, 3);
    MethodBinding remove = getMethod(cacheTypeBinding, "remove".toCharArray(), 1); //$NON-NLS-1$
    MethodBinding put = cacheTypeBinding.getMethod(scope, "put".toCharArray()); //$NON-NLS-1$
    // accessing the base object (using _OT$removeRole() and _OT$addRole()):
    WeavingScheme weavingScheme = scope.compilerOptions().weavingScheme;
    ReferenceBinding iboundBase = (ReferenceBinding) scope
            .getType(weavingScheme == WeavingScheme.OTDRE ? IOTConstants.ORG_OBJECTTEAMS_IBOUNDBASE2
                    : IOTConstants.ORG_OBJECTTEAMS_IBOUNDBASE, 3);

    // remove old from cache
    codeStream.aload_0(); // this
    codeStream.fieldAccess(Opcodes.OPC_getfield, enclosingInstanceField(roleBinding), // this.this$n
            roleBinding);//w ww  .  j a va2  s  .c  o m
    codeStream.fieldAccess(Opcodes.OPC_getfield, roleBinding.enclosingType().getField(cacheName, true), // this.this$n._OT$cache$R
            roleBinding.enclosingType());
    codeStream.dup(); // for use in put() below
    codeStream.aload_0(); // this
    codeStream.fieldAccess(Opcodes.OPC_getfield, baseField, // this._OT$base
            roleBinding);
    codeStream.dup(); // share for nested method call         // this._OT$base
    // remove role from this (old) base
    genAddOrRemoveRole(codeStream, scope, iboundBase, false);// -> void      // -> base._OT$removeRole(this)
    codeStream.invoke(Opcodes.OPC_invokevirtual, remove, // -> cache.remove(base)
            cacheTypeBinding);
    codeStream.pop(); // discard result

    // this._OT$base = (MyBase)otherBase
    codeStream.aload_0(); // this
    codeStream.aload_1(); // otherBase
    codeStream.checkcast(roleBinding.baseclass());
    codeStream.fieldAccess(Opcodes.OPC_putfield, baseField, roleBinding);

    // add new to cache (cache is still on the stack)
    codeStream.aload_1(); // otherBase
    codeStream.aload_0(); // this (role)
    codeStream.invoke(Opcodes.OPC_invokevirtual, put, cacheTypeBinding);

    // add to new base:
    codeStream.aload_1(); // otherBase
    genAddOrRemoveRole(codeStream, scope, iboundBase, true); // -> void      // -> base._OT$addRemoveRole(this, false)

    codeStream.return_();
}