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

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

Introduction

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

Prototype

null SYNTHETIC_ENCLOSING_INSTANCE_PREFIX

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

Click Source Link

Usage

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

License:Open Source License

public FieldBinding addSyntheticFieldForInnerclass(ReferenceBinding enclosingType) {
    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(enclosingType);
    if (synthField == null) {
        synthField = new SyntheticFieldBinding(
                CharOperation.concat(TypeConstants.SYNTHETIC_ENCLOSING_INSTANCE_PREFIX,
                        String.valueOf(enclosingType.depth()).toCharArray()),
                enclosingType,//  w  ww.  jav  a 2  s.  co m
                ClassFileConstants.AccDefault | ClassFileConstants.AccFinal | ClassFileConstants.AccSynthetic,
                this, Constant.NotAConstant, this.synthetics[SourceTypeBinding.FIELD_EMUL].size());
        this.synthetics[SourceTypeBinding.FIELD_EMUL].put(enclosingType, synthField);
    }
    // ensure there is not already such a field defined by the user
    boolean needRecheck;
    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) {
                    if (this.scope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_5) {
                        synthField.name = CharOperation.concat(synthField.name, "$".toCharArray()); //$NON-NLS-1$
                        needRecheck = true;
                    } else {
                        this.scope.problemReporter().duplicateFieldInType(this, fieldDecl);
                    }
                    break;
                }
            }
        }
    } while (needRecheck);
    return synthField;
}

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

License:Open Source License

public FieldBinding getSyntheticField(ReferenceBinding targetEnclosingType, boolean onlyExactMatch) {

    if (this.synthetics == null || this.synthetics[SourceTypeBinding.FIELD_EMUL] == null)
        return null;
    FieldBinding field = (FieldBinding) this.synthetics[SourceTypeBinding.FIELD_EMUL].get(targetEnclosingType);
    if (field != null)
        return field;

    // type compatibility : to handle cases such as
    // class T { class M{}}
    // class S extends T { class N extends M {}} --> need to use S as a default enclosing instance for the super constructor call in N().
    if (!onlyExactMatch) {
        Iterator accessFields = this.synthetics[SourceTypeBinding.FIELD_EMUL].values().iterator();
        while (accessFields.hasNext()) {
            field = (FieldBinding) accessFields.next();
            if (CharOperation.prefixEquals(TypeConstants.SYNTHETIC_ENCLOSING_INSTANCE_PREFIX, field.name)
                    && field.type.findSuperTypeOriginatingFrom(targetEnclosingType) != null)
                return field;
        }/*from  w  w  w  .  j  a  v  a2  s.  c  om*/
    }
    return null;
}

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

License:Open Source License

public FieldBinding findFieldByName(ReferenceBinding clazz, char[] name) {
    char[] prefix = TypeConstants.SYNTHETIC_ENCLOSING_INSTANCE_PREFIX;
    if (CharOperation.prefixEquals(prefix, name)) {
        TypeBinding original = clazz.original();
        if (original instanceof NestedTypeBinding) {
            if (original.isMemberType() || original.isLocalType()) {
                NestedTypeBinding ntb = (NestedTypeBinding) original;
                SyntheticArgumentBinding[] sab = ntb.syntheticEnclosingInstances();
                for (int i = 0; i < sab.length; i++) {
                    if (CharOperation.equals(name, sab[i].name))
                        return sab[i].matchingField;
                }/*  ww  w.ja v  a  2s  .  co m*/
            }
        }
        // no name adjustment or synthetics needed at the reading (source) side.
    }
    // either regular field or synthetic in a BinaryTypeBinding:
    return clazz.getField(name, true);
}

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

License:Open Source License

public static FieldBinding findFieldByBinding(ReferenceBinding clazz, FieldBinding refField) {
    char[] thisPrefix = TypeConstants.SYNTHETIC_ENCLOSING_INSTANCE_PREFIX;
    char[] classPrefix = TypeConstants.SYNTHETIC_CLASS;
    char[] name = refField.name;
    if (CharOperation.prefixEquals(thisPrefix, name)) {
        int distance = refField.declaringClass.depth() - ((ReferenceBinding) refField.type).depth();
        if (clazz instanceof NestedTypeBinding) {
            {/*  w w  w.j  a  va 2s . c om*/
                NestedTypeBinding mtb = (NestedTypeBinding) clazz;
                ReferenceBinding dstFieldType = clazz;
                while (distance-- > 0) {
                    dstFieldType = dstFieldType.enclosingType();
                }
                return mtb.addSyntheticFieldForInnerclass(dstFieldType);
            }
        } else { // BinaryTypeBinding
            int depth = clazz.depth() - distance;
            name = CharOperation.concat(thisPrefix, String.valueOf(depth).toCharArray());
        }
    } else if (CharOperation.prefixEquals(classPrefix, name)) {
        // assume the synthetic field is present, just create a new binding.
        return new FieldBinding(refField.name, refField.type, 0, clazz, null);
    }
    // directly find field in clazz or superclass(es)
    ReferenceBinding current = clazz;
    while (current != null) {
        FieldBinding f = current.getField(name, true);
        if (f != null)
            return f;
        current = current.superclass();
    }
    return null;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.TypeAnalyzer.java

License:Open Source License

/**
 * When asking for a field should synthetic fields be searched?
 * @param scope        site of usage, if this is a generated methods, searching synthetics is OK
 * @param receiverType class containing the field
 * @param fieldName/*from   ww  w. j  av  a  2  s  .  c  o  m*/
 * @return the answer
 */
public static boolean isSearchingForSyntheticField(MethodScope scope, TypeBinding receiverType,
        char[] fieldName) {
    return CharOperation.prefixEquals(TypeConstants.SYNTHETIC_ENCLOSING_INSTANCE_PREFIX, fieldName)
            && scope != null && ((AbstractMethodDeclaration) scope.referenceContext).isGenerated
            && receiverType instanceof ReferenceBinding && ((ReferenceBinding) receiverType).isRole();
}