Package org.revapi.java.spi
Class CheckBase
- java.lang.Object
-
- org.revapi.java.spi.CheckBase
-
- All Implemented Interfaces:
org.revapi.configuration.Configurable,Check
public abstract class CheckBase extends Object implements Check
A basic implementation of theCheckinterface. This class easies the matching of thevisit*()methods and their correspondingvisitEnd()by keeping track of the "depth" individual calls (see the recursive nature of thecall 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:
pushActive(JavaElement, JavaElement, Object...),popIfActive()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected 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 Constructor Description CheckBase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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.AnalysisContextgetAnalysisContext()StringgetExtensionId()ReadergetJSONSchema()TypeEnvironmentgetNewTypeEnvironment()TypeEnvironmentgetOldTypeEnvironment()voidinitialize(org.revapi.AnalysisContext analysisContext)booleanisAccessible(JavaModelElement e)This method checks that the provided element and all its parent elements are accessible (public or protected).booleanisBothAccessible(JavaModelElement a, JavaModelElement b)Checks whether both provided elements are public or protected.booleanisBothPrivate(JavaModelElement a, JavaModelElement b)Checks whether both provided elements are (package) private.booleanisDescendingOnNonExisting()The default implementation returns false, because that is the right decision most of the time.booleanisMissing(Element e)The element is deemed missing if its type kind (TypeMirror.getKind()) isTypeKind.ERROR.protected CheckBase.ActiveElements<?>peekLastActive()protected <T extends JavaElement>
CheckBase.ActiveElements<T>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.protected <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.voidsetNewTypeEnvironment(TypeEnvironment env)The environment containing the new version of the classes.voidsetOldTypeEnvironment(TypeEnvironment env)The environment containing the old version of the classes.List<org.revapi.Difference>visitAnnotation(JavaAnnotationElement oldAnnotation, JavaAnnotationElement newAnnotation)Please override thedoVisitAnnotation(JavaAnnotationElement, JavaAnnotationElement)instead.voidvisitClass(JavaTypeElement oldType, JavaTypeElement newType)Please override thedoVisitClass(JavaTypeElement, JavaTypeElement)List<org.revapi.Difference>visitEnd()Please override thedoEnd()method instead.voidvisitField(JavaFieldElement oldField, JavaFieldElement newField)Please override thedoVisitField(JavaFieldElement, JavaFieldElement)instead.voidvisitMethod(JavaMethodElement oldMethod, JavaMethodElement newMethod)Please override thedoVisitMethod(JavaMethodElement, JavaMethodElement)instead.voidvisitMethodParameter(JavaMethodParameterElement oldParameter, JavaMethodParameterElement newParameter)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.revapi.java.spi.Check
getInterest
-
-
-
-
Method Detail
-
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
public boolean isBothPrivate(@Nullable JavaModelElement a, @Nullable JavaModelElement b)
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
public boolean isBothAccessible(@Nullable JavaModelElement a, @Nullable JavaModelElement b)
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
public boolean isAccessible(@Nonnull JavaModelElement e)
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
public boolean isMissing(@Nonnull Element e)
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
@Nonnull protected org.revapi.Difference createDifference(@Nonnull Code code, LinkedHashMap<String,String> attachments)
-
createDifferenceWithExplicitParams
@Nonnull protected org.revapi.Difference createDifferenceWithExplicitParams(@Nonnull Code code, LinkedHashMap<String,String> attachments, String... params)
-
getOldTypeEnvironment
@Nonnull public TypeEnvironment getOldTypeEnvironment()
-
getNewTypeEnvironment
@Nonnull public TypeEnvironment getNewTypeEnvironment()
-
getAnalysisContext
@Nonnull public org.revapi.AnalysisContext getAnalysisContext()
-
getExtensionId
@Nullable public String getExtensionId()
- Specified by:
getExtensionIdin interfaceorg.revapi.configuration.Configurable
-
getJSONSchema
@Nullable public Reader getJSONSchema()
- Specified by:
getJSONSchemain interfaceorg.revapi.configuration.Configurable
-
initialize
public void initialize(@Nonnull org.revapi.AnalysisContext analysisContext)
- Specified by:
initializein interfaceorg.revapi.configuration.Configurable
-
setOldTypeEnvironment
public void setOldTypeEnvironment(@Nonnull TypeEnvironment env)
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
public void setNewTypeEnvironment(@Nonnull TypeEnvironment env)
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
@Nullable public final List<org.revapi.Difference> visitEnd()
Please override thedoEnd()method instead.- Specified by:
visitEndin interfaceCheck- Returns:
- the list of found differences between corresponding elements or null if no differences found (null is considered equivalent to returning an empty collection).
- See Also:
Check.visitEnd()
-
visitClass
public final void visitClass(@Nullable JavaTypeElement oldType, @Nullable JavaTypeElement newType)
Please override thedoVisitClass(JavaTypeElement, JavaTypeElement)- Specified by:
visitClassin interfaceCheck- See Also:
Check.visitClass(JavaTypeElement, JavaTypeElement)
-
doVisitClass
protected void doVisitClass(@Nullable JavaTypeElement oldType, @Nullable JavaTypeElement newType)
-
visitMethod
public final void visitMethod(@Nullable JavaMethodElement oldMethod, @Nullable JavaMethodElement newMethod)
Please override thedoVisitMethod(JavaMethodElement, JavaMethodElement)instead.- Specified by:
visitMethodin interfaceCheck- See Also:
Check.visitMethod(JavaMethodElement, JavaMethodElement)
-
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:
Check.visitField(JavaFieldElement, JavaFieldElement)
-
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:
Check.visitAnnotation(JavaAnnotationElement, JavaAnnotationElement)
-
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
@Nullable protected <T extends JavaElement> CheckBase.ActiveElements<T> 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
-
peekLastActive
@Nullable protected CheckBase.ActiveElements<?> 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.
-
-