Example usage for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding sortFields

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

Introduction

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

Prototype

public static void sortFields(FieldBinding[] sortedFields, int left, int right) 

Source Link

Document

Sort the field array using a quicksort

Usage

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

License:Open Source License

public FieldBinding[] fields() {
    if ((this.tagBits & TagBits.AreFieldsComplete) != 0)
        return this.fields;

    int failed = 0;
    FieldBinding[] resolvedFields = this.fields;
    try {/*from  ww w .j  av a 2  s  . c om*/
        // lazily sort fields
        if ((this.tagBits & TagBits.AreFieldsSorted) == 0) {
            int length = this.fields.length;
            if (length > 1)
                ReferenceBinding.sortFields(this.fields, 0, length);
            this.tagBits |= TagBits.AreFieldsSorted;
        }
        for (int i = 0, length = this.fields.length; i < length; i++) {
            if (resolveTypeFor(this.fields[i]) == null) {
                // do not alter original field array until resolution is over, due to reentrance (143259)
                if (resolvedFields == this.fields) {
                    System.arraycopy(this.fields, 0, resolvedFields = new FieldBinding[length], 0, length);
                }
                resolvedFields[i] = null;
                failed++;
            }
        }
    } finally {
        if (failed > 0) {
            // ensure fields are consistent reqardless of the error
            int newSize = resolvedFields.length - failed;
            if (newSize == 0)
                return this.fields = Binding.NO_FIELDS;

            FieldBinding[] newFields = new FieldBinding[newSize];
            for (int i = 0, j = 0, length = resolvedFields.length; i < length; i++) {
                if (resolvedFields[i] != null)
                    newFields[j++] = resolvedFields[i];
            }
            this.fields = newFields;
        }
    }
    this.tagBits |= TagBits.AreFieldsComplete;
    return this.fields;
}

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

License:Open Source License

public FieldBinding getField(char[] fieldName, boolean needResolve) {

    if ((this.tagBits & TagBits.AreFieldsComplete) != 0)
        return ReferenceBinding.binarySearch(fieldName, this.fields);

    // lazily sort fields
    if ((this.tagBits & TagBits.AreFieldsSorted) == 0) {
        int length = this.fields.length;
        if (length > 1)
            ReferenceBinding.sortFields(this.fields, 0, length);
        this.tagBits |= TagBits.AreFieldsSorted;
    }/*from ww w .j  a  v  a2 s.  c om*/
    // always resolve anyway on source types
    FieldBinding field = ReferenceBinding.binarySearch(fieldName, this.fields);
    if (field != null) {
        FieldBinding result = null;
        try {
            result = resolveTypeFor(field);
            return result;
        } finally {
            if (result == null) {
                // ensure fields are consistent reqardless of the error
                int newSize = this.fields.length - 1;
                if (newSize == 0) {
                    this.fields = Binding.NO_FIELDS;
                } else {
                    FieldBinding[] newFields = new FieldBinding[newSize];
                    int index = 0;
                    for (int i = 0, length = this.fields.length; i < length; i++) {
                        FieldBinding f = this.fields[i];
                        if (f == field)
                            continue;
                        newFields[index++] = f;
                    }
                    this.fields = newFields;
                }
            }
        }
    }
    return null;
}