Class SourceOrdering

java.lang.Object
org.immutables.generator.SourceOrdering

public final class SourceOrdering extends Object
Utility that abstracts away hacks to retrieve elements in source order. Currently, Javac returns elements in proper source order, but EJC returns elements in alphabetical order.

Based on a workaround idea provided by Christian Humer NOTE: The Eclipse bug is fixed, and this workaround can be disabled by setting the system property org.immutables.disableEclipseOrderingProvider=true.

  • Field Details

  • Constructor Details

    • SourceOrdering

      private SourceOrdering()
  • Method Details

    • getEnclosedElements

      public static com.google.common.collect.ImmutableList<Element> getEnclosedElements(Element element)
    • enclosedBy

      public static com.google.common.collect.Ordering<Element> enclosedBy(Element element)
    • createProvider

      private static SourceOrdering.OrderingProvider createProvider()
    • getAllAccessorsProvider

      public static SourceOrdering.AccessorProvider getAllAccessorsProvider(Elements elements, Types types, TypeElement originatingType)
      While we have SourceOrdering, there's still a problem: We have inheritance hierarchy and we want to have all defined or inherited accessors returned as members of target type, like Elements.getAllMembers(TypeElement), but we need to have them properly and stably sorted. This implementation doesn't try to correctly resolve order for accessors inherited from different supertypes(interfaces), just something that stable and reasonable wrt source ordering without handling complex cases.
      Parameters:
      elements - the elements utility
      types - the types utility
      originatingType - the type to traverse
      Returns:
      provider of all accessors in source order and mapping
    • disambiguateMethods

      private static List<ExecutableElement> disambiguateMethods(Iterable<? extends ExecutableElement> methods)
    • isJavaLangObject

      static boolean isJavaLangObject(TypeElement element)