Author: jncharpin
Date: Fri Aug 17 17:01:04 2007
New Revision: 866

Modified:
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/JCLMatcher.java
   
slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/JCLMatcherTest.java

Log:
adding rules

Modified: 
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/JCLMatcher.java
==============================================================================
--- 
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/JCLMatcher.java   
    (original)
+++ 
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/JCLMatcher.java   
    Fri Aug 17 17:01:04 2007
@@ -12,14 +12,27 @@
        }
 
        protected void initRules() {
+               //matching : import org.apache.commons.logging.LogFactory; 
                PatternWrapper p0 = new 
PatternWrapper(Pattern.compile("import\\s*+org.apache.commons.logging.LogFactory;"));
+               //matching : import org.apache.commons.logging.Log; 
                PatternWrapper p1 = new 
PatternWrapper(Pattern.compile("import\\s*+org.apache.commons.logging.Log;"));
+               //matching declaration and instanciation : protected Log myLog 
= LogFactory.getFactory().getInstance(MyClass.class); //comment or other 
instruction 
                PatternWrapper p2 = new 
PatternWrapper(Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(Log)(\\s+\\w+\\s*+=\\s*+)(LogFactory.getFactory\\(\\).getInstance\\()(\\w+)(.class\\);)((\\w*+\\W*+\\.*)*;*+)"));
+               //matching declaration and instanciation : protected static Log 
myLog = LogFactory.getLog(MyClass.class); //comment or other instruction 
                PatternWrapper p3 = new 
PatternWrapper(Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(Log)(\\s+\\w+\\s*+=\\s*+)(LogFactory.getLog\\()(\\w+)(.class\\);)((\\w*+\\W*+\\.*)*;*+)"));
+               //matching instanciation without declaration :  myLog = 
LogFactory.getFactory().getInstance(MyClass.class); //comment or other 
instruction 
                PatternWrapper p4 = new 
PatternWrapper(Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(\\w+\\s*+=\\s*+)(LogFactory.getFactory\\(\\).getInstance\\()(\\w+)(.class\\);)((\\w*+\\W*+\\.*)*;*+)"));
+               //matching instanciation without declaration :  myLog = 
LogFactory.getLog(MyClass.class); //comment or other instruction 
                PatternWrapper p5 = new 
PatternWrapper(Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(\\w+\\s*+=\\s*+)(LogFactory.getLog\\()(\\w+)(.class\\);)((\\w*+\\W*+\\.*)*;*+)"));
+               //matching declaration without instanciation : public static 
final Log myLog //comment or other instruction
                PatternWrapper p6 = new 
PatternWrapper(Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(Log)(\\s*+\\w+\\s*+;)((\\w*+\\W*+\\.*)*;*+)"));
-
+               //matching incomplete instanciation : protected Log log =
+               PatternWrapper p7 = new 
PatternWrapper(Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(Log)(\\s+\\w+\\s*+=*\\s*+)"));
+               //matching incomlete instanciation : 
LogFactory.getLog(MyComponent.class);
+               PatternWrapper p8 = new 
PatternWrapper(Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(LogFactory.getLog\\()(\\w+)(.class\\);)((\\w*+\\W*+\\.*)*;*+)"));
+               //matching incomlete instanciation : 
LogFactory.getFactory().getInstance(MyComponent.class);
+               PatternWrapper p9 = new 
PatternWrapper(Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(LogFactory.getFactory\\(\\).getInstance\\()(\\w+)(.class\\);)((\\w*+\\W*+\\.*)*;*+)"));
+               
                p0.addReplacement(Constant.INDEX_0,"import 
org.slf4j.LoggerFactory;");
                p1.addReplacement(Constant.INDEX_0,"import org.slf4j.Logger;");
                p2.addReplacement(Constant.INDEX_3,"Logger");
@@ -34,6 +47,13 @@
                p5.addReplacement(Constant.INDEX_2,"");
                p6.addReplacement(Constant.INDEX_3,"Logger");
                p6.addReplacement(Constant.INDEX_2,"");
+               p7.addReplacement(Constant.INDEX_3, "Logger");
+               p7.addReplacement(Constant.INDEX_2, "");
+               p8.addReplacement(Constant.INDEX_3, "LoggerFactory.getLogger(");
+               p8.addReplacement(Constant.INDEX_1, "");
+               p9.addReplacement(Constant.INDEX_3, "LoggerFactory.getLogger(");
+               p9.addReplacement(Constant.INDEX_1, "");
+               
                
                rules = new ArrayList<PatternWrapper>();
                rules.add(p0);
@@ -43,5 +63,8 @@
                rules.add(p4);
                rules.add(p5);
                rules.add(p6);
+               rules.add(p7);
+               rules.add(p8);
+               rules.add(p9);
        }
 }

Modified: 
slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/JCLMatcherTest.java
==============================================================================
--- 
slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/JCLMatcherTest.java
   (original)
+++ 
slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/JCLMatcherTest.java
   Fri Aug 17 17:01:04 2007
@@ -23,8 +23,8 @@
                assertEquals(jclMatcher.replace("Log mylog4 = 
LogFactory.getFactory().getInstance(MyClass.class);//logger 
instanciation"),"Logger mylog4 = 
LoggerFactory.getLogger(MyClass.class);//logger instanciation");
                assertEquals(jclMatcher.replace("Log myLog6;//logger 
declaration"),"Logger myLog6;//logger declaration");
                
assertEquals(jclMatcher.replace("//log7=LogFactory.getFactory().getInstance(MyClass.class);"),"//log7=LoggerFactory.getLogger(MyClass.class);");
-               assertEquals(jclMatcher.replace("log8 
=LogFactory.getFactory().getInstance(MyClass.class);"),"log8 
=LoggerFactory.getLogger(MyClass.class);");
-               assertEquals(jclMatcher.replace("myLog9 = 
LogFactory.getLog(MyClass.class);"),"myLog9 = 
LoggerFactory.getLogger(MyClass.class);");
+               assertEquals(jclMatcher.replace(" log8 
=LogFactory.getFactory().getInstance(MyClass.class);")," log8 
=LoggerFactory.getLogger(MyClass.class);");
+               assertEquals(jclMatcher.replace(" myLog9 = 
LogFactory.getLog(MyClass.class);")," myLog9 = 
LoggerFactory.getLogger(MyClass.class);");
                assertEquals(jclMatcher.replace("private Log 
mylog10;"),"private Logger mylog10;");
                assertEquals(jclMatcher.replace("protected final Log 
myLog11;"),"protected final Logger myLog11;");
                assertEquals(jclMatcher.replace("public static final Log 
myLog12;"),"public static final Logger myLog12;");
@@ -32,6 +32,10 @@
                assertEquals(jclMatcher.replace("public static final Log 
myLog14;System.out.println(\"Log\");"),"public static final Logger 
myLog14;System.out.println(\"Log\");");
                
assertEquals(jclMatcher.replace("System.out.println(\"\");public static final 
Log myLog15;System.out.println(\"Log\")  
;System.out.println(\"Log2\");"),"System.out.println(\"\");public static final 
Logger myLog15;System.out.println(\"Log\")  ;System.out.println(\"Log2\");");
                
assertEquals(jclMatcher.replace("((Pojo)pojo.getPojo()).get(\"pojo\",pojo);public
 static final Log myLog16;"),"((Pojo)pojo.getPojo()).get(\"pojo\",pojo);public 
static final Logger myLog16;");
+               assertEquals(jclMatcher.replace("protected Log log ="), 
"protected Logger log =");
+               assertEquals(jclMatcher.replace("           
LogFactory.getLog(MyComponent.class);"), "      
LoggerFactory.getLogger(MyComponent.class);");
+               assertEquals(jclMatcher.replace("protected Log log "), 
"protected Logger log ");
+               assertEquals(jclMatcher.replace(" =         
LogFactory.getFactory().getInstance(MyComponent.class);"), " =          
LoggerFactory.getLogger(MyComponent.class);");
        }
        
 
_______________________________________________
dev mailing list
[email protected]
http://www.slf4j.org/mailman/listinfo/dev

Reply via email to