public abstract class ContractReturnValue
extends java.lang.Object
MethodContract
return value. It may represent the concrete value (e.g. "false") or pose some constraints
to the method return value (e.g. "!null").Modifier and Type | Class and Description |
---|---|
static class |
ContractReturnValue.BooleanReturnValue
Boolean return value (either "true" or "false").
|
static class |
ContractReturnValue.ParameterReturnValue |
Modifier and Type | Method and Description |
---|---|
static ContractReturnValue |
fail() |
abstract DfaValue |
getDfaValue(DfaValueFactory factory,
DfaValue defaultValue,
com.intellij.codeInspection.dataFlow.DfaCallState callState)
Converts this return value to the most suitable
DfaValue which represents the same constraints. |
java.lang.String |
getMethodCompatibilityProblem(PsiMethod method)
Checks whether this return value makes sense for the specified method signature.
|
int |
hashCode() |
ContractReturnValue |
intersect(ContractReturnValue other) |
boolean |
isBoolean() |
boolean |
isFail() |
boolean |
isMethodCompatible(PsiMethod method)
Checks whether this return value makes sense for the specified method signature.
|
boolean |
isNotNull() |
boolean |
isNull() |
boolean |
isSuperValueOf(ContractReturnValue value) |
abstract boolean |
isValueCompatible(DfaMemoryState state,
DfaValue value)
Returns true if the supplied
DfaValue could be compatible with this return value. |
int |
ordinal()
Returns a unique non-negative number which identifies this return value.
|
static ContractReturnValue |
returnAny() |
static ContractReturnValue.BooleanReturnValue |
returnBoolean(boolean value) |
static ContractReturnValue.BooleanReturnValue |
returnFalse() |
static ContractReturnValue |
returnNew() |
static ContractReturnValue |
returnNotNull() |
static ContractReturnValue |
returnNull() |
static ContractReturnValue |
returnParameter(int n) |
static ContractReturnValue |
returnThis() |
static ContractReturnValue.BooleanReturnValue |
returnTrue() |
java.lang.String |
toString() |
static ContractReturnValue |
valueOf(int ordinal)
Returns a
ContractReturnValue which corresponds to given ordinal index. |
static ContractReturnValue |
valueOf(java.lang.String value)
Returns a
ContractReturnValue which corresponds to given string representation. |
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
Contract
annotation.public final java.lang.String getMethodCompatibilityProblem(PsiMethod method)
boolean
, but does not make sense for method returning int
.
This method can be used to check the contract correctness.method
- public final boolean isMethodCompatible(PsiMethod method)
boolean
, but does not make sense for method returning int
.
This method can be used to check the contract correctness.method
- public ContractReturnValue intersect(ContractReturnValue other)
public boolean isSuperValueOf(ContractReturnValue value)
public abstract DfaValue getDfaValue(DfaValueFactory factory, DfaValue defaultValue, com.intellij.codeInspection.dataFlow.DfaCallState callState)
DfaValue
which represents the same constraints.factory
- a DfaValueFactory
which can be used to create new values if necessarydefaultValue
- a default method return type value in the absence of the contracts (may contain method type information)callState
- call statepublic abstract boolean isValueCompatible(DfaMemoryState state, DfaValue value)
DfaValue
could be compatible with this return value. If false is returned, then
returning given DfaValue
would violate the contract with this return value. This method can be used
to check the contract correctness.state
- memory state to usevalue
- value to checkpublic int ordinal()
a
and b
the following holds:
a.ordinal() == b.ordinal() <=> a.equals(b)
.public boolean isNotNull()
public boolean isNull()
public boolean isFail()
public boolean isBoolean()
public static ContractReturnValue valueOf(int ordinal)
ContractReturnValue
which corresponds to given ordinal index. For any return value x
the following holds: ContractReturnValue.valueOf(x.ordinal()).equals(x)
.ordinal
- ordinal to create a ContractReturnValue object frompublic static ContractReturnValue valueOf(java.lang.String value)
ContractReturnValue
which corresponds to given string representation. For any return value x
the following holds: ContractReturnValue.valueOf(x.toString()).equals(x)
and for string str
the following holds:
ContractReturnValue.valueOf(str) == null || ContractReturnValue.valueOf(str).toString().equals(str)
.value
- string representation of return valuepublic static ContractReturnValue returnAny()
public static ContractReturnValue fail()
public static ContractReturnValue.BooleanReturnValue returnBoolean(boolean value)
value
- a boolean value to returnpublic static ContractReturnValue.BooleanReturnValue returnTrue()
public static ContractReturnValue.BooleanReturnValue returnFalse()
public static ContractReturnValue returnNull()
public static ContractReturnValue returnNotNull()
public static ContractReturnValue returnNew()
public static ContractReturnValue returnThis()
public static ContractReturnValue returnParameter(int n)