@NotNull
  @Override
  public Collection<PsiElement> getPsiTargets(
      @NotNull SourceContributorDeclarationHandlerParameter parameter) {
    String contents = parameter.getHandlerParameter().getContents();
    if (StringUtils.isBlank(contents)) {
      return Collections.emptyList();
    }

    String sourceParameter = parameter.getSourceParameter();
    if (sourceParameter == null) {
      return Collections.emptyList();
    }

    final Collection<PsiElement> psiElements = new ArrayList<PsiElement>();

    for (PhpClass phpClass :
        PhpIndex.getInstance(parameter.getProject()).getAllSubclasses(sourceParameter)) {
      if (StringUtils.stripStart(contents, "\\")
          .equalsIgnoreCase(StringUtils.stripStart(phpClass.getPresentableFQN(), "\\"))) {
        psiElements.add(phpClass);
      }
    }

    return psiElements;
  }
Esempio n. 2
0
  /** 2、字符串的Trim */
  @Test
  public void test2() {
    // trim
    System.out.println(StringUtils.trim(null)); // null
    System.out.println(StringUtils.trim("")); // ""
    System.out.println(StringUtils.trim("     ")); // ""
    System.out.println(StringUtils.trim("abc")); // "abc"
    System.out.println(StringUtils.trim("    abc")); // "abc"
    System.out.println(StringUtils.trim("    abc  ")); // "abc"
    System.out.println(StringUtils.trim("    ab c  ")); // "ab c"

    // strip
    System.out.println(StringUtils.strip(null)); // null
    System.out.println(StringUtils.strip("")); // ""
    System.out.println(StringUtils.strip("   ")); // ""
    System.out.println(StringUtils.strip("abc")); // "abc"
    System.out.println(StringUtils.strip("  abc")); // "abc"
    System.out.println(StringUtils.strip("abc  ")); // "abc"
    System.out.println(StringUtils.strip(" abc ")); // "abc"
    System.out.println(StringUtils.strip(" ab c ")); // "ab c"

    System.out.println(StringUtils.strip("  abcyx", "xyz")); // "  abc"

    System.out.println(StringUtils.stripStart("yxabcxyz  ", "xyz")); // "abcxyz  "
    System.out.println(StringUtils.stripEnd("  xyzabcyx", "xyz")); // "  xyzabc"
  }
Esempio n. 3
0
    Collection<String> addComments(String[] lines) {
        int prevlevel = 0;
        final int indent = 2;
        LinkedList<String> outlines = new LinkedList<String>();
        Stack<String> hierarchy = new Stack<String>();
        for (String line : lines) {
            String content = StringUtils.stripStart(line, " ");
            int spaces = line.length() - content.length(),
                    level = spaces / indent + 1;
            String[] tokens = content.split(":", 2);
            String name = tokens[0];
            if (level <= prevlevel) {
                for (int i = 0; i <= prevlevel - level; ++i) {
                    hierarchy.pop();
                }
            }
            hierarchy.push(name);
            prevlevel = level;
            String id = StringUtils.join(hierarchy, "_").replaceAll(" ", "__").replaceAll(prefix + ".", "");
            boolean modified = false;

            Comment comment = null;
            try {
                comment = getClass().getDeclaredField(id).getAnnotation(Comment.class);
            } catch (NoSuchFieldException ignored) {
            }
            if (comment != null) {
                String indentPrefix = StringUtils.repeat(" ", spaces);
                if (comment.location() == Comment.CommentLocation.TOP)
                    for (String data : comment._())
                        outlines.add(indentPrefix + "# " + data);

                if (comment.location() == Comment.CommentLocation.INLINE) {
                    String[] comments = comment._();
                    outlines.add(line + " # " + comments[0]);
                    for (int i = 1; i < comments.length; ++i)
                        outlines.add(StringUtils.repeat(" ", line.length() + 1) + "# " + comments[i]);
                } else
                    outlines.add(line);

                if (comment.location() == Comment.CommentLocation.BOTTOM)
                    for (String data : comment._())
                        outlines.add(indentPrefix + "# " + data);

                modified = true;

            }
            if (!modified)
                outlines.add(line);
        }
        return outlines;
    }
 private String getPathPrefix(File file, String subDirPrefix) throws IOException {
   String fname = file.getCanonicalPath();
   Preconditions.checkState(fname.startsWith(sourceDirectory.getCanonicalPath()));
   fname = fname.substring(sourceDirectory.getCanonicalPath().length(), fname.length());
   if (fname.contains(subDirPrefix)) {
     fname = fname.substring(0, fname.indexOf(subDirPrefix));
     fname = StringUtils.stripStart(fname, "/");
     if (StringUtils.isEmpty(fname)) {
       fname = PREFIX_TOP_LEVEL;
     }
     return fname;
   } else {
     logger.error("Could not find subDirPrefix {} in path: {}", subDirPrefix, fname);
     return PREFIX_TOP_LEVEL;
   }
 }
  private List<String> getPartitionValues(String partitionSpec) {
    // Warning - incorrect for cases where there are commas in values and
    // other corner cases.
    String[] partitionSpecSplit = partitionSpec.split(",");
    List<String> partitionValues = new ArrayList<>();

    for (String columnSpec : partitionSpecSplit) {
      columnSpec = StringUtils.stripEnd(columnSpec, " \t\n");
      columnSpec = StringUtils.stripStart(columnSpec, " \t\n");
      // columnSpec should be something of the form ds='1'
      String[] columnSpecSplit = columnSpec.split("=");
      if (columnSpecSplit.length != 2) {
        throw new RuntimeException("Unexpected column spec " + columnSpec);
      }
      String partitionColumnValue = columnSpecSplit[1].replace("'", "");
      partitionValues.add(partitionColumnValue);
    }
    return partitionValues;
  }
  /**
   * Return string array containing the paths in the view that should be used when polling for
   * changes.
   *
   * @param variableResolver TODO
   * @param build TODO
   * @param launcher TODO
   * @return string array that will be used by the lshistory command and for constructing the config
   *     spec, etc.
   * @throws InterruptedException
   * @throws IOException
   */
  public String[] getViewPaths(
      VariableResolver<String> variableResolver, AbstractBuild build, Launcher launcher)
      throws IOException, InterruptedException {
    String loadRules = getLoadRules();
    if (StringUtils.isBlank(loadRules)) {
      return null;
    }

    String[] rules = loadRules.split("[\\r\\n]+");
    for (int i = 0; i < rules.length; i++) {
      String rule = rules[i];
      // Remove "load " from the string, just in case.
      rule = StringUtils.removeStart(rule, "load ");
      // Remove "\\", "\" or "/" from the load rule. (bug#1706) Only if
      // the view is not dynamic
      // the user normally enters a load rule beginning with those chars
      rule = StringUtils.stripStart(rule, "\\/");
      rules[i] = rule;
    }
    return rules;
  }
 private String stripEndAndStart(String srcString, String stripChars) {
   srcString = StringUtils.stripEnd(srcString, stripChars);
   srcString = StringUtils.stripStart(srcString, stripChars);
   return srcString;
 }
 private String trimWhitespace(String str) {
   str = StringUtils.stripEnd(str, " \t\n");
   str = StringUtils.stripStart(str, " \t\n");
   return str;
 }