JDR: do not create package fragment for class statics if class cannot be resolved
This keeps behaviour consistent in rare cases when JavaClass can be found but not resolved As of now this can happen in IDE if we take PsiClass from index but file structure is wrong so we can't resolve the class Add test which documents this case
This commit is contained in:
+2
-1
@@ -43,7 +43,8 @@ public class LazyJavaPackageFragmentProvider(
|
||||
else {
|
||||
val jClass = c.findJavaClass(fqName)
|
||||
if (jClass != null && DescriptorResolverUtils.isJavaClassVisibleAsPackage(jClass)) {
|
||||
LazyPackageFragmentForJavaClass(c, _module, jClass)
|
||||
val correspondingClass = c.javaClassResolver.resolveClass(jClass)
|
||||
if (correspondingClass != null) LazyPackageFragmentForJavaClass(c, _module, jClass) else null
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
@@ -92,6 +92,7 @@ import org.jetbrains.jet.completion.AbstractKotlinSourceInJavaCompletionTest
|
||||
import org.jetbrains.jet.plugin.intentions.AbstractIntentionTest
|
||||
import org.jetbrains.jet.checkers.AbstractJetDiagnosticsTestWithStdLib
|
||||
import org.jetbrains.jet.plugin.codeInsight.AbstractInsertImportOnPasteTest
|
||||
import org.jetbrains.jet.resolve.AbstractReferenceToJavaWithWrongFileStructureTest
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
System.setProperty("java.awt.headless", "true")
|
||||
@@ -403,6 +404,10 @@ fun main(args: Array<String>) {
|
||||
model("resolve/referenceInLib", recursive = false)
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractReferenceToJavaWithWrongFileStructureTest>()) {
|
||||
model("resolve/referenceToJavaWithWrongFileStructure", recursive = false)
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractJetFindUsagesTest>()) {
|
||||
model("findUsages/kotlin", pattern = """^(.+)\.0\.kt$""")
|
||||
model("findUsages/java", pattern = """^(.+)\.0\.java$""")
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package wrong;
|
||||
|
||||
public class ClassStatics {
|
||||
public static void staticMethod() {}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package wrong
|
||||
|
||||
fun foo() {
|
||||
<caret>ClassStatics.staticMethod()
|
||||
}
|
||||
|
||||
// REF_EMPTY
|
||||
@@ -0,0 +1,4 @@
|
||||
package wrong;
|
||||
|
||||
public class SimpleClass {
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package wrong
|
||||
|
||||
fun foo(w: <caret>SimpleClass) {
|
||||
}
|
||||
|
||||
// REF_EMPTY
|
||||
@@ -73,6 +73,10 @@ public abstract class AbstractReferenceResolveTest extends LightPlatformCodeInsi
|
||||
myFixture.configureByFile(path);
|
||||
}
|
||||
|
||||
performChecks();
|
||||
}
|
||||
|
||||
protected void performChecks() {
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(myFixture.getFile().getText(), MULTIRESOLVE)) {
|
||||
doMultiResolveTest();
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public abstract class AbstractReferenceToJavaWithWrongFileStructureTest extends AbstractReferenceResolveTest {
|
||||
@Override
|
||||
protected void doTest(String path) {
|
||||
//this line intentionally creates wrong file structure for java file
|
||||
myFixture.configureByFile(path.replace(".kt", ".java"));
|
||||
myFixture.configureByFile(path);
|
||||
performChecks();
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 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.AbstractReferenceToJavaWithWrongFileStructureTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/resolve/referenceToJavaWithWrongFileStructure")
|
||||
public class ReferenceToJavaWithWrongFileStructureTestGenerated extends AbstractReferenceToJavaWithWrongFileStructureTest {
|
||||
public void testAllFilesPresentInReferenceToJavaWithWrongFileStructure() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/resolve/referenceToJavaWithWrongFileStructure"), Pattern.compile("^(.+)\\.kt$"), false);
|
||||
}
|
||||
|
||||
@TestMetadata("ClassStatics.kt")
|
||||
public void testClassStatics() throws Exception {
|
||||
doTest("idea/testData/resolve/referenceToJavaWithWrongFileStructure/ClassStatics.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("SimpleClass.kt")
|
||||
public void testSimpleClass() throws Exception {
|
||||
doTest("idea/testData/resolve/referenceToJavaWithWrongFileStructure/SimpleClass.kt");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user