Search in sources :

Example 71 with Contract

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();
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) NotNull(org.jetbrains.annotations.NotNull) Contract(org.jetbrains.annotations.Contract)

Example 72 with Contract

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;
}
Also used : Matcher(java.util.regex.Matcher) NotNull(org.jetbrains.annotations.NotNull) Contract(org.jetbrains.annotations.Contract)

Example 73 with Contract

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;
}
Also used : PatternMatcher(org.apache.oro.text.regex.PatternMatcher) Matcher(java.util.regex.Matcher) Contract(org.jetbrains.annotations.Contract)

Example 74 with Contract

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) NotNull(org.jetbrains.annotations.NotNull) Contract(org.jetbrains.annotations.Contract)

Example 75 with Contract

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;
}
Also used : Field(java.lang.reflect.Field) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Contract (org.jetbrains.annotations.Contract)111 NotNull (org.jetbrains.annotations.NotNull)48 Nullable (org.jetbrains.annotations.Nullable)40 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)29 PsiElement (com.intellij.psi.PsiElement)19 Call (org.elixir_lang.psi.call.Call)17 ASTNode (com.intellij.lang.ASTNode)14 CallDefinitionClause.enclosingModularMacroCall (org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall)9 PsiFile (com.intellij.psi.PsiFile)6 IElementType (com.intellij.psi.tree.IElementType)6 BigInteger (java.math.BigInteger)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Quotable (org.elixir_lang.psi.Quotable)5 Project (com.intellij.openapi.project.Project)4 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)3 Matcher (java.util.regex.Matcher)3 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)2 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)2 TextRange (com.intellij.openapi.util.TextRange)2 File (java.io.File)2