package com.asakusafw.lang.compiler.cli;

import java.util.regex.Pattern;

import com.asakusafw.lang.compiler.common.Predicate;

/**
 * Predicate of class names.
 */
public class ClassNamePredicate implements Predicate<Class<?>> {

    private final Pattern pattern;

    /**
     * Creates a new instance.
     * @param pattern the regex pattern
     */
    public ClassNamePredicate(Pattern pattern) {
        this.pattern = pattern;
    }

    /**
     * Creates a new instance.
     * @param pattern the class name pattern ({@code "*"} as a wildcard)
     * @return the created instance
     */
    public static ClassNamePredicate parse(String pattern) {
        Pattern regex = toRegex(pattern);
        return new ClassNamePredicate(regex);
    }

    private static Pattern toRegex(String pattern) {
        StringBuilder buf = new StringBuilder();
        int start = 0;
        while (true) {
            int next = pattern.indexOf('*', start);
            if (next < 0) {
                break;
            }
            buf.append(Pattern.quote(pattern.substring(start, next)));
            buf.append(".*"); //$NON-NLS-1$
            start = next + 1;
        }
        if (start < pattern.length()) {
            buf.append(Pattern.quote(pattern.substring(start)));
        }
        return Pattern.compile(buf.toString());
    }

    @Override
    public boolean apply(Class<?> argument) {
        String name = argument.getName();
        return pattern.matcher(name).matches();
    }
}

@@ -68,16 +68,74 @@
 ttern;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A
 import c
@@ -179,16 +179,16 @@
 dicate;%0A
-
 %0A/**%0A * 
@@ -283,16 +283,98 @@
 %3C?%3E%3E %7B%0A%0A
+    static final Logger LOG = LoggerFactory.getLogger(ClassNamePredicate.class);%0A%0A
     priv
@@ -1145,32 +1145,68 @@
 ;%0A            %7D%0A
+            if (start %3C next) %7B%0A    
             buf.
@@ -1256,24 +1256,38 @@
 t, next)));%0A
+            %7D%0A
             
@@ -1638,22 +1638,31 @@
         
-return
+boolean match =
  pattern
@@ -1683,20 +1683,259 @@
 .matches();%0A
+        if (LOG.isDebugEnabled()) %7B%0A            LOG.debug(%22match(%7B%7D, /%7B%7D/): %7B%7D%22, new Object%5B%5D %7B //$NON-NLS-1$%0A                    name,%0A                    pattern,%0A                    match%0A            %7D);%0A        %7D%0A        return match;%0A
     %7D%0A%7D%0A

Revise debug logs.