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. |
| Constructor and Description |
|---|
CheckBase() |
| Modifier and Type | Method and Description |
|---|---|
protected Difference |
createDifference(Code code,
Object... params) |
protected Difference |
createDifference(Code code,
Object[] params,
Object... attachments) |
protected List<Difference> |
doEnd() |
protected List<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) |
AnalysisContext |
getAnalysisContext() |
String[] |
getConfigurationRootPaths() |
Reader |
getJSONSchema(String configurationRootPath) |
TypeEnvironment |
getNewTypeEnvironment() |
TypeEnvironment |
getOldTypeEnvironment() |
void |
initialize(AnalysisContext analysisContext) |
static boolean |
isAccessible(Element e) |
static boolean |
isAccessibleOrInAPI(Element e,
TypeEnvironment env)
Certain elements might be forced into the API even if they are not accessible (this is most usually a
programming error).
|
static boolean |
isBothAccessible(Element a,
Element b)
Checks whether both provided elements are public or protected.
|
static boolean |
isBothAccessibleOrInApi(Element a,
TypeEnvironment envA,
Element b,
TypeEnvironment envB)
Extension of the
isAccessibleOrInAPI(javax.lang.model.element.Element, TypeEnvironment) method for 2 elements. |
static boolean |
isBothPrivate(Element a,
Element b)
Checks whether both provided elements are (package) private.
|
static boolean |
isEffectivelyAccessible(Element e)
Similar to
isAccessible(javax.lang.model.element.Element) but also checks that all enclosing
elements of the provided element are accessible, too. |
static boolean |
isMissing(Element e)
The element is deemed missing if its type kind (
TypeMirror.getKind()) is
TypeKind.ERROR. |
static boolean |
isPubliclyUsedAs(TypeElement type,
TypeEnvironment env,
Collection<UseSite.Type> uses)
Checks if the type is publicly used as any of the provided use types.
|
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.
|
List<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<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) |
public static boolean isBothPrivate(@Nullable Element a, @Nullable Element b)
a - first elementb - second elementpublic static boolean isBothAccessible(@Nullable Element a, @Nullable Element b)
a - first elementb - second elementpublic static boolean isAccessible(@Nonnull Element e)
e - the element to checkpublic static boolean isEffectivelyAccessible(@Nonnull Element e)
isAccessible(javax.lang.model.element.Element) but also checks that all enclosing
elements of the provided element are accessible, too.e - the element to checkpublic static boolean isMissing(@Nonnull Element e)
TypeMirror.getKind()) is
TypeKind.ERROR.e - the elementpublic static boolean isAccessibleOrInAPI(@Nonnull Element e, @Nonnull TypeEnvironment env)
This method returns true if the provided element is either accessible or is used as anything but super-class or super-interface. A non-accessible super-class of a public class is not an error nor a design flaw, so is the inaccessible interface being implemented.
e - the elementenv - the type environment from which the element comes frompublic static 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 static boolean isBothAccessibleOrInApi(@Nonnull Element a, @Nonnull TypeEnvironment envA, @Nonnull Element b, @Nonnull TypeEnvironment envB)
isAccessibleOrInAPI(javax.lang.model.element.Element, TypeEnvironment) method for 2 elements.a - the first elementenvA - the type environment of the first elementb - the second elementenvB - the type environment of the second element@Nonnull protected Difference createDifference(@Nonnull Code code, Object... params)
@Nonnull protected Difference createDifference(@Nonnull Code code, @Nonnull Object[] params, Object... attachments)
@Nonnull public TypeEnvironment getOldTypeEnvironment()
@Nonnull public TypeEnvironment getNewTypeEnvironment()
@Nonnull public AnalysisContext getAnalysisContext()
@Nullable public String[] getConfigurationRootPaths()
getConfigurationRootPaths in interface Configurable@Nullable public Reader getJSONSchema(@Nonnull String configurationRootPath)
getJSONSchema in interface Configurablepublic void initialize(@Nonnull AnalysisContext analysisContext)
initialize in interface 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<Difference> visitEnd()
doEnd() method instead.visitEnd in interface CheckCheck.visitEnd()@Nullable protected List<Difference> doEnd()
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<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<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 © 2015. All Rights Reserved.