[FE] Add tests for 'containingClassForStaticMemberAttr'

This commit is contained in:
Yan Zhulanow
2022-11-26 00:37:02 +09:00
committed by Space Team
parent 4489ccf864
commit 10fc86ef92
28 changed files with 604 additions and 50 deletions
@@ -23462,6 +23462,52 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/override/derivedClasses")
@TestDataPath("$PROJECT_ROOT")
public class DerivedClasses {
@Test
public void testAllFilesPresentInDerivedClasses() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/override/derivedClasses"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@Test
@TestMetadata("Constructor.kt")
public void testConstructor() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/derivedClasses/Constructor.kt");
}
@Test
@TestMetadata("DelegatedConstructor.kt")
public void testDelegatedConstructor() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/derivedClasses/DelegatedConstructor.kt");
}
@Test
@TestMetadata("EnumValues.kt")
public void testEnumValues() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/derivedClasses/EnumValues.kt");
}
@Test
@TestMetadata("Instance.kt")
public void testInstance() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/derivedClasses/Instance.kt");
}
@Test
@TestMetadata("StaticFieldFromJava.kt")
public void testStaticFieldFromJava() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/derivedClasses/StaticFieldFromJava.kt");
}
@Test
@TestMetadata("StaticMethodFromJava.kt")
public void testStaticMethodFromJava() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/derivedClasses/StaticMethodFromJava.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/override/parameterNames")
@TestDataPath("$PROJECT_ROOT")
@@ -11,17 +11,16 @@ import org.jetbrains.kotlin.checkers.diagnostics.factories.DebugInfoDiagnosticFa
import org.jetbrains.kotlin.checkers.utils.TypeOfCall
import org.jetbrains.kotlin.diagnostics.*
import org.jetbrains.kotlin.diagnostics.rendering.Renderers
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.builder.FirSyntaxErrors
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
import org.jetbrains.kotlin.fir.declarations.FirFile
import org.jetbrains.kotlin.fir.declarations.FirFunction
import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.psi
import org.jetbrains.kotlin.fir.references.FirNamedReference
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
import org.jetbrains.kotlin.fir.renderForDebugInfo
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
@@ -156,7 +155,9 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes
}
override fun visitFunctionCall(functionCall: FirFunctionCall) {
consumer.reportCallDiagnostic(functionCall, functionCall.calleeReference)
val reference = functionCall.calleeReference
consumer.reportCallDiagnostic(functionCall, reference)
consumer.reportContainingClassDiagnostic(functionCall, reference)
super.visitFunctionCall(functionCall)
}
@@ -166,10 +167,27 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes
if (selector is FirQualifiedAccess) {
val reference = selector.calleeReference as FirNamedReference
consumer.reportCallDiagnostic(safeCallExpression, reference)
consumer.reportContainingClassDiagnostic(safeCallExpression, reference)
}
super.visitSafeCallExpression(safeCallExpression)
}
override fun visitPropertyAccessExpression(propertyAccessExpression: FirPropertyAccessExpression) {
val reference = propertyAccessExpression.calleeReference
if (reference is FirNamedReference) {
consumer.reportContainingClassDiagnostic(propertyAccessExpression, reference)
}
super.visitPropertyAccessExpression(propertyAccessExpression)
}
override fun visitDelegatedConstructorCall(delegatedConstructorCall: FirDelegatedConstructorCall) {
val reference = delegatedConstructorCall.calleeReference as FirNamedReference
consumer.reportContainingClassDiagnostic(delegatedConstructorCall, reference)
super.visitDelegatedConstructorCall(delegatedConstructorCall)
}
}.let(firFile::accept)
val codeMetaInfos = result.flatMap { diagnostic ->
@@ -208,6 +226,18 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes
}
}
private fun DebugDiagnosticConsumer.reportContainingClassDiagnostic(element: FirElement, reference: FirNamedReference) {
report(DebugInfoDiagnosticFactory1.CALLABLE_OWNER, element) {
val resolvedSymbol = (reference as? FirResolvedNamedReference)?.resolvedSymbol
val callable = resolvedSymbol?.fir as? FirCallableDeclaration ?: return@report ""
DebugInfoDiagnosticFactory1.renderCallableOwner(
callable.symbol.callableId,
callable.containingClassLookupTag()?.classId,
callable.containingClassForStaticMemberAttr == null
)
}
}
private fun getTypeOfCall(
reference: FirNamedReference,
resolvedSymbol: FirBasedSymbol<*>?
@@ -253,7 +283,8 @@ private class DebugDiagnosticConsumer(
KtRealSourceElementKind,
KtFakeSourceElementKind.DesugaredCompoundAssignment,
KtFakeSourceElementKind.ReferenceInAtomicQualifiedAccess,
KtFakeSourceElementKind.SmartCastExpression
KtFakeSourceElementKind.SmartCastExpression,
KtFakeSourceElementKind.DelegatingConstructorCall
)
}