Java 类com.intellij.util.PatternUtil 实例源码

项目:intellij-ce-playground    文件:PatternPackageReferenceSet.java   
@Override
public Collection<PsiPackage> resolvePackageName(@Nullable final PsiPackage context, final String packageName) {
  if (context == null) return Collections.emptySet();

  if (packageName.contains("*")) {
    final Set<PsiPackage> packages = new LinkedHashSet<PsiPackage>();
    int indexOf = packageName.indexOf("*");
    if (indexOf == 0 || context.getQualifiedName().startsWith(packageName.substring(0, indexOf))) {
        final Pattern pattern = PatternUtil.fromMask(packageName);
        processSubPackages(context, new Processor<PsiPackage>() {
          @Override
          public boolean process(PsiPackage psiPackage) {
            String name = psiPackage.getName();
            if (name != null && pattern.matcher(name).matches()) {
              packages.add(psiPackage);
            }
            return true;
          }
        });
      }

    return packages;
  }

  return super.resolvePackageName(context, packageName);
}
项目:intellij-ce-playground    文件:FindInProjectUtil.java   
@Nullable
public static Pattern createFileMaskRegExp(@Nullable String filter) {
  if (filter == null) {
    return null;
  }
  String pattern;
  final List<String> strings = StringUtil.split(filter, ",");
  if (strings.size() == 1) {
    pattern = PatternUtil.convertToRegex(filter.trim());
  }
  else {
    pattern = StringUtil.join(strings, new Function<String, String>() {
      @NotNull
      @Override
      public String fun(@NotNull String s) {
        return "(" + PatternUtil.convertToRegex(s.trim()) + ")";
      }
    }, "|");
  }
  return Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
}
项目:intellij-ce-playground    文件:PyPySdkFlavor.java   
@Nullable
@Override
public String getVersionStringFromOutput(@NotNull String output) {
  final List<String> lines = Arrays.asList(StringUtil.splitByLines(output));
  final String version = PatternUtil.getFirstMatch(lines, VERSION_RE);
  final String pythonVersion = PatternUtil.getFirstMatch(lines, PYTHON_VERSION_RE);
  if (version != null) {
    final StringBuilder builder = new StringBuilder();
    builder.append(version);
    if (pythonVersion != null) {
      builder.append(" [");
      builder.append(pythonVersion);
      builder.append("]");
    }
    return builder.toString();
  }
  return null;
}
项目:tools-idea    文件:PatternPackageReferenceSet.java   
@Override
public Collection<PsiPackage> resolvePackageName(@Nullable final PsiPackage context, final String packageName) {
  if (context == null) return Collections.emptySet();

  if (packageName.contains("*")) {
    final Pattern pattern = PatternUtil.fromMask(packageName);
    final Set<PsiPackage> packages = new HashSet<PsiPackage>();

    processSubPackages(context, new Processor<PsiPackage>() {
      @Override
      public boolean process(PsiPackage psiPackage) {
        String name = psiPackage.getName();
        if (name != null && pattern.matcher(name).matches()) {
          packages.add(psiPackage);
        }
        return true;
      }
    });

    return packages;
  }
  else {
    return super.resolvePackageName(context, packageName);
  }
}
项目:tools-idea    文件:FindInProjectUtil.java   
@Nullable
public static Pattern createFileMaskRegExp(@Nullable String filter) {
  if (filter == null) {
    return null;
  }
  String pattern;
  final List<String> strings = StringUtil.split(filter, ",");
  if (strings.size() == 1) {
    pattern = PatternUtil.convertToRegex(filter.trim());
  }
  else {
    pattern = StringUtil.join(strings, new Function<String, String>() {
      @NotNull
      @Override
      public String fun(@NotNull String s) {
        return "(" + PatternUtil.convertToRegex(s.trim()) + ")";
      }
    }, "|");
  }
  return Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
}
项目:consulo    文件:FindInProjectUtil.java   
/**
 * @deprecated to be removed in IDEA 16
 */
@Nullable
public static Pattern createFileMaskRegExp(@Nullable String filter) {
  if (filter == null) {
    return null;
  }
  String pattern;
  final List<String> strings = StringUtil.split(filter, ",");
  if (strings.size() == 1) {
    pattern = PatternUtil.convertToRegex(filter.trim());
  }
  else {
    pattern = StringUtil.join(strings, s -> "(" + PatternUtil.convertToRegex(s.trim()) + ")", "|");
  }
  return Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
}
项目:consulo-java    文件:PatternPackageReferenceSet.java   
@Override
public Collection<PsiJavaPackage> resolvePackageName(@Nullable final PsiJavaPackage context, final String packageName) {
  if (context == null) return Collections.emptySet();

  if (packageName.contains("*")) {
    final Pattern pattern = PatternUtil.fromMask(packageName);
    final Set<PsiJavaPackage> packages = new HashSet<PsiJavaPackage>();

    processSubPackages(context, new Processor<PsiJavaPackage>() {
      @Override
      public boolean process(PsiJavaPackage psiPackage) {
        String name = psiPackage.getName();
        if (name != null && pattern.matcher(name).matches()) {
          packages.add(psiPackage);
        }
        return true;
      }
    });

    return packages;
  }
  else {
    return super.resolvePackageName(context, packageName);
  }
}
项目:consulo-java    文件:WildcardMethodBreakpoint.java   
private boolean matchesMethod(Method method)
{
    StringBuilder sb = new StringBuilder();
    for(String mask : StringUtil.split(getMethodName(), ","))
    {
        if(sb.length() > 0)
        {
            sb.append('|');
        }
        sb.append('(').append(PatternUtil.convertToRegex(mask)).append(')');
    }

    try
    {
        return method != null && Pattern.compile(sb.toString()).matcher(method.name()).matches();
    }
    catch(PatternSyntaxException e)
    {
        LOG.warn(e);
        return false;
    }
}
项目:intellij-ce-playground    文件:FileTypesTest.java   
public void testMaskToPattern() {
  for (char i = 0; i < 256; i++) {
    if (i == '?' || i == '*') continue;
    String str = "x" + i + "y";
    assertTrue("char: " + i + "(" + (int)i + ")", PatternUtil.fromMask(str).matcher(str).matches());
  }
  String allSymbols = "+.\\*/^?$[]()";
  assertTrue(PatternUtil.fromMask(allSymbols).matcher(allSymbols).matches());
  Pattern pattern = PatternUtil.fromMask("?\\?/*");
  assertTrue(pattern.matcher("a\\b/xyz").matches());
  assertFalse(pattern.matcher("x/a\\b").matches());
}
项目:intellij-ce-playground    文件:FindModel.java   
/**
 * Sets the string to find.
 *
 * @param s the string to find.
 */
public void setStringToFind(@NotNull String s) {
  boolean changed = !StringUtil.equals(s, myStringToFind);
  myStringToFind = s;
  myPattern = PatternUtil.NOTHING;
  if (changed) {
    notifyObservers();
  }
}
项目:intellij-ce-playground    文件:FindModel.java   
/**
 * Sets the Case Sensitive flag.
 *
 * @param val the value of the Case Sensitive flag.
 */
public void setCaseSensitive(boolean val) {
  boolean changed = val != isCaseSensitive;
  isCaseSensitive = val;
  if (changed) {
    myPattern = PatternUtil.NOTHING;
    notifyObservers();
  }
}
项目:intellij-ce-playground    文件:FindModel.java   
public Pattern compileRegExp() {
  String toFind = getStringToFind();

  Pattern pattern = myPattern;
  if (pattern == PatternUtil.NOTHING) {
    try {
      myPattern = pattern = Pattern.compile(toFind, isCaseSensitive() ? Pattern.MULTILINE : Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
    }
    catch (PatternSyntaxException e) {
      myPattern = pattern = null;
    }
  }

  return pattern;
}
项目:intellij-ce-playground    文件:IgnoredFileBean.java   
IgnoredFileBean(String mask) {
  myType = IgnoreSettingsType.MASK;
  myMask = mask;
  if (mask == null) {
    myMatcher = null;
  }
  else {
    myMatcher = PatternUtil.fromMask(mask).matcher("");
  }
  myPath = null;
  myFilenameIfFile = null;
  myProject = null;
}
项目:intellij-ce-playground    文件:Strings.java   
public static String translateMasks(final Collection<String> masks) {
  final StringBuilder patterns = new StringBuilder();
  for (String mask : masks) {
    if (patterns.length() != 0) {
      patterns.append('|');
    }
    patterns.append(PatternUtil.convertToRegex(mask));
  }
  return patterns.toString();
}
项目:intellij-ce-playground    文件:CvsMessagePattern.java   
private static String createRegex(@NonNls String[] groups) {
  final StringBuilder result = new StringBuilder();
  for (String group : groups) {
    result.append("(");
    result.append(PatternUtil.convertToRegex(group));
    result.append(")");
  }
  return result.toString();
}
项目:tools-idea    文件:IgnoredFileBean.java   
IgnoredFileBean(String mask) {
  myType = IgnoreSettingsType.MASK;
  myMask = mask;
  if (mask == null) {
    myMatcher = null;
  }
  else {
    myMatcher = PatternUtil.fromMask(mask).matcher("");
  }
  myPath = null;
  myFilenameIfFile = null;
  myProject = null;
}
项目:tools-idea    文件:CvsMessagePattern.java   
private static String createRegex(@NonNls String[] groups) {
  final StringBuilder result = new StringBuilder();
  for (String group : groups) {
    result.append("(");
    result.append(PatternUtil.convertToRegex(group));
    result.append(")");
  }
  return result.toString();
}
项目:consulo    文件:FindModel.java   
/**
 * Sets the string to find.
 *
 * @param s the string to find.
 */
public void setStringToFind(@Nonnull String s) {
  boolean changed = !StringUtil.equals(s, myStringToFind);
  myStringToFind = s;
  myPattern = PatternUtil.NOTHING;
  if (changed) {
    notifyObservers();
  }
}
项目:consulo    文件:FindModel.java   
/**
 * Sets the Case Sensitive flag.
 *
 * @param val the value of the Case Sensitive flag.
 */
public void setCaseSensitive(boolean val) {
  boolean changed = val != isCaseSensitive;
  isCaseSensitive = val;
  if (changed) {
    myPattern = PatternUtil.NOTHING;
    notifyObservers();
  }
}
项目:consulo    文件:FindModel.java   
public Pattern compileRegExp() {
  String toFind = getStringToFind();

  Pattern pattern = myPattern;
  if (pattern == PatternUtil.NOTHING) {
    try {
      myPattern = pattern = Pattern.compile(toFind, isCaseSensitive() ? Pattern.MULTILINE : Pattern.MULTILINE | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
    }
    catch (PatternSyntaxException e) {
      myPattern = pattern = null;
    }
  }

  return pattern;
}
项目:consulo    文件:IgnoredFileBean.java   
IgnoredFileBean(String mask) {
  myType = IgnoreSettingsType.MASK;
  myMask = mask;
  if (mask == null) {
    myMatcher = null;
  }
  else {
    myMatcher = PatternUtil.fromMask(mask).matcher("");
  }
  myPath = null;
  myFilenameIfFile = null;
  myProject = null;
}
项目:consulo    文件:FindInProjectUtil.java   
@Nonnull
public static Condition<CharSequence> createFileMaskCondition(@Nullable String filter) throws PatternSyntaxException {
  if (filter == null) {
    return Conditions.alwaysTrue();
  }

  String pattern = "";
  String negativePattern = "";
  final List<String> masks = StringUtil.split(filter, ",");

  for (String mask : masks) {
    mask = mask.trim();
    if (StringUtil.startsWith(mask, "!")) {
      negativePattern += (negativePattern.isEmpty() ? "" : "|") + "(" + PatternUtil.convertToRegex(mask.substring(1)) + ")";
    }
    else {
      pattern += (pattern.isEmpty() ? "" : "|") + "(" + PatternUtil.convertToRegex(mask) + ")";
    }
  }

  if (pattern.isEmpty()) pattern = PatternUtil.convertToRegex("*");
  final String finalPattern = pattern;
  final String finalNegativePattern = negativePattern;

  return new Condition<CharSequence>() {
    final Pattern regExp = Pattern.compile(finalPattern, Pattern.CASE_INSENSITIVE);
    final Pattern negativeRegExp = StringUtil.isEmpty(finalNegativePattern) ? null : Pattern.compile(finalNegativePattern, Pattern.CASE_INSENSITIVE);

    @Override
    public boolean value(CharSequence input) {
      return regExp.matcher(input).matches() && (negativeRegExp == null || !negativeRegExp.matcher(input).matches());
    }
  };
}
项目:intellij-ce-playground    文件:WildcardFileNameMatcher.java   
private RegexpMatcher(String pattern) {
  myMatcher = PatternUtil.fromMask(pattern).matcher("");
}
项目:intellij-ce-playground    文件:DirDiffSettings.java   
public void setFilter(String filter) {
  this.filter = filter;
  filterPattern = PatternUtil.fromMask(StringUtil.isEmpty(filter) ? "*" : filter);
}
项目:intellij-ce-playground    文件:IronPythonSdkFlavor.java   
@Nullable
@Override
public String getVersionStringFromOutput(@NotNull String output) {
  final String match = PatternUtil.getFirstMatch(Arrays.asList(StringUtil.splitByLines(output)), VERSION_RE);
  return match != null ? getName() + " " + match : null;
}
项目:intellij-ce-playground    文件:PythonSdkFlavor.java   
@Nullable
public String getVersionStringFromOutput(@NotNull String output) {
  return PatternUtil.getFirstMatch(Arrays.asList(StringUtil.splitByLines(output)), VERSION_RE);
}
项目:intellij-ce-playground    文件:JythonSdkFlavor.java   
@Nullable
@Override
public String getVersionStringFromOutput(@NotNull String output) {
  return PatternUtil.getFirstMatch(Arrays.asList(StringUtil.splitByLines(output)), VERSION_RE);
}
项目:tools-idea    文件:WildcardFileNameMatcher.java   
private RegexpMatcher(String pattern) {
  myMatcher = PatternUtil.fromMask(pattern).matcher("");
}
项目:tools-idea    文件:DirDiffSettings.java   
public void setFilter(String filter) {
  this.filter = filter;
  filterPattern = PatternUtil.fromMask(StringUtil.isEmpty(filter) ? "*" : filter);
}
项目:consulo    文件:DirDiffSettings.java   
public void setFilter(String filter) {
  this.filter = filter;
  filterPattern = PatternUtil.fromMask(StringUtil.isEmpty(filter) ? "*" : filter);
}
项目:consulo    文件:WildcardFileNameMatcher.java   
private RegexpMatcher(String pattern) {
  myMatcher = PatternUtil.fromMask(pattern).matcher("");
}
项目:consulo-java    文件:JavaProjectCodeInsightSettings.java   
@Nullable
@Override
protected Pattern create(String key)
{
    return PatternUtil.fromMask(key);
}