This commit is contained in:
Alexey Kudravtsev
2018-10-10 18:25:02 +03:00
parent 7e67a42a53
commit 9adeb72b6c
2 changed files with 13 additions and 14 deletions
@@ -53,7 +53,7 @@ public class LanguageFindUsages extends LanguageExtension<FindUsagesProvider> {
* @return true iff could be found usages by some provider for this element
*/
public static boolean canFindUsagesFor(@NotNull PsiElement psiElement) {
return applyForProviders(p -> p.canFindUsagesFor(psiElement), psiElement, Boolean.FALSE);
return getFromProviders(psiElement, Boolean.FALSE, p -> p.canFindUsagesFor(psiElement));
}
/**
@@ -77,7 +77,7 @@ public class LanguageFindUsages extends LanguageExtension<FindUsagesProvider> {
*/
@NotNull
public static String getDescriptiveName(@NotNull PsiElement psiElement) {
return applyForProviders(p -> p.getDescriptiveName(psiElement), psiElement, "");
return getFromProviders(psiElement, "", p -> p.getDescriptiveName(psiElement));
}
/**
@@ -86,7 +86,7 @@ public class LanguageFindUsages extends LanguageExtension<FindUsagesProvider> {
*/
@NotNull
public static String getType(@NotNull PsiElement psiElement) {
return applyForProviders(p -> p.getType(psiElement), psiElement, "");
return getFromProviders(psiElement, "", p -> p.getType(psiElement));
}
/**
@@ -95,7 +95,7 @@ public class LanguageFindUsages extends LanguageExtension<FindUsagesProvider> {
*/
@NotNull
public static String getNodeText(@NotNull PsiElement psiElement, boolean useFullName) {
return applyForProviders(p -> p.getNodeText(psiElement, useFullName), psiElement, "");
return getFromProviders(psiElement, "", p -> p.getNodeText(psiElement, useFullName));
}
/**
@@ -104,16 +104,17 @@ public class LanguageFindUsages extends LanguageExtension<FindUsagesProvider> {
*/
@Nullable
public static String getHelpId(@NotNull PsiElement psiElement) {
return applyForProviders(p -> p.getHelpId(psiElement), psiElement, null);
return getFromProviders(psiElement, null, p -> p.getHelpId(psiElement));
}
private static <T> T applyForProviders(@NotNull Function<FindUsagesProvider, T> method, @NotNull PsiElement psiElement, T defaultValue) {
private static <T> T getFromProviders(@NotNull PsiElement psiElement,
T defaultValue, @NotNull Function<FindUsagesProvider, T> getter) {
Language language = psiElement.getLanguage();
List<FindUsagesProvider> providers = INSTANCE.allForLanguage(language);
assert !providers.isEmpty() : "Element: " + psiElement + ", language: " + language;
for (FindUsagesProvider provider : providers) {
T res = method.apply(provider);
T res = getter.apply(provider);
if (res != null && !res.equals(defaultValue)) {
return res;
}
@@ -29,11 +29,10 @@ import com.intellij.openapi.vfs.newvfs.BulkFileListener;
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
import com.intellij.util.EventDispatcher;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class LocalHistoryEventDispatcher implements VirtualFileManagerListener, CommandListener,
class LocalHistoryEventDispatcher implements VirtualFileManagerListener, CommandListener,
BulkFileListener, VirtualFileListener {
private static final Key<Boolean> WAS_VERSIONED_KEY =
Key.create(LocalHistoryEventDispatcher.class.getSimpleName() + ".WAS_VERSIONED_KEY");
@@ -42,7 +41,7 @@ public class LocalHistoryEventDispatcher implements VirtualFileManagerListener,
private final IdeaGateway myGateway;
private final EventDispatcher<VirtualFileListener> myVfsEventsDispatcher = EventDispatcher.create(VirtualFileListener.class);
public LocalHistoryEventDispatcher(LocalHistoryFacade vcs, IdeaGateway gw) {
LocalHistoryEventDispatcher(LocalHistoryFacade vcs, IdeaGateway gw) {
myVcs = vcs;
myGateway = gw;
myVfsEventsDispatcher.addListener(this);
@@ -68,12 +67,12 @@ public class LocalHistoryEventDispatcher implements VirtualFileManagerListener,
endChangeSet(e.getCommandName());
}
public void startAction() {
void startAction() {
myGateway.registerUnsavedDocuments(myVcs);
myVcs.forceBeginChangeSet();
}
public void finishAction(String name) {
void finishAction(String name) {
myGateway.registerUnsavedDocuments(myVcs);
endChangeSet(name);
}
@@ -103,7 +102,6 @@ public class LocalHistoryEventDispatcher implements VirtualFileManagerListener,
return true;
}
@Nullable
@Override
public Iterable<VirtualFile> getChildrenIterable(@NotNull VirtualFile f) {
// For unversioned files we try to get cached children in hope that they are already generated by content root manager:
@@ -213,7 +211,7 @@ public class LocalHistoryEventDispatcher implements VirtualFileManagerListener,
});
}
public void addVirtualFileListener(VirtualFileListener virtualFileListener, Disposable disposable) {
void addVirtualFileListener(VirtualFileListener virtualFileListener, Disposable disposable) {
myVfsEventsDispatcher.addListener(virtualFileListener, disposable);
}
}