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(javax.lang.model.element.Element, javax.lang.model.element.Element, Object...),
popIfActive()| Modifier and Type | Class and Description |
|---|---|
protected static class |
CheckBase.ActiveElements<T extends Element>
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,
Object... params) |
protected org.revapi.Difference |
createDifference(Code code,
Object[] params,
Object... attachments) |
protected List<org.revapi.Difference> |
doEnd() |
protected List<org.revapi.Difference> |
doVisitAnnotation(AnnotationMirror oldAnnotation,
AnnotationMirror newAnnotation) |
protected void |
doVisitClass(TypeElement oldType,
TypeElement newType) |
protected void |
doVisitField(VariableElement oldField,
VariableElement newField) |
protected void |
doVisitMethod(ExecutableElement oldMethod,
ExecutableElement newMethod) |
protected void |
doVisitMethodParameter(VariableElement oldParameter,
VariableElement newParameter) |
org.revapi.AnalysisContext |
getAnalysisContext() |
String[] |
getConfigurationRootPaths() |
Reader |
getJSONSchema(String configurationRootPath) |
TypeEnvironment |
getNewTypeEnvironment() |
TypeEnvironment |
getOldTypeEnvironment() |
void |
initialize(org.revapi.AnalysisContext analysisContext) |
boolean |
isAccessible(Element e,
TypeEnvironment env) |
boolean |
isBothAccessible(Element a,
TypeEnvironment envA,
Element b,
TypeEnvironment envB)
Checks whether both provided elements are public or protected.
|
boolean |
isBothPrivate(Element a,
TypeEnvironment envA,
Element b,
TypeEnvironment envB)
Checks whether both provided elements are (package) private.
|
boolean |
isMissing(Element e)
The element is deemed missing if its type kind (
TypeMirror.getKind()) is
TypeKind.ERROR. |
boolean |
isPubliclyUsedAs(TypeElement type,
TypeEnvironment env,
Collection<UseSite.Type> uses)
Checks if the type is publicly used as any of the provided use types.
|
boolean |
isSkipUseTracking()
This base class reads the configuration during the initialization and if the "revapi.java.deepUseChainAnalysis"
is set to true, it does expensive checks for usage of private classes in a public manner.
|
protected <T extends Element> |
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 Element> |
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.
|
protected void |
setSkipUseTracking(boolean value)
By default, this value is read from the configuration during the
initialize(AnalysisContext) call. |
List<org.revapi.Difference> |
visitAnnotation(AnnotationMirror oldAnnotation,
AnnotationMirror newAnnotation)
Please override the
doVisitAnnotation(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror)
instead. |
void |
visitClass(TypeElement oldType,
TypeElement newType)
Please override the
doVisitClass(javax.lang.model.element.TypeElement, javax.lang.model.element.TypeElement) instead. |
List<org.revapi.Difference> |
visitEnd()
Please override the
doEnd() method instead. |
void |
visitField(VariableElement oldField,
VariableElement newField)
Please override the
doVisitField(javax.lang.model.element.VariableElement, javax.lang.model.element.VariableElement)
instead. |
void |
visitMethod(ExecutableElement oldMethod,
ExecutableElement newMethod)
Please override the
doVisitMethod(javax.lang.model.element.ExecutableElement, javax.lang.model.element.ExecutableElement)
instead. |
void |
visitMethodParameter(VariableElement oldParameter,
VariableElement newParameter) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetInterestpublic boolean isBothPrivate(@Nullable Element a, TypeEnvironment envA, @Nullable Element b, TypeEnvironment envB)
a - first elementenvA - the type environment of the first elementb - second elementenvB - the type environment of the second elementpublic boolean isBothAccessible(@Nullable Element a, @Nonnull TypeEnvironment envA, @Nullable Element b, @Nonnull TypeEnvironment envB)
a - first elementenvA - the type environment of the first elementb - second elementenvB - the type environment of the second elementpublic boolean isAccessible(@Nonnull Element e, @Nonnull TypeEnvironment env)
e - the element to checkenv - the type environment of the elementpublic boolean isMissing(@Nonnull Element e)
TypeMirror.getKind()) is
TypeKind.ERROR.e - the elementpublic boolean isPubliclyUsedAs(@Nonnull TypeElement type, TypeEnvironment env, Collection<UseSite.Type> uses)
type - the typeenv - the environment in which the type existsuses - the use types to check forpublic boolean isSkipUseTracking()
isAccessible(Element, TypeEnvironment) method, false if it
isprotected void setSkipUseTracking(boolean value)
initialize(AnalysisContext) call.
If you need to override that value for some reason, use this method.value - the new value of the skipUseTracking property@Nonnull protected org.revapi.Difference createDifference(@Nonnull Code code, Object... params)
@Nonnull protected org.revapi.Difference createDifference(@Nonnull Code code, @Nullable Object[] params, Object... attachments)
@Nonnull public TypeEnvironment getOldTypeEnvironment()
@Nonnull public TypeEnvironment getNewTypeEnvironment()
@Nonnull public org.revapi.AnalysisContext getAnalysisContext()
@Nullable public String[] getConfigurationRootPaths()
getConfigurationRootPaths in interface org.revapi.configuration.Configurable@Nullable public Reader getJSONSchema(@Nonnull String configurationRootPath)
getJSONSchema in interface org.revapi.configuration.Configurablepublic void initialize(@Nonnull org.revapi.AnalysisContext analysisContext)
initialize in interface org.revapi.configuration.Configurablepublic void setOldTypeEnvironment(@Nonnull TypeEnvironment env)
CheckCalled once after the check has been instantiated.
setOldTypeEnvironment in interface Checkenv - the environment to obtain the helper objects using which one can navigate and examine typespublic void setNewTypeEnvironment(@Nonnull TypeEnvironment env)
CheckCalled once after the check has been instantiated.
setNewTypeEnvironment in interface Checkenv - 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 CheckCheck.visitEnd()public final void visitClass(@Nullable TypeElement oldType, @Nullable TypeElement newType)
doVisitClass(javax.lang.model.element.TypeElement, javax.lang.model.element.TypeElement) instead.visitClass in interface CheckCheck.visitClass(javax.lang.model.element.TypeElement, javax.lang.model.element.TypeElement)protected void doVisitClass(@Nullable TypeElement oldType, @Nullable TypeElement newType)
public final void visitMethod(@Nullable ExecutableElement oldMethod, @Nullable ExecutableElement newMethod)
doVisitMethod(javax.lang.model.element.ExecutableElement, javax.lang.model.element.ExecutableElement)
instead.visitMethod in interface CheckCheck.visitMethod(javax.lang.model.element.ExecutableElement, javax.lang.model.element.ExecutableElement)protected void doVisitMethod(@Nullable ExecutableElement oldMethod, @Nullable ExecutableElement newMethod)
public final void visitMethodParameter(@Nullable VariableElement oldParameter, @Nullable VariableElement newParameter)
visitMethodParameter in interface Checkprotected void doVisitMethodParameter(@Nullable VariableElement oldParameter, @Nullable VariableElement newParameter)
public final void visitField(@Nullable VariableElement oldField, @Nullable VariableElement newField)
doVisitField(javax.lang.model.element.VariableElement, javax.lang.model.element.VariableElement)
instead.visitField in interface CheckCheck.visitField(javax.lang.model.element.VariableElement, javax.lang.model.element.VariableElement)protected void doVisitField(@Nullable VariableElement oldField, @Nullable VariableElement newField)
@Nullable public final List<org.revapi.Difference> visitAnnotation(@Nullable AnnotationMirror oldAnnotation, @Nullable AnnotationMirror newAnnotation)
doVisitAnnotation(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror)
instead.visitAnnotation in interface CheckoldAnnotation - the annotation in the old APInewAnnotation - the annotation in the new APICheck.visitAnnotation(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror)@Nullable protected List<org.revapi.Difference> doVisitAnnotation(@Nullable AnnotationMirror oldAnnotation, @Nullable AnnotationMirror newAnnotation)
protected final <T extends Element> 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 Element> 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 elementsCopyright © 2016 Lukas Krejci. All Rights Reserved.