Class AstSorter


  • @PublicApi
    public class AstSorter
    extends java.lang.Object
    A class that helps you sort AST nodes
    • Constructor Summary

      Constructors 
      Constructor Description
      AstSorter()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private <T,​U extends java.lang.Comparable<? super U>>
      java.util.Comparator<T>
      comparing​(java.util.function.Function<? super T,​? extends U> keyExtractor)  
      private java.util.Comparator<Definition> comparingDefinitions()  
      private java.util.Comparator<Selection> comparingSelections()  
      private java.util.Comparator<Type> comparingTypes()  
      private <T> java.util.List<T> sort​(java.util.List<T> items, java.util.Comparator<T> comparing)  
      <T extends Node>
      T
      sort​(T nodeToBeSorted)
      This will sort nodes in specific orders and then alphabetically.
      private SelectionSet sortSelectionSet​(SelectionSet selectionSet)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AstSorter

        public AstSorter()
    • Method Detail

      • sort

        public <T extends Node> T sort​(T nodeToBeSorted)
        This will sort nodes in specific orders and then alphabetically. The order is :
        • Query operation definitions
        • Mutation operation definitions
        • Subscriptions operation definitions
        • Fragment definitions
        • Directive definitions
        • Schema definitions
        • Object Type definitions
        • Interface Type definitions
        • Union Type definitions
        • Enum Type definitions
        • Scalar Type definitions
        • Input Object Type definitions
        After those groupings they will be sorted alphabetic. All arguments and directives on elements will be sorted alphabetically by name.
        Type Parameters:
        T - of type Node
        Parameters:
        nodeToBeSorted - the node to be sorted
        Returns:
        a new sorted node (because Nodes are immutable)
      • comparingTypes

        private java.util.Comparator<Type> comparingTypes()
      • comparingSelections

        private java.util.Comparator<Selection> comparingSelections()
      • comparingDefinitions

        private java.util.Comparator<Definition> comparingDefinitions()
      • sort

        private <T> java.util.List<T> sort​(java.util.List<T> items,
                                           java.util.Comparator<T> comparing)
      • comparing

        private <T,​U extends java.lang.Comparable<? super U>> java.util.Comparator<T> comparing​(java.util.function.Function<? super T,​? extends U> keyExtractor)