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 booleanaddLeadingSpace(boolean gotSeparateLine, int pos, char precedingChar) Indicates if a preceding space should be added to this insertion.protected booleanaddTrailingSpace(boolean gotSeparateLine) Indicates if a trailing space should be added to this insertion.static StringcollectionToString(Collection<? extends Insertion> list) Format a list of insertions, with one insertion on each line.static voiddecorateType(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 voiddecorateType(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.KindgetKind()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 StringgetText(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, andprecedingCharparameters.booleanReturns true if this insertion has already been inserted into source code.booleanReturns true if the insertion goes on a separate line.Removes and returns the leading package.static voidsetAlwaysQualify(Set<String> set) Sets the set of annotation names that should always be qualified.voidsetInserted(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, andprecedingCharparameters.- 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-trueif 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 ifposis 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-trueif 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 ifposis 0.- Returns:
trueif a leading space should be added,falseotherwise
-
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-trueif this insertion is actually added on a separate line- Returns:
- true if a trailing space should be added,
falseotherwise
-
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:
trueif this insertion has already been inserted,falseotherwise
-
setInserted
public void setInserted(boolean inserted) Sets whether this insertion has already been inserted into source code.- Parameters:
inserted-trueif this insertion has already been inserted,falseotherwise
-
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 and returns the leading package.- Parameters:
s- the string representation of an annotation- Returns:
- given
@com.foo.bar(baz)it returns a pair ofcom.fooand@bar(baz).
-
typeToString
Converts the given type to a String. This method can't be in theTypeclass because this method relies on theInsertionclass to format annotations, and theInsertionclass 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'Criteriamust contain aGenericArrayLocationCriterionandGenericArrayLocationCriterion.getLocation()must return a non-empty list.outerType- the type to add the insertions to
-
decorateType
-