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

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

Introduction

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

Prototype

int CLASS_LITERAL_EMUL

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

Click Source Link

Usage

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

License:Open Source License

public FieldBinding addSyntheticFieldForClassLiteral(TypeBinding targetType, BlockScope blockScope) {
    if (this.synthetics == null)
        this.synthetics = new HashMap[MAX_SYNTHETICS];
    if (this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL] == null)
        this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL] = new HashMap(5);

    // use a different table than FIELDS, given there might be a collision between emulation of X.this$0 and X.class.
    FieldBinding synthField = (FieldBinding) this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL]
            .get(targetType);/*  w  w  w . j a va  2 s .  c om*/
    if (synthField == null) {
        synthField = new SyntheticFieldBinding(
                CharOperation.concat(TypeConstants.SYNTHETIC_CLASS,
                        String.valueOf(this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL].size())
                                .toCharArray()),
                blockScope.getJavaLangClass(),
                ClassFileConstants.AccDefault | ClassFileConstants.AccStatic | ClassFileConstants.AccSynthetic,
                this, Constant.NotAConstant, this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL].size());
        this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL].put(targetType, synthField);
    }
    // ensure there is not already such a field defined by the user
    FieldBinding existingField;
    if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
        TypeDeclaration typeDecl = blockScope.referenceType();
        FieldDeclaration[] typeDeclarationFields = typeDecl.fields;
        int max = typeDeclarationFields == null ? 0 : typeDeclarationFields.length;
        for (int i = 0; i < max; i++) {
            FieldDeclaration fieldDecl = typeDeclarationFields[i];
            if (fieldDecl.binding == existingField) {
                blockScope.problemReporter().duplicateFieldInType(this, fieldDecl);
                break;
            }
        }
    }
    return synthField;
}

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