[slf4j-dev] svn commit: r865 - slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter
jncharpin at slf4j.org
jncharpin at slf4j.org
Fri Aug 17 16:03:28 CEST 2007
Author: jncharpin
Date: Fri Aug 17 16:03:28 2007
New Revision: 865
Removed:
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ReplacementWrapper.java
Modified:
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/AbstractMatcher.java
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Constant.java
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/JCLMatcher.java
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/PatternWrapper.java
Log:
Regrouping pattern matching and replacement rules in same object.
Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/AbstractMatcher.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/AbstractMatcher.java (original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/AbstractMatcher.java Fri Aug 17 16:03:28 2007
@@ -1,14 +1,14 @@
package org.slf4j.converter;
import java.util.Iterator;
-import java.util.TreeMap;
+import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class AbstractMatcher {
- protected TreeMap<PatternWrapper, ReplacementWrapper> rulesMap;
+ protected ArrayList<PatternWrapper> rules;
protected boolean commentConversion = true;
@@ -39,18 +39,16 @@
Pattern pattern;
Matcher matcher;
String replacementText;
- ReplacementWrapper replacementWrapper;
- Iterator rulesIter = rulesMap.keySet().iterator();
+ Iterator rulesIter = rules.iterator();
while (rulesIter.hasNext()) {
patternWrapper = (PatternWrapper) rulesIter.next();
pattern = patternWrapper.getPattern();
matcher = pattern.matcher(text);
if (matcher.matches()) {
System.out.println("matching " + text);
- replacementWrapper = rulesMap.get(patternWrapper);
StringBuffer replacementBuffer = new StringBuffer();
for (int group = 0; group <= matcher.groupCount(); group++) {
- replacementText = replacementWrapper.getReplacement(group);
+ replacementText = patternWrapper.getReplacement(group);
if (replacementText != null) {
System.out.println("replacing group " + group + " : "
+ matcher.group(group) + " with "
Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Constant.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Constant.java (original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Constant.java Fri Aug 17 16:03:28 2007
@@ -2,12 +2,26 @@
public class Constant {
- public final static int JCL_TO_SLF4J = 1;
-
+ public final static int JCL_TO_SLF4J = 1;
+
public final static String LINE_COMMENT = "//";
public final static String BLOCK_COMMENT_START = "/*";
public final static String BLOCK_COMMENT_END = "*/";
-
+
+ public final static Integer INDEX_0 = new Integer(0);
+
+ public final static Integer INDEX_1 = new Integer(1);
+
+ public final static Integer INDEX_2 = new Integer(2);
+
+ public final static Integer INDEX_3 = new Integer(3);
+
+ public final static Integer INDEX_4 = new Integer(4);
+
+ public final static Integer INDEX_5 = new Integer(5);
+
+ public final static int NB_FILES_MAX = 1000;
+
}
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 16:03:28 2007
@@ -1,6 +1,6 @@
package org.slf4j.converter;
-import java.util.TreeMap;
+import java.util.ArrayList;
import java.util.regex.Pattern;
@@ -12,31 +12,36 @@
}
protected void initRules() {
- PatternWrapper p0 = new PatternWrapper("0", Pattern.compile("import\\s*+org.apache.commons.logging.LogFactory;"));
- PatternWrapper p1 = new PatternWrapper("1", Pattern.compile("import\\s*+org.apache.commons.logging.Log;"));
- PatternWrapper p2 = new PatternWrapper("2",Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(Log)(\\s+\\w+\\s*+=\\s*+)(LogFactory.getFactory\\(\\).getInstance\\()(\\w+)(.class\\);)((\\w*+\\W*+\\.*)*;*+)"));
- PatternWrapper p3 = new PatternWrapper("3",Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(Log)(\\s+\\w+\\s*+=\\s*+)(LogFactory.getLog\\()(\\w+)(.class\\);)((\\w*+\\W*+\\.*)*;*+)"));
- PatternWrapper p4 = new PatternWrapper("4",Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(\\w+\\s*+=\\s*+)(LogFactory.getFactory\\(\\).getInstance\\()(\\w+)(.class\\);)((\\w*+\\W*+\\.*)*;*+)"));
- PatternWrapper p5 = new PatternWrapper("5",Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(\\w+\\s*+=\\s*+)(LogFactory.getLog\\()(\\w+)(.class\\);)((\\w*+\\W*+\\.*)*;*+)"));
- PatternWrapper p6 = new PatternWrapper("6",Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(Log)(\\s*+\\w+\\s*+;)((\\w*+\\W*+\\.*)*;*+)"));
-
- ReplacementWrapper r0 = new ReplacementWrapper("0","import org.slf4j.LoggerFactory;");
- ReplacementWrapper r1 = new ReplacementWrapper("0","import org.slf4j.Logger;");
- ReplacementWrapper r2 = new ReplacementWrapper("3", "Logger");
- r2.addReplacement("2", "");
- r2.addReplacement("5", "LoggerFactory.getLogger(");
- ReplacementWrapper r3 = new ReplacementWrapper("4","LoggerFactory.getLogger(");
- r3.addReplacement("2", "");
- ReplacementWrapper r4 = new ReplacementWrapper("3", "Logger");
- r4.addReplacement("2", "");
+ PatternWrapper p0 = new PatternWrapper(Pattern.compile("import\\s*+org.apache.commons.logging.LogFactory;"));
+ PatternWrapper p1 = new PatternWrapper(Pattern.compile("import\\s*+org.apache.commons.logging.Log;"));
+ PatternWrapper p2 = new PatternWrapper(Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(Log)(\\s+\\w+\\s*+=\\s*+)(LogFactory.getFactory\\(\\).getInstance\\()(\\w+)(.class\\);)((\\w*+\\W*+\\.*)*;*+)"));
+ PatternWrapper p3 = new PatternWrapper(Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(Log)(\\s+\\w+\\s*+=\\s*+)(LogFactory.getLog\\()(\\w+)(.class\\);)((\\w*+\\W*+\\.*)*;*+)"));
+ PatternWrapper p4 = new PatternWrapper(Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(\\w+\\s*+=\\s*+)(LogFactory.getFactory\\(\\).getInstance\\()(\\w+)(.class\\);)((\\w*+\\W*+\\.*)*;*+)"));
+ PatternWrapper p5 = new PatternWrapper(Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(\\w+\\s*+=\\s*+)(LogFactory.getLog\\()(\\w+)(.class\\);)((\\w*+\\W*+\\.*)*;*+)"));
+ PatternWrapper p6 = new PatternWrapper(Pattern.compile("((\\w*+\\W*+\\.*)*;*+)(Log)(\\s*+\\w+\\s*+;)((\\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");
+ p2.addReplacement(Constant.INDEX_2,"");
+ p2.addReplacement(Constant.INDEX_5,"LoggerFactory.getLogger(");
+ p3.addReplacement(Constant.INDEX_3,"Logger");
+ p3.addReplacement(Constant.INDEX_2,"");
+ p3.addReplacement(Constant.INDEX_5,"LoggerFactory.getLogger(");
+ p4.addReplacement(Constant.INDEX_4,"LoggerFactory.getLogger(");
+ p4.addReplacement(Constant.INDEX_2,"");
+ p5.addReplacement(Constant.INDEX_4,"LoggerFactory.getLogger(");
+ p5.addReplacement(Constant.INDEX_2,"");
+ p6.addReplacement(Constant.INDEX_3,"Logger");
+ p6.addReplacement(Constant.INDEX_2,"");
- rulesMap = new TreeMap<PatternWrapper, ReplacementWrapper>();
- rulesMap.put(p0, r0);
- rulesMap.put(p1, r1);
- rulesMap.put(p2, r2);
- rulesMap.put(p3, r2);
- rulesMap.put(p4, r3);
- rulesMap.put(p5, r3);
- rulesMap.put(p6, r4);
+ rules = new ArrayList<PatternWrapper>();
+ rules.add(p0);
+ rules.add(p1);
+ rules.add(p2);
+ rules.add(p3);
+ rules.add(p4);
+ rules.add(p5);
+ rules.add(p6);
}
}
Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/PatternWrapper.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/PatternWrapper.java (original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/PatternWrapper.java Fri Aug 17 16:03:28 2007
@@ -1,28 +1,30 @@
package org.slf4j.converter;
+import java.util.HashMap;
import java.util.regex.Pattern;
-public class PatternWrapper implements Comparable {
-
- private String index;
+public class PatternWrapper {
private Pattern pattern;
+
+ private HashMap<Integer, String> replacementMap;
- public PatternWrapper(String index, Pattern pattern) {
- this.index = index;
+ public PatternWrapper(Pattern pattern) {
this.pattern = pattern;
+ this.replacementMap = new HashMap<Integer, String>();
}
- public String getIndex() {
- return index;
- }
public Pattern getPattern() {
return pattern;
}
- public int compareTo(Object o) {
- String oIndex = ((PatternWrapper) o).index;
- return this.index.compareTo(oIndex);
+ public void addReplacement(Integer groupIndex, String replacement) {
+ replacementMap.put(groupIndex, replacement);
+ }
+
+ public String getReplacement(int groupIndex) {
+ return replacementMap.get(new Integer(groupIndex));
}
+
}
More information about the slf4j-dev
mailing list