From a5ac8ea1d2a6f820fa2cf9ad9de977e2d556d031 Mon Sep 17 00:00:00 2001 From: Sergey Ignatov Date: Tue, 7 Oct 2014 18:01:26 +0200 Subject: [PATCH] cleanup --- .../ide/scratch/NewScratchFileAction.java | 19 +++++-------------- .../ide/scratch/ScratchpadManagerImpl.java | 5 +++-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/scratch/NewScratchFileAction.java b/platform/lang-impl/src/com/intellij/ide/scratch/NewScratchFileAction.java index 8e15a6ce5a36..be74f8ca6588 100644 --- a/platform/lang-impl/src/com/intellij/ide/scratch/NewScratchFileAction.java +++ b/platform/lang-impl/src/com/intellij/ide/scratch/NewScratchFileAction.java @@ -44,7 +44,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -65,25 +64,17 @@ public class NewScratchFileAction extends AnAction implements DumbAware { public static List getLastUsedLanguagesIds(Project project) { String[] values = PropertiesComponent.getInstance(project).getValues(ScratchpadManager.class.getName()); - if (values == null) { - return ContainerUtil.emptyList(); - } - return ContainerUtil.list(values); + return values == null ? ContainerUtil.emptyList() : ContainerUtil.list(values); } - @Override public void actionPerformed(@NotNull AnActionEvent e) { final Project project = e.getProject(); if (project == null) return; - Language context = null; PsiFile file = e.getData(CommonDataKeys.PSI_FILE); - - if (file != null) { - context = file.getLanguage(); - } - + Language context = file != null ? file.getLanguage() : null; + ListPopup popup = buildLanguagePopup(project, context, new Consumer() { @Override public void consume(Language language) { @@ -98,7 +89,7 @@ public class NewScratchFileAction extends AnAction implements DumbAware { @NotNull static ListPopup buildLanguagePopup(@NotNull Project project, @Nullable Language context, final Consumer onChoosen) { List languages = LanguageUtil.getFileLanguages(); - final List ids = new ArrayList(getLastUsedLanguagesIds(project)); + final List ids = ContainerUtil.newArrayList(getLastUsedLanguagesIds(project)); if (context != null) { ids.add(context.getID()); } @@ -108,7 +99,7 @@ public class NewScratchFileAction extends AnAction implements DumbAware { ContainerUtil.sort(languages, new Comparator() { @Override - public int compare(Language o1, Language o2) { + public int compare(@NotNull Language o1, @NotNull Language o2) { int ind1 = ids.indexOf(o1.getID()); int ind2 = ids.indexOf(o2.getID()); if (ind1 == -1) ind1 = 666; diff --git a/platform/lang-impl/src/com/intellij/ide/scratch/ScratchpadManagerImpl.java b/platform/lang-impl/src/com/intellij/ide/scratch/ScratchpadManagerImpl.java index 6cc2e81cecc8..c7dc4462475a 100644 --- a/platform/lang-impl/src/com/intellij/ide/scratch/ScratchpadManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/scratch/ScratchpadManagerImpl.java @@ -26,9 +26,10 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.StatusBar; import com.intellij.openapi.wm.WindowManager; import com.intellij.util.ArrayUtil; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; +import java.util.List; public class ScratchpadManagerImpl extends ScratchpadManager implements Disposable { private final Project myProject; @@ -61,7 +62,7 @@ public class ScratchpadManagerImpl extends ScratchpadManager implements Disposab private static void updateHistory(Project project, Language language) { String[] values = PropertiesComponent.getInstance(project).getValues(ScratchpadManager.class.getName()); - ArrayList lastUsed = new ArrayList(5); + List lastUsed = ContainerUtil.newArrayListWithCapacity(5); lastUsed.add(language.getID()); if (values != null) { for (String value : values) {