use of org.jetbrains.annotations.Contract in project intellij-community by JetBrains.
the class StringUtil method formatLinks.
@NotNull
@Contract(pure = true)
public static String formatLinks(@NotNull String message) {
Pattern linkPattern = Pattern.compile("http://[a-zA-Z0-9\\./\\-\\+]+");
StringBuffer result = new StringBuffer();
Matcher m = linkPattern.matcher(message);
while (m.find()) {
m.appendReplacement(result, "<a href=\"" + m.group() + "\">" + m.group() + "</a>");
}
m.appendTail(result);
return result.toString();
}
use of org.jetbrains.annotations.Contract in project intellij-community by JetBrains.
the class StringUtil method findMatches.
@NotNull
@Contract(pure = true)
public static List<String> findMatches(@NotNull String s, @NotNull Pattern pattern, int groupIndex) {
List<String> result = new SmartList<String>();
Matcher m = pattern.matcher(s);
while (m.find()) {
String group = m.group(groupIndex);
if (group != null) {
result.add(group);
}
}
return result;
}
use of org.jetbrains.annotations.Contract in project intellij-community by JetBrains.
the class PathManager method substituteVars.
@Contract("null, _ -> null")
public static String substituteVars(String s, String ideaHomePath) {
if (s == null)
return null;
if (s.startsWith("..")) {
s = ideaHomePath + File.separatorChar + BIN_FOLDER + File.separatorChar + s;
}
Matcher m = PROPERTY_REF.matcher(s);
while (m.find()) {
String key = m.group(1);
String value = System.getProperty(key);
if (value == null) {
if (PROPERTY_HOME_PATH.equals(key) || PROPERTY_HOME.equals(key)) {
value = ideaHomePath;
} else if (PROPERTY_CONFIG_PATH.equals(key)) {
value = getConfigPath();
} else if (PROPERTY_SYSTEM_PATH.equals(key)) {
value = getSystemPath();
}
}
if (value == null) {
log("Unknown property: " + key);
value = "";
}
s = StringUtil.replace(s, m.group(), value);
m = PROPERTY_REF.matcher(s);
}
return s;
}
use of org.jetbrains.annotations.Contract in project intellij-community by JetBrains.
the class ModuleRootManagerTestCase method retainRtJarOnlyAndSetVersion.
@NotNull
@Contract(pure = true)
private static Sdk retainRtJarOnlyAndSetVersion(Sdk jdk) {
try {
jdk = (Sdk) jdk.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
final SdkModificator modificator = jdk.getSdkModificator();
VirtualFile rtJar = null;
for (VirtualFile root : modificator.getRoots(OrderRootType.CLASSES)) {
if (root.getName().equals("rt.jar")) {
rtJar = root;
break;
}
}
assertNotNull("rt.jar not found in jdk: " + jdk, rtJar);
modificator.setVersionString(IdeaTestUtil.getMockJdkVersion(jdk.getHomePath()));
modificator.removeAllRoots();
modificator.addRoot(rtJar, OrderRootType.CLASSES);
modificator.commitChanges();
return jdk;
}
use of org.jetbrains.annotations.Contract in project intellij-community by JetBrains.
the class ClassSerializer method write.
@Nullable
@Contract("_, _, false -> null")
public Object write(@NotNull String name, @NotNull Object value, boolean retPrevValue) {
try {
final Field field = getPreparedField(myInstance.getClass().getField(name));
if (field != null) {
Object ret = retPrevValue ? field.get(myInstance) : null;
field.set(myInstance, value);
return ret;
}
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
Aggregations