summaryrefslogtreecommitdiff
path: root/platform/util/src/com/intellij/openapi
diff options
context:
space:
mode:
Diffstat (limited to 'platform/util/src/com/intellij/openapi')
-rw-r--r--platform/util/src/com/intellij/openapi/diagnostic/Log.java8
-rw-r--r--platform/util/src/com/intellij/openapi/progress/ProcessCanceledException.java5
-rw-r--r--platform/util/src/com/intellij/openapi/util/TextRange.java10
-rw-r--r--platform/util/src/com/intellij/openapi/util/io/FileUtil.java6
-rw-r--r--platform/util/src/com/intellij/openapi/util/registry/Registry.java45
-rw-r--r--platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java47
-rw-r--r--platform/util/src/com/intellij/openapi/util/text/StringUtil.java3
7 files changed, 67 insertions, 57 deletions
diff --git a/platform/util/src/com/intellij/openapi/diagnostic/Log.java b/platform/util/src/com/intellij/openapi/diagnostic/Log.java
index dfc00ae9b4c6..842a8356f591 100644
--- a/platform/util/src/com/intellij/openapi/diagnostic/Log.java
+++ b/platform/util/src/com/intellij/openapi/diagnostic/Log.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2010 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,13 +15,11 @@
*/
package com.intellij.openapi.diagnostic;
-
import java.util.ArrayList;
import java.util.List;
-/**
- * This is a very primitive fast logging class, primary for race-conditions debugging.
- */
+/** @deprecated use {@link com.intellij.openapi.diagnostic.Logger} (to be removed in IDEA 15) */
+@SuppressWarnings("unused")
public class Log {
private static final List<String> myStrings = new ArrayList<String>();
private static final List<Throwable> myThrowables = new ArrayList<Throwable>();
diff --git a/platform/util/src/com/intellij/openapi/progress/ProcessCanceledException.java b/platform/util/src/com/intellij/openapi/progress/ProcessCanceledException.java
index e3029934b2e5..e6133b255411 100644
--- a/platform/util/src/com/intellij/openapi/progress/ProcessCanceledException.java
+++ b/platform/util/src/com/intellij/openapi/progress/ProcessCanceledException.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.
@@ -18,10 +18,9 @@ package com.intellij.openapi.progress;
import com.intellij.util.SystemProperties;
public class ProcessCanceledException extends RuntimeException {
- private static boolean ourHasStackTraces = SystemProperties.getBooleanProperty("idea.is.internal", false);
+ private static final boolean ourHasStackTraces = SystemProperties.getBooleanProperty("idea.is.internal", false);
public ProcessCanceledException() {
- int i = 0;
}
public ProcessCanceledException(Throwable cause) {
diff --git a/platform/util/src/com/intellij/openapi/util/TextRange.java b/platform/util/src/com/intellij/openapi/util/TextRange.java
index 797bc23ee747..4c09b969a570 100644
--- a/platform/util/src/com/intellij/openapi/util/TextRange.java
+++ b/platform/util/src/com/intellij/openapi/util/TextRange.java
@@ -99,6 +99,16 @@ public class TextRange implements Segment, Serializable {
}
@NotNull
+ public CharSequence subSequence(@NotNull CharSequence str) {
+ try {
+ return str.subSequence(myStartOffset, myEndOffset);
+ }
+ catch (IndexOutOfBoundsException e) {
+ throw new IndexOutOfBoundsException("Can't extract " + this + " range from " + str);
+ }
+ }
+
+ @NotNull
public TextRange cutOut(@NotNull TextRange subRange) {
assert subRange.getStartOffset() <= getLength() : subRange + "; this="+this;
assert subRange.getEndOffset() <= getLength() : subRange + "; this="+this;
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 cfcbe7967d35..adec13d20412 100644
--- a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java
+++ b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java
@@ -1264,10 +1264,10 @@ public class FileUtil extends FileUtilRt {
if (path == null) return null;
if (SystemInfo.isUnix || !unixOnly) {
- final File projectDir = new File(path);
- final File userHomeDir = new File(SystemProperties.getUserHome());
+ File projectDir = new File(path);
+ File userHomeDir = new File(SystemProperties.getUserHome());
if (isAncestor(userHomeDir, projectDir, true)) {
- return "~/" + getRelativePath(userHomeDir, projectDir);
+ return '~' + File.separator + getRelativePath(userHomeDir, projectDir);
}
}
diff --git a/platform/util/src/com/intellij/openapi/util/registry/Registry.java b/platform/util/src/com/intellij/openapi/util/registry/Registry.java
index e418e553fb6b..d41ea08161b3 100644
--- a/platform/util/src/com/intellij/openapi/util/registry/Registry.java
+++ b/platform/util/src/com/intellij/openapi/util/registry/Registry.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.
@@ -18,6 +18,7 @@ package com.intellij.openapi.util.registry;
import com.intellij.util.containers.HashMap;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.PropertyKey;
import java.awt.*;
@@ -33,30 +34,29 @@ public class Registry {
@NonNls
private static final String REGISTRY_BUNDLE = "misc.registry";
- private final LinkedHashMap<String, String> myUserProperties = new LinkedHashMap<String, String>();
+ private final Map<String, String> myUserProperties = new LinkedHashMap<String, String>();
private final Map<String, String> myLoadedUserProperties = new HashMap<String, String>();
private final Map<String, RegistryValue> myValues = new ConcurrentHashMap<String, RegistryValue>();
private static final Registry ourInstance = new Registry();
- public static RegistryValue get(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) String key) {
+ @NotNull
+ public static RegistryValue get(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) @NotNull String key) {
final Registry registry = getInstance();
- if (registry.myValues.containsKey(key)) {
- return registry.myValues.get(key);
- }
- else {
- final RegistryValue value = new RegistryValue(registry, key);
+ RegistryValue value = registry.myValues.get(key);
+ if (value == null) {
+ value = new RegistryValue(registry, key);
registry.myValues.put(key, value);
- return value;
}
+ return value;
}
- public static boolean is(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) String key) {
+ public static boolean is(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) @NotNull String key) throws MissingResourceException {
return get(key).asBoolean();
}
- public static boolean is(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) String key, boolean defaultValue) {
+ public static boolean is(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) @NotNull String key, boolean defaultValue) {
try {
return get(key).asBoolean();
}
@@ -65,11 +65,11 @@ public class Registry {
}
}
- public static int intValue(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) String key) {
+ public static int intValue(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) @NotNull String key) throws MissingResourceException {
return get(key).asInteger();
}
- public static int intValue(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) String key, int defaultValue) {
+ public static int intValue(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) @NotNull String key, int defaultValue) {
try {
return get(key).asInteger();
}
@@ -78,18 +78,20 @@ public class Registry {
}
}
- public static double doubleValue(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) String key) {
+ public static double doubleValue(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) @NotNull String key) throws MissingResourceException {
return get(key).asDouble();
}
- public static String stringValue(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) String key) {
+ @NotNull
+ public static String stringValue(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) @NotNull String key) throws MissingResourceException {
return get(key).asString();
}
- public static Color getColor(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) String key, Color defaultValue) {
+ public static Color getColor(@PropertyKey(resourceBundle = REGISTRY_BUNDLE) @NotNull String key, Color defaultValue) throws MissingResourceException {
return get(key).asColor(defaultValue);
}
+ @NotNull
static ResourceBundle getBundle() {
ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle);
if (bundle == null) {
@@ -104,6 +106,7 @@ public class Registry {
return ourInstance;
}
+ @NotNull
public Element getState() {
final Element state = new Element("registry");
for (String eachKey : myUserProperties.keySet()) {
@@ -115,7 +118,7 @@ public class Registry {
return state;
}
- public void loadState(Element state) {
+ public void loadState(@NotNull Element state) {
final List entries = state.getChildren("entry");
for (Object each : entries) {
final Element eachEntry = (Element) each;
@@ -132,15 +135,17 @@ public class Registry {
}
}
+ @NotNull
Map<String, String> getUserProperties() {
return myUserProperties;
}
+ @NotNull
public static List<RegistryValue> getAll() {
final ResourceBundle bundle = getBundle();
final Enumeration<String> keys = bundle.getKeys();
- final ArrayList<RegistryValue> result = new ArrayList<RegistryValue>();
+ List<RegistryValue> result = new ArrayList<RegistryValue>();
while (keys.hasMoreElements()) {
final String each = keys.nextElement();
@@ -152,7 +157,7 @@ public class Registry {
}
public void restoreDefaults() {
- final HashMap<String, String> old = new HashMap<String, String>();
+ Map<String, String> old = new HashMap<String, String>();
old.putAll(myUserProperties);
for (String each : old.keySet()) {
get(each).resetToDefault();
@@ -167,7 +172,7 @@ public class Registry {
return isRestartNeeded(myUserProperties) || isRestartNeeded(myLoadedUserProperties);
}
- private static boolean isRestartNeeded(Map<String, String> map) {
+ private static boolean isRestartNeeded(@NotNull Map<String, String> map) {
for (String s : map.keySet()) {
final RegistryValue eachValue = get(s);
if (eachValue.isRestartRequired() && eachValue.isChangedSinceAppStart()) return true;
diff --git a/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java b/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java
index 6c89311457f4..ae3873b8744f 100644
--- a/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java
+++ b/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.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.
@@ -42,16 +42,18 @@ public class RegistryValue {
private Double myDoubleCachedValue;
private Boolean myBooleanCachedValue;
- RegistryValue(Registry registry, String key) {
+ RegistryValue(@NotNull Registry registry, @NotNull String key) {
myRegistry = registry;
myKey = key;
}
+ @NotNull
public String getKey() {
return myKey;
}
+ @NotNull
public String asString() {
final String value = get(myKey, null, true);
assert value != null : myKey;
@@ -97,6 +99,7 @@ public class RegistryValue {
return defaultValue;
}
+ @NotNull
public String getDescription() {
return get(myKey + ".description", "", false);
}
@@ -109,42 +112,36 @@ public class RegistryValue {
return !asString().equals(getBundleValue(myKey, false));
}
- private String get(String key, String defaultValue, boolean isValue) {
+ private String get(@NotNull String key, String defaultValue, boolean isValue) throws MissingResourceException {
if (isValue) {
if (myStringCachedValue == null) {
myStringCachedValue = _get(key, defaultValue, isValue);
- }
- if (isBoolean()) {
- myStringCachedValue = Boolean.valueOf(myStringCachedValue).toString();
+ if (isBoolean()) {
+ myStringCachedValue = Boolean.valueOf(myStringCachedValue).toString();
+ }
}
return myStringCachedValue;
}
- else {
- return _get(key, defaultValue, isValue);
- }
+ return _get(key, defaultValue, isValue);
}
- private String _get(String key, String defaultValue, boolean mustExistInBundle) {
+ private String _get(@NotNull String key, String defaultValue, boolean mustExistInBundle) throws MissingResourceException {
final String userValue = myRegistry.getUserProperties().get(key);
- if (userValue == null) {
- String systemProperty = System.getProperty(key);
- if (systemProperty != null) {
- return systemProperty;
- }
- final String bundleValue = getBundleValue(key, mustExistInBundle);
- if (bundleValue != null) {
- return bundleValue;
- }
- else {
- return defaultValue;
- }
- }
- else {
+ if (userValue != null) {
return userValue;
}
+ String systemProperty = System.getProperty(key);
+ if (systemProperty != null) {
+ return systemProperty;
+ }
+ final String bundleValue = getBundleValue(key, mustExistInBundle);
+ if (bundleValue != null) {
+ return bundleValue;
+ }
+ return defaultValue;
}
- private String getBundleValue(String key, boolean mustExist) {
+ private static String getBundleValue(@NotNull String key, boolean mustExist) throws MissingResourceException {
try {
return Registry.getBundle().getString(key);
}
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 bc37f673bb03..e364a8568fda 100644
--- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java
+++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java
@@ -1331,6 +1331,7 @@ public class StringUtil extends StringUtilRt {
}
public static boolean isQuotedString(@NotNull String text) {
+ if (text.length() < 2) return false;
return startsWithChar(text, '\"') && endsWithChar(text, '\"')
|| startsWithChar(text, '\'') && endsWithChar(text, '\'');
}
@@ -2678,7 +2679,7 @@ public class StringUtil extends StringUtilRt {
continue;
}
- if (i > 0 && (ch == '/' || ch == '\\' || ch == '.' || Character.isUpperCase(ch))) {
+ if (i > 0 && (ch == '/' || ch == '\\' || ch == '.' || ch == '-' || Character.isUpperCase(ch))) {
words.add(builder.toString());
builder.delete(0, builder.length());
}