Class ReceiverInsertion


public class ReceiverInsertion extends TypedInsertion
An insertion for a method receiver. This supports inserting an annotation on an existing receiver and creating a new (annotated) receiver if none are present.
  • Constructor Details

    • ReceiverInsertion

      public ReceiverInsertion(DeclaredType type, Criteria criteria, List<Insertion> innerTypeInsertions)
      Construct a ReceiverInsertion.

      If the receiver parameter already exists in the method declaration, then pass a DeclaredType whose name is the empty String. This will only insert an annotation on the existing receiver.

      To insert the annotation and the receiver (for example, @Anno Type this) the DeclaredType's name should be set to the type to insert. This can either be done before calling this constructor, or by modifying the return value of TypedInsertion.getType().

      A comma will not be added to the end of the receiver. In the case that there is a parameter following the inserted receiver pass true to setAddComma(boolean) to add a comma to the end of the receiver.

      Parameters:
      type - the type to use when inserting the receiver
      criteria - where to insert the text
      innerTypeInsertions - the inner types to go on this receiver
  • Method Details

    • setAddComma

      public void setAddComma(boolean addComma)
      If true a comma will be added at the end of the receiver. This will only happen if a receiver is inserted (see ReceiverInsertion(DeclaredType, Criteria, List) for a description of when a receiver is inserted). This is useful if the method already has one or more parameters.
    • setQualifyType

      public void setQualifyType(boolean qualifyThis)
      If true, qualify this with the name of the superclass. This will only happen if a receiver is inserted (see ReceiverInsertion(DeclaredType, Criteria, List) for a description of when a receiver is inserted). This is useful for inner class constructors.
    • getText

      protected String getText(boolean abbreviate)
      Description copied from class: Insertion
      Gets the insertion text.
      Specified by:
      getText in class Insertion
      Parameters:
      abbreviate - if true, the package name will be removed from the annotations. The package name can be retrieved again by calling the Insertion.getPackageNames() method.
      Returns:
      the text to insert
    • addLeadingSpace

      protected boolean addLeadingSpace(boolean gotSeparateLine, int pos, char precedingChar)
      Description copied from class: Insertion
      Indicates if a preceding space should be added to this insertion. Subclasses may override this method for custom leading space rules.
      Overrides:
      addLeadingSpace in class Insertion
      Parameters:
      gotSeparateLine - true if this insertion is actually added on a separate line
      pos - the source position where this insertion will be inserted
      precedingChar - the character directly preceding where this insertion will be inserted. This value will be ignored if pos is 0.
      Returns:
      true if a leading space should be added, false otherwise
    • addTrailingSpace

      protected boolean addTrailingSpace(boolean gotSeparateLine)
      Description copied from class: Insertion
      Indicates if a trailing space should be added to this insertion. Subclasses may override this method for custom trailing space rules.
      Overrides:
      addTrailingSpace in class Insertion
      Parameters:
      gotSeparateLine - true if this insertion is actually added on a separate line
      Returns:
      true if a trailing space should be added, false otherwise
    • getKind

      public Insertion.Kind getKind()
      Description copied from class: Insertion
      Gets the kind of this insertion.
      Specified by:
      getKind in class Insertion
      Returns:
      the kind of this insertion