Package com.google.code.regexp

Examples of com.google.code.regexp.Matcher


    private static final String VALUE_FIELD_REGEX = "private static final %s\\[\\] [$\\w\\d]+ = new %s\\[\\]\\{.*?\\};";

    public static String processFile(String fileName, String text) throws IOException
    {
        StringBuffer out = new StringBuffer();
        Matcher m = SYNTHETICS.matcher(text);
        while(m.find())
        {
            m.appendReplacement(out, synthetic_replacement(m).replace("$", "\\$"));
        }
        m.appendTail(out);
        text = out.toString();

        text = text.replaceAll(TRAILING, "");
       
        text = text.replaceAll(TRAILINGZERO, "$1$2");
View Full Code Here


                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;
                String classPath;
                if (Strings.isNullOrEmpty(qualifiedName))
                {
                    classPath = matcher.group("name");
                    newIndent = indent;
                }
                else
                {
                    classPath = qualifiedName + "." + matcher.group("name");
                    newIndent = indent+ "   ";
                }
               
                // fund an enum class, parse it seperately
                if (matcher.group("type").equals("enum"))
                    processEnum(lines, newIndent, i+1, classPath, matcher.group("name"));
               
                // nested class searching
                i = processClass(lines, newIndent, i+1, classPath, matcher.group("name"));
            }
           
            // class has finished
            if (line.startsWith(indent + "}"))
                return i;
View Full Code Here

        {
            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

        List<String> output = new ArrayList<String>(lines.length);
        MethodInfo method = null;

        for (String line : lines)
        {
            Matcher matcher = METHOD_REG.matcher(line);
            boolean found = matcher.find();
            if (!line.endsWith(";") && !line.endsWith(",") && found)// && !line.contains("=") && !NESTED_PERINTH.matcher(line).find())
            {
                method = new MethodInfo(method, matcher.group("indent"));
                method.lines.add(line);

                boolean invalid = false; // Can't think of a better way to filter out enum declarations, so make sure that all the parameters have types
                String args = matcher.group("parameters");
                if (args != null)
                {
                    for (String str : Splitter.on(',').trimResults().omitEmptyStrings().split(args))
                    {
                        if (str.indexOf(' ') == -1)
                        {
                            invalid = true;
                            break;
                        }
                        method.addVar(str);
                    }
                }

                if (invalid || METHOD_DEC_END.matcher(line).find())
                {
                    if (method.parent != null)
                    {
                        method.parent.children.remove(method);
                    }
                    method = method.parent;
                   
                    if (method == null) // dont output if there is a parent method.
                        output.add(line);
                }
            }
            else if (method != null && method.ENDING.equals(line))
            {
                method.lines.add(line);

                if (method.parent == null)
                {
                    for (String l : Splitter.on(Constants.NEWLINE).split(method.rename(null)))
                    {
                        output.add(l);
                    }
                }

                method = method.parent;
            }
            else if (method != null)
            {
                method.lines.add(line);
                matcher = CATCH_REG.matcher(line);
                if (matcher.find())
                {
                    method.addVar(matcher.group(1));
                }
                else
                {
                    matcher = VAR_CALL.matcher(line);
                    while (matcher.find())
                    {
                        String match = matcher.group();
                        if (!match.startsWith("return") && !match.startsWith("throw"))
                        {
                            method.addVar(match);
                        }
                    }
View Full Code Here

      this.source = part;
      this.position = position;
    }
   
    protected static String getGroupName(String input,String groupName,Pattern pattern){
      Matcher m = pattern.matcher(input);
      if(m.matches()){
        return m.group(groupName);
      }
      return null;
    }
View Full Code Here

  Pattern fieldOrArray = Pattern.compile("^(?<name>(\\w+))(\\[(?<arrayIndex>(0|(?!0)\\d+))\\])?$");
 
  @Test
  public void testFieldRegex(){
    String field = "field";
    Matcher m = fieldOrArray.matcher(field);
    assertTrue(m.matches());
    assertEquals(field,m.group("name"));
  }
View Full Code Here

  }
 
  @Test
  public void testFieldUnderscoreRegex(){
    String field = "_field";
    Matcher m = fieldOrArray.matcher(field);
    assertTrue(m.matches());
    assertEquals(field,m.group("name"));
  }
View Full Code Here

    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();
    } catch (IOException e) {
      throw new GrokException(e.getMessage());
View Full Code Here

  public Match match(String text) {
    if (compiledNamedRegex == null || StringUtils.isBlank(text)) {
      return Match.EMPTY;
    }

    Matcher m = compiledNamedRegex.matcher(text);
    Match match = new Match();
    if (m.find()) {
      match.setSubject(text);
      match.setGrok(this);
      match.setMatch(m);
      match.setStart(m.start(0));
      match.setEnd(m.end(0));
    }
    return match;
  }
View Full Code Here

      if (iterationLeft <= 0) {
        throw new GrokException("Deep recursion pattern compilation of " + originalGrokPattern);
      }
      iterationLeft--;

      Matcher m = GrokUtils.GROK_PATTERN.matcher(namedRegex);
      // Match %{Foo:bar} -> pattern name and subname
      // Match %{Foo=regex} -> add new regex definition
      if (m.find()) {
        continueIteration = true;
        Map<String, String> group = m.namedGroups();
        if (group.get("definition") != null) {
          try {
            addPattern(group.get("pattern"), group.get("definition"));
            group.put("name", group.get("name") + "=" + group.get("definition"));
          } catch (GrokException e) {
View Full Code Here

TOP

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

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.