Secondary constructors delegation calls and body resolve

This commit is contained in:
Denis Zharkov
2015-02-03 14:14:37 +03:00
parent b2cecf1dd0
commit 1555eec954
71 changed files with 1093 additions and 50 deletions
@@ -10397,17 +10397,65 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/secondaryConstructors"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("argumentsResolveInBodyAndDelegationCall.kt")
public void testArgumentsResolveInBodyAndDelegationCall() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/argumentsResolveInBodyAndDelegationCall.kt");
doTest(fileName);
}
@TestMetadata("constructorCallType.kt")
public void testConstructorCallType() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/constructorCallType.kt");
doTest(fileName);
}
@TestMetadata("generics.kt")
public void testGenerics() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/generics.kt");
doTest(fileName);
}
@TestMetadata("memberAccessBeforeSuperCall.kt")
public void testMemberAccessBeforeSuperCall() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/memberAccessBeforeSuperCall.kt");
doTest(fileName);
}
@TestMetadata("noPrimaryConstructor.kt")
public void testNoPrimaryConstructor() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/noPrimaryConstructor.kt");
doTest(fileName);
}
@TestMetadata("superAnyNonEmpty.kt")
public void testSuperAnyNonEmpty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/superAnyNonEmpty.kt");
doTest(fileName);
}
@TestMetadata("superSecondaryNonExisting.kt")
public void testSuperSecondaryNonExisting() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/superSecondaryNonExisting.kt");
doTest(fileName);
}
@TestMetadata("thisNonExisting.kt")
public void testThisNonExisting() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/thisNonExisting.kt");
doTest(fileName);
}
@TestMetadata("varargsInDelegationCallToPrimary.kt")
public void testVarargsInDelegationCallToPrimary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/varargsInDelegationCallToPrimary.kt");
doTest(fileName);
}
@TestMetadata("varargsInDelegationCallToSecondary.kt")
public void testVarargsInDelegationCallToSecondary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/varargsInDelegationCallToSecondary.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/diagnostics/tests/senselessComparison")
@@ -39,6 +39,10 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.resolve.scopes.receivers.ClassReceiver
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.psi.JetFile
import com.intellij.psi.PsiElement
public abstract class AbstractResolvedCallsTest : JetLiteFixture() {
override fun createEnvironment(): JetCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.ALL)
@@ -49,10 +53,7 @@ public abstract class AbstractResolvedCallsTest : JetLiteFixture() {
val jetFile = JetPsiFactory(getProject()).createFile(text.replace("<caret>", ""))
val bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegration(jetFile).bindingContext
val element = jetFile.findElementAt(text.indexOf("<caret>"))
val expression = element.getStrictParentOfType<JetExpression>()
val cachedCall = expression?.getParentResolvedCall(bindingContext, strict = false)
val (element, cachedCall) = buildCachedCall(bindingContext, jetFile, text)
val resolvedCall = if (cachedCall !is VariableAsFunctionResolvedCall) cachedCall
else if ("(" == element?.getText()) cachedCall.functionCall
@@ -61,6 +62,17 @@ public abstract class AbstractResolvedCallsTest : JetLiteFixture() {
val resolvedCallInfoFileName = FileUtil.getNameWithoutExtension(filePath) + ".txt"
JetTestUtils.assertEqualsToFile(File(resolvedCallInfoFileName), "$text\n\n\n${resolvedCall?.renderToText()}")
}
open protected fun buildCachedCall(
bindingContext: BindingContext, jetFile: JetFile, text: String
): Pair<PsiElement?, ResolvedCall<out CallableDescriptor>?> {
val element = jetFile.findElementAt(text.indexOf("<caret>"))
val expression = element.getStrictParentOfType<JetExpression>()
val cachedCall = expression?.getParentResolvedCall(bindingContext, strict = false)
return Pair(element, cachedCall)
}
}
private fun ReceiverValue.getText() = when (this) {
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2015 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.kotlin.resolve.calls
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.psi.JetFile
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
import org.jetbrains.kotlin.psi.JetSecondaryConstructor
import org.jetbrains.kotlin.psi.debugText.getDebugText
import org.jetbrains.kotlin.resolve.calls.callUtil.getParentResolvedCall
abstract public class AbstractResolvedConstructorDelegationCallsTests : AbstractResolvedCallsTest() {
override fun buildCachedCall(
bindingContext: BindingContext, jetFile: JetFile, text: String
): Pair<PsiElement?, ResolvedCall<out CallableDescriptor>?> {
val element = jetFile.findElementAt(text.indexOf("<caret>"))
val constructor = element?.getNonStrictParentOfType<JetSecondaryConstructor>()!!
val delegationCall = constructor.getDelegationCall()
val cachedCall = delegationCall.getParentResolvedCall(bindingContext, strict = false)
return Pair(delegationCall, cachedCall)
}
}
@@ -0,0 +1,140 @@
/*
* Copyright 2010-2015 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.kotlin.resolve.calls;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.InnerTestClasses;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.JetTestUtils;
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("compiler/testData/resolveConstructorDelegationCalls")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class ResolvedConstructorDelegationCallsTestsGenerated extends AbstractResolvedConstructorDelegationCallsTests {
public void testAllFilesPresentInResolveConstructorDelegationCalls() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/resolveConstructorDelegationCalls"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("classWithGenerics.kt")
public void testClassWithGenerics() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/classWithGenerics.kt");
doTest(fileName);
}
@TestMetadata("inheritanceWithGeneric.kt")
public void testInheritanceWithGeneric() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/inheritanceWithGeneric.kt");
doTest(fileName);
}
@TestMetadata("innerClassDelegatingPrimary.kt")
public void testInnerClassDelegatingPrimary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/innerClassDelegatingPrimary.kt");
doTest(fileName);
}
@TestMetadata("innerClassDelegatingSecondary.kt")
public void testInnerClassDelegatingSecondary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/innerClassDelegatingSecondary.kt");
doTest(fileName);
}
@TestMetadata("superAnyEmpty.kt")
public void testSuperAnyEmpty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/superAnyEmpty.kt");
doTest(fileName);
}
@TestMetadata("superAnyImplicit.kt")
public void testSuperAnyImplicit() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/superAnyImplicit.kt");
doTest(fileName);
}
@TestMetadata("superPrimary.kt")
public void testSuperPrimary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/superPrimary.kt");
doTest(fileName);
}
@TestMetadata("superPrimaryEmpty.kt")
public void testSuperPrimaryEmpty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/superPrimaryEmpty.kt");
doTest(fileName);
}
@TestMetadata("superPrimaryImplicit.kt")
public void testSuperPrimaryImplicit() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/superPrimaryImplicit.kt");
doTest(fileName);
}
@TestMetadata("superSecondary.kt")
public void testSuperSecondary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/superSecondary.kt");
doTest(fileName);
}
@TestMetadata("superSecondaryImplicit.kt")
public void testSuperSecondaryImplicit() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/superSecondaryImplicit.kt");
doTest(fileName);
}
@TestMetadata("superSecondaryOverload.kt")
public void testSuperSecondaryOverload() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/superSecondaryOverload.kt");
doTest(fileName);
}
@TestMetadata("thisPrimary.kt")
public void testThisPrimary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/thisPrimary.kt");
doTest(fileName);
}
@TestMetadata("thisPrimaryEmpty.kt")
public void testThisPrimaryEmpty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/thisPrimaryEmpty.kt");
doTest(fileName);
}
@TestMetadata("thisSecondary.kt")
public void testThisSecondary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/thisSecondary.kt");
doTest(fileName);
}
@TestMetadata("thisSecondaryOverload.kt")
public void testThisSecondaryOverload() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/thisSecondaryOverload.kt");
doTest(fileName);
}
@TestMetadata("varargs.kt")
public void testVarargs() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolveConstructorDelegationCalls/varargs.kt");
doTest(fileName);
}
}