CallMatcher: purity annotations

GitOrigin-RevId: edd1e90a4f0a7294a651f3595b78e5bb2068672b
This commit is contained in:
Tagir Valeev
2019-07-02 06:52:16 +03:00
committed by intellij-monorepo-bot
parent b015e8996d
commit 3cddd7b1ee
@@ -47,7 +47,7 @@ public interface CallMatcher extends Predicate<PsiMethodCallExpression> {
* @param expression expression to test
* @return true if the supplied expression matches this matcher
*/
@Contract("null -> false")
@Contract(value = "null -> false", pure = true)
default boolean matches(@Nullable PsiExpression expression) {
expression = PsiUtil.skipParenthesizedExprDown(expression);
return expression instanceof PsiMethodCallExpression && test((PsiMethodCallExpression)expression);
@@ -110,6 +110,7 @@ public interface CallMatcher extends Predicate<PsiMethodCallExpression> {
* @param methodNames names of the methods
* @return a new matcher
*/
@Contract(pure = true)
static Simple instanceCall(@NotNull String className, String... methodNames) {
return new Simple(className, ContainerUtil.newTroveSet(methodNames), null, CallType.INSTANCE);
}
@@ -121,6 +122,7 @@ public interface CallMatcher extends Predicate<PsiMethodCallExpression> {
* @param methodNames names of the methods
* @return a new matcher
*/
@Contract(pure = true)
static Simple exactInstanceCall(@NotNull String className, String... methodNames) {
return new Simple(className, ContainerUtil.newTroveSet(methodNames), null, CallType.EXACT_INSTANCE);
}
@@ -132,6 +134,7 @@ public interface CallMatcher extends Predicate<PsiMethodCallExpression> {
* @param methodNames names of the methods
* @return a new matcher
*/
@Contract(pure = true)
static Simple staticCall(@NotNull String className, String... methodNames) {
return new Simple(className, ContainerUtil.newTroveSet(methodNames), null, CallType.STATIC);
}
@@ -151,6 +154,7 @@ public interface CallMatcher extends Predicate<PsiMethodCallExpression> {
* @return PsiReferenceExpression if match is successful, null otherwise
*/
@Nullable
@Contract(pure = true)
default PsiReferenceExpression getReferenceIfMatched(PsiExpression expression) {
if (expression instanceof PsiMethodReferenceExpression && methodReferenceMatches((PsiMethodReferenceExpression)expression)) {
return (PsiReferenceExpression)expression;
@@ -164,6 +168,7 @@ public interface CallMatcher extends Predicate<PsiMethodCallExpression> {
/**
* @return call matcher with additional check before actual call matching
*/
@Contract(pure = true)
default CallMatcher withContextFilter(@NotNull Predicate<? super PsiElement> filter) {
return new CallMatcher() {
@Override
@@ -199,6 +204,7 @@ public interface CallMatcher extends Predicate<PsiMethodCallExpression> {
/**
* @return call matcher, that matches element for file with given language level or higher
*/
@Contract(pure = true)
default CallMatcher withLanguageLevelAtLeast(@NotNull LanguageLevel level) {
return withContextFilter(element -> PsiUtil.getLanguageLevel(element).isAtLeast(level));
}
@@ -231,6 +237,7 @@ public interface CallMatcher extends Predicate<PsiMethodCallExpression> {
* @return a new matcher
* @throws IllegalStateException if this matcher is already limited to parameters count or types
*/
@Contract(pure = true)
public Simple parameterCount(int count) {
if (myParameters != null) {
throw new IllegalStateException("Parameter count is already set to " + count);
@@ -246,6 +253,7 @@ public interface CallMatcher extends Predicate<PsiMethodCallExpression> {
* @return a new matcher
* @throws IllegalStateException if this matcher is already limited to parameters count or types
*/
@Contract(pure = true)
public Simple parameterTypes(@NotNull String... types) {
if (myParameters != null) {
throw new IllegalStateException("Parameters are already registered");
@@ -260,6 +268,7 @@ public interface CallMatcher extends Predicate<PsiMethodCallExpression> {
psiType instanceof PsiClassType && ((PsiClassType)psiType).rawType().equalsToText(type);
}
@Contract(pure = true)
@Override
public boolean methodReferenceMatches(PsiMethodReferenceExpression methodRef) {
if (methodRef == null) return false;
@@ -271,6 +280,7 @@ public interface CallMatcher extends Predicate<PsiMethodCallExpression> {
return parametersMatch(parameterList);
}
@Contract(pure = true)
@Override
public boolean test(PsiMethodCallExpression call) {
if (call == null) return false;
@@ -298,7 +308,7 @@ public interface CallMatcher extends Predicate<PsiMethodCallExpression> {
}
@Override
@Contract("null -> false")
@Contract(value = "null -> false", pure = true)
public boolean methodMatches(PsiMethod method) {
if (method == null) return false;
if (!myNames.contains(method.getName())) return false;