summaryrefslogtreecommitdiff
path: root/platform/util/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'platform/util/src/com')
-rw-r--r--platform/util/src/com/intellij/icons/AllIcons.java3
-rw-r--r--platform/util/src/com/intellij/openapi/ui/Divider.java34
-rw-r--r--platform/util/src/com/intellij/openapi/ui/Splitter.java10
-rw-r--r--platform/util/src/com/intellij/openapi/util/io/FileUtil.java9
-rw-r--r--platform/util/src/com/intellij/openapi/util/io/win32/IdeaWin32.java2
-rw-r--r--platform/util/src/com/intellij/openapi/util/text/StringUtil.java73
-rw-r--r--platform/util/src/com/intellij/ui/JBColor.java120
-rw-r--r--platform/util/src/com/intellij/util/EventDispatcher.java8
-rw-r--r--platform/util/src/com/intellij/util/PatternUtil.java46
-rw-r--r--platform/util/src/com/intellij/util/ReflectionUtil.java20
-rw-r--r--platform/util/src/com/intellij/util/Restarter.java11
-rw-r--r--platform/util/src/com/intellij/util/containers/ContainerUtil.java1
-rw-r--r--platform/util/src/com/intellij/util/containers/LongStack.java75
-rw-r--r--platform/util/src/com/intellij/util/diff/DiffTree.java8
-rw-r--r--platform/util/src/com/intellij/util/io/LongInlineKeyDescriptor.java50
-rw-r--r--platform/util/src/com/intellij/util/text/StringSearcher.java3
-rw-r--r--platform/util/src/com/intellij/util/ui/UIUtil.java8
-rw-r--r--platform/util/src/com/intellij/util/xmlb/XmlSerializerImpl.java13
18 files changed, 414 insertions, 80 deletions
diff --git a/platform/util/src/com/intellij/icons/AllIcons.java b/platform/util/src/com/intellij/icons/AllIcons.java
index db897fd8c52d..be3f4f212072 100644
--- a/platform/util/src/com/intellij/icons/AllIcons.java
+++ b/platform/util/src/com/intellij/icons/AllIcons.java
@@ -74,6 +74,7 @@ public class AllIcons {
public static final Icon Forward = IconLoader.getIcon("/actions/forward.png"); // 16x16
public static final Icon GC = IconLoader.getIcon("/actions/gc.png"); // 16x16
public static final Icon Get = IconLoader.getIcon("/actions/get.png"); // 16x16
+ public static final Icon GroupByFile = IconLoader.getIcon("/actions/GroupByFile.png"); // 16x16
public static final Icon GroupByMethod = IconLoader.getIcon("/actions/groupByMethod.png"); // 16x16
public static final Icon GroupByModule = IconLoader.getIcon("/actions/GroupByModule.png"); // 16x16
public static final Icon GroupByModuleGroup = IconLoader.getIcon("/actions/GroupByModuleGroup.png"); // 16x16
@@ -459,6 +460,8 @@ public class AllIcons {
public static final Icon PluginManager = IconLoader.getIcon("/general/pluginManager.png"); // 32x32
public static final Icon Progress = IconLoader.getIcon("/general/progress.png"); // 8x10
public static final Icon ProjectConfigurable = IconLoader.getIcon("/general/projectConfigurable.png"); // 9x9
+ public static final Icon ProjectConfigurableBanner = IconLoader.getIcon("/general/projectConfigurableBanner.png"); // 9x9
+ public static final Icon ProjectConfigurableSelected = IconLoader.getIcon("/general/projectConfigurableSelected.png"); // 9x9
public static final Icon ProjectSettings = IconLoader.getIcon("/general/projectSettings.png"); // 16x16
public static final Icon ProjectStructure = IconLoader.getIcon("/general/projectStructure.png"); // 16x16
public static final Icon ProjectTab = IconLoader.getIcon("/general/projectTab.png"); // 16x16
diff --git a/platform/util/src/com/intellij/openapi/ui/Divider.java b/platform/util/src/com/intellij/openapi/ui/Divider.java
new file mode 100644
index 000000000000..1b2b6b1a3d6a
--- /dev/null
+++ b/platform/util/src/com/intellij/openapi/ui/Divider.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2000-2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.openapi.ui;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**
+ * @author Konstantin Bulenkov
+ */
+public abstract class Divider extends JPanel {
+ public Divider(LayoutManager layout) {
+ super(layout);
+ }
+
+ public abstract void setResizeEnabled(boolean resizeEnabled);
+
+ public abstract void setSwitchOrientationEnabled(boolean switchOrientationEnabled);
+
+ public abstract void setOrientation(boolean vertical);
+}
diff --git a/platform/util/src/com/intellij/openapi/ui/Splitter.java b/platform/util/src/com/intellij/openapi/ui/Splitter.java
index 44d2317088c6..71a026702563 100644
--- a/platform/util/src/com/intellij/openapi/ui/Splitter.java
+++ b/platform/util/src/com/intellij/openapi/ui/Splitter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
@@ -177,7 +177,7 @@ public class Splitter extends JPanel {
}
protected Divider createDivider() {
- return new Divider();
+ return new DividerImpl();
}
@Override
@@ -481,12 +481,12 @@ public class Splitter extends JPanel {
return myDivider;
}
- public class Divider extends JPanel {
+ public class DividerImpl extends Divider {
private boolean myResizeEnabled;
private boolean mySwitchOrientationEnabled;
protected Point myPoint;
- public Divider() {
+ public DividerImpl() {
super(new GridBagLayout());
myResizeEnabled = true;
mySwitchOrientationEnabled = false;
@@ -496,7 +496,7 @@ public class Splitter extends JPanel {
setOrientation(myVerticalSplit);
}
- private void setOrientation(boolean isVerticalSplit) {
+ public void setOrientation(boolean isVerticalSplit) {
removeAll();
setCursor(isVertical() ?
diff --git a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java
index 0f95577cf2b5..cfcbe7967d35 100644
--- a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java
+++ b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java
@@ -1255,10 +1255,15 @@ public class FileUtil extends FileUtilRt {
}
@Contract("null -> null")
- public static String getLocationRelativeToUserHome(@Nullable final String path) {
+ public static String getLocationRelativeToUserHome(@Nullable String path) {
+ return getLocationRelativeToUserHome(path, true);
+ }
+
+ @Contract("null,_ -> null")
+ public static String getLocationRelativeToUserHome(@Nullable String path, boolean unixOnly) {
if (path == null) return null;
- if (SystemInfo.isUnix) {
+ if (SystemInfo.isUnix || !unixOnly) {
final File projectDir = new File(path);
final File userHomeDir = new File(SystemProperties.getUserHome());
if (isAncestor(userHomeDir, projectDir, true)) {
diff --git a/platform/util/src/com/intellij/openapi/util/io/win32/IdeaWin32.java b/platform/util/src/com/intellij/openapi/util/io/win32/IdeaWin32.java
index 3484d0625d37..586668af3864 100644
--- a/platform/util/src/com/intellij/openapi/util/io/win32/IdeaWin32.java
+++ b/platform/util/src/com/intellij/openapi/util/io/win32/IdeaWin32.java
@@ -35,7 +35,7 @@ public class IdeaWin32 {
static {
IdeaWin32 instance = null;
- if (SystemInfo.isWin2kOrNewer) {
+ if (SystemInfo.isWin2kOrNewer && Boolean.parseBoolean(System.getProperty("idea.use.native.fs.for.win", "true"))) {
try {
UrlClassLoader.loadPlatformLibrary("IdeaWin32");
instance = new IdeaWin32();
diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java
index 7ee904c1f344..bc37f673bb03 100644
--- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java
+++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java
@@ -923,6 +923,10 @@ public class StringUtil extends StringUtilRt {
}
}
+ public static String defaultIfEmpty(@Nullable String value, String defaultValue) {
+ return isEmpty(value) ? defaultValue : value;
+ }
+
@Contract("null -> false")
public static boolean isNotEmpty(@Nullable String s) {
return s != null && !s.isEmpty();
@@ -2513,10 +2517,9 @@ public class StringUtil extends StringUtilRt {
public static String shortenTextWithEllipsis(@NotNull final String text,
final int maxLength,
final int suffixLength,
- boolean useEllipsisSymbol) {
+ @NotNull String symbol) {
final int textLength = text.length();
if (textLength > maxLength) {
- String symbol = useEllipsisSymbol ? "\u2026" : "...";
final int prefixLength = maxLength - suffixLength - symbol.length();
assert prefixLength > 0;
return text.substring(0, prefixLength) + symbol + text.substring(textLength - suffixLength);
@@ -2527,6 +2530,15 @@ public class StringUtil extends StringUtilRt {
}
@NotNull
+ public static String shortenTextWithEllipsis(@NotNull final String text,
+ final int maxLength,
+ final int suffixLength,
+ boolean useEllipsisSymbol) {
+ String symbol = useEllipsisSymbol ? "\u2026" : "...";
+ return shortenTextWithEllipsis(text, maxLength, suffixLength, symbol);
+ }
+
+ @NotNull
public static String shortenPathWithEllipsis(@NotNull final String path, final int maxLength, boolean useEllipsisSymbol) {
return shortenTextWithEllipsis(path, maxLength, (int)(maxLength * 0.7), useEllipsisSymbol);
}
@@ -2650,6 +2662,63 @@ public class StringUtil extends StringUtilRt {
return s.startsWith(smallPart.toLowerCase()) && bigPart.toLowerCase().startsWith(s);
}
+ public static String getShortened(String s, int maxWidth) {
+ int length = s.length();
+ if (isEmpty(s) || length <= maxWidth) return s;
+ ArrayList<String> words = new ArrayList<String>();
+
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ char ch = s.charAt(i);
+
+ if (i == length - 1) {
+ builder.append(ch);
+ words.add(builder.toString());
+ builder.delete(0, builder.length());
+ continue;
+ }
+
+ if (i > 0 && (ch == '/' || ch == '\\' || ch == '.' || Character.isUpperCase(ch))) {
+ words.add(builder.toString());
+ builder.delete(0, builder.length());
+ }
+ builder.append(ch);
+ }
+ for (int i = 0; i < words.size(); i++) {
+ String word = words.get(i);
+ if (i < words.size() - 1 && word.length() == 1) {
+ words.remove(i);
+ words.set(i, word + words.get(i));
+ }
+ }
+
+ int removedLength = 0;
+
+ String toPaste = "...";
+ int index;
+ while (true) {
+ index = Math.max(0, (words.size() - 1) / 2);
+ String aWord = words.get(index);
+ words.remove(index);
+ int toCut = length - removedLength - maxWidth + 3;
+ if (words.size() < 2 || (toCut < aWord.length() - 2 && removedLength == 0)) {
+ int pos = (aWord.length() - toCut) / 2;
+ toPaste = aWord.substring(0, pos) + "..." + aWord.substring(pos+toCut);
+ break;
+ }
+ removedLength += aWord.length();
+ if (length - removedLength <= maxWidth - 3) {
+ break;
+ }
+ }
+ for (int i = 0; i < words.size(); i++) {
+ String word = words.get(i);
+ if (i == index || words.size() == 1) builder.append(toPaste);
+ builder.append(word);
+ }
+ return builder.toString().replaceAll("\\.{4,}", "...");
+ }
+
/**
* Expirable CharSequence. Very useful to control external library execution time,
* i.e. when java.util.regex.Pattern match goes out of control.
diff --git a/platform/util/src/com/intellij/ui/JBColor.java b/platform/util/src/com/intellij/ui/JBColor.java
index d2b4a3bd7623..3669e725610d 100644
--- a/platform/util/src/com/intellij/ui/JBColor.java
+++ b/platform/util/src/com/intellij/ui/JBColor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
@@ -15,7 +15,9 @@
*/
package com.intellij.ui;
+import com.intellij.util.NotNullProducer;
import com.intellij.util.ui.UIUtil;
+import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.awt.color.ColorSpace;
@@ -32,6 +34,7 @@ public class JBColor extends Color {
private static volatile boolean DARK = UIUtil.isUnderDarcula();
private final Color darkColor;
+ private final NotNullProducer<Color> func;
public JBColor(int rgb, int darkRGB) {
this(new Color(rgb), new Color(darkRGB));
@@ -42,6 +45,13 @@ public class JBColor extends Color {
darkColor = dark;
//noinspection AssignmentToStaticFieldFromInstanceMethod
DARK = UIUtil.isUnderDarcula(); //Double check. Sometimes DARK != isDarcula() after dialogs appear on splash screen
+ func = null;
+ }
+
+ public JBColor(NotNullProducer<Color> function) {
+ super(0);
+ darkColor = null;
+ func = function;
}
public static void setDark(boolean dark) {
@@ -52,99 +62,142 @@ public class JBColor extends Color {
return darkColor;
}
+ Color getColor() {
+ if (func != null) {
+ return func.produce();
+ } else {
+ return DARK ? getDarkVariant() : this;
+ }
+ }
+
@Override
public int getRed() {
- return DARK ? getDarkVariant().getRed() : super.getRed();
+ final Color c = getColor();
+ return c == this ? super.getRed() : c.getRed();
}
@Override
public int getGreen() {
- return DARK ? getDarkVariant().getGreen() : super.getGreen();
+ final Color c = getColor();
+ return c == this ? super.getGreen() : c.getGreen();
}
@Override
public int getBlue() {
- return DARK ? getDarkVariant().getBlue() : super.getBlue();
+ final Color c = getColor();
+ return c == this ? super.getBlue() : c.getBlue();
}
@Override
public int getAlpha() {
- return DARK ? getDarkVariant().getAlpha() : super.getAlpha();
+ final Color c = getColor();
+ return c == this ? super.getAlpha() : c.getAlpha();
}
@Override
public int getRGB() {
- return DARK ? getDarkVariant().getRGB() : super.getRGB();
+ final Color c = getColor();
+ return c == this ? super.getRGB() : c.getRGB();
}
@Override
public Color brighter() {
+ if (func != null) {
+ return new JBColor(new NotNullProducer<Color>() {
+ @NotNull
+ @Override
+ public Color produce() {
+ return func.produce().brighter();
+ }
+ });
+ }
return new JBColor(super.brighter(), getDarkVariant().brighter());
}
@Override
public Color darker() {
+ if (func != null) {
+ return new JBColor(new NotNullProducer<Color>() {
+ @NotNull
+ @Override
+ public Color produce() {
+ return func.produce().darker();
+ }
+ });
+ }
return new JBColor(super.darker(), getDarkVariant().darker());
}
@Override
public int hashCode() {
- return DARK ? getDarkVariant().hashCode() : super.hashCode();
+ final Color c = getColor();
+ return c == this ? super.hashCode() : c.hashCode();
}
@Override
public boolean equals(Object obj) {
- return DARK ? getDarkVariant().equals(obj) : super.equals(obj);
+ final Color c = getColor();
+ return c == this ? super.equals(obj) : c.equals(obj);
}
@Override
public String toString() {
- return DARK ? getDarkVariant().toString() : super.toString();
+ final Color c = getColor();
+ return c == this ? super.toString() : c.toString();
}
@Override
public float[] getRGBComponents(float[] compArray) {
- return DARK ? getDarkVariant().getRGBComponents(compArray) : super.getRGBComponents(compArray);
+ final Color c = getColor();
+ return c == this ? super.getRGBComponents(compArray) : c.getRGBComponents(compArray);
}
@Override
public float[] getRGBColorComponents(float[] compArray) {
- return DARK ? getDarkVariant().getRGBColorComponents(compArray) : super.getRGBComponents(compArray);
+ final Color c = getColor();
+ return c == this ? super.getRGBComponents(compArray) : c.getRGBColorComponents(compArray);
}
@Override
public float[] getComponents(float[] compArray) {
- return DARK ? getDarkVariant().getComponents(compArray) : super.getComponents(compArray);
+ final Color c = getColor();
+ return c == this ? super.getComponents(compArray) : c.getComponents(compArray);
}
@Override
public float[] getColorComponents(float[] compArray) {
- return DARK ? getDarkVariant().getColorComponents(compArray) : super.getColorComponents(compArray);
+ final Color c = getColor();
+ return c == this ? super.getColorComponents(compArray) : c.getColorComponents(compArray);
}
@Override
public float[] getComponents(ColorSpace cspace, float[] compArray) {
- return DARK ? getDarkVariant().getComponents(cspace, compArray) : super.getComponents(cspace, compArray);
+ final Color c = getColor();
+ return c == this ? super.getComponents(cspace, compArray) : c.getComponents(cspace, compArray);
}
@Override
public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
- return DARK ? getDarkVariant().getColorComponents(cspace, compArray) : super.getColorComponents(cspace, compArray);
+ final Color c = getColor();
+ return c == this ? super.getColorComponents(cspace, compArray) : c.getColorComponents(cspace, compArray);
}
@Override
public ColorSpace getColorSpace() {
- return DARK ? getDarkVariant().getColorSpace() : super.getColorSpace();
+ final Color c = getColor();
+ return c == this ? super.getColorSpace() : c.getColorSpace();
}
@Override
public synchronized PaintContext createContext(ColorModel cm, Rectangle r, Rectangle2D r2d, AffineTransform xform, RenderingHints hints) {
- return DARK ? getDarkVariant().createContext(cm, r, r2d, xform, hints) : super.createContext(cm, r, r2d, xform, hints);
+ final Color c = getColor();
+ return c == this ? super.createContext(cm, r, r2d, xform, hints) : c.createContext(cm, r, r2d, xform, hints);
}
@Override
public int getTransparency() {
- return DARK ? getDarkVariant().getTransparency() : super.getTransparency();
+ final Color c = getColor();
+ return c == this ? super.getTransparency() : c.getTransparency();
}
public static final JBColor red = new JBColor(Color.red, DarculaColors.RED);
@@ -196,7 +249,34 @@ public class JBColor extends Color {
public static final Color cyan = new JBColor(Color.cyan, new Color(0, 137, 137));
public static final Color CYAN = cyan;
- public static Color foreground() {return UIUtil.getLabelForeground();}
+ public static Color foreground() {
+ return new JBColor(new NotNullProducer<Color>() {
+ @NotNull
+ @Override
+ public Color produce() {
+ return UIUtil.getLabelForeground();
+ }
+ });
+ }
- public static Color background() {return UIUtil.getListBackground();}
+ public static Color background() {
+ return new JBColor(new NotNullProducer<Color>() {
+ @NotNull
+ @Override
+ public Color produce() {
+ return UIUtil.getListBackground();
+ }
+ });
+ }
+
+ public static Color border() {
+ return new JBColor(new NotNullProducer<Color>() {
+ @NotNull
+ @Override
+ public Color produce() {
+ //noinspection deprecation
+ return UIUtil.getBorderColor();
+ }
+ });
+ }
}
diff --git a/platform/util/src/com/intellij/util/EventDispatcher.java b/platform/util/src/com/intellij/util/EventDispatcher.java
index 34361a8ff31b..e17c6e46e5f3 100644
--- a/platform/util/src/com/intellij/util/EventDispatcher.java
+++ b/platform/util/src/com/intellij/util/EventDispatcher.java
@@ -43,6 +43,7 @@ public class EventDispatcher<T extends EventListener> {
}
private EventDispatcher(@NotNull Class<T> listenerClass) {
+ LOG.assertTrue(listenerClass.isInterface(), "listenerClass must be an interface");
InvocationHandler handler = new InvocationHandler() {
@Override
@NonNls
@@ -71,10 +72,7 @@ public class EventDispatcher<T extends EventListener> {
};
//noinspection unchecked
- myMulticaster = (T)Proxy.newProxyInstance(listenerClass.getClassLoader(),
- new Class[]{listenerClass},
- handler
- );
+ myMulticaster = (T)Proxy.newProxyInstance(listenerClass.getClassLoader(), new Class[]{listenerClass}, handler);
}
@NotNull
@@ -82,7 +80,7 @@ public class EventDispatcher<T extends EventListener> {
return myMulticaster;
}
- private void dispatch(final Method method, final Object[] args) {
+ private void dispatch(@NotNull Method method, Object[] args) {
method.setAccessible(true);
for (T listener : myListeners) {
diff --git a/platform/util/src/com/intellij/util/PatternUtil.java b/platform/util/src/com/intellij/util/PatternUtil.java
index 7159a90d1601..0b683dddc1e6 100644
--- a/platform/util/src/com/intellij/util/PatternUtil.java
+++ b/platform/util/src/com/intellij/util/PatternUtil.java
@@ -17,8 +17,9 @@ package com.intellij.util;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.util.containers.HashMap;
-import org.jetbrains.annotations.NonNls;
+import com.intellij.util.containers.ContainerUtil;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -29,30 +30,22 @@ import java.util.regex.PatternSyntaxException;
public class PatternUtil {
private static final Logger LOG = Logger.getInstance("#com.intellij.util.PatternUtil");
- private static final HashMap<String, String> ourEscapeRules = new HashMap<String, String>();
+
+ public static final Pattern NOTHING = Pattern.compile("(a\\A)");
+
+ private static final Map<String, String> ourEscapeRules = ContainerUtil.newLinkedHashMap();
static {
// '.' should be escaped first
ourEscapeRules.put("*", ".*");
ourEscapeRules.put("?", ".");
- escape2('+');
- escape2('(');
- escape2(')');
- escape2('[');
- escape2(']');
- escape2('/');
- escape2('^');
- escape2('$');
- escape2('{');
- escape2('}');
- escape2('|');
- }
-
- private static void escape2(char symbol) {
- ourEscapeRules.put(String.valueOf(symbol), "\\" + symbol);
+ for (char c : "+()[]/^${}|".toCharArray()) {
+ ourEscapeRules.put(String.valueOf(c), "\\" + c);
+ }
}
- public static String convertToRegex(String mask) {
+ @NotNull
+ public static String convertToRegex(@NotNull String mask) {
List<String> strings = StringUtil.split(mask, "\\");
StringBuilder pattern = new StringBuilder();
String separator = "";
@@ -69,17 +62,26 @@ public class PatternUtil {
return pattern.toString();
}
- public static Pattern fromMask(@NonNls String mask) {
-// String pattern = mask.replaceAll("\\.", "\\.").replaceAll("\\*", ".*").replaceAll("\\?", ".");
+ @NotNull
+ public static Pattern fromMask(@NotNull String mask) {
try {
return Pattern.compile(convertToRegex(mask));
}
catch (PatternSyntaxException e) {
LOG.error(mask, e);
- return Pattern.compile("");
+ return NOTHING;
}
}
+ @Contract("_, !null->!null")
+ public static Pattern compileSafe(String pattern, Pattern def) {
+ try {
+ return Pattern.compile(pattern);
+ }
+ catch (Exception e) {
+ return def;
+ }
+ }
/**
* Finds the first match in a list os Strings.
*
diff --git a/platform/util/src/com/intellij/util/ReflectionUtil.java b/platform/util/src/com/intellij/util/ReflectionUtil.java
index a4bf4318a76e..df33a80d4cba 100644
--- a/platform/util/src/com/intellij/util/ReflectionUtil.java
+++ b/platform/util/src/com/intellij/util/ReflectionUtil.java
@@ -426,6 +426,26 @@ public class ReflectionUtil {
}
}
+ /**
+ * {@link Class#newInstance()} cannot instantiate private classes
+ */
+ @NotNull
+ public static <T> T newInstance(@NotNull Class<T> aClass, @NotNull Class... parameterTypes) {
+ try {
+ Constructor<T> constructor = aClass.getDeclaredConstructor(parameterTypes);
+ try {
+ constructor.setAccessible(true);
+ }
+ catch (SecurityException e) {
+ return aClass.newInstance();
+ }
+ return constructor.newInstance();
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
@NotNull
public static <T> T createInstance(@NotNull Constructor<T> constructor, @NotNull Object... args) {
try {
diff --git a/platform/util/src/com/intellij/util/Restarter.java b/platform/util/src/com/intellij/util/Restarter.java
index 7f1584dc73dc..01e7fc494f5b 100644
--- a/platform/util/src/com/intellij/util/Restarter.java
+++ b/platform/util/src/com/intellij/util/Restarter.java
@@ -153,12 +153,11 @@ public class Restarter {
}
public static File createTempExecutable(File executable) throws IOException {
- String ext = FileUtilRt.getExtension(executable.getName());
- File copy = FileUtilRt.createTempFile(FileUtilRt.getNameWithoutExtension(executable.getName()),
- StringUtil.isEmptyOrSpaces(ext) ? ".tmp" : ("." + ext),
- false);
- FileUtilRt.copy(executable, copy);
- if (!copy.setExecutable(executable.canExecute())) throw new IOException("Cannot make file executable: " + copy);
+ File copy = new File(System.getProperty("user.home") + "/." + System.getProperty("idea.paths.selector") + "/restart/" + executable.getName());
+ if (FileUtilRt.ensureCanCreateFile(copy)) {
+ FileUtilRt.copy(executable, copy);
+ if (!copy.setExecutable(executable.canExecute())) throw new IOException("Cannot make file executable: " + copy);
+ }
return copy;
}
diff --git a/platform/util/src/com/intellij/util/containers/ContainerUtil.java b/platform/util/src/com/intellij/util/containers/ContainerUtil.java
index 6052df2b701e..171cfababfa9 100644
--- a/platform/util/src/com/intellij/util/containers/ContainerUtil.java
+++ b/platform/util/src/com/intellij/util/containers/ContainerUtil.java
@@ -828,6 +828,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
public static <T> List<T> findAll(@NotNull Collection<? extends T> collection, @NotNull Condition<? super T> condition) {
+ if (collection.isEmpty()) return emptyList();
final List<T> result = new SmartList<T>();
for (final T t : collection) {
if (condition.value(t)) {
diff --git a/platform/util/src/com/intellij/util/containers/LongStack.java b/platform/util/src/com/intellij/util/containers/LongStack.java
new file mode 100644
index 000000000000..8e1005bd0af2
--- /dev/null
+++ b/platform/util/src/com/intellij/util/containers/LongStack.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2000-2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.util.containers;
+
+/**
+ * @author lambdamix
+ */
+import java.util.EmptyStackException;
+
+public class LongStack {
+ private long[] data;
+ private int size;
+ public LongStack(int initialCapacity) {
+ data = new long[initialCapacity];
+ size = 0;
+ }
+
+ public LongStack() {
+ this(5);
+ }
+
+ public void push(long t) {
+ if (size >= data.length) {
+ long[] newdata = new long[data.length * 3 / 2];
+ System.arraycopy(data, 0, newdata, 0, size);
+ data = newdata;
+ }
+ data[size++] = t;
+ }
+
+ public long peek() {
+ if (size == 0) throw new EmptyStackException();
+ return data[size - 1];
+ }
+
+ public long pop() {
+ if (size == 0) throw new EmptyStackException();
+ return data[--size];
+ }
+
+ public boolean empty() {
+ return size == 0;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof LongStack) {
+ LongStack otherStack = (LongStack)o;
+ if (size != otherStack.size) return false;
+ for (int i = 0; i < otherStack.size; i++) {
+ if (data[i] != otherStack.data[i]) return false;
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ public void clear() {
+ size = 0;
+ }
+}
diff --git a/platform/util/src/com/intellij/util/diff/DiffTree.java b/platform/util/src/com/intellij/util/diff/DiffTree.java
index 0bab60dc87da..680b15b7d1de 100644
--- a/platform/util/src/com/intellij/util/diff/DiffTree.java
+++ b/platform/util/src/com/intellij/util/diff/DiffTree.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package com.intellij.util.diff;
import com.intellij.openapi.util.Ref;
@@ -39,7 +38,6 @@ public class DiffTree<OT, NT> {
final FlyweightCapableTreeStructure<NT> newTree,
final ShallowNodeComparator<OT, NT> comparator,
final DiffTreeChangeBuilder<OT, NT> consumer) {
-
myOldTree = oldTree;
myNewTree = newTree;
myComparator = comparator;
@@ -53,7 +51,7 @@ public class DiffTree<OT, NT> {
new DiffTree<OT, NT>(oldTree, newTree, comparator, consumer).build(oldTree.getRoot(), newTree.getRoot(), 0);
}
- private static enum CompareResult {
+ private enum CompareResult {
EQUAL, // 100% equal
DRILL_DOWN_NEEDED, // element types are equal, but elements are composite
TYPE_ONLY, // only element types are equal
@@ -146,6 +144,7 @@ public class DiffTree<OT, NT> {
newIndex++;
continue;
}
+
CompareResult c12 = looksEqual(comparator, oldChild1, newChild2);
if (c12 == CompareResult.EQUAL || c12 == CompareResult.DRILL_DOWN_NEEDED || c12 == CompareResult.TYPE_ONLY) {
myConsumer.nodeInserted(oldNode, newChild1, newIndex);
@@ -170,6 +169,7 @@ public class DiffTree<OT, NT> {
oldIndex++;
continue;
}
+
myConsumer.nodeReplaced(oldChild1, newChild1);
oldIndex++;
newIndex++;
diff --git a/platform/util/src/com/intellij/util/io/LongInlineKeyDescriptor.java b/platform/util/src/com/intellij/util/io/LongInlineKeyDescriptor.java
new file mode 100644
index 000000000000..78f1fdd02f78
--- /dev/null
+++ b/platform/util/src/com/intellij/util/io/LongInlineKeyDescriptor.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2000-2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.util.io;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+/**
+ * @author lambdamix
+ */
+public class LongInlineKeyDescriptor implements KeyDescriptor<Long> {
+ public static LongInlineKeyDescriptor INSTANCE = new LongInlineKeyDescriptor();
+
+ @Override
+ public final int getHashCode(Long value) {
+ return value.hashCode();
+ }
+
+ @Override
+ public final boolean isEqual(Long val1, Long val2) {
+ return val1.longValue() == val2.longValue();
+ }
+
+ @Override
+ public final void save(@NotNull DataOutput out, Long value) throws IOException {
+ out.writeLong(value.longValue());
+ }
+
+ @Override
+ public final Long read(@NotNull DataInput in) throws IOException {
+ return in.readLong();
+ }
+
+}
diff --git a/platform/util/src/com/intellij/util/text/StringSearcher.java b/platform/util/src/com/intellij/util/text/StringSearcher.java
index 22e9db2d9428..d5bc95f99cef 100644
--- a/platform/util/src/com/intellij/util/text/StringSearcher.java
+++ b/platform/util/src/com/intellij/util/text/StringSearcher.java
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
+import java.util.Locale;
public class StringSearcher {
private static final Logger LOG = Logger.getInstance("#com.intellij.util.text.StringSearcher");
@@ -48,7 +49,7 @@ public class StringSearcher {
myPattern = pattern;
myCaseSensitive = caseSensitive;
myForwardDirection = forwardDirection;
- myPatternArray = myCaseSensitive ? myPattern.toCharArray() : myPattern.toLowerCase().toCharArray();
+ myPatternArray = myCaseSensitive ? myPattern.toCharArray() : myPattern.toLowerCase(Locale.US).toCharArray();
myPatternLength = myPatternArray.length;
Arrays.fill(mySearchTable, -1);
myJavaIdentifier = pattern.isEmpty() ||
diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java
index 7ed8021bd94b..aec2a356ded0 100644
--- a/platform/util/src/com/intellij/util/ui/UIUtil.java
+++ b/platform/util/src/com/intellij/util/ui/UIUtil.java
@@ -1586,7 +1586,7 @@ public class UIUtil {
@NotNull Graphics g,
boolean useRetinaCondition,
Consumer<Graphics2D> paintRoutine) {
- if (!useRetinaCondition || !isRetina() || Registry.is("ide.mac.retina.disableDrawingFix", false)) {
+ if (!useRetinaCondition || !isRetina() || Registry.is("ide.mac.retina.disableDrawingFix")) {
paintRoutine.consume((Graphics2D)g);
}
else {
@@ -1904,6 +1904,10 @@ public class UIUtil {
return INACTIVE_HEADER_COLOR;
}
+ /**
+ * @deprecated
+ * @use JBColor.border()
+ */
public static Color getBorderColor() {
return isUnderDarcula() ? Gray._50 : BORDER_COLOR;
}
@@ -2769,7 +2773,7 @@ public class UIUtil {
@NotNull
public static Paint getGradientPaint(float x1, float y1, @NotNull Color c1, float x2, float y2, @NotNull Color c2) {
- return (Registry.is("ui.no.bangs.and.whistles", false)) ? ColorUtil.mix(c1, c2, .5) : new GradientPaint(x1, y1, c1, x2, y2, c2);
+ return (Registry.is("ui.no.bangs.and.whistles")) ? ColorUtil.mix(c1, c2, .5) : new GradientPaint(x1, y1, c1, x2, y2, c2);
}
@Nullable
diff --git a/platform/util/src/com/intellij/util/xmlb/XmlSerializerImpl.java b/platform/util/src/com/intellij/util/xmlb/XmlSerializerImpl.java
index c25ea4eda084..6cc2124c695a 100644
--- a/platform/util/src/com/intellij/util/xmlb/XmlSerializerImpl.java
+++ b/platform/util/src/com/intellij/util/xmlb/XmlSerializerImpl.java
@@ -16,13 +16,13 @@
package com.intellij.util.xmlb;
import com.intellij.openapi.util.Pair;
+import com.intellij.util.ReflectionUtil;
import org.jdom.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.lang.annotation.Annotation;
import java.lang.ref.SoftReference;
-import java.lang.reflect.Constructor;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*;
@@ -184,16 +184,9 @@ class XmlSerializerImpl {
/**
* {@link Class#newInstance()} cannot instantiate private classes
*/
- static <T> T newInstance(Class<T> aClass) {
+ static <T> T newInstance(@NotNull Class<T> aClass) {
try {
- Constructor<T> constructor = aClass.getDeclaredConstructor();
- try {
- constructor.setAccessible(true);
- }
- catch (SecurityException e) {
- return aClass.newInstance();
- }
- return constructor.newInstance();
+ return ReflectionUtil.newInstance(aClass);
}
catch (Exception e) {
throw new XmlSerializationException(e);