diff --git a/idea/testData/libraries/internalClasses/InternalClasses.kt b/idea/testData/libraries/internalClasses/InternalClasses.kt new file mode 100644 index 00000000000..9836ed66a7d --- /dev/null +++ b/idea/testData/libraries/internalClasses/InternalClasses.kt @@ -0,0 +1,31 @@ +package test + +trait T { + fun foo() { + } + + fun boo() +} + +trait TT : T { +} + +fun f() { + var i = 0 + val myLocalFun = { + ++i + } + + class MyLocalClass { + } +} + +class A { + class B { + class C { + } + } + + inner class C { + } +} diff --git a/idea/tests/org/jetbrains/jet/plugin/javaFacade/NoPackageFragmentsInJavaPsiFacadeTest.java b/idea/tests/org/jetbrains/jet/plugin/javaFacade/NoPackageFragmentsInJavaPsiFacadeTest.java deleted file mode 100644 index 473c7041e98..00000000000 --- a/idea/tests/org/jetbrains/jet/plugin/javaFacade/NoPackageFragmentsInJavaPsiFacadeTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.plugin.javaFacade; - -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiPackage; -import com.intellij.testFramework.LightProjectDescriptor; -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.plugin.JetWithJdkAndRuntimeLightProjectDescriptor; - -import java.util.Set; -import java.util.TreeSet; - -public class NoPackageFragmentsInJavaPsiFacadeTest extends LightCodeInsightFixtureTestCase { - public void testPackageFragmentsAreNotVisible() { - PsiPackage psiPackage = myFixture.findPackage("kotlin"); - - Set packageFragments = new TreeSet(); - for (PsiClass psiClass : psiPackage.getClasses()) { - String qualifiedName = psiClass.getQualifiedName(); - if (qualifiedName != null && qualifiedName.contains("-")) { - packageFragments.add(qualifiedName); - } - } - - assertEmpty("Package fragment classes should not be found via JavaPsiFacade:\n" + packageFragments, packageFragments); - } - - @NotNull - @Override - protected LightProjectDescriptor getProjectDescriptor() { - return JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE; - } -} diff --git a/idea/tests/org/jetbrains/jet/plugin/libraries/InternalCompiledClassesTest.kt b/idea/tests/org/jetbrains/jet/plugin/libraries/InternalCompiledClassesTest.kt new file mode 100644 index 00000000000..1e685fbc0d5 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/libraries/InternalCompiledClassesTest.kt @@ -0,0 +1,78 @@ +/* + * 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.plugin.libraries + +import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase +import com.intellij.testFramework.LightProjectDescriptor +import org.jetbrains.jet.plugin.JdkAndMockLibraryProjectDescriptor +import org.jetbrains.jet.plugin.PluginTestCaseBase +import com.intellij.openapi.vfs.VirtualFile +import org.jetbrains.jet.lang.resolve.java.JvmAbi +import com.intellij.psi.PsiManager +import junit.framework.Assert +import org.jetbrains.jet.lang.resolve.java.PackageClassUtils +import com.intellij.psi.ClassFileViewProvider + +//TODO: test for local functions and classes +public class InternalCompiledClassesTest : JetLightCodeInsightFixtureTestCase() { + + private val TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/libraries/internalClasses" + + fun testPackagePartIsInvisible() = doTestNoPsiFilesAreBuiltFor("package part") { + getNameWithoutExtension().contains(PackageClassUtils.PACKAGE_CLASS_NAME_SUFFIX + "-") + } + + fun testAnonymousFunctionIsInvisible() = doTestNoPsiFilesAreBuiltFor("anonymous function") { + isAnonymousFunction(this) + } + + fun testInnerClassIsInvisible() = doTestNoPsiFilesAreBuiltFor("inner or nested class") { + ClassFileViewProvider.isInnerClass(this) + } + + override fun getProjectDescriptor(): LightProjectDescriptor { + return JdkAndMockLibraryProjectDescriptor(TEST_DATA_PATH, withSources = false) + } + + private fun doTestNoPsiFilesAreBuiltFor(fileKind: String, condition: VirtualFile.() -> Boolean) { + val root = NavigateToDecompiledLibraryTest.findTestLibraryRoot(myModule!!)!! + val project = getProject()!! + var foundAtLeastOneFile = false + root.checkRecursively { + if (condition()) { + foundAtLeastOneFile = true + val psiFile = PsiManager.getInstance(project).findFile(this) + Assert.assertNull("PSI files for $fileKind classes should not be build, is was build for: ${this.getPresentableName()}", + psiFile) + } + } + Assert.assertTrue("Should find at least one file of kind ($fileKind). This assertion can fail in following scenarios:\n" + + "1. Test data is bad and doesn't cover this case.\n2. ABI has changed and test no longer checks anything.", + foundAtLeastOneFile) + } + + private fun VirtualFile.checkRecursively(body: VirtualFile.() -> Unit) { + if (!isDirectory()) { + body() + } + else { + for (file in getChildren()!!) { + file.checkRecursively(body) + } + } + } +} diff --git a/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToDecompiledLibraryTest.java b/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToDecompiledLibraryTest.java index e16ce12943f..9a15ffa94d8 100644 --- a/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToDecompiledLibraryTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToDecompiledLibraryTest.java @@ -154,29 +154,33 @@ public class NavigateToDecompiledLibraryTest extends AbstractNavigateToLibraryTe return new JdkAndMockLibraryProjectDescriptor(TEST_DATA_PATH + "/library", false); } - @Nullable - private static LibraryOrderEntry findOurTestLibrary(@NotNull Module module) { - for (OrderEntry orderEntry : ModuleRootManager.getInstance(module).getOrderEntries()) { - if (orderEntry instanceof LibraryOrderEntry) { - return (LibraryOrderEntry) orderEntry; - } - } - return null; - } - @NotNull /*package*/ static VirtualFile getClassFile( @NotNull String packageName, @NotNull String className, @NotNull Module module ) { - LibraryOrderEntry library = findOurTestLibrary(module); - assertNotNull(library); - - VirtualFile packageDir = library.getFiles(OrderRootType.CLASSES)[0].findFileByRelativePath(packageName.replace(".", "/")); + VirtualFile root = findTestLibraryRoot(module); + assertNotNull(root); + VirtualFile packageDir = root.findFileByRelativePath(packageName.replace(".", "/")); assertNotNull(packageDir); VirtualFile classFile = packageDir.findChild(className + ".class"); assertNotNull(classFile); return classFile; } + + @Nullable + /*package*/ static VirtualFile findTestLibraryRoot(@NotNull Module module) { + for (OrderEntry orderEntry : ModuleRootManager.getInstance(module).getOrderEntries()) { + if (orderEntry instanceof LibraryOrderEntry) { + return findTestLibraryRoot((LibraryOrderEntry) orderEntry); + } + } + return null; + } + + @NotNull + private static VirtualFile findTestLibraryRoot(@NotNull LibraryOrderEntry library) { + return library.getFiles(OrderRootType.CLASSES)[0]; + } } \ No newline at end of file