}
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);
/*
- * 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.
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;
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));
}
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);
}
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();
}
}
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) {
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());
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);
}
if (PATH_FIELD.is(dataId)) {
- return new PathField() {
- public void toggleVisible() {
- toggleShowTextField();
- }
- };
+ return (PathField)FileChooserDialogImpl.this::toggleShowTextField;
}
if (FileSystemTree.DATA_KEY.is(dataId)) {
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());
}
/*
- * 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.
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;
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));
}
/*
- * 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.
@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;
}
/*
- * 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.
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());
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;
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(
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();
@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 {
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();
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;
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();
@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);
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) {
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);
}
}
}
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();
/*
- * 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.
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");
@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));
}
@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));
}
}
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) {
/*
- * 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.
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);
+ }
+ });
});
}
});
}
}
- myPathTextField.setText(text, now, new Runnable() {
- public void run() {
- myPathTextField.getField().selectAll();
- }
- });
+ myPathTextField.setText(text, now, () -> myPathTextField.getField().selectAll());
}
/*
- * 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.
import com.intellij.util.SystemProperties;
import com.intellij.util.containers.ContainerUtil;
+import java.util.Locale;
import java.util.Set;
/**
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), "/"));
}