Enum Class PartialInlineability

java.lang.Object
java.lang.Enum<PartialInlineability>
com.palantir.javaformat.PartialInlineability
All Implemented Interfaces:
Serializable, Comparable<PartialInlineability>, Constable

public enum PartialInlineability extends Enum<PartialInlineability>
What are the conditions for a level to be partially inlineable. Partial inlining refers to the behaviour of BreakBehaviours.breakOnlyIfInnerLevelsThenFitOnOneLine(boolean) where a level is too large to fit on the current line, but a prefix thereof is partially inlined onto the current line.

Specifically, when inlining a level with the above behaviour, the partial inlineability of its first child level (and that level's first child, recursively) is queried in order to determine if we need to ensure there's enough room for some additional prefix of that level.

The reason for this is to prevent degenerate formattings like

 Object foo = someSuperLongMethod(some |
         .fully                        |
         .qualified                    |
         .ClassName                    |
         .doSomething());              |
 
and instead prefer breaking earlier to keep the prefix on the same line, like:
 Object foo = someSuperLongMethod(     |
         some.fully.qualified.ClassName|
                 .doSomething());      |
 

Note that this works as a mandatory access control. Namely, if it's allowed to partially inline a level, what are the additional conditions that have to be met in order for the inlining to go ahead.

  • Enum Constant Details

    • ALWAYS_PARTIALLY_INLINEABLE

      public static final PartialInlineability ALWAYS_PARTIALLY_INLINEABLE
      The level may always be partially inlined, regardless of how much space is left on the current line.

      This is usually only appropriate for levels that start with a direct Break, as opposed to a Break that's nested inside some other levels.

    • IF_FIRST_LEVEL_FITS

      public static final PartialInlineability IF_FIRST_LEVEL_FITS
      Partially inlineable if the first inner level of this level fits on the current line.

      This assumes that the next Doc after that starts with a Break (see StartsWithBreakVisitor) and makes sense in contexts like JavaInputAstVisitor.visitDotWithPrefix(java.util.List<com.sun.source.tree.ExpressionTree>, boolean, java.util.Collection<java.lang.Integer>, com.palantir.javaformat.doc.FillMode) where we want to treat first doc (the longest prefix) as a single entity to be fit onto the same line.

  • Method Details

    • values

      public static PartialInlineability[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static PartialInlineability valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null