Example usage for org.eclipse.jdt.internal.compiler.lookup TypeConstants SYNTHETIC_OUTER_LOCAL_PREFIX

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

Introduction

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

Prototype

null SYNTHETIC_OUTER_LOCAL_PREFIX

To view the source code for org.eclipse.jdt.internal.compiler.lookup TypeConstants SYNTHETIC_OUTER_LOCAL_PREFIX.

Click Source Link

Usage

From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java

License:Open Source License

public FieldBinding addSyntheticFieldForInnerclass(LocalVariableBinding actualOuterLocalVariable) {
    if (this.synthetics == null)
        this.synthetics = new HashMap[MAX_SYNTHETICS];
    if (this.synthetics[SourceTypeBinding.FIELD_EMUL] == null)
        this.synthetics[SourceTypeBinding.FIELD_EMUL] = new HashMap(5);

    FieldBinding synthField = (FieldBinding) this.synthetics[SourceTypeBinding.FIELD_EMUL]
            .get(actualOuterLocalVariable);
    if (synthField == null) {
        synthField = new SyntheticFieldBinding(
                CharOperation.concat(TypeConstants.SYNTHETIC_OUTER_LOCAL_PREFIX, actualOuterLocalVariable.name),
                actualOuterLocalVariable.type,
                ClassFileConstants.AccPrivate | ClassFileConstants.AccFinal | ClassFileConstants.AccSynthetic,
                this, Constant.NotAConstant, this.synthetics[SourceTypeBinding.FIELD_EMUL].size());
        this.synthetics[SourceTypeBinding.FIELD_EMUL].put(actualOuterLocalVariable, synthField);
    }/*w w  w  . java2  s  .  c o m*/

    // ensure there is not already such a field defined by the user
    boolean needRecheck;
    int index = 1;
    do {
        needRecheck = false;
        FieldBinding existingField;
        if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
            TypeDeclaration typeDecl = this.scope.referenceContext;
            FieldDeclaration[] fieldDeclarations = typeDecl.fields;
            int max = fieldDeclarations == null ? 0 : fieldDeclarations.length;
            for (int i = 0; i < max; i++) {
                FieldDeclaration fieldDecl = fieldDeclarations[i];
                if (fieldDecl.binding == existingField) {
                    synthField.name = CharOperation.concat(TypeConstants.SYNTHETIC_OUTER_LOCAL_PREFIX,
                            actualOuterLocalVariable.name, ("$" + String.valueOf(index++)).toCharArray()); //$NON-NLS-1$
                    needRecheck = true;
                    break;
                }
            }
        }
    } while (needRecheck);
    return synthField;
}

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;//from   w ww.j a v  a  2 s.  c  om
    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;
}