Add tests for EA-52767 and KT-4366: "java.lang.IllegalArgumentException: Could not find a classifier for "...
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<root>
|
||||
<item name='com.intellij.codeInsight.navigation.GotoTargetHandler.GotoData targets'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
</root>
|
||||
@@ -44,10 +44,12 @@ import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.jet.storage.MemoizedFunctionToNullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils.safeNameForLazyResolve;
|
||||
|
||||
@@ -205,13 +207,19 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
// class A {} class A { fun foo(): A<completion here>}
|
||||
// and if we find the class by name only, we may b-not get the right one.
|
||||
// This call is only needed to make sure the classes are written to trace
|
||||
resolutionScope.getClassifier(name);
|
||||
DeclarationDescriptor declaration = getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, classOrObject);
|
||||
ClassifierDescriptor scopeDescriptor = resolutionScope.getClassifier(name);
|
||||
DeclarationDescriptor descriptor = getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, classOrObject);
|
||||
|
||||
if (declaration == null) {
|
||||
throw new IllegalArgumentException("Could not find a classifier for " + classOrObject + " " + classOrObject.getText());
|
||||
if (descriptor == null) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Could not find a classifier for %s.\n" +
|
||||
"Found descriptor: %s (%s).\n",
|
||||
JetPsiUtil.getElementTextWithContext(classOrObject),
|
||||
scopeDescriptor != null ? DescriptorRenderer.DEBUG_TEXT.render(scopeDescriptor) : "null",
|
||||
scopeDescriptor != null ? (scopeDescriptor.getContainingDeclaration().getClass()) : null));
|
||||
}
|
||||
return (ClassDescriptor) declaration;
|
||||
|
||||
return (ClassDescriptor) descriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -84,6 +84,7 @@ import org.jetbrains.jet.plugin.conversion.copy.AbstractJavaToKotlinCopyPasteCon
|
||||
import org.jetbrains.jet.shortenRefs.AbstractShortenRefsTest
|
||||
import org.jetbrains.jet.completion.handlers.AbstractSmartCompletionHandlerTest
|
||||
import org.jetbrains.jet.resolve.AbstractAdditionalLazyResolveDescriptorRendererTest
|
||||
import org.jetbrains.jet.resolve.AbstractReferenceResolveInLibrarySourcesTest
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
System.setProperty("java.awt.headless", "true")
|
||||
@@ -393,6 +394,10 @@ fun main(args: Array<String>) {
|
||||
model("resolve/referenceWithLib", recursive = false)
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractReferenceResolveInLibrarySourcesTest>()) {
|
||||
model("resolve/referenceInLib", recursive = false)
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractJetFindUsagesTest>()) {
|
||||
model("findUsages/kotlin", pattern = """^(.+)\.0\.kt$""")
|
||||
model("findUsages/java", pattern = """^(.+)\.0\.java$""")
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
val a: <caret>Number? = null
|
||||
|
||||
// CONTEXT: public abstract fun toDouble() : <caret>Double
|
||||
// RUNTIME
|
||||
|
||||
// REF: (jet).Double
|
||||
@@ -0,0 +1,8 @@
|
||||
import inlibrary.test.*
|
||||
|
||||
val a: <caret>ReferenceTest? = null
|
||||
|
||||
// CONTEXT: val test: <caret>Test? = null
|
||||
// WITH_LIBRARY: /resolve/referenceInLib/inLibrarySource
|
||||
|
||||
// REF: (inlibrary.test).Test
|
||||
@@ -0,0 +1,5 @@
|
||||
package inlibrary.test
|
||||
|
||||
class ReferenceTest {
|
||||
val test: Test? = null
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package inlibrary.test
|
||||
|
||||
trait Test
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
class Foo {
|
||||
val s: <caret>String = ""
|
||||
}
|
||||
|
||||
// REF: (jet).String
|
||||
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
class Foo
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class JetLightCodeInsightFixtureTestCase extends LightCodeInsightFixtureTestCase {
|
||||
@Override
|
||||
@@ -46,7 +47,11 @@ public abstract class JetLightCodeInsightFixtureTestCase extends LightCodeInsigh
|
||||
try {
|
||||
String fileText = FileUtil.loadFile(new File(getTestDataPath(), fileName()));
|
||||
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(fileText, "RUNTIME")) {
|
||||
List<String> withLibraryDirective = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, "WITH_LIBRARY:");
|
||||
if (!withLibraryDirective.isEmpty()) {
|
||||
return new JdkAndMockLibraryProjectDescriptor(PluginTestCaseBase.getTestDataPathBase() + "/" + withLibraryDirective.get(0), true);
|
||||
}
|
||||
else if (InTextDirectivesUtils.isDirectiveDefined(fileText, "RUNTIME")) {
|
||||
return JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE;
|
||||
}
|
||||
else if (InTextDirectivesUtils.isDirectiveDefined(fileText, "JS")) {
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.resolve
|
||||
|
||||
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.jet.plugin.navigation.NavigationTestUtils
|
||||
import org.jetbrains.jet.InTextDirectivesUtils
|
||||
import java.io.File
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase
|
||||
import org.junit.Assert
|
||||
import junit.framework.AssertionFailedError
|
||||
|
||||
public abstract class AbstractReferenceResolveInLibrarySourcesTest : JetLightCodeInsightFixtureTestCase() {
|
||||
class object {
|
||||
val CARET_MARKER = "<caret>"
|
||||
}
|
||||
|
||||
fun doTest(path: String) {
|
||||
val fixture = myFixture!!
|
||||
|
||||
fixture.configureByFile(path)
|
||||
|
||||
val expectedResolveData = AbstractReferenceResolveTest.readResolveData(fixture.getFile()!!.getText())
|
||||
|
||||
val gotoData = NavigationTestUtils.invokeGotoImplementations(fixture.getEditor(), fixture.getFile())!!
|
||||
Assert.assertEquals("Single target expected for origianl file", 1, gotoData.targets.size)
|
||||
|
||||
val testedPsiElement = gotoData.targets[0]
|
||||
val testedElementFile = testedPsiElement.getContainingFile()!!
|
||||
|
||||
val lineContext = InTextDirectivesUtils.findStringWithPrefixes(fixture.getFile()!!.getText(), "CONTEXT:")
|
||||
if (lineContext == null) {
|
||||
throw AssertionFailedError("'CONTEXT: ' directive is expected to set up position in library file: ${testedElementFile.getName()}")
|
||||
}
|
||||
|
||||
val inContextOffset = lineContext.indexOf(CARET_MARKER)
|
||||
if (inContextOffset == -1) throw IllegalStateException("No '$CARET_MARKER' marker found in 'CONTEXT: $lineContext'")
|
||||
|
||||
val contextStr = lineContext.replace(CARET_MARKER, "")
|
||||
val offsetInFile = testedElementFile.getText()!!.indexOf(contextStr)
|
||||
if (offsetInFile == -1) throw IllegalStateException("Context '$contextStr' wasn't found in file ${testedElementFile.getName()}")
|
||||
|
||||
val offset = offsetInFile + inContextOffset
|
||||
|
||||
val reference = testedElementFile.findReferenceAt(offset)!!
|
||||
|
||||
AbstractReferenceResolveTest.checkReferenceResolve(expectedResolveData, offset, reference)
|
||||
}
|
||||
|
||||
override fun getTestDataPath() : String = File(PluginTestCaseBase.getTestDataPathBase(), "/resolve/referenceInLib").getPath() + File.separator
|
||||
override fun fileName(): String = getTestName(true) + ".kt"
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.resolve;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
|
||||
import org.jetbrains.jet.resolve.AbstractReferenceResolveInLibrarySourcesTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/resolve/referenceInLib")
|
||||
public class ReferenceResolveInLibrarySourcesTestGenerated extends AbstractReferenceResolveInLibrarySourcesTest {
|
||||
public void testAllFilesPresentInReferenceInLib() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/resolve/referenceInLib"), Pattern.compile("^(.+)\\.kt$"), false);
|
||||
}
|
||||
|
||||
@TestMetadata("builtInNumber.kt")
|
||||
public void testBuiltInNumber() throws Exception {
|
||||
doTest("idea/testData/resolve/referenceInLib/builtInNumber.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inLibrarySource.kt")
|
||||
public void testInLibrarySource() throws Exception {
|
||||
doTest("idea/testData/resolve/referenceInLib/inLibrarySource.kt");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -46,4 +46,9 @@ public class ReferenceResolveWithLibTestGenerated extends AbstractReferenceResol
|
||||
doTest("idea/testData/resolve/referenceWithLib/fakeOverride2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sameNameInLib.kt")
|
||||
public void testSameNameInLib() throws Exception {
|
||||
doTest("idea/testData/resolve/referenceWithLib/sameNameInLib.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user