query project value before returning defaults

This commit is contained in:
Gregory.Shrago
2013-07-11 20:58:41 +04:00
parent 1cca4498e2
commit 7e625e47cb
3 changed files with 21 additions and 18 deletions
@@ -27,6 +27,7 @@ import com.intellij.util.indexing.FileBasedIndex;
import com.intellij.util.io.DataInputOutputUtil;
import com.intellij.util.messages.MessageBus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -42,7 +43,7 @@ public class JavaLanguageLevelPusher implements FilePropertyPusher<LanguageLevel
}
@Override
public void initExtra(Project project, MessageBus bus, Engine languageLevelUpdater) {
public void initExtra(@NotNull Project project, @NotNull MessageBus bus, @NotNull Engine languageLevelUpdater) {
// nothing
}
@@ -64,24 +65,24 @@ public class JavaLanguageLevelPusher implements FilePropertyPusher<LanguageLevel
}
@Override
public LanguageLevel getImmediateValue(Project project, VirtualFile file) {
public LanguageLevel getImmediateValue(@NotNull Project project, @Nullable VirtualFile file) {
return null;
}
@Override
public LanguageLevel getImmediateValue(Module module) {
public LanguageLevel getImmediateValue(@NotNull Module module) {
return LanguageLevelUtil.getEffectiveLanguageLevel(module);
}
@Override
public boolean acceptsFile(VirtualFile file) {
public boolean acceptsFile(@NotNull VirtualFile file) {
return false;
}
private static final FileAttribute PERSISTENCE = new FileAttribute("language_level_persistence", 2, true);
@Override
public void persistAttribute(VirtualFile fileOrDir, @NotNull LanguageLevel level) throws IOException {
public void persistAttribute(@NotNull VirtualFile fileOrDir, @NotNull LanguageLevel level) throws IOException {
final DataInputStream iStream = PERSISTENCE.readAttribute(fileOrDir);
if (iStream != null) {
try {
@@ -105,6 +106,6 @@ public class JavaLanguageLevelPusher implements FilePropertyPusher<LanguageLevel
}
@Override
public void afterRootsChanged(Project project) {
public void afterRootsChanged(@NotNull Project project) {
}
}
@@ -33,7 +33,7 @@ import java.io.IOException;
public interface FilePropertyPusher<T> {
ExtensionPointName<FilePropertyPusher> EP_NAME = ExtensionPointName.create("com.intellij.filePropertyPusher");
void initExtra(Project project, MessageBus bus, Engine languageLevelUpdater);
void initExtra(@NotNull Project project, @NotNull MessageBus bus, @NotNull Engine languageLevelUpdater);
@NotNull
Key<T> getFileDataKey();
boolean pushDirectoriesOnly();
@@ -42,19 +42,19 @@ public interface FilePropertyPusher<T> {
T getDefaultValue();
@Nullable
T getImmediateValue(Project project, VirtualFile file);
T getImmediateValue(@NotNull Project project, @Nullable VirtualFile file);
@Nullable
T getImmediateValue(Module module);
T getImmediateValue(@NotNull Module module);
boolean acceptsFile(VirtualFile file);
boolean acceptsFile(@NotNull VirtualFile file);
void persistAttribute(VirtualFile fileOrDir, @NotNull T value) throws IOException;
void persistAttribute(@NotNull VirtualFile fileOrDir, @NotNull T value) throws IOException;
public interface Engine {
interface Engine {
void pushAll();
void pushRecursively(final VirtualFile vile, final Project project);
void pushRecursively(VirtualFile vile, Project project);
}
void afterRootsChanged(Project project);
void afterRootsChanged(@NotNull Project project);
}
@@ -125,23 +125,25 @@ public class PushedFilePropertiesUpdater {
});
}
private static <T> T findPusherValuesUpwards(final Project project, final VirtualFile dir, FilePropertyPusher<T> pusher, T moduleValue) {
private static <T> T findPusherValuesUpwards(Project project, 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();
T projectValue = pusher.getImmediateValue(project, null);
return projectValue != null? projectValue : pusher.getDefaultValue();
}
private static <T> T findPusherValuesUpwards(final Project project, final VirtualFile dir, FilePropertyPusher<T> pusher) {
private static <T> T findPusherValuesUpwards(Project project, 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();
T projectValue = pusher.getImmediateValue(project, null);
return projectValue != null ? projectValue : pusher.getDefaultValue();
}
public void pushAll(final FilePropertyPusher... pushers) {