Files
kotlin-fork/idea/tests/org/jetbrains/jet/completion/DataFlowValueRenderingTest.kt
T
Denis Zharkov b3bf8933df Extensions PsiElement.getParentOfType with reified T
1. Renamed *ByType -> *OfType (as in PsiTreeUtil.java)
2. Introduced PsiElement.getStrictParentOfType and PsiElement.getNonStrictParentOfType
with reified TP
3. Replaced current usages of PsiTreeUtil.getParentOfType and current
extensions
4. Made reified version of PsiElement.getParentOfTypeAndBranch with
default strict value --- false (as it used)
2014-12-01 22:28:35 +03:00

56 lines
2.4 KiB
Kotlin

/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.completion
import org.jetbrains.jet.plugin.PluginTestCaseBase
import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.plugin.completion.renderDataFlowValue
import org.jetbrains.jet.JetTestUtils
import com.intellij.openapi.util.io.FileUtil
import java.io.File
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getDataFlowInfo
import org.jetbrains.jet.plugin.caches.resolve.analyze
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
public abstract class AbstractDataFlowValueRenderingTest: JetLightCodeInsightFixtureTestCase() {
override fun getTestDataPath() : String {
return PluginTestCaseBase.getTestDataPathBase() + "/dataFlowValueRendering/"
}
override fun getProjectDescriptor(): LightProjectDescriptor {
return LightCodeInsightFixtureTestCase.JAVA_LATEST
}
fun doTest(fileName: String) {
val fixture = myFixture
fixture.configureByFile(fileName)
val jetFile = fixture.getFile() as JetFile
val element = jetFile.findElementAt(fixture.getCaretOffset())
val expression = element.getStrictParentOfType<JetExpression>()!!
val info = expression.analyze().getDataFlowInfo(expression)
val allValues = (info.getCompleteTypeInfo().keySet() + info.getCompleteNullabilityInfo().keySet()).toSet()
val actual = allValues.map { renderDataFlowValue(it) }.filterNotNull().sort().makeString("\n")
JetTestUtils.assertEqualsToFile(File(FileUtil.getNameWithoutExtension(fileName) + ".txt"), actual)
}
}