01: /**
02: * Copyright (C) 2001-2005 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package org.objectweb.speedo.generation.enhancer.common;
18:
19: import org.objectweb.asm.ClassAdapter;
20: import org.objectweb.asm.ClassVisitor;
21: import org.objectweb.asm.Constants;
22: import org.objectweb.asm.Type;
23: import org.objectweb.jorm.type.api.PType;
24: import org.objectweb.jorm.util.lib.StringReplace;
25: import org.objectweb.speedo.lib.Personality;
26: import org.objectweb.util.monolog.api.BasicLevel;
27: import org.objectweb.util.monolog.api.Logger;
28:
29: /**
30: *
31: * @author S.Chassande-Barrioz
32: */
33: public class LoggedClassAdapter extends ClassAdapter implements
34: Constants {
35: protected Personality personality;
36: protected Logger logger;
37: protected boolean debug = false;
38:
39: public LoggedClassAdapter(ClassVisitor classVisitor, Personality p) {
40: super (classVisitor);
41: personality = p;
42: }
43:
44: public LoggedClassAdapter(ClassVisitor classVisitor, Personality p,
45: Logger logger) {
46: super (classVisitor);
47: personality = p;
48: this .logger = logger;
49: if (logger != null) {
50: debug = logger.isLoggable(BasicLevel.DEBUG);
51: }
52: }
53:
54: public Logger getLogger() {
55: return logger;
56: }
57:
58: public void setLogger(Logger logger) {
59: this .logger = logger;
60: }
61:
62: public final static String getJVMClassName(String className) {
63: return StringReplace.replaceChar('.', '/', className);
64: }
65:
66: public final static String getJVMClassName(java.lang.Class clazz) {
67: return getJVMClassName(clazz.getName());
68: }
69:
70: public final static String getJVMType(java.lang.Class clazz) {
71: return getJVMType(clazz.getName());
72: }
73:
74: public final static String getJVMType(String className) {
75: return "L" + getJVMClassName(className) + ";";
76: }
77:
78: public final static String getJVMType(PType pt) {
79: return Type.getType(pt.getJavaClass()).getDescriptor();
80: }
81: }
|