Search in sources :

Example 6 with SourcePosition

use of com.webcohesion.enunciate.javac.decorations.SourcePosition in project enunciate by stoicflame.

the class MemberComparator method compare.

// Inherited.
public int compare(Member accessor1, Member accessor2) {
    if (isSameId(accessor1, accessor2)) {
        // if the elements have the same identifier.
        return 0;
    }
    // they're not the same, so now determine relative order:
    String propertyName1 = accessor1.getSimpleName().toString();
    String propertyName2 = accessor2.getSimpleName().toString();
    if (this.propOrder != null && this.propOrder.length > 0) {
        // apply the specified property order
        int propertyIndex1 = find(this.propOrder, propertyName1);
        int propertyIndex2 = find(this.propOrder, propertyName2);
        if (propertyIndex1 < 0) {
            // not in the property list; just use the hash.
            propertyIndex1 = Math.abs(propertyName1.hashCode());
        }
        if (propertyIndex2 < 0) {
            // not in the property list; just use the hash.
            propertyIndex2 = Math.abs(propertyName2.hashCode());
        }
        return propertyIndex1 - propertyIndex2;
    } else if (this.alphabetical) {
        return propertyName1.compareTo(propertyName2);
    }
    // If no order is specified, it's undefined. We'll put it in source order.
    SourcePosition position1 = this.env.findSourcePosition(accessor1);
    SourcePosition position2 = this.env.findSourcePosition(accessor2);
    if (position1 != null && position2 != null) {
        return position1.compareTo(position2);
    } else {
        // don't have source positions... just provide a random sort order.
        return accessor1.hashCode() - accessor2.hashCode();
    }
}
Also used : SourcePosition(com.webcohesion.enunciate.javac.decorations.SourcePosition)

Aggregations

SourcePosition (com.webcohesion.enunciate.javac.decorations.SourcePosition)6 JavaFileObject (javax.tools.JavaFileObject)2 EnunciateException (com.webcohesion.enunciate.EnunciateException)1 File (java.io.File)1 URI (java.net.URI)1