GenerationStrategy removed

This commit is contained in:
Andrey Breslav
2013-01-17 12:19:06 +04:00
parent 99aee736d1
commit e1831877b7
8 changed files with 17 additions and 91 deletions
@@ -20,7 +20,6 @@ import com.intellij.openapi.util.Pair;
import com.intellij.util.containers.MultiMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.GenerationStrategy;
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
@@ -38,7 +37,7 @@ import static org.jetbrains.jet.codegen.binding.CodegenBinding.registerClassName
public class KotlinCodegenFacade {
public static void compileCorrectFiles(
@NotNull GenerationState state,
@NotNull GenerationStrategy strategy, @NotNull CompilationErrorHandler errorHandler
@NotNull CompilationErrorHandler errorHandler
) {
for (JetFile file : state.getFiles()) {
if (file.isScript()) {
@@ -60,9 +59,19 @@ public class KotlinCodegenFacade {
}
for (Map.Entry<FqName, Collection<JetFile>> entry : namespaceGrouping.entrySet()) {
strategy.generateNamespace(state, entry.getKey(), entry.getValue(), errorHandler);
generateNamespace(state, entry.getKey(), entry.getValue(), errorHandler);
}
}
public static void generateNamespace(
@NotNull GenerationState state,
@NotNull FqName fqName,
@NotNull Collection<JetFile> jetFiles,
@NotNull CompilationErrorHandler errorHandler
) {
NamespaceCodegen codegen = state.getFactory().forNamespace(fqName, jetFiles);
codegen.generate(errorHandler);
}
private KotlinCodegenFacade() {}
}
@@ -27,7 +27,6 @@ import org.jetbrains.jet.codegen.context.CodegenContext;
import org.jetbrains.jet.codegen.context.ScriptContext;
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.StandardGenerationStrategy;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
@@ -251,7 +250,7 @@ public class ScriptCodegen extends MemberCodegen {
registerClassNameForScript(state.getBindingTrace(), script, className);
state.beforeCompile();
StandardGenerationStrategy.INSTANCE.generateNamespace(
KotlinCodegenFacade.generateNamespace(
state,
JetPsiUtil.getFQName((JetFile) script.getContainingFile()),
Collections.singleton((JetFile) script.getContainingFile()),
@@ -1,33 +0,0 @@
/*
* Copyright 2010-2012 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.codegen.state;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.codegen.CompilationErrorHandler;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.name.FqName;
import java.util.Collection;
public interface GenerationStrategy {
void generateNamespace(
@NotNull GenerationState state,
@NotNull FqName fqName,
@NotNull Collection<JetFile> jetFiles,
@NotNull CompilationErrorHandler errorHandler
);
}
@@ -1,44 +0,0 @@
/*
* Copyright 2010-2012 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.codegen.state;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.codegen.CompilationErrorHandler;
import org.jetbrains.jet.codegen.NamespaceCodegen;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.name.FqName;
import java.util.Collection;
public class StandardGenerationStrategy implements GenerationStrategy {
public static final GenerationStrategy INSTANCE = new StandardGenerationStrategy();
private StandardGenerationStrategy() {
}
@Override
public void generateNamespace(
@NotNull GenerationState state,
@NotNull FqName fqName,
@NotNull Collection<JetFile> jetFiles,
@NotNull CompilationErrorHandler errorHandler
) {
NamespaceCodegen codegen = state.getFactory().forNamespace(fqName, jetFiles);
codegen.generate(errorHandler);
}
}
@@ -36,7 +36,6 @@ import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
import org.jetbrains.jet.codegen.*;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.Progress;
import org.jetbrains.jet.codegen.state.StandardGenerationStrategy;
import org.jetbrains.jet.config.CommonConfigurationKeys;
import org.jetbrains.jet.config.CompilerConfiguration;
import org.jetbrains.jet.lang.parsing.JetScriptDefinition;
@@ -49,7 +48,6 @@ import org.jetbrains.jet.lang.resolve.ScriptNameUtil;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.plugin.JetMainDetector;
import org.jetbrains.jet.utils.ExceptionUtils;
import org.jetbrains.jet.utils.KotlinPaths;
@@ -360,7 +358,7 @@ public class KotlinToJVMBytecodeCompiler {
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, false),
/*generateDeclaredClasses = */true
);
KotlinCodegenFacade.compileCorrectFiles(generationState, StandardGenerationStrategy.INSTANCE, CompilationErrorHandler.THROW_EXCEPTION);
KotlinCodegenFacade.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION);
CompilerPluginContext context = new CompilerPluginContext(project, exhaust.getBindingContext(), environment.getSourceFiles());
for (CompilerPlugin plugin : configuration.getList(CLIConfigurationKeys.COMPILER_PLUGINS)) {
@@ -33,7 +33,6 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.StandardGenerationStrategy;
import org.jetbrains.jet.config.CompilerConfiguration;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
@@ -372,7 +371,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true),
/*generateDeclaredClasses = */true
);
KotlinCodegenFacade.compileCorrectFiles(state, StandardGenerationStrategy.INSTANCE, CompilationErrorHandler.THROW_EXCEPTION);
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
return state;
}
@@ -22,7 +22,6 @@ import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.StandardGenerationStrategy;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
@@ -59,7 +58,7 @@ public class GenerationUtils {
public static GenerationState compileFilesGetGenerationState(@NotNull Project project, @NotNull AnalyzeExhaust analyzeExhaust, @NotNull List<JetFile> files) {
analyzeExhaust.throwIfError();
GenerationState state = new GenerationState(project, ClassBuilderFactories.TEST, analyzeExhaust.getBindingContext(), files);
KotlinCodegenFacade.compileCorrectFiles(state, StandardGenerationStrategy.INSTANCE, CompilationErrorHandler.THROW_EXCEPTION);
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
return state;
}
}
@@ -33,7 +33,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.codegen.*;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.StandardGenerationStrategy;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.plugin.internal.Location;
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
@@ -92,7 +91,7 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
return printStackTraceToString(exhaust.getError());
}
state = new GenerationState(jetFile.getProject(), ClassBuilderFactories.TEXT, exhaust.getBindingContext(), Collections.singletonList(jetFile));
KotlinCodegenFacade.compileCorrectFiles(state, StandardGenerationStrategy.INSTANCE, CompilationErrorHandler.THROW_EXCEPTION);
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
}
catch (ProcessCanceledException e) {
throw e;