Dropping package facades:

- use KotlinCodegenFacade to build light classes
(PackageCodegen is not enough to obtain proper diagnostics)
This commit is contained in:
Dmitry Petrov
2015-10-16 18:02:59 +03:00
parent 9de45f4c56
commit 31a85132c6
2 changed files with 19 additions and 8 deletions
@@ -21,7 +21,6 @@ import com.intellij.util.containers.MultiMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.codegen.state.GenerationState;
import org.jetbrains.kotlin.fileClasses.JvmFileClassInfo;
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.JetFile;
@@ -61,10 +60,18 @@ public class KotlinCodegenFacade {
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
doGenerateFiles(state.getFiles(), state, errorHandler);
}
public static void doGenerateFiles(
@NotNull Collection<JetFile> files,
@NotNull GenerationState state,
@NotNull CompilationErrorHandler errorHandler
) {
MultiMap<FqName, JetFile> filesInPackages = new MultiMap<FqName, JetFile>();
MultiMap<FqName, JetFile> filesInMultifileClasses = new MultiMap<FqName, JetFile>();
for (JetFile file : state.getFiles()) {
for (JetFile file : files) {
if (file == null) throw new IllegalArgumentException("A null file given for compilation");
JvmFileClassInfo fileClassInfo = state.getFileClassesProvider().getFileClassInfo(file);
@@ -79,20 +86,26 @@ public class KotlinCodegenFacade {
Set<FqName> obsoleteMultifileClasses = new HashSet<FqName>(state.getObsoleteMultifileClasses());
for (FqName multifileClassFqName : Sets.union(filesInMultifileClasses.keySet(), obsoleteMultifileClasses)) {
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
doCheckCancelled(state);
generateMultifileClass(state, multifileClassFqName, filesInMultifileClasses.get(multifileClassFqName), errorHandler);
}
Set<FqName> packagesWithObsoleteParts = new HashSet<FqName>(state.getPackagesWithObsoleteParts());
for (FqName packageFqName : Sets.union(packagesWithObsoleteParts, filesInPackages.keySet())) {
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
doCheckCancelled(state);
generatePackage(state, packageFqName, filesInPackages.get(packageFqName), errorHandler);
}
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
doCheckCancelled(state);
state.getFactory().done();
}
private static void doCheckCancelled(GenerationState state) {
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
}
}
public static void generatePackage(
@NotNull GenerationState state,
@NotNull FqName packageFqName,
@@ -141,9 +141,7 @@ public class KotlinJavaFileStubProvider<T extends WithFileStubAndExtraDiagnostic
@Override
public void generate(@NotNull GenerationState state, @NotNull Collection<JetFile> files) {
PackageCodegen codegen = state.getFactory().forPackage(packageFqName, files);
codegen.generate(CompilationErrorHandler.THROW_EXCEPTION);
state.getFactory().asList();
KotlinCodegenFacade.doGenerateFiles(files, state, CompilationErrorHandler.THROW_EXCEPTION);
}
@Override