Example usage for org.eclipse.jdt.internal.compiler.lookup FieldBinding FieldBinding

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

Introduction

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

Prototype

public FieldBinding(FieldBinding initialFieldBinding, ReferenceBinding declaringClass) 

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectMapper.java

License:Open Source License

/**
 * This method realizes the logic of the mapping for fields.
 * @param srcMethod        where to copy from
 * @param refFieldBinding  what to copy/remap
 * @param dstTeam          where to copy to
 * @return destination field//from  www . j a  va2s  . co  m
 */
public static FieldBinding mapField(MethodBinding srcMethod, FieldBinding refFieldBinding,
        ReferenceBinding dstTeam) {
    // if Binding points at Role-Field of Superteamclass, then mapping must be done
    if (dstTeam != null) {
        if (isMappableField(refFieldBinding)) {
            if (refFieldBinding.isSynthetic()) {
                RoleModel role = ((ReferenceBinding) mapClass(srcMethod, refFieldBinding.declaringClass,
                        dstTeam)).roleModel;
                if (role != null) {
                    FieldBinding dstField = role.mapSyntheticField(refFieldBinding);
                    if (dstField != null)
                        return dstField;
                }
            }
            ReferenceBinding refTeamBinding = getTeam(refFieldBinding);
            if (refTeamBinding != null) {
                ReferenceBinding srcTeamBinding = getTeam(srcMethod);
                if (srcTeamBinding != null) {
                    if (TypeBinding.equalsEquals(refTeamBinding, srcTeamBinding)) {
                        FieldBinding newBinding = searchRoleField(refFieldBinding, dstTeam);
                        if (newBinding != null && TypeBinding.notEquals(newBinding.declaringClass, dstTeam)
                                && !TeamModel.isTeamContainingRole(dstTeam, newBinding.declaringClass)) {
                            // field is declared neither in dstTeam nor one of its roles.
                            // find the class, that corresponds to the field's declaring class:
                            ReferenceBinding updatedClass = (ReferenceBinding) mapClass(srcMethod,
                                    newBinding.declaringClass, dstTeam);
                            // update field binding to new declaring class?
                            if (TypeBinding.notEquals(newBinding.declaringClass, updatedClass))
                                newBinding = new FieldBinding(newBinding, updatedClass);
                        }
                        return newBinding;
                    }
                }
            }
        }
    }
    return refFieldBinding;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectReader.java

License:Open Source License

private FieldBinding getFieldRef(int index) {
    int start = getConstantPoolStartPosition(index);
    assert (u1At(start) == FieldRefTag);
    int class_index = u2At(start + 1);
    int name_index = u2At(start + 3);
    ReferenceBinding class_rb = getClassBinding(class_index);
    ReferenceBinding actualReceiver = class_rb;
    if (class_rb == null)
        return null;

    char[][] nameandtype = getNameAndType(name_index);
    char[] name = nameandtype[0];
    char[] type = nameandtype[1];
    FieldBinding fb = null;// w  w  w .java2s.c  o  m
    if (class_rb.erasure() instanceof SourceTypeBinding) {
        SourceTypeBinding sourceType = (SourceTypeBinding) class_rb.erasure();
        // can't find synthetics in 'fields'.
        if (CharOperation.prefixEquals(TypeConstants.SYNTHETIC_OUTER_LOCAL_PREFIX, name))
            return sourceType.getSyntheticOuterLocal(name);
        if (CharOperation.prefixEquals(TypeConstants.SYNTHETIC_CLASS, name))
            return sourceType.getSyntheticClassLiteral(name);
    } // FIXME(SH): else read from RoleModel??

    do {
        fb = findFieldBinding(class_rb, name, type);
        if (fb != null) {
            if (TypeBinding.notEquals(actualReceiver, class_rb))
                // return sourceType.getUpdatedFieldBinding(fb, actualReceiver);
                // no sourceType available so directly create the updated binding:
                return new FieldBinding(fb, actualReceiver);
            return fb;
        }
        class_rb = class_rb.superclass();
    } while (!CharOperation.equals(class_rb.constantPoolName(), ConstantPool.JavaLangObjectConstantPoolName));
    return fb;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticRoleFieldAccess.java

License:Open Source License

private FieldBinding checkAdjustRoleFieldAccess(FieldBinding fieldBinding, CodeStream codeStream) {
    if (fieldBinding.declaringClass.isRole() && !fieldBinding.declaringClass.isInterface()) {
        ReferenceBinding roleType = fieldBinding.declaringClass;
        roleType = (ReferenceBinding) TeamModel.strengthenRoleType(this.declaringClass, roleType);
        roleType = roleType.getRealClass();
        if (!fieldBinding.isStatic())
            codeStream.checkcast(roleType); // receiver cast

        fieldBinding = new FieldBinding(fieldBinding, roleType);
    }//from   w  ww.  j  a v a  2 s.c  om
    return fieldBinding;
}