cleanup
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Fri, 27 May 2016 15:17:34 +0000 (17:17 +0200)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Mon, 30 May 2016 10:02:42 +0000 (12:02 +0200)
platform/lang-impl/src/com/intellij/ide/util/projectWizard/ExistingModuleLoader.java
platform/platform-impl/src/com/intellij/application/options/pathMacros/PathMacroTable.java
platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileChooserDialogImpl.java
platform/platform-impl/src/com/intellij/openapi/fileChooser/impl/FileChooserFactoryImpl.java
platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectMacrosUtil.java
platform/projectModel-impl/src/com/intellij/application/options/PathMacrosCollector.java
platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.java
platform/projectModel-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java
plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectLocationStep.java
plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcPathMacros.java

index cb458b2493fb401c3965ebd891bc96b458a47799..caffc07a2716907e8b543497831e0350c267bfaa 100644 (file)
@@ -99,9 +99,8 @@ public class ExistingModuleLoader extends ModuleBuilder {
         }
         final Element root = JDOMUtil.load(file);
         final Set<String> usedMacros = PathMacrosCollector.getMacroNames(root);
-        final Set<String> definedMacros = PathMacros.getInstance().getAllMacroNames();
         usedMacros.remove("$" + PathMacrosImpl.MODULE_DIR_MACRO_NAME + "$");
-        usedMacros.removeAll(definedMacros);
+        usedMacros.removeAll(PathMacros.getInstance().getAllMacroNames());
 
         if (usedMacros.size() > 0) {
           final boolean ok = ProjectMacrosUtil.showMacrosConfigurationDialog(current, usedMacros);
index 54cf150b2287a1577e1ead2a4fce332647ee0365..e0638c94c7c3eabd47555be7b853c2db415dbfed 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ public class PathMacroTable extends Table {
   private static final int NAME_COLUMN = 0;
   private static final int VALUE_COLUMN = 1;
 
-  private final List<Couple<String>> myMacros = new ArrayList<Couple<String>>();
+  private final List<Couple<String>> myMacros = new ArrayList<>();
   private static final Comparator<Couple<String>> MACRO_COMPARATOR = (pair, pair1) -> pair.getFirst().compareTo(pair1.getFirst());
 
   private final Collection<String> myUndefinedMacroNames;
@@ -77,10 +77,6 @@ public class PathMacroTable extends Table {
     return (String) getValueAt(row, VALUE_COLUMN);
   }
 
-  public String getMacroNameAt(int row) {
-    return (String)getValueAt(row, NAME_COLUMN);
-  }
-
   public void addMacro() {
     final String title = ApplicationBundle.message("title.add.variable");
     final PathMacroEditor macroEditor = new PathMacroEditor(title, "", "", new AddValidator(title));
@@ -196,7 +192,7 @@ public class PathMacroTable extends Table {
   }
 
   public boolean isModified() {
-    final ArrayList<Couple<String>> macros = new ArrayList<Couple<String>>();
+    final ArrayList<Couple<String>> macros = new ArrayList<>();
     obtainMacroPairs(macros);
     return !macros.equals(myMacros);
   }
@@ -265,8 +261,9 @@ public class PathMacroTable extends Table {
 
   private static class EditValidator implements PathMacroEditor.Validator {
     public boolean checkName(String name) {
-      if (name.length() == 0) return false;
-      if (PathMacros.getInstance().getSystemMacroNames().contains(name)) return false;
+      if (name.isEmpty() || PathMacros.getInstance().getSystemMacroNames().contains(name)) {
+        return false;
+      }
 
       return PathMacrosCollector.MACRO_PATTERN.matcher("$" + name + "$").matches();
     }
index edc19252cf4da39074e24e250d76f8ce06336b84..c8a2fa1ab8f7967cf5fd2ce27ae34b416ee72332 100644 (file)
@@ -194,7 +194,7 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD
   }
 
   protected void saveRecent(String path) {
-    final List<String> files = new ArrayList<String>(Arrays.asList(getRecentFiles()));
+    final List<String> files = new ArrayList<>(Arrays.asList(getRecentFiles()));
     files.remove(path);
     files.add(0, path);
     while (files.size() > 30) {
@@ -440,7 +440,7 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD
     internalTree.setShowsRootHandles(true);
     Disposer.register(myDisposable, myFileSystemTree);
 
-    myFileSystemTree.addOkAction(() -> doOKAction());
+    myFileSystemTree.addOkAction(this::doOKAction);
     JTree tree = myFileSystemTree.getTree();
     tree.setCellRenderer(new NodeRenderer());
     tree.getSelectionModel().addTreeSelectionListener(new FileTreeSelectionListener());
@@ -501,7 +501,7 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD
     return myFileSystemTree.getSelectedFiles();
   }
 
-  private final Map<String, LocalFileSystem.WatchRequest> myRequests = new HashMap<String, LocalFileSystem.WatchRequest>();
+  private final Map<String, LocalFileSystem.WatchRequest> myRequests = new HashMap<>();
 
   private static boolean isToShowTextField() {
     return PropertiesComponent.getInstance().getBoolean(FILE_CHOOSER_SHOW_PATH_PROPERTY, true);
@@ -604,11 +604,7 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD
       }
 
       if (PATH_FIELD.is(dataId)) {
-        return new PathField() {
-          public void toggleVisible() {
-            toggleShowTextField();
-          }
-        };
+        return (PathField)FileChooserDialogImpl.this::toggleShowTextField;
       }
 
       if (FileSystemTree.DATA_KEY.is(dataId)) {
@@ -632,7 +628,7 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD
     myTextFieldAction.update();
     myNorthPanel.remove(myPathTextFieldWrapper);
     if (isToShowTextField()) {
-      final ArrayList<VirtualFile> selection = new ArrayList<VirtualFile>();
+      final ArrayList<VirtualFile> selection = new ArrayList<>();
       if (myFileSystemTree.getSelectedFile() != null) {
         selection.add(myFileSystemTree.getSelectedFile());
       }
index 5fb25bdf17e78161be533e3a35864899307c122d..37287bd607f77d0079a5da01647d03bf5ba54ad9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -29,12 +29,12 @@ import com.intellij.openapi.util.SystemInfo;
 import com.intellij.openapi.util.registry.Registry;
 import com.intellij.ui.mac.MacFileChooserDialogImpl;
 import com.intellij.util.SystemProperties;
+import gnu.trove.THashMap;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import java.awt.*;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
@@ -95,7 +95,7 @@ public class FileChooserFactoryImpl extends FileChooserFactory {
   public static Map<String, String> getMacroMap() {
     final PathMacros macros = PathMacros.getInstance();
     final Set<String> allNames = macros.getAllMacroNames();
-    final HashMap<String, String> map = new HashMap<String, String>();
+    final Map<String, String> map = new THashMap<>(allNames.size());
     for (String eachMacroName : allNames) {
       map.put("$" + eachMacroName + "$", macros.getValue(eachMacroName));
     }
index b770b05c1f3f50f9548235a6b2f66b36ab117414..444b264772f72fcb787441f8b3b8e433df763f38 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -90,7 +90,7 @@ public class ProjectMacrosUtil {
   @NotNull
   public static Set<String> getDefinedMacros() {
     PathMacros pathMacros = PathMacros.getInstance();
-    Set<String> definedMacros = new THashSet<String>(pathMacros.getUserMacroNames());
+    Set<String> definedMacros = new THashSet<>(pathMacros.getUserMacroNames());
     definedMacros.addAll(pathMacros.getSystemMacroNames());
     return definedMacros;
   }
index bdc097b6d5f971237aee628c356207891993f5ea..902cf784f18ddc8298c33b8fcee513802d89bf04 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -64,7 +64,7 @@ public class PathMacrosCollector extends PathMacroMap {
       return Collections.emptySet();
     }
 
-    Set<String> result = new SmartHashSet<String>(preResult);
+    Set<String> result = new SmartHashSet<>(preResult);
     result.removeAll(pathMacros.getSystemMacroNames());
     result.removeAll(pathMacros.getLegacyMacroNames());
     result.removeAll(PathMacrosImpl.getToolMacroNames());
index 195b3b687aa50dd6628c616bf5ef4b620da8f09b..27ccd099f6c401ad14a71bb45fc6bf7c204ad874 100644 (file)
@@ -20,8 +20,8 @@ import com.intellij.openapi.components.*;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.containers.ContainerUtil;
-import com.intellij.util.containers.HashMap;
 import com.intellij.util.containers.hash.LinkedHashMap;
+import gnu.trove.THashMap;
 import gnu.trove.THashSet;
 import org.jdom.Element;
 import org.jetbrains.annotations.NonNls;
@@ -30,7 +30,10 @@ import org.jetbrains.annotations.Nullable;
 import org.jetbrains.jps.model.serialization.JpsGlobalLoader;
 import org.jetbrains.jps.model.serialization.PathMacroUtil;
 
-import java.util.*;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 @State(
@@ -40,8 +43,8 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 public class PathMacrosImpl extends PathMacros implements PersistentStateComponent<Element> {
   private static final Logger LOG = Logger.getInstance(PathMacrosImpl.class);
 
-  private final Map<String, String> myLegacyMacros = new HashMap<String, String>();
-  private final Map<String, String> myMacros = new LinkedHashMap<String, String>();
+  private final Map<String, String> myLegacyMacros = new THashMap<>();
+  private final Map<String, String> myMacros = new LinkedHashMap<>();
   private int myModificationStamp = 0;
   private final ReentrantReadWriteLock myLock = new ReentrantReadWriteLock();
   private final List<String> myIgnoredMacros = ContainerUtil.createLockFreeCopyOnWriteList();
@@ -63,7 +66,7 @@ public class PathMacrosImpl extends PathMacros implements PersistentStateCompone
   @NonNls
   public static final String USER_HOME_MACRO_NAME = PathMacroUtil.USER_HOME_NAME;
 
-  private static final Set<String> SYSTEM_MACROS = new HashSet<String>();
+  private static final Set<String> SYSTEM_MACROS = new THashSet<>();
   @NonNls public static final String EXT_FILE_NAME = "path.macros";
 
   static {
@@ -146,7 +149,7 @@ public class PathMacrosImpl extends PathMacros implements PersistentStateCompone
   public Set<String> getUserMacroNames() {
     myLock.readLock().lock();
     try {
-      return new THashSet<String>(myMacros.keySet()); // keyset should not escape the lock
+      return new THashSet<>(myMacros.keySet()); // keyset should not escape the lock
     }
     finally {
       myLock.readLock().unlock();
@@ -197,7 +200,7 @@ public class PathMacrosImpl extends PathMacros implements PersistentStateCompone
   public Set<String> getAllMacroNames() {
     final Set<String> userMacroNames = getUserMacroNames();
     final Set<String> systemMacroNames = getSystemMacroNames();
-    final Set<String> allNames = new HashSet<String>(userMacroNames.size() + systemMacroNames.size());
+    final Set<String> allNames = new THashSet<>(userMacroNames.size() + systemMacroNames.size());
     allNames.addAll(systemMacroNames);
     allNames.addAll(userMacroNames);
     return allNames;
@@ -230,7 +233,8 @@ public class PathMacrosImpl extends PathMacros implements PersistentStateCompone
   public Collection<String> getLegacyMacroNames() {
     try {
       myLock.readLock().lock();
-      return new THashSet<String>(myLegacyMacros.keySet()); // keyset should not escape the lock
+      // keyset should not escape the lock
+      return new THashSet<>(myLegacyMacros.keySet());
     }
     finally {
       myLock.readLock().unlock();
@@ -239,7 +243,10 @@ public class PathMacrosImpl extends PathMacros implements PersistentStateCompone
 
   @Override
   public void setMacro(@NotNull String name, @NotNull String value) {
-    if (value.trim().isEmpty()) return;
+    if (StringUtil.isEmptyOrSpaces(value)) {
+      return;
+    }
+
     try {
       myLock.writeLock().lock();
       myMacros.put(name, value);
@@ -310,9 +317,7 @@ public class PathMacrosImpl extends PathMacros implements PersistentStateCompone
     try {
       myLock.writeLock().lock();
 
-      final List children = element.getChildren(MACRO_ELEMENT);
-      for (Object aChildren : children) {
-        Element macro = (Element)aChildren;
+      for (Element macro : element.getChildren(MACRO_ELEMENT)) {
         final String name = macro.getAttributeValue(NAME_ATTR);
         String value = macro.getAttributeValue(VALUE_ATTR);
         if (name == null || value == null) {
@@ -330,11 +335,9 @@ public class PathMacrosImpl extends PathMacros implements PersistentStateCompone
         myMacros.put(name, value);
       }
 
-      final List ignoredChildren = element.getChildren(IGNORED_MACRO_ELEMENT);
-      for (final Object child : ignoredChildren) {
-        final Element macroElement = (Element)child;
-        final String ignoredName = macroElement.getAttributeValue(NAME_ATTR);
-        if (ignoredName != null && !ignoredName.isEmpty() && !myIgnoredMacros.contains(ignoredName)) {
+      for (Element macroElement : element.getChildren(IGNORED_MACRO_ELEMENT)) {
+        String ignoredName = macroElement.getAttributeValue(NAME_ATTR);
+        if (!StringUtil.isEmpty(ignoredName) && !myIgnoredMacros.contains(ignoredName)) {
           myIgnoredMacros.add(ignoredName);
         }
       }
@@ -346,16 +349,20 @@ public class PathMacrosImpl extends PathMacros implements PersistentStateCompone
   }
 
   public void addMacroReplacements(ReplacePathToMacroMap result) {
-    for (final String name : getUserMacroNames()) {
-      final String value = getValue(name);
-      if (value != null && !value.trim().isEmpty()) result.addMacroReplacement(value, name);
+    for (String name : getUserMacroNames()) {
+      String value = getValue(name);
+      if (!StringUtil.isEmptyOrSpaces(value)) {
+        result.addMacroReplacement(value, name);
+      }
     }
   }
 
   public void addMacroExpands(ExpandMacroToPathMap result) {
-    for (final String name : getUserMacroNames()) {
-      final String value = getValue(name);
-      if (value != null && !value.trim().isEmpty()) result.addMacroExpand(name, value);
+    for (String name : getUserMacroNames()) {
+      String value = getValue(name);
+      if (!StringUtil.isEmptyOrSpaces(value)) {
+        result.addMacroExpand(name, value);
+      }
     }
 
     myLock.readLock().lock();
index 351d579290e7460b27c384cf804cd27b2c9c62fd..e201900c41c20ed81533476063089b6532124a7b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -40,7 +40,10 @@ import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.jps.model.serialization.PathMacroUtil;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
 
 public class BasePathMacroManager extends PathMacroManager {
   private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.components.impl.BasePathMacroManager");
@@ -218,7 +221,7 @@ public class BasePathMacroManager extends PathMacroManager {
     @Override
     public Set<String> getComponents(@NotNull Collection<String> macros) {
       synchronized (myLock) {
-        Set<String> result = new SmartHashSet<String>();
+        Set<String> result = new SmartHashSet<>();
         for (String macro : macros) {
           result.addAll(myMacroToComponentNames.get(macro));
         }
@@ -230,8 +233,8 @@ public class BasePathMacroManager extends PathMacroManager {
     @Override
     public Set<String> getUnknownMacros(@Nullable String componentName) {
       synchronized (myLock) {
-        Set<String> list = componentName == null ? myMacroToComponentNames.keySet() : (Set<String>)myComponentNameToMacros.get(componentName);
-        return ContainerUtil.isEmpty(list) ? Collections.<String>emptySet() : Collections.unmodifiableSet(list);
+        return ContainerUtil.notNullize(
+          componentName == null ? myMacroToComponentNames.keySet() : (Set<String>)myComponentNameToMacros.get(componentName));
       }
     }
 
@@ -240,8 +243,8 @@ public class BasePathMacroManager extends PathMacroManager {
       if (unknownMacros.isEmpty()) {
         return;
       }
-      
-      LOG.debug("Registering unknown macros " + new ArrayList<String>(unknownMacros) + " in component " + componentName);
+
+      LOG.debug("Registering unknown macros " + new ArrayList<>(unknownMacros) + " in component " + componentName);
 
       synchronized (myLock) {
         for (String unknownMacro : unknownMacros) {
index 276e6568b291aa3e943dc79b78e25b3596d1e62b..ba270198c2458d7276a74881e87b40f623b48e36 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -194,17 +194,15 @@ public abstract class SelectLocationStep extends WizardStep {
 
     myUiUpdater.queue(new Update("treeFromPath.1") {
       public void run() {
-        ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
-          public void run() {
-            final LocalFsFinder.VfsFile toFind = (LocalFsFinder.VfsFile)myPathTextField.getFile();
-            if (toFind == null || !toFind.exists()) return;
-
-            myUiUpdater.queue(new Update("treeFromPath.2") {
-              public void run() {
-                selectInTree(toFind.getFile(), text);
-              }
-            });
-          }
+        ApplicationManager.getApplication().executeOnPooledThread(() -> {
+          final LocalFsFinder.VfsFile toFind = (LocalFsFinder.VfsFile)myPathTextField.getFile();
+          if (toFind == null || !toFind.exists()) return;
+
+          myUiUpdater.queue(new Update("treeFromPath.2") {
+            public void run() {
+              selectInTree(toFind.getFile(), text);
+            }
+          });
         });
       }
     });
@@ -264,11 +262,7 @@ public abstract class SelectLocationStep extends WizardStep {
       }
     }
 
-    myPathTextField.setText(text, now, new Runnable() {
-      public void run() {
-        myPathTextField.getField().selectAll();
-      }
-    });
+    myPathTextField.setText(text, now, () -> myPathTextField.getField().selectAll());
   }
 
 
index df6fdc5fc17a8db72b38ca8c00fc129c043d7924..f7e183e2a8b63e94c6b20df6270d1872a33eaf60 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.SystemProperties;
 import com.intellij.util.containers.ContainerUtil;
 
+import java.util.Locale;
 import java.util.Set;
 
 /**
@@ -32,7 +33,7 @@ public class MvcPathMacros {
   public MvcPathMacros() {
     Set<String> macroNames = PathMacros.getInstance().getUserMacroNames();
     for (String framework : ContainerUtil.ar("grails", "griffon")) {
-      String name = "USER_HOME_" + framework.toUpperCase();
+      String name = "USER_HOME_" + framework.toUpperCase(Locale.ENGLISH);
       if (!macroNames.contains(name)) { // OK, it may appear/disappear during the application lifetime, but we ignore that for now. Restart will help anyway
         PathMacros.getInstance().addLegacyMacro(name, StringUtil.trimEnd(getSdkWorkDirParent(framework), "/"));
       }