Search in sources :

Example 1 with Unwrapper

use of com.intellij.codeInsight.unwrap.Unwrapper in project kotlin by JetBrains.

the class AbstractUnwrapRemoveTest method doTest.

private void doTest(@NotNull String path, final Class<? extends Unwrapper> unwrapperClass) throws Exception {
    configureByFile(path);
    String fileText = FileUtil.loadFile(new File(path), true);
    String isApplicableString = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// IS_APPLICABLE: ");
    boolean isApplicableExpected = isApplicableString == null || isApplicableString.equals("true");
    String option = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// OPTION: ");
    Integer optionIndex = option != null ? Integer.parseInt(option) : 0;
    List<Pair<PsiElement, Unwrapper>> unwrappersWithPsi = new KotlinUnwrapDescriptor().collectUnwrappers(getProject(), getEditor(), getFile());
    if (isApplicableExpected) {
        final Pair<PsiElement, Unwrapper> selectedUnwrapperWithPsi = unwrappersWithPsi.get(optionIndex);
        assertEquals(unwrapperClass, selectedUnwrapperWithPsi.second.getClass());
        final PsiElement first = selectedUnwrapperWithPsi.first;
        ApplicationManager.getApplication().runWriteAction(new Runnable() {

            @Override
            public void run() {
                selectedUnwrapperWithPsi.second.unwrap(getEditor(), first);
            }
        });
        checkResultByFile(path + ".after");
    } else {
        assertTrue(ContainerUtil.and(unwrappersWithPsi, new Condition<Pair<PsiElement, Unwrapper>>() {

            @Override
            public boolean value(Pair<PsiElement, Unwrapper> pair) {
                return pair.second.getClass() != unwrapperClass;
            }
        }));
    }
}
Also used : Condition(com.intellij.openapi.util.Condition) Unwrapper(com.intellij.codeInsight.unwrap.Unwrapper) File(java.io.File) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair)

Aggregations

Unwrapper (com.intellij.codeInsight.unwrap.Unwrapper)1 Condition (com.intellij.openapi.util.Condition)1 Pair (com.intellij.openapi.util.Pair)1 PsiElement (com.intellij.psi.PsiElement)1 File (java.io.File)1