void (final @NotNull CompileContext context) { if (ourInstance != null) { return; } final BuildDataManager dataManager = context.getProjectDescriptor().dataManager; final File buildDir = dataManager.getDataPaths().getDataStorageRoot(); if (isEnabled()) { boolean isRebuild = isRebuildInAllJavaModules(context); if (!JavaCompilers.JAVAC_ID.equals(JavaBuilder.getUsedCompilerId(context)) || !JavaBuilder.IS_ENABLED.get(context, Boolean.TRUE)) { CompilerReferenceIndex.removeIndexFiles(buildDir); return; } boolean cleanupOk = true; if (isRebuild) { CompilerReferenceIndex.removeIndexFiles(buildDir); cleanupOk = !CompilerReferenceIndex.exists(buildDir); } else if (CompilerReferenceIndex.versionDiffers(buildDir, JavaCompilerIndices.VERSION)) { CompilerReferenceIndex.removeIndexFiles(buildDir); if ((ourInitAttempt++ == 0 && areAllJavaModulesAffected(context))) { throw new BuildDataCorruptedException("backward reference index will be updated to actual version"); } // do not request a rebuild if a project is affected incompletely and version is changed, just disable indices return; } if (cleanupOk) { ourInstance = new JavaBackwardReferenceIndexWriter(new JavaCompilerBackwardReferenceIndex(buildDir, dataManager.getRelativizer(), false)); ShutDownTracker.getInstance().registerShutdownTask(() -> closeIfNeeded(false)); } } else { CompilerReferenceIndex.removeIndexFiles(buildDir); } }