[FIR IDE] File symbol scope and symbol test
This commit is contained in:
@@ -92,6 +92,7 @@ import org.jetbrains.kotlin.idea.folding.AbstractKotlinFoldingTest
|
||||
import org.jetbrains.kotlin.idea.frontend.api.components.AbstractExpectedExpressionTypeTest
|
||||
import org.jetbrains.kotlin.idea.frontend.api.components.AbstractReturnExpressionTargetTest
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.AbstractResolveCallTest
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.AbstractFileScopeTest
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.AbstractMemberScopeByFqNameTest
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.*
|
||||
import org.jetbrains.kotlin.idea.hierarchy.AbstractHierarchyTest
|
||||
@@ -1013,6 +1014,10 @@ fun main(args: Array<String>) {
|
||||
model("memberScopeByFqName", extension = "txt")
|
||||
}
|
||||
|
||||
testClass<AbstractFileScopeTest> {
|
||||
model("fileScopeTest", extension = "kt")
|
||||
}
|
||||
|
||||
testClass<AbstractSymbolFromSourcePointerRestoreTest> {
|
||||
model("symbolPointer", extension = "kt")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fun test(): Int = 3
|
||||
|
||||
val testVal: Int = 2
|
||||
|
||||
class C {
|
||||
fun r() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
interface I
|
||||
@@ -0,0 +1,83 @@
|
||||
FILE SYMBOL:
|
||||
KtFirFileSymbol:
|
||||
annotations: []
|
||||
origin: SOURCE
|
||||
|
||||
CALLABLE NAMES:
|
||||
[test, testVal]
|
||||
|
||||
CALLABLE SYMBOLS:
|
||||
KtFirFunctionSymbol:
|
||||
annotations: []
|
||||
callableIdIfNonLocal: test
|
||||
isExtension: false
|
||||
isExternal: false
|
||||
isInline: false
|
||||
isOperator: false
|
||||
isOverride: false
|
||||
isSuspend: false
|
||||
modality: FINAL
|
||||
name: test
|
||||
origin: SOURCE
|
||||
receiverTypeAndAnnotations: null
|
||||
symbolKind: TOP_LEVEL
|
||||
type: kotlin/Int
|
||||
typeParameters: []
|
||||
valueParameters: []
|
||||
visibility: PUBLIC
|
||||
|
||||
KtFirKotlinPropertySymbol:
|
||||
annotations: []
|
||||
callableIdIfNonLocal: testVal
|
||||
getter: KtFirPropertyGetterSymbol(<getter>)
|
||||
hasBackingField: true
|
||||
hasGetter: true
|
||||
hasSetter: false
|
||||
initializer: 2
|
||||
isConst: false
|
||||
isExtension: false
|
||||
isLateInit: false
|
||||
isOverride: false
|
||||
isVal: true
|
||||
modality: FINAL
|
||||
name: testVal
|
||||
origin: SOURCE
|
||||
receiverTypeAndAnnotations: null
|
||||
setter: null
|
||||
symbolKind: TOP_LEVEL
|
||||
type: kotlin/Int
|
||||
visibility: PUBLIC
|
||||
|
||||
CLASSIFIER NAMES:
|
||||
[C, I]
|
||||
|
||||
CLASSIFIER SYMBOLS:
|
||||
KtFirClassOrObjectSymbol:
|
||||
annotations: []
|
||||
classIdIfNonLocal: C
|
||||
classKind: CLASS
|
||||
companionObject: null
|
||||
isInner: false
|
||||
modality: FINAL
|
||||
name: C
|
||||
origin: SOURCE
|
||||
primaryConstructor: KtFirConstructorSymbol(<constructor>)
|
||||
superTypes: [kotlin/Any]
|
||||
symbolKind: TOP_LEVEL
|
||||
typeParameters: []
|
||||
visibility: PUBLIC
|
||||
|
||||
KtFirClassOrObjectSymbol:
|
||||
annotations: []
|
||||
classIdIfNonLocal: I
|
||||
classKind: INTERFACE
|
||||
companionObject: null
|
||||
isInner: false
|
||||
modality: ABSTRACT
|
||||
name: I
|
||||
origin: SOURCE
|
||||
primaryConstructor: null
|
||||
superTypes: [kotlin/Any]
|
||||
symbolKind: TOP_LEVEL
|
||||
typeParameters: []
|
||||
visibility: PUBLIC
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.frontend.api.scopes
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.idea.executeOnPooledThreadInReadAction
|
||||
import org.jetbrains.kotlin.idea.frontend.api.analyze
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.DebugSymbolRenderer
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractFileScopeTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
|
||||
protected fun doTest(path: String) {
|
||||
val ktFile = myFixture.configureByText("file.kt", FileUtil.loadFile(File(path))) as KtFile
|
||||
|
||||
val actual = executeOnPooledThreadInReadAction {
|
||||
analyze(ktFile) {
|
||||
val symbol = ktFile.getFileSymbol()
|
||||
val scope = symbol.getFileScope()
|
||||
|
||||
val renderedSymbol = DebugSymbolRenderer.render(symbol)
|
||||
val callableNames = scope.getCallableNames()
|
||||
val renderedCallables = scope.getCallableSymbols().map { DebugSymbolRenderer.render(it) }
|
||||
val classifierNames = scope.getClassifierNames()
|
||||
val renderedClassifiers = scope.getClassifierSymbols().map { DebugSymbolRenderer.render(it) }
|
||||
|
||||
"FILE SYMBOL:\n" + renderedSymbol +
|
||||
"\nCALLABLE NAMES:\n" + callableNames.joinToString(prefix = "[", postfix = "]\n", separator = ", ") +
|
||||
"\nCALLABLE SYMBOLS:\n" + renderedCallables.joinToString(separator = "\n") +
|
||||
"\nCLASSIFIER NAMES:\n" + classifierNames.joinToString(prefix = "[", postfix = "]\n", separator = ", ") +
|
||||
"\nCLASSIFIER SYMBOLS:\n" + renderedClassifiers.joinToString(separator = "\n")
|
||||
}
|
||||
}
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(File("$path.result"), actual)
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.frontend.api.scopes;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/idea-frontend-fir/testData/fileScopeTest")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class FileScopeTestGenerated extends AbstractFileScopeTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInFileScopeTest() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-frontend-fir/testData/fileScopeTest"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("simpleFileScope.kt")
|
||||
public void testSimpleFileScope() throws Exception {
|
||||
runTest("idea/idea-frontend-fir/testData/fileScopeTest/simpleFileScope.kt");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user