Add additional check to AbstractPsiCheckerTest

Check that KtDeclaration.resolveToDescriptor() utility does not throw
This commit is contained in:
Pavel V. Talanov
2016-03-01 19:03:11 +03:00
parent 37500e2cd5
commit e121ef0fdc
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2016 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -20,20 +20,28 @@ import com.intellij.rt.execution.junit.FileComparisonFailure;
import com.intellij.spellchecker.inspections.SpellCheckingInspection; import com.intellij.spellchecker.inspections.SpellCheckingInspection;
import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.LightProjectDescriptor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionUtils;
import org.jetbrains.kotlin.idea.highlighter.NameHighlighter; import org.jetbrains.kotlin.idea.highlighter.NameHighlighter;
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase; import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase;
import org.jetbrains.kotlin.psi.KtDeclaration;
import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.psi.KtTreeVisitorVoid;
import java.io.File; import java.io.File;
import static org.jetbrains.kotlin.resolve.lazy.ResolveSession.areDescriptorsCreatedForDeclaration;
public abstract class AbstractPsiCheckerTest extends KotlinLightCodeInsightFixtureTestCase { public abstract class AbstractPsiCheckerTest extends KotlinLightCodeInsightFixtureTestCase {
public void doTest(@NotNull String filePath) throws Exception { public void doTest(@NotNull String filePath) throws Exception {
myFixture.configureByFile(filePath); myFixture.configureByFile(filePath);
checkHighlighting(true, false, false); checkHighlighting(true, false, false);
checkResolveToDescriptor();
} }
public void doTest(@NotNull String... filePath) throws Exception { public void doTest(@NotNull String... filePath) throws Exception {
myFixture.configureByFiles(filePath); myFixture.configureByFiles(filePath);
checkHighlighting(true, false, false); checkHighlighting(true, false, false);
checkResolveToDescriptor();
} }
public void doTestWithInfos(@NotNull String filePath) throws Exception { public void doTestWithInfos(@NotNull String filePath) throws Exception {
@@ -45,6 +53,7 @@ public abstract class AbstractPsiCheckerTest extends KotlinLightCodeInsightFixtu
NameHighlighter.INSTANCE.setNamesHighlightingEnabled(false); NameHighlighter.INSTANCE.setNamesHighlightingEnabled(false);
checkHighlighting(true, true, false); checkHighlighting(true, true, false);
checkResolveToDescriptor();
} }
finally { finally {
NameHighlighter.INSTANCE.setNamesHighlightingEnabled(true); NameHighlighter.INSTANCE.setNamesHighlightingEnabled(true);
@@ -60,6 +69,19 @@ public abstract class AbstractPsiCheckerTest extends KotlinLightCodeInsightFixtu
} }
} }
void checkResolveToDescriptor() {
KtFile file = (KtFile) myFixture.getFile();
file.accept(new KtTreeVisitorVoid() {
@Override
public void visitDeclaration(@NotNull KtDeclaration dcl) {
if (areDescriptorsCreatedForDeclaration(dcl)) {
ResolutionUtils.resolveToDescriptor(dcl); // check for exceptions
}
dcl.acceptChildren(this, null);
}
});
}
@NotNull @NotNull
@Override @Override
protected LightProjectDescriptor getProjectDescriptor() { protected LightProjectDescriptor getProjectDescriptor() {