public class JavaMethodContractUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ORG_JETBRAINS_ANNOTATIONS_CONTRACT
JetBrains contract annotation fully-qualified name
|
Modifier and Type | Method and Description |
---|---|
static PsiAnnotation |
findContractAnnotation(PsiMethod method)
Returns a contract annotation for given method, checking the hierarchy
|
static PsiExpression |
findReturnedValue(PsiMethodCallExpression call)
For given method call find the returned expression if the method is known to return always the same parameter or its qualifier
(unless fail).
|
static java.util.List<? extends MethodContract> |
getMethodCallContracts(PsiCallExpression call)
Returns a list of contracts defined for given method call (including hardcoded contracts if any)
|
static java.util.List<? extends MethodContract> |
getMethodCallContracts(PsiMethod method,
PsiCallExpression call)
Returns a list of contracts defined for given method call (including hardcoded contracts if any)
|
static java.util.List<StandardMethodContract> |
getMethodContracts(PsiMethod method)
Returns a list of contracts defined for given method call (excluding hardcoded contracts)
|
static ContractReturnValue |
getNonFailingReturnValue(java.util.List<? extends MethodContract> contracts)
Returns the common return value of the method assuming that it does not fail
|
static boolean |
hasExplicitContractAnnotation(PsiMethod method)
Checks whether method has an explicit contract annotation (either in source code or as external annotation)
|
static boolean |
isPure(PsiMethod method)
Checks the method purity based on its contract
|
static java.util.List<StandardMethodContract> |
parseContracts(PsiMethod method,
PsiAnnotation contractAnno)
Parse contracts for given method.
|
static PsiAnnotation |
updateContract(PsiAnnotation annotation,
java.util.List<StandardMethodContract> contracts)
Creates a new
PsiAnnotation describing the updated contract. |
public static final java.lang.String ORG_JETBRAINS_ANNOTATIONS_CONTRACT
public static java.util.List<? extends MethodContract> getMethodCallContracts(PsiCallExpression call)
call
- a method call site.public static java.util.List<? extends MethodContract> getMethodCallContracts(PsiMethod method, PsiCallExpression call)
method
- a method to check the contracts forcall
- an optional call site. If specified, could be taken into account to derive contracts for some
testing methods like assertThat(x, is(null))public static java.util.List<StandardMethodContract> getMethodContracts(PsiMethod method)
method
- a method to check the contracts forpublic static boolean hasExplicitContractAnnotation(PsiMethod method)
method
- method to checkpublic static PsiAnnotation updateContract(PsiAnnotation annotation, java.util.List<StandardMethodContract> contracts)
PsiAnnotation
describing the updated contract. Only contract clauses are updated;
purity and mutation signature (if exist) are left as is.annotation
- original annotation to updatecontracts
- new contractsPsiAnnotation
object which describes updated contracts or null if no annotation is required to represent
the target contracts (i.e. contracts is empty, method has no mutation signature and is not marked as pure).public static java.util.List<StandardMethodContract> parseContracts(PsiMethod method, PsiAnnotation contractAnno)
getMethodContracts(PsiMethod)
instead.method
- method to parse contracts forcontractAnno
- a contract annotationpublic static PsiAnnotation findContractAnnotation(PsiMethod method)
method
- a methodpublic static boolean isPure(PsiMethod method)
method
- method to checkContract#pure()
for details).public static ContractReturnValue getNonFailingReturnValue(java.util.List<? extends MethodContract> contracts)
contracts
- method contractspublic static PsiExpression findReturnedValue(PsiMethodCallExpression call)
call
- call to analyze