Package com.google.code.regexp

Examples of com.google.code.regexp.Pattern


        return text;
    }
   
    private static int processClass(List<String> lines, String indent, int startIndex, String qualifiedName, String simpleName)
    {
        Pattern classPattern = Pattern.compile(indent + CLASS_REGEX);
       
        for (int i = startIndex; i < lines.size(); i++)
        {
            String line = lines.get(i);
           
            // who knows.....
            if (Strings.isNullOrEmpty(line))
                continue;
            // ignore packages and imports
            else if (line.startsWith("package") || line.startsWith("import"))
                continue;
           
            Matcher matcher = classPattern.matcher(line);
           
            // found a class!
            if (matcher.find())
            {
                String newIndent;
View Full Code Here


    }
   
    private static void processEnum(List<String> lines, String indent, int startIndex, String qualifiedName, String simpleName)
    {
        String newIndent = indent + "   ";
        Pattern enumEntry = Pattern.compile(newIndent + ENUM_ENTRY_REGEX);
        Pattern constructor = Pattern.compile(newIndent + String.format(CONSTRUCTOR_REGEX, simpleName));
        Pattern constructorCall = Pattern.compile(newIndent + "   " + CONSTRUCTOR_CALL_REGEX);
        String formatted = newIndent + String.format(VALUE_FIELD_REGEX, qualifiedName, qualifiedName);
        Pattern valueField = Pattern.compile(formatted);
        String newLine;
        boolean prevSynthetic = false;
       
        for (int i = startIndex; i < lines.size(); i++)
        {
            newLine = null;
            String line = lines.get(i);
           
            // find and replace enum entries
            Matcher matcher = enumEntry.matcher(line);
            if (matcher.find())
            {
                String body = matcher.group("body");
               
                newLine = newIndent + matcher.group("name");
               
                if (!Strings.isNullOrEmpty(body))
                {
                    String[] args = body.split(", ");

                    if (line.endsWith("{"))
                    {
                        if (args[args.length - 1].equals("null"))
                        {
                            args = Arrays.copyOf(args, args.length - 1);
                        }
                    }
                    body = Joiner.on(", ").join(args);
                }
               
                if (Strings.isNullOrEmpty(body))
                    newLine += matcher.group("end");
                else
                    newLine += "(" + body + ")" + matcher.group("end");
            }
           
            // find and replace constructor
            matcher = constructor.matcher(line);
            if (matcher.find())
            {
                StringBuilder tmp = new StringBuilder();
                tmp.append(newIndent).append(matcher.group("modifiers")).append(simpleName).append("(");
               
                String[] args = matcher.group("parameters").split(", ");
                for(int x = 2; x < args.length; x++)
                    tmp.append(args[x]).append(x < args.length - 1 ? ", " : "");
                tmp.append(")");
               
                tmp.append(matcher.group("end"));
                newLine = tmp.toString();
               
                if (args.length <= 2 && newLine.endsWith("}"))
                    newLine = "";
            }
           
            // find constructor calls...
            matcher = constructorCall.matcher(line);
            if (matcher.find())
            {
                String body = matcher.group("body");
               
                if (!Strings.isNullOrEmpty(body))
                {
                    String[] args = body.split(", ");
                    args = Arrays.copyOfRange(args, 2, args.length);
                    body = Joiner.on(", ").join(args);
                }
               
                newLine = newIndent + "   " + matcher.group("name") + "(" + body + ")" + matcher.group("end");
            }
           
            if (prevSynthetic)
            {
                matcher = valueField.matcher(line);
                if (matcher.find())
                    newLine = "";
            }
           
            if (line.contains("// $FF: synthetic field"))
View Full Code Here

   */
  public void addPatternFromReader(Reader r) throws GrokException {
    BufferedReader br = new BufferedReader(r);
    String line;
    // We dont want \n and commented line
    Pattern pattern = Pattern.compile("^([A-z0-9_]+)\\s+(.*)$");
    try {
      while ((line = br.readLine()) != null) {
        Matcher m = pattern.matcher(line);
        if (m.matches()) {
          this.addPattern(m.group(1), m.group(2));
        }
      }
      br.close();
View Full Code Here

      }
      // get the part of the matched text
      String part = getPart(m, text);

      // we skip boundary word
      Pattern pattern = Pattern.compile(".\\b.");
      Matcher ma = pattern.matcher(part);
      if (!ma.find()) {
        continue;
      }

      // We skip the part that already include %{Foo}
      Pattern pattern2 = Pattern.compile("%\\{[^}+]\\}");
      Matcher ma2 = pattern2.matcher(part);

      if (ma2.find()) {
        continue;
      }
      texte = StringUtils.replace(texte, part, "%{" + key + "}");
View Full Code Here

TOP

Related Classes of com.google.code.regexp.Pattern

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.