Skip to content

Commit 944a35a

Browse files
authored
Merge pull request #81 from Haehnchen/feature/cross-api
ConstructorMockIntention should support all API version related to pr…
2 parents 9f459f1 + 2b2baa2 commit 944a35a

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/main/java/de/espend/idea/php/phpunit/intention/ConstructorMockIntention.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.intellij.codeInsight.intention.HighPriorityAction;
44
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction;
5+
import com.intellij.codeInsight.intention.preview.IntentionPreviewUtils;
56
import com.intellij.openapi.command.WriteCommandAction;
67
import com.intellij.openapi.editor.Editor;
78
import com.intellij.openapi.project.Project;
@@ -49,19 +50,26 @@ public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement
4950
continue;
5051
}
5152

52-
WriteCommandAction.runWriteCommandAction(
53-
psiElement.getProject(),
54-
getText(),
55-
"",
56-
new MyConstructorCommandActionArgument(
57-
psiElement,
58-
PsiTreeUtil.getChildOfType(newExpression, ParameterList.class),
59-
constructor,
60-
newExpression
61-
),
62-
psiElement.getContainingFile()
53+
MyConstructorCommandActionArgument runnable = new MyConstructorCommandActionArgument(
54+
psiElement,
55+
PsiTreeUtil.getChildOfType(newExpression, ParameterList.class),
56+
constructor,
57+
newExpression
6358
);
6459

60+
// support cross API version compatibility
61+
if (IntentionPreviewUtils.isPreviewElement(psiElement)) {
62+
runnable.run();
63+
} else {
64+
WriteCommandAction.runWriteCommandAction(
65+
psiElement.getProject(),
66+
getText(),
67+
"",
68+
runnable,
69+
psiElement.getContainingFile()
70+
);
71+
}
72+
6573
return;
6674
}
6775
}

0 commit comments

Comments
 (0)