mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
pushing faster + @NotNulls
This commit is contained in:
@@ -53,6 +53,7 @@ public class JavaLanguageLevelPusher implements FilePropertyPusher<LanguageLevel
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public LanguageLevel getDefaultValue() {
|
||||
return LanguageLevel.HIGHEST;
|
||||
}
|
||||
@@ -71,7 +72,7 @@ public class JavaLanguageLevelPusher implements FilePropertyPusher<LanguageLevel
|
||||
|
||||
private static final FileAttribute PERSISTENCE = new FileAttribute("language_level_persistence", 1, true);
|
||||
|
||||
public void persistAttribute(VirtualFile fileOrDir, LanguageLevel level) throws IOException {
|
||||
public void persistAttribute(VirtualFile fileOrDir, @NotNull LanguageLevel level) throws IOException {
|
||||
final DataInputStream iStream = PERSISTENCE.readAttribute(fileOrDir);
|
||||
if (iStream != null) {
|
||||
try {
|
||||
|
||||
@@ -38,6 +38,7 @@ public interface FilePropertyPusher<T> {
|
||||
Key<T> getFileDataKey();
|
||||
boolean pushDirectoriesOnly();
|
||||
|
||||
@NotNull
|
||||
T getDefaultValue();
|
||||
|
||||
@Nullable
|
||||
@@ -48,7 +49,7 @@ public interface FilePropertyPusher<T> {
|
||||
|
||||
boolean acceptsFile(VirtualFile file);
|
||||
|
||||
void persistAttribute(VirtualFile fileOrDir, T value) throws IOException;
|
||||
void persistAttribute(VirtualFile fileOrDir, @NotNull T value) throws IOException;
|
||||
|
||||
public interface Engine {
|
||||
void pushAll();
|
||||
|
||||
+19
-28
@@ -33,6 +33,7 @@ import com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -100,7 +101,7 @@ public class PushedFilePropertiesUpdater {
|
||||
}
|
||||
|
||||
public void pushRecursively(VirtualFile file, Project project) {
|
||||
PushedFilePropertiesUpdater.this.pushRecursively(file, project, pusher);
|
||||
PushedFilePropertiesUpdater.pushRecursively(file, project, pusher);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -108,44 +109,28 @@ public class PushedFilePropertiesUpdater {
|
||||
});
|
||||
}
|
||||
|
||||
public void pushRecursively(final VirtualFile dir, final Project project, final FilePropertyPusher... pushers) {
|
||||
private static void pushRecursively(final VirtualFile dir, final Project project, final FilePropertyPusher... pushers) {
|
||||
if (pushers.length == 0) return;
|
||||
ProjectRootManager.getInstance(project).getFileIndex().iterateContentUnderDirectory(dir, new ContentIterator() {
|
||||
public boolean processFile(final VirtualFile fileOrDir) {
|
||||
final boolean isDir = fileOrDir.isDirectory();
|
||||
for (FilePropertyPusher<Object> pusher : pushers) {
|
||||
if (!isDir && (pusher.pushDirectoriesOnly() || !pusher.acceptsFile(fileOrDir))) continue;
|
||||
findAndUpdateValue(project, fileOrDir, pusher, null);
|
||||
findAndUpdateValue(project, fileOrDir, pusher, pusher.getDefaultValue());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static <T> T findPusherValuesUpwards(final Project project, final VirtualFile dir, FilePropertyPusher<T> pusher, T moduleValue) {
|
||||
final T value = pusher.getImmediateValue(project, dir);
|
||||
if (value != null) return value;
|
||||
if (moduleValue != null) return moduleValue;
|
||||
final VirtualFile parent = dir.getParent();
|
||||
if (parent != null) return findPusherValuesUpwards(project, parent, pusher);
|
||||
return pusher.getDefaultValue();
|
||||
}
|
||||
|
||||
private static <T> T findPusherValuesUpwards(final Project project, final VirtualFile dir, FilePropertyPusher<T> pusher) {
|
||||
final T userValue = dir.getUserData(pusher.getFileDataKey());
|
||||
if (userValue != null) return userValue;
|
||||
final T value = pusher.getImmediateValue(project, dir);
|
||||
if (value != null) return value;
|
||||
final VirtualFile parent = dir.getParent();
|
||||
if (parent != null) return findPusherValuesUpwards(project, parent, pusher);
|
||||
return pusher.getDefaultValue();
|
||||
}
|
||||
|
||||
public void pushAll(final FilePropertyPusher... pushers) {
|
||||
for (Module module : ModuleManager.getInstance(myProject).getModules()) {
|
||||
final Object[] moduleValues = new Object[pushers.length];
|
||||
for (int i = 0; i < moduleValues.length; i++) {
|
||||
moduleValues[i] = pushers[i].getImmediateValue(module);
|
||||
final Object[] values = new Object[pushers.length];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
values[i] = pushers[i].getImmediateValue(module);
|
||||
if (values[i] == null) {
|
||||
values[i] = pushers[i].getDefaultValue();
|
||||
}
|
||||
}
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModuleFileIndex index = rootManager.getFileIndex();
|
||||
@@ -156,7 +141,7 @@ public class PushedFilePropertiesUpdater {
|
||||
for (int i = 0, pushersLength = pushers.length; i < pushersLength; i++) {
|
||||
final FilePropertyPusher<Object> pusher = pushers[i];
|
||||
if (!isDir && (pusher.pushDirectoriesOnly() || !pusher.acceptsFile(fileOrDir))) continue;
|
||||
findAndUpdateValue(myProject, fileOrDir, pusher, moduleValues[i]);
|
||||
values[i] = findAndUpdateValue(myProject, fileOrDir, pusher, values[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -165,9 +150,15 @@ public class PushedFilePropertiesUpdater {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void findAndUpdateValue(final Project project, final VirtualFile fileOrDir, final FilePropertyPusher<T> pusher, final T moduleValue) {
|
||||
final T value = findPusherValuesUpwards(project, fileOrDir, pusher, moduleValue);
|
||||
@Nullable
|
||||
public static <T> T findAndUpdateValue(final Project project,
|
||||
final VirtualFile fileOrDir,
|
||||
final FilePropertyPusher<T> pusher,
|
||||
final T parentValue) {
|
||||
final T immediateValue = pusher.getImmediateValue(project, fileOrDir);
|
||||
final T value = immediateValue != null ? immediateValue : parentValue;
|
||||
updateValue(fileOrDir, value, pusher);
|
||||
return value;
|
||||
}
|
||||
|
||||
private static <T> void updateValue(final VirtualFile fileOrDir, final T value, final FilePropertyPusher<T> pusher) {
|
||||
|
||||
Reference in New Issue
Block a user