Serializing incremental package fragment from our module instead of random one.

This commit is contained in:
Evgeny Gerashchenko
2014-06-19 13:41:27 +04:00
parent aa41ae09ed
commit 92849dda3b
7 changed files with 33 additions and 14 deletions
@@ -125,10 +125,10 @@ public class PackageCodegen {
}
// TODO rewrite it to something more robust when module system is implemented
for (PackageFragmentDescriptor anotherFragment : state.getModule().getPackageFragmentProvider()
.getPackageFragments(fqName)) {
if (anotherFragment instanceof IncrementalPackageFragmentProvider.IncrementalPackageFragment) {
return anotherFragment;
for (PackageFragmentDescriptor fragment : state.getModule().getPackageFragmentProvider().getPackageFragments(fqName)) {
if (fragment instanceof IncrementalPackageFragmentProvider.IncrementalPackageFragment &&
((IncrementalPackageFragmentProvider.IncrementalPackageFragment) fragment).getModuleId().equals(state.getModuleId())) {
return fragment;
}
}
return null;
@@ -107,6 +107,9 @@ public class GenerationState {
@NotNull
private final Collection<FqName> packagesWithRemovedFiles;
@Nullable
private final String moduleId; // for PackageCodegen in incremental compilation mode
public GenerationState(
@NotNull Project project,
@NotNull ClassBuilderFactory builderFactory,
@@ -115,7 +118,7 @@ public class GenerationState {
@NotNull List<JetFile> files
) {
this(project, builderFactory, Progress.DEAF, module, bindingContext, files, true, false, GenerateClassFilter.GENERATE_ALL,
InlineCodegenUtil.DEFAULT_INLINE_FLAG, null);
InlineCodegenUtil.DEFAULT_INLINE_FLAG, null, null);
}
public GenerationState(
@@ -129,12 +132,14 @@ public class GenerationState {
boolean generateNotNullParamAssertions,
GenerateClassFilter generateClassFilter,
boolean inlineEnabled,
@Nullable Collection<FqName> packagesWithRemovedFiles
@Nullable Collection<FqName> packagesWithRemovedFiles,
@Nullable String moduleId
) {
this.project = project;
this.progress = progress;
this.module = module;
this.files = files;
this.moduleId = moduleId;
this.packagesWithRemovedFiles = packagesWithRemovedFiles == null ? Collections.<FqName>emptySet() : packagesWithRemovedFiles;
this.classBuilderMode = builderFactory.getClassBuilderMode();
this.inlineEnabled = inlineEnabled;
@@ -261,4 +266,9 @@ public class GenerationState {
public Collection<FqName> getPackagesWithRemovedFiles() {
return packagesWithRemovedFiles;
}
@Nullable
public String getModuleId() {
return moduleId;
}
}
@@ -328,13 +328,19 @@ public class KotlinToJVMBytecodeCompiler {
: IncrementalPackage.getPackagesWithRemovedFiles(
incrementalCacheProvider.getIncrementalCache(incrementalCacheDir), moduleId, environment.getSourceFiles());
GenerationState generationState = new GenerationState(
environment.getProject(), ClassBuilderFactories.BINARIES, Progress.DEAF,
exhaust.getModuleDescriptor(), exhaust.getBindingContext(), sourceFiles,
environment.getProject(),
ClassBuilderFactories.BINARIES,
Progress.DEAF,
exhaust.getModuleDescriptor(),
exhaust.getBindingContext(),
sourceFiles,
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, false),
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, false),
GenerationState.GenerateClassFilter.GENERATE_ALL,
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineCodegenUtil.DEFAULT_INLINE_FLAG),
packagesWithRemovedFiles);
packagesWithRemovedFiles,
moduleId
);
KotlinCodegenFacade.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION);
return generationState;
}
@@ -100,6 +100,9 @@ public class IncrementalPackageFragmentProvider(
public inner class IncrementalPackageFragment(fqName: FqName) : PackageFragmentDescriptorImpl(module, fqName) {
public val moduleId: String
get() = this@IncrementalPackageFragmentProvider.moduleId
val descriptorFinder = object : DescriptorFinder {
override fun findClass(classId: ClassId): ClassDescriptor? =
javaDescriptorResolver.resolveClass(DeserializedResolverUtils.kotlinFqNameToJavaFqName(classId.asSingleFqName()))
@@ -277,8 +277,8 @@ public class KotlinJavaFileStubProvider<T extends WithFileStub> implements Cache
/*not-null assertions*/false, false,
/*generateClassFilter=*/stubGenerationStrategy.getGenerateClassFilter(),
/*to generate inline flag on methods*/true,
null
);
null,
null);
state.beforeCompile();
bindingContext = state.getBindingContext();
@@ -63,8 +63,8 @@ public class CodegenTestUtil {
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true),
GenerationState.GenerateClassFilter.GENERATE_ALL,
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineCodegenUtil.DEFAULT_INLINE_FLAG),
null
);
null,
null);
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
return state.getFactory();
}
@@ -114,7 +114,7 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
exhaust.getModuleDescriptor(), exhaust.getBindingContext(),
Collections.singletonList(jetFile), true, true,
GenerationState.GenerateClassFilter.GENERATE_ALL,
enableInline.isSelected(), null);
enableInline.isSelected(), null, null);
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
}
catch (ProcessCanceledException e) {