1 4 package com.puppycrawl.tools.checkstyle.bcel; 5 6 import java.util.Set ; 7 8 import com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter; 9 import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; 10 import com.puppycrawl.tools.checkstyle.api.LocalizedMessages; 11 import java.util.HashMap ; 12 import org.apache.bcel.classfile.JavaClass; 13 14 18 public abstract class AbstractCheckVisitor 20 extends AbstractViolationReporter 21 implements IObjectSetVisitor, 22 IDeepVisitor 23 { 24 25 private HashMap mMessageMap; 27 private String NO_FILE = "File not available"; 28 29 30 public org.apache.bcel.classfile.Visitor getClassFileVisitor() 31 { 32 return new EmptyClassFileVisitor(); 33 } 34 35 38 public org.apache.bcel.generic.Visitor getGenericVisitor() 39 { 40 return new EmptyGenericVisitor(); 41 } 42 43 47 public void init() 48 { 49 } 50 51 54 public void destroy() 55 { 56 } 57 58 62 public final void setMessageMap(HashMap aMessageMap) 63 { 64 mMessageMap = aMessageMap; 65 } 66 67 76 protected final void log(JavaClass javaClass, int aLine, String aKey, Object aArgs[]) 77 { 78 final String file = javaClass.getFileName(); 80 log(file, aLine, aKey, aArgs); 81 } 82 83 92 private final void log(String fileName, int aLine, String aKey, Object aArgs[]) 93 { 94 LocalizedMessages localizedMessages = (LocalizedMessages) mMessageMap.get(fileName); 95 if (localizedMessages == null) { 96 localizedMessages = new LocalizedMessages(); 97 mMessageMap.put(fileName, localizedMessages); 98 } 99 localizedMessages.add( 100 new LocalizedMessage( 101 aLine, 102 getMessageBundle(), 103 aKey, 104 aArgs, 105 getSeverityLevel(), 106 this.getClass())); 107 } 108 109 118 protected final void log(int aLine, String aKey, Object aArgs[]) 119 { 120 log(NO_FILE, aLine, aKey, aArgs); 121 } 122 123 126 protected void log(int aLine, int aCol, String aKey, Object [] aArgs) 127 { 128 log(aLine, aKey, aArgs); 130 } 131 132 133 public void visitObject(Object aObject) 134 { 135 } 136 137 138 public void leaveObject(Object aObject) 139 { 140 } 141 142 143 public void visitSet(Set aJavaClassDefs) 144 { 145 } 146 147 148 public void leaveSet(Set aJavaClassDefs) 149 { 150 } 151 152 156 public abstract IDeepVisitor getVisitor(); 157 } 158 | Popular Tags |