public abstract class CheckBase extends Object implements 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.
pushActive(JavaElement, JavaElement, Object...)
,
popIfActive()
Modifier and Type | Class and Description |
---|---|
protected static class |
CheckBase.ActiveElements<T extends JavaElement>
Represents the elements that have been
pushed onto
the active elements stack. |
Check.Type
Constructor and Description |
---|
CheckBase() |
Modifier and Type | Method and Description |
---|---|
protected org.revapi.Difference |
createDifference(Code code,
LinkedHashMap<String,String> attachments) |
protected org.revapi.Difference |
createDifferenceWithExplicitParams(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 void |
doVisitClass(JavaTypeElement oldType,
JavaTypeElement newType) |
protected void |
doVisitField(JavaFieldElement oldField,
JavaFieldElement newField) |
protected void |
doVisitMethod(JavaMethodElement oldMethod,
JavaMethodElement newMethod) |
protected void |
doVisitMethodParameter(JavaMethodParameterElement oldParameter,
JavaMethodParameterElement newParameter) |
org.revapi.AnalysisContext |
getAnalysisContext() |
String |
getExtensionId() |
Reader |
getJSONSchema() |
TypeEnvironment |
getNewTypeEnvironment() |
TypeEnvironment |
getOldTypeEnvironment() |
void |
initialize(org.revapi.AnalysisContext analysisContext) |
boolean |
isAccessible(JavaModelElement e)
This method checks that the provided element and all its parent elements are accessible (public or protected).
|
boolean |
isBothAccessible(JavaModelElement a,
JavaModelElement b)
Checks whether both provided elements are public or protected.
|
boolean |
isBothPrivate(JavaModelElement a,
JavaModelElement b)
Checks whether both provided elements are (package) private.
|
boolean |
isDescendingOnNonExisting()
The default implementation returns false, because that is the right decision most of the time.
|
boolean |
isMissing(Element e)
The element is deemed missing if its type kind (
TypeMirror.getKind() ) is
TypeKind.ERROR . |
protected CheckBase.ActiveElements<?> |
peekLastActive() |
protected <T extends JavaElement> |
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> |
pushActive(T oldElement,
T newElement,
Object... context)
If called in one of the
doVisit*() methods, this method will push the elements along with some
contextual
data onto an internal stack. |
void |
setNewTypeEnvironment(TypeEnvironment env)
The environment containing the new version of the classes.
|
void |
setOldTypeEnvironment(TypeEnvironment env)
The environment containing the old version of the classes.
|
List<org.revapi.Difference> |
visitAnnotation(JavaAnnotationElement oldAnnotation,
JavaAnnotationElement newAnnotation)
Please override the
doVisitAnnotation(JavaAnnotationElement, JavaAnnotationElement)
instead. |
void |
visitClass(JavaTypeElement oldType,
JavaTypeElement newType)
Please override the
doVisitClass(JavaTypeElement, JavaTypeElement) |
List<org.revapi.Difference> |
visitEnd()
Please override the
doEnd() method instead. |
void |
visitField(JavaFieldElement oldField,
JavaFieldElement newField)
Please override the
doVisitField(JavaFieldElement, JavaFieldElement)
instead. |
void |
visitMethod(JavaMethodElement oldMethod,
JavaMethodElement newMethod)
Please override the
doVisitMethod(JavaMethodElement, JavaMethodElement)
instead. |
void |
visitMethodParameter(JavaMethodParameterElement oldParameter,
JavaMethodParameterElement newParameter) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getInterest
public boolean isDescendingOnNonExisting()
isDescendingOnNonExisting
in interface Check
public boolean isBothPrivate(@Nullable JavaModelElement a, @Nullable JavaModelElement b)
a
- first elementb
- second elementpublic boolean isBothAccessible(@Nullable JavaModelElement a, @Nullable JavaModelElement b)
a
- first elementb
- second elementpublic boolean isAccessible(@Nonnull JavaModelElement e)
e
- the element to checkpublic boolean isMissing(@Nonnull Element e)
TypeMirror.getKind()
) is
TypeKind.ERROR
.e
- the element@Nonnull protected org.revapi.Difference createDifference(@Nonnull Code code, LinkedHashMap<String,String> attachments)
@Nonnull protected org.revapi.Difference createDifferenceWithExplicitParams(@Nonnull Code code, LinkedHashMap<String,String> attachments, String... params)
@Nonnull public TypeEnvironment getOldTypeEnvironment()
@Nonnull public TypeEnvironment getNewTypeEnvironment()
@Nonnull public org.revapi.AnalysisContext getAnalysisContext()
@Nullable public String getExtensionId()
getExtensionId
in interface org.revapi.configuration.Configurable
@Nullable public Reader getJSONSchema()
getJSONSchema
in interface org.revapi.configuration.Configurable
public void initialize(@Nonnull org.revapi.AnalysisContext analysisContext)
initialize
in interface org.revapi.configuration.Configurable
public void setOldTypeEnvironment(@Nonnull TypeEnvironment env)
Check
Called once after the check has been instantiated.
setOldTypeEnvironment
in interface Check
env
- the environment to obtain the helper objects using which one can navigate and examine typespublic void setNewTypeEnvironment(@Nonnull TypeEnvironment env)
Check
Called once after the check has been instantiated.
setNewTypeEnvironment
in interface Check
env
- the environment to obtain the helper objects using which one can navigate and examine types@Nullable public final List<org.revapi.Difference> visitEnd()
doEnd()
method instead.visitEnd
in interface Check
Check.visitEnd()
public final void visitClass(@Nullable JavaTypeElement oldType, @Nullable JavaTypeElement newType)
doVisitClass(JavaTypeElement, JavaTypeElement)
visitClass
in interface Check
Check.visitClass(JavaTypeElement, JavaTypeElement)
protected void doVisitClass(@Nullable JavaTypeElement oldType, @Nullable JavaTypeElement newType)
public final void visitMethod(@Nullable JavaMethodElement oldMethod, @Nullable JavaMethodElement newMethod)
doVisitMethod(JavaMethodElement, JavaMethodElement)
instead.visitMethod
in interface Check
Check.visitMethod(JavaMethodElement, JavaMethodElement)
protected void doVisitMethod(@Nullable JavaMethodElement oldMethod, @Nullable JavaMethodElement newMethod)
public final void visitMethodParameter(@Nullable JavaMethodParameterElement oldParameter, @Nullable JavaMethodParameterElement newParameter)
visitMethodParameter
in interface Check
protected void doVisitMethodParameter(@Nullable JavaMethodParameterElement oldParameter, @Nullable JavaMethodParameterElement newParameter)
public final void visitField(@Nullable JavaFieldElement oldField, @Nullable JavaFieldElement newField)
doVisitField(JavaFieldElement, JavaFieldElement)
instead.visitField
in interface Check
Check.visitField(JavaFieldElement, JavaFieldElement)
protected void doVisitField(@Nullable JavaFieldElement oldField, @Nullable JavaFieldElement newField)
@Nullable public final List<org.revapi.Difference> visitAnnotation(@Nullable JavaAnnotationElement oldAnnotation, @Nullable JavaAnnotationElement newAnnotation)
doVisitAnnotation(JavaAnnotationElement, JavaAnnotationElement)
instead.visitAnnotation
in interface Check
oldAnnotation
- the annotation in the old APInewAnnotation
- the annotation in the new APICheck.visitAnnotation(JavaAnnotationElement, JavaAnnotationElement)
@Nullable protected List<org.revapi.Difference> doVisitAnnotation(@Nullable JavaAnnotationElement oldAnnotation, @Nullable JavaAnnotationElement newAnnotation)
protected final <T extends JavaElement> void pushActive(@Nullable T oldElement, @Nullable T newElement, Object... context)
doVisit*()
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 the
popIfActive()
method.
T
- the type of the elementsoldElement
- the old API elementnewElement
- the new API elementcontext
- optional contextual data@Nullable protected <T extends JavaElement> CheckBase.ActiveElements<T> popIfActive()
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.
T
- the type of the elements@Nullable protected CheckBase.ActiveElements<?> peekLastActive()
Copyright © 2014-2020 Lukas Krejci. All Rights Reserved.