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

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

Introduction

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

Prototype

int FIELD_EMUL

To view the source code for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding FIELD_EMUL.

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);
    }//from ww  w .  ja va 2s  .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.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,/*from   ww  w  . jav a 2  s  .  c o  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 addSyntheticFieldForAssert(BlockScope blockScope) {
    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("assertionEmulation"); //$NON-NLS-1$
    if (synthField == null) {
        synthField = new SyntheticFieldBinding(TypeConstants.SYNTHETIC_ASSERT_DISABLED, TypeBinding.BOOLEAN,
                ClassFileConstants.AccDefault | ClassFileConstants.AccStatic | ClassFileConstants.AccSynthetic
                        | ClassFileConstants.AccFinal,
                this, Constant.NotAConstant, this.synthetics[SourceTypeBinding.FIELD_EMUL].size());
        this.synthetics[SourceTypeBinding.FIELD_EMUL].put("assertionEmulation", synthField); //$NON-NLS-1$
    }//w w w. j  ava 2  s .co m
    // ensure there is not already such a field defined by the user
    // ensure there is not already such a field defined by the user
    boolean needRecheck;
    int index = 0;
    do {
        needRecheck = false;
        FieldBinding existingField;
        if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
            TypeDeclaration typeDecl = this.scope.referenceContext;
            int max = (typeDecl.fields == null) ? 0 : typeDecl.fields.length;
            for (int i = 0; i < max; i++) {
                FieldDeclaration fieldDecl = typeDecl.fields[i];
                if (fieldDecl.binding == existingField) {
                    synthField.name = CharOperation.concat(TypeConstants.SYNTHETIC_ASSERT_DISABLED,
                            ("_" + String.valueOf(index++)).toCharArray()); //$NON-NLS-1$
                    needRecheck = true;
                    break;
                }
            }
        }
    } while (needRecheck);
    return synthField;
}

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

License:Open Source License

public FieldBinding addSyntheticFieldForEnumValues() {
    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("enumConstantValues"); //$NON-NLS-1$
    if (synthField == null) {
        synthField = new SyntheticFieldBinding(TypeConstants.SYNTHETIC_ENUM_VALUES,
                this.scope.createArrayType(this, 1),
                ClassFileConstants.AccPrivate | ClassFileConstants.AccStatic | ClassFileConstants.AccSynthetic
                        | ClassFileConstants.AccFinal,
                this, Constant.NotAConstant, this.synthetics[SourceTypeBinding.FIELD_EMUL].size());
        this.synthetics[SourceTypeBinding.FIELD_EMUL].put("enumConstantValues", synthField); //$NON-NLS-1$
    }/* ww  w  .  ja  v a2s.c om*/
    // ensure there is not already such a field defined by the user
    // ensure there is not already such a field defined by the user
    boolean needRecheck;
    int index = 0;
    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_ENUM_VALUES,
                            ("_" + String.valueOf(index++)).toCharArray()); //$NON-NLS-1$
                    needRecheck = true;
                    break;
                }
            }
        }
    } while (needRecheck);
    return synthField;
}

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

License:Open Source License

public SyntheticFieldBinding addSyntheticFieldForSwitchEnum(char[] fieldName, String key) {
    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);

    SyntheticFieldBinding synthField = (SyntheticFieldBinding) this.synthetics[SourceTypeBinding.FIELD_EMUL]
            .get(key);//from   w  w  w.java 2 s . co m
    if (synthField == null) {
        synthField = new SyntheticFieldBinding(fieldName, this.scope.createArrayType(TypeBinding.INT, 1),
                ClassFileConstants.AccPrivate | ClassFileConstants.AccStatic | ClassFileConstants.AccSynthetic,
                this, Constant.NotAConstant, this.synthetics[SourceTypeBinding.FIELD_EMUL].size());
        this.synthetics[SourceTypeBinding.FIELD_EMUL].put(key, synthField);
    }
    // ensure there is not already such a field defined by the user
    boolean needRecheck;
    int index = 0;
    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(fieldName,
                            ("_" + String.valueOf(index++)).toCharArray()); //$NON-NLS-1$
                    needRecheck = true;
                    break;
                }
            }
        }
    } while (needRecheck);
    return synthField;
}

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

License:Open Source License

public FieldBinding getSyntheticField(LocalVariableBinding actualOuterLocalVariable) {
    if (this.synthetics == null || this.synthetics[SourceTypeBinding.FIELD_EMUL] == null)
        return null;
    return (FieldBinding) this.synthetics[SourceTypeBinding.FIELD_EMUL].get(actualOuterLocalVariable);
}

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 ww .  j  a  v  a  2 s.  c o  m*/
    }
    return null;
}

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

License:Open Source License

/**
 * Answer the collection of synthetic fields to append into the classfile
 *///  w  ww . j  av  a  2s  . c  o m
public FieldBinding[] syntheticFields() {
    if (this.synthetics == null)
        return null;
    int fieldSize = this.synthetics[SourceTypeBinding.FIELD_EMUL] == null ? 0
            : this.synthetics[SourceTypeBinding.FIELD_EMUL].size();
    int literalSize = this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL] == null ? 0
            : this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL].size();
    int totalSize = fieldSize + literalSize;
    if (totalSize == 0)
        return null;
    FieldBinding[] bindings = new FieldBinding[totalSize];

    // add innerclass synthetics
    if (this.synthetics[SourceTypeBinding.FIELD_EMUL] != null) {
        Iterator elements = this.synthetics[SourceTypeBinding.FIELD_EMUL].values().iterator();
        for (int i = 0; i < fieldSize; i++) {
            SyntheticFieldBinding synthBinding = (SyntheticFieldBinding) elements.next();
            bindings[synthBinding.index] = synthBinding;
        }
    }
    // add class literal synthetics
    if (this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL] != null) {
        Iterator elements = this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL].values().iterator();
        for (int i = 0; i < literalSize; i++) {
            SyntheticFieldBinding synthBinding = (SyntheticFieldBinding) elements.next();
            bindings[fieldSize + synthBinding.index] = synthBinding;
        }
    }
    return bindings;
}