diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt index 2cefcdfff03..2614c3fe52c 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt @@ -35,7 +35,9 @@ import com.intellij.openapi.fileTypes.PlainTextFileType import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.io.FileUtil +import com.intellij.openapi.util.io.FileUtilRt import com.intellij.openapi.util.text.StringUtil +import com.intellij.openapi.vfs.PersistentFSConstants import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.FileContextProvider import com.intellij.psi.PsiElementFinder @@ -111,6 +113,10 @@ public class KotlinCoreEnvironment private constructor( it } + init { + PersistentFSConstants.setMaxIntellisenseFileSize(FileUtilRt.LARGE_FOR_CONTENT_LOADING) + } + init { val project = projectEnvironment.getProject() project.registerService(javaClass(), CliDeclarationProviderFactoryService(sourceFiles)) diff --git a/compiler/testData/integration/smoke/largeJavaFile/largeJavaFile.compile.expected b/compiler/testData/integration/smoke/largeJavaFile/largeJavaFile.compile.expected new file mode 100644 index 00000000000..a14ac74940f --- /dev/null +++ b/compiler/testData/integration/smoke/largeJavaFile/largeJavaFile.compile.expected @@ -0,0 +1 @@ +Return code: 0 diff --git a/compiler/testData/integration/smoke/largeKotlinFile/largeKotlinFile.compile.expected b/compiler/testData/integration/smoke/largeKotlinFile/largeKotlinFile.compile.expected new file mode 100644 index 00000000000..a14ac74940f --- /dev/null +++ b/compiler/testData/integration/smoke/largeKotlinFile/largeKotlinFile.compile.expected @@ -0,0 +1 @@ +Return code: 0 diff --git a/compiler/tests/org/jetbrains/kotlin/integration/CompilerFileLimitTest.kt b/compiler/tests/org/jetbrains/kotlin/integration/CompilerFileLimitTest.kt new file mode 100644 index 00000000000..9cf04703f18 --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/integration/CompilerFileLimitTest.kt @@ -0,0 +1,116 @@ +/* + * 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.integration + +import com.intellij.openapi.util.io.FileUtil +import org.jetbrains.kotlin.test.KotlinTestUtils +import org.junit.Assert +import java.io.File + +class CompilerFileLimitTest : CompilerSmokeTestBase() { + fun testLargeKotlinFile() { + val size = 300 + + val dir = tempDir("largeKotlinFileSrc") + val file = File(dir, "largeKotlinFile.kt") + file.writeText(generateLargeKotlinFile(size)) + + assertIsLargeButNotTooLarge(file) + + runCompiler("largeKotlinFile.compile", file.absolutePath, "-d", tempDir("largeKotlinFileOut").absolutePath) + } + + private fun generateLargeKotlinFile(size: Int): String { + return buildString { + append("package large\n\n") + (0..size).forEach { + appendln("class Class$it") + appendln("{") + appendln("\tfun foo(): Long = $it") + appendln("}") + appendln("\n") + repeat(2000) { + appendln("// kotlin rules ... and stuff") + } + } + appendln("fun main(args: Array)") + appendln("{") + appendln("\tval result = Class5().foo() + Class$size().foo()") + appendln("\tprintln(result)") + appendln("}") + } + + } + + fun testLargeJavaFile() { + val size = 300 + + val dir = tempDir("largeJavaFileSrc") + val javaDir = File(dir, "large") + javaDir.mkdir() + val javaFile = File(javaDir, "Large.java") + javaFile.writeText(generateLargeJavaFile(size)) + val ktFile = File(dir, "useLargerJava.kt") + ktFile.writeText(generateKotlinFileThatUsesLargeJavaFile(size)) + + assertIsLargeButNotTooLarge(javaFile) + + runCompiler("largeJavaFile.compile", dir.absolutePath, "-d", tempDir("largeJavaFileOut").absolutePath) + } + + private fun assertIsLargeButNotTooLarge(file: File) { + Assert.assertTrue(file.length() > 15 * FileUtil.MEGABYTE) + Assert.assertTrue(file.length() < 20 * FileUtil.MEGABYTE) + } + + private fun generateKotlinFileThatUsesLargeJavaFile(size: Int): String { + return buildString { + append("package usesLarge\n\n") + append("import large.Large\n\n") + appendln("fun main(args: Array)") + appendln("{") + appendln("\tval result = Large.Class0().foo() + Large.Class$size().foo()") + appendln("\tprintln(result)") + appendln("}") + } + } + + private fun generateLargeJavaFile(size: Int): String { + return buildString { + append("package large;\n\n") + appendln("public class Large") + appendln("{") + (0..size).forEach { + appendln("\tpublic static class Class$it") + appendln("\t{") + appendln("\t\tpublic long foo()") + appendln("\t\t{") + appendln("\t\t\t return $it;") + appendln("\t\t}") + appendln("\t}") + appendln("\n") + repeat(2000) { + appendln("// kotlin rules ... and stuff") + } + } + appendln("}") + } + + } + + private fun tempDir(markerName: String) = KotlinTestUtils.tmpDir("${CompilerFileLimitTest::class.simpleName}$markerName") +} diff --git a/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTest.java b/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTest.java index bfcd62a8b14..ddb78010012 100644 --- a/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTest.java +++ b/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTest.java @@ -16,36 +16,9 @@ package org.jetbrains.kotlin.integration; -import com.intellij.util.ArrayUtil; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.utils.StringsKt; - import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -public class CompilerSmokeTest extends KotlinIntegrationTestBase { - private int run(String logName, String... args) throws Exception { - return runJava(KotlinTestUtils.getTestDataPathBase() + "/integration/smoke/" + getTestName(true), logName, args); - } - - private int runCompiler(String logName, String... arguments) throws Exception { - Collection javaArgs = new ArrayList(); - - javaArgs.add("-cp"); - javaArgs.add(StringsKt.join(Arrays.asList( - getCompilerLib().getAbsolutePath() + File.separator + "kotlin-compiler.jar", - new File("dependencies/bootstrap-compiler/Kotlin/kotlinc/lib/kotlin-runtime.jar").getAbsolutePath(), - new File("dependencies/bootstrap-compiler/Kotlin/kotlinc/lib/kotlin-reflect.jar").getAbsolutePath() - ), File.pathSeparator)); - javaArgs.add("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler"); - - Collections.addAll(javaArgs, arguments); - - return run(logName, ArrayUtil.toStringArray(javaArgs)); - } +public class CompilerSmokeTest extends CompilerSmokeTestBase { public void testHelloApp() throws Exception { String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; diff --git a/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTestBase.java b/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTestBase.java new file mode 100644 index 00000000000..7a4f0bbc998 --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTestBase.java @@ -0,0 +1,49 @@ +/* + * 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.integration; + +import com.intellij.util.ArrayUtil; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.utils.StringsKt; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +public abstract class CompilerSmokeTestBase extends KotlinIntegrationTestBase { + protected int run(String logName, String... args) throws Exception { + return runJava(KotlinTestUtils.getTestDataPathBase() + "/integration/smoke/" + getTestName(true), logName, args); + } + + protected int runCompiler(String logName, String... arguments) throws Exception { + Collection javaArgs = new ArrayList(); + + javaArgs.add("-cp"); + javaArgs.add(StringsKt.join(Arrays.asList( + getCompilerLib().getAbsolutePath() + File.separator + "kotlin-compiler.jar", + new File("dependencies/bootstrap-compiler/Kotlin/kotlinc/lib/kotlin-runtime.jar").getAbsolutePath(), + new File("dependencies/bootstrap-compiler/Kotlin/kotlinc/lib/kotlin-reflect.jar").getAbsolutePath() + ), File.pathSeparator)); + javaArgs.add("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler"); + + Collections.addAll(javaArgs, arguments); + + return run(logName, ArrayUtil.toStringArray(javaArgs)); + } +}