Increase file size limit of compiler to 20 (was 2.5) megabytes (compiler will not read files larger than that)
Current IDEA api makes it possible to increase that to a higher value only by passing system property on compiler startup
This commit is contained in:
@@ -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<DeclarationProviderFactoryService>(), CliDeclarationProviderFactoryService(sourceFiles))
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
Return code: 0
|
||||
+1
@@ -0,0 +1 @@
|
||||
Return code: 0
|
||||
@@ -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<String>)")
|
||||
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<String>)")
|
||||
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")
|
||||
}
|
||||
@@ -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<String> javaArgs = new ArrayList<String>();
|
||||
|
||||
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";
|
||||
|
||||
@@ -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<String> javaArgs = new ArrayList<String>();
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user