From 69080b72af064b0b6bc232e601987b1575116f9e Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Mon, 24 Dec 2012 15:25:36 +0400 Subject: [PATCH] When generating light class for package, do not generate other classes --- .../jet/codegen/NamespaceCodegen.java | 6 +++-- .../jet/codegen/state/GenerationState.java | 12 +++++++-- .../compiler/KotlinToJVMBytecodeCompiler.java | 3 ++- .../KotlinLightClassForPackageProvider.java | 25 +++++++++++++------ .../jet/codegen/CodegenTestCase.java | 3 ++- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java index cbce46a3719..3afb65e43d1 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java @@ -124,8 +124,10 @@ public class NamespaceCodegen extends MemberCodegen { } } else if (declaration instanceof JetClassOrObject) { - final CodegenContext context = CodegenContext.STATIC.intoNamespace(descriptor); - genClassOrObject(context, (JetClassOrObject) declaration); + if (state.isGenerateDeclaredClasses()) { + final CodegenContext context = CodegenContext.STATIC.intoNamespace(descriptor); + genClassOrObject(context, (JetClassOrObject) declaration); + } } else if (declaration instanceof JetScript) { state.getScriptCodegen().generate((JetScript) declaration); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java index eaa075ec397..ebdf330bd78 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java @@ -66,8 +66,10 @@ public class GenerationState { private final boolean generateNotNullParamAssertions; + private final boolean generateDeclaredClasses; + public GenerationState(Project project, ClassBuilderFactory builderFactory, BindingContext bindingContext, List files) { - this(project, builderFactory, Progress.DEAF, bindingContext, files, BuiltinToJavaTypesMapping.ENABLED, true, false); + this(project, builderFactory, Progress.DEAF, bindingContext, files, BuiltinToJavaTypesMapping.ENABLED, true, false, true); } public GenerationState( @@ -78,7 +80,8 @@ public class GenerationState { @NotNull List files, @NotNull BuiltinToJavaTypesMapping builtinToJavaTypesMapping, boolean generateNotNullAssertions, - boolean generateNotNullParamAssertions + boolean generateNotNullParamAssertions, + boolean generateDeclaredClasses ) { this.project = project; this.progress = progress; @@ -100,6 +103,7 @@ public class GenerationState { this.generateNotNullAssertions = generateNotNullAssertions; this.generateNotNullParamAssertions = generateNotNullParamAssertions; + this.generateDeclaredClasses = generateDeclaredClasses; } @NotNull @@ -160,6 +164,10 @@ public class GenerationState { return generateNotNullParamAssertions; } + public boolean isGenerateDeclaredClasses() { + return generateDeclaredClasses; + } + public void beforeCompile() { markUsed(); diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java index 12bc564b2b4..72664f14055 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java @@ -353,7 +353,8 @@ public class KotlinToJVMBytecodeCompiler { project, ClassBuilderFactories.binaries(stubs), backendProgress, exhaust.getBindingContext(), environment.getSourceFiles(), configuration.get(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY, BuiltinToJavaTypesMapping.ENABLED), configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, false), - configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, false) + configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, false), + /*generateDeclaredClasses = */true ); KotlinCodegenFacade.compileCorrectFiles(generationState, StandardGenerationStrategy.INSTANCE, CompilationErrorHandler.THROW_EXCEPTION); diff --git a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightClassForPackageProvider.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightClassForPackageProvider.java index cae646aaba8..3ee21a6eef7 100644 --- a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightClassForPackageProvider.java +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightClassForPackageProvider.java @@ -5,7 +5,11 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apacheither express or implied. + * 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. */ @@ -26,12 +30,10 @@ import com.intellij.testFramework.LightVirtualFile; import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.codegen.ClassBuilder; -import org.jetbrains.jet.codegen.ClassBuilderFactory; -import org.jetbrains.jet.codegen.ClassBuilderMode; -import org.jetbrains.jet.codegen.CompilationErrorHandler; +import org.jetbrains.jet.codegen.*; import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.codegen.state.GenerationStrategy; +import org.jetbrains.jet.codegen.state.Progress; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.resolve.java.JvmAbi; import org.jetbrains.jet.lang.resolve.name.FqName; @@ -75,10 +77,19 @@ public class KotlinLightClassForPackageProvider implements CachedValueProvider