Class CheckBase
- All Implemented Interfaces:
org.revapi.configuration.Configurable,Check
Check interface. This class easies the matching of the visit*() methods
and their corresponding visitEnd() by keeping track of the "depth" individual calls (see the recursive
nature of the call order).
This class also contains a couple of utility methods for checking the accessibility of elements, etc.
- Since:
- 0.1
- Author:
- Lukas Krejci
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classCheckBase.ActiveElements<T extends JavaElement>Represents the elements that have beenpushedonto the active elements stack.Nested classes/interfaces inherited from interface org.revapi.java.spi.Check
Check.Type -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.revapi.DifferencecreateDifference(Code code, LinkedHashMap<String, String> attachments) protected org.revapi.DifferencecreateDifferenceWithExplicitParams(Code code, LinkedHashMap<String, String> attachments, String... params) protected List<org.revapi.Difference> doEnd()protected List<org.revapi.Difference> doVisitAnnotation(JavaAnnotationElement oldAnnotation, JavaAnnotationElement newAnnotation) protected voiddoVisitClass(JavaTypeElement oldType, JavaTypeElement newType) protected voiddoVisitField(JavaFieldElement oldField, JavaFieldElement newField) protected voiddoVisitMethod(JavaMethodElement oldMethod, JavaMethodElement newMethod) protected voiddoVisitMethodParameter(JavaMethodParameterElement oldParameter, JavaMethodParameterElement newParameter) org.revapi.AnalysisContextvoidinitialize(org.revapi.AnalysisContext analysisContext) booleanThis method checks that the provided element and all its parent elements are accessible (public or protected).booleanChecks whether both provided elements are public or protected.booleanChecks whether both provided elements are (package) private.booleanThe default implementation returns false, because that is the right decision most of the time.booleanThe element is deemed missing if its type kind (TypeMirror.getKind()) isTypeKind.ERROR.protected CheckBase.ActiveElements<?> protected <T extends JavaElement>
CheckBase.ActiveElements<T> Pops the top of the stack of active elements if the current position in the call stack corresponds to the one that pushed the active elements.protected <T extends JavaElement>
CheckBase.ActiveElements<T> popIfActive(Class<T> type) Pops the top of the stack of the active elements if the current position in the call stack corresponds to the one that pushed the active elements.protected final <T extends JavaElement>
voidpushActive(T oldElement, T newElement, Object... context) If called in one of thedoVisit*()methods, this method will push the elements along with some contextual data onto an internal stack.voidThe environment containing the new version of the classes.voidThe environment containing the old version of the classes.final List<org.revapi.Difference> visitAnnotation(JavaAnnotationElement oldAnnotation, JavaAnnotationElement newAnnotation) Please override thedoVisitAnnotation(JavaAnnotationElement, JavaAnnotationElement)instead.final voidvisitClass(JavaTypeElement oldType, JavaTypeElement newType) Please override thedoVisitClass(JavaTypeElement, JavaTypeElement)final List<org.revapi.Difference> visitEnd()Please override thedoEnd()method instead.final voidvisitField(JavaFieldElement oldField, JavaFieldElement newField) Please override thedoVisitField(JavaFieldElement, JavaFieldElement)instead.final voidvisitMethod(JavaMethodElement oldMethod, JavaMethodElement newMethod) Please override thedoVisitMethod(JavaMethodElement, JavaMethodElement)instead.final voidvisitMethodParameter(JavaMethodParameterElement oldParameter, JavaMethodParameterElement newParameter) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.revapi.java.spi.Check
getInterest
-
Constructor Details
-
CheckBase
public CheckBase()
-
-
Method Details
-
isDescendingOnNonExisting
public boolean isDescendingOnNonExisting()The default implementation returns false, because that is the right decision most of the time.- Specified by:
isDescendingOnNonExistingin interfaceCheck- Returns:
- false
-
isBothPrivate
Checks whether both provided elements are (package) private. If one of them is null, the fact cannot be determined and therefore this method would return false.- Parameters:
a- first elementb- second element- Returns:
- true if both elements are not null and are private or package private
-
isBothAccessible
Checks whether both provided elements are public or protected. If one at least one of them is null, the method returns false, because the accessibility cannot be truthfully detected in that case.- Parameters:
a- first elementb- second element- Returns:
- true if both elements are not null and accessible (i.e. public or protected)
-
isAccessible
This method checks that the provided element and all its parent elements are accessible (public or protected). Additionally, if the provided element is a type, it must be in API or, if it is not a type, its nearest enclosing type must be in API.- Parameters:
e- the element to check- Returns:
- true if the provided element is accessible and in API, false otherwise.
-
isMissing
The element is deemed missing if its type kind (TypeMirror.getKind()) isTypeKind.ERROR.- Parameters:
e- the element- Returns:
- true if the element is missing, false otherwise
-
createDifference
-
createDifferenceWithExplicitParams
-
getOldTypeEnvironment
-
getNewTypeEnvironment
-
getAnalysisContext
-
getExtensionId
-
getJSONSchema
-
initialize
- Specified by:
initializein interfaceorg.revapi.configuration.Configurable
-
setOldTypeEnvironment
Description copied from interface:CheckThe environment containing the old version of the classes. This can be used to reason about the classes when doing the checks.Called once after the check has been instantiated.
- Specified by:
setOldTypeEnvironmentin interfaceCheck- Parameters:
env- the environment to obtain the helper objects using which one can navigate and examine types
-
setNewTypeEnvironment
Description copied from interface:CheckThe environment containing the new version of the classes. This can be used to reason about the classes when doing the checks.Called once after the check has been instantiated.
- Specified by:
setNewTypeEnvironmentin interfaceCheck- Parameters:
env- the environment to obtain the helper objects using which one can navigate and examine types
-
visitEnd
Please override thedoEnd()method instead. -
doEnd
-
visitClass
Please override thedoVisitClass(JavaTypeElement, JavaTypeElement)- Specified by:
visitClassin interfaceCheck- See Also:
-
doVisitClass
-
visitMethod
public final void visitMethod(@Nullable JavaMethodElement oldMethod, @Nullable JavaMethodElement newMethod) Please override thedoVisitMethod(JavaMethodElement, JavaMethodElement)instead.- Specified by:
visitMethodin interfaceCheck- See Also:
-
doVisitMethod
protected void doVisitMethod(@Nullable JavaMethodElement oldMethod, @Nullable JavaMethodElement newMethod) -
visitMethodParameter
public final void visitMethodParameter(@Nullable JavaMethodParameterElement oldParameter, @Nullable JavaMethodParameterElement newParameter) - Specified by:
visitMethodParameterin interfaceCheck
-
doVisitMethodParameter
protected void doVisitMethodParameter(@Nullable JavaMethodParameterElement oldParameter, @Nullable JavaMethodParameterElement newParameter) -
visitField
public final void visitField(@Nullable JavaFieldElement oldField, @Nullable JavaFieldElement newField) Please override thedoVisitField(JavaFieldElement, JavaFieldElement)instead.- Specified by:
visitFieldin interfaceCheck- See Also:
-
doVisitField
protected void doVisitField(@Nullable JavaFieldElement oldField, @Nullable JavaFieldElement newField) -
visitAnnotation
@Nullable public final List<org.revapi.Difference> visitAnnotation(@Nullable JavaAnnotationElement oldAnnotation, @Nullable JavaAnnotationElement newAnnotation) Please override thedoVisitAnnotation(JavaAnnotationElement, JavaAnnotationElement)instead.- Specified by:
visitAnnotationin interfaceCheck- Parameters:
oldAnnotation- the annotation in the old APInewAnnotation- the annotation in the new API- Returns:
- the list of differences between the two annotations
- See Also:
-
doVisitAnnotation
@Nullable protected List<org.revapi.Difference> doVisitAnnotation(@Nullable JavaAnnotationElement oldAnnotation, @Nullable JavaAnnotationElement newAnnotation) -
pushActive
protected final <T extends JavaElement> void pushActive(@Nullable T oldElement, @Nullable T newElement, Object... context) If called in one of thedoVisit*()methods, this method will push the elements along with some contextual data onto an internal stack.You can then retrieve the contents on the top of the stack in your
doEnd()override by calling thepopIfActive()method.- Type Parameters:
T- the type of the elements- Parameters:
oldElement- the old API elementnewElement- the new API elementcontext- optional contextual data
-
popIfActive
Pops the top of the stack of active elements if the current position in the call stack corresponds to the one that pushed the active elements.This method does not do any type checks, so take care to retrieve the elements with the same types used to push to them onto the stack.
- Type Parameters:
T- the type of the elements- Returns:
- the active elements or null if the current call stack did not push any active elements onto the stack
-
popIfActive
Pops the top of the stack of the active elements if the current position in the call stack corresponds to the one that pushed the active elements.The stack is always popped but a non-null value is returned only if there was an active element AND the element is assignable to the provided type.
This method is a more type-safe variant of
popIfActive()and should be used in situations where more than 1 type can be expected in thedoEnd()implementation.- Parameters:
type- the expected type of the elements- Returns:
- non-null if there were active elements and the elements have the provided type
-
peekLastActive
- Returns:
- the last activation. This can be called at any point and can refer to any of the enclosing elements of the currently processed element pair, depending on how this check activated them.
-