Class Insertion
java.lang.Object
org.checkerframework.afu.annotator.find.Insertion
- Direct Known Subclasses:
AnnotationInsertion
,CastInsertion
,CloseParenthesisInsertion
,TypedInsertion
Specifies something that needs to be inserted into a source file, including the "what" and the
"where".
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionSet of annotation names that should always be inserted fully-qualified, even whengetText(boolean)
is called with abbreviate=true.The package names for the annotations being inserted by this Insertion. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
addLeadingSpace
(boolean gotSeparateLine, int pos, char precedingChar) Indicates if a preceding space should be added to this insertion.protected boolean
addTrailingSpace
(boolean gotSeparateLine) Indicates if a trailing space should be added to this insertion.static String
collectionToString
(Collection<? extends Insertion> list) Format a list of insertions, with one insertion on each line.static void
decorateType
(List<Insertion> innerTypeInsertions, Type outerType) Adds each of the given inner type insertions to the correct part of the type, based on the insertion's type path.static void
decorateType
(List<Insertion> innerTypeInsertions, Type outerType, ASTPath outerPath) Gets the set of annotation names that should always be inserted fully-qualified.Gets the insertion criteria.abstract Insertion.Kind
getKind()
Gets the kind of this insertion.Gets the package name.getText()
Gets the insertion text (not commented or abbreviated, and without added leading or trailing whitespace).protected abstract String
getText
(boolean abbreviate) Gets the insertion text.getText
(boolean abbreviate, boolean gotSeparateLine, int pos, char precedingChar) Gets the insertion text with a leading and/or trailing space added based on the values of thegotSeparateLine
,pos
, andprecedingChar
parameters.boolean
Returns true if this insertion has already been inserted into source code.boolean
Returns true if the insertion goes on a separate line.Removes the leading package.static void
setAlwaysQualify
(Set<String> set) Sets the set of annotation names that should always be qualified.void
setInserted
(boolean inserted) Sets whether this insertion has already been inserted into source code.toString()
Format this without reporting its class name.typeToString
(Type type, boolean abbreviate) Converts the given type to a String.
-
Field Details
-
packageNames
The package names for the annotations being inserted by this Insertion. This will be empty unlessgetText(boolean)
is called with abbreviate=true. -
alwaysQualify
Set of annotation names that should always be inserted fully-qualified, even whengetText(boolean)
is called with abbreviate=true.
-
-
Constructor Details
-
Insertion
Creates a new insertion.- Parameters:
criteria
- where to insert the textseparateLine
- if true, insert the text on its own line
-
-
Method Details
-
getCriteria
Gets the insertion criteria.- Returns:
- the criteria
-
getText
Gets the insertion text (not commented or abbreviated, and without added leading or trailing whitespace).- Returns:
- the text to insert
-
getText
Gets the insertion text with a leading and/or trailing space added based on the values of thegotSeparateLine
,pos
, andprecedingChar
parameters.- Parameters:
abbreviate
- if true, the package name will be removed from the annotations. The package name can be retrieved again by calling thegetPackageNames()
method.gotSeparateLine
-true
if this insertion is actually added on a separate linepos
- the source position where this insertion will be insertedprecedingChar
- the character directly preceding where this insertion will be inserted. This value will be ignored ifpos
is 0.- Returns:
- the text to insert
-
getText
Gets the insertion text.- Parameters:
abbreviate
- if true, the package name will be removed from the annotations. The package name can be retrieved again by calling thegetPackageNames()
method.- Returns:
- the text to insert
-
addLeadingSpace
protected boolean addLeadingSpace(boolean gotSeparateLine, int pos, char precedingChar) Indicates if a preceding space should be added to this insertion. Subclasses may override this method for custom leading space rules.- Parameters:
gotSeparateLine
-true
if this insertion is actually added on a separate linepos
- the source position where this insertion will be insertedprecedingChar
- the character directly preceding where this insertion will be inserted. This value will be ignored ifpos
is 0.- Returns:
true
if a leading space should be added,false
otherwise
-
addTrailingSpace
protected boolean addTrailingSpace(boolean gotSeparateLine) Indicates if a trailing space should be added to this insertion. Subclasses may override this method for custom trailing space rules.- Parameters:
gotSeparateLine
-true
if this insertion is actually added on a separate line- Returns:
- true if a trailing space should be added,
false
otherwise
-
getPackageNames
Gets the package name.- Returns:
- the package name of the annotation being inserted by this Insertion. This will be empty
unless
getText(boolean)
is called with abbreviate=true.
-
getAlwaysQualify
Gets the set of annotation names that should always be inserted fully-qualified.- Returns:
- the annotation names that should always be inserted fully-qualified
-
setAlwaysQualify
Sets the set of annotation names that should always be qualified.- Parameters:
set
- the annotation names that should always be inserted fully-qualified
-
isSeparateLine
public boolean isSeparateLine()Returns true if the insertion goes on a separate line.- Returns:
- true if the insertion goes on a separate line
-
isInserted
public boolean isInserted()Returns true if this insertion has already been inserted into source code.- Returns:
true
if this insertion has already been inserted,false
otherwise
-
setInserted
public void setInserted(boolean inserted) Sets whether this insertion has already been inserted into source code.- Parameters:
inserted
-true
if this insertion has already been inserted,false
otherwise
-
toString
-
toStringWithoutClass
Format this without reporting its class name.- Returns:
- a representation of this, without its class name
-
collectionToString
Format a list of insertions, with one insertion on each line.- Parameters:
list
- a collection of insertions- Returns:
- a multi-line string representation of the list
-
getKind
Gets the kind of this insertion.- Returns:
- the kind of this insertion
-
removePackage
Removes the leading package.- Returns:
- given
@com.foo.bar(baz)
it returns the pair{ com.foo, @bar(baz) }
.
-
typeToString
Converts the given type to a String. This method can't be in theType
class because this method relies on theInsertion
class to format annotations, and theInsertion
class is not available fromType
.- Parameters:
type
- the type to convertabbreviate
- if true, the package name will be removed from the annotations. The package name can be retrieved again by calling thegetPackageNames()
method.- Returns:
- the type as a string
-
decorateType
Adds each of the given inner type insertions to the correct part of the type, based on the insertion's type path.- Parameters:
innerTypeInsertions
- the insertions to add to the type. These must be inner type insertions, meaning each of the insertions'Criteria
must contain aGenericArrayLocationCriterion
andGenericArrayLocationCriterion.getLocation()
must return a non-empty list.outerType
- the type to add the insertions to
-
decorateType
-