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;
}
}));
}
}
Aggregations