mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't blink with pure contract on gutter when starting to write a method
This commit is contained in:
+10
-1
@@ -58,6 +58,7 @@ public class PurityInference {
|
||||
if (body == null) return false;
|
||||
|
||||
final Ref<Boolean> impureFound = Ref.create(false);
|
||||
final Ref<Boolean> hasReturns = Ref.create(false);
|
||||
final List<PsiMethodCallExpression> calls = ContainerUtil.newArrayList();
|
||||
body.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
@Override
|
||||
@@ -68,6 +69,14 @@ public class PurityInference {
|
||||
super.visitAssignmentExpression(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitReturnStatement(PsiReturnStatement statement) {
|
||||
if (statement.getReturnValue() != null) {
|
||||
hasReturns.set(true);
|
||||
}
|
||||
super.visitReturnStatement(statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPrefixExpression(PsiPrefixExpression expression) {
|
||||
if (isMutatingOperation(expression.getOperationTokenType()) && !isLocalVarReference(expression.getOperand())) {
|
||||
@@ -95,7 +104,7 @@ public class PurityInference {
|
||||
}
|
||||
});
|
||||
|
||||
if (impureFound.get() || calls.size() > 1) return false;
|
||||
if (impureFound.get() || calls.size() > 1 || !hasReturns.get()) return false;
|
||||
if (calls.isEmpty()) return true;
|
||||
|
||||
final PsiMethod called = calls.get(0).resolveMethod();
|
||||
|
||||
+9
@@ -120,6 +120,15 @@ int smthPure() { return 3; }
|
||||
"""
|
||||
}
|
||||
|
||||
public void "test don't analyze methods without returns"() {
|
||||
assertPure false, """
|
||||
Object method() {
|
||||
smthPure();
|
||||
}
|
||||
int smthPure() { return 3; }
|
||||
"""
|
||||
}
|
||||
|
||||
private void assertPure(boolean expected, String classBody) {
|
||||
def clazz = myFixture.addClass("final class Foo { $classBody }")
|
||||
assert expected == PurityInference.inferPurity(clazz.methods[0])
|
||||
|
||||
Reference in New Issue
Block a user