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