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.Attribute;
20: import org.objectweb.asm.ClassVisitor;
21: import org.objectweb.asm.CodeVisitor;
22: import org.objectweb.speedo.lib.Personality;
23: import org.objectweb.util.monolog.api.BasicLevel;
24: import org.objectweb.util.monolog.api.Logger;
25:
26: import java.util.HashSet;
27: import java.util.Set;
28:
29: /**
30: * Is a simple visitor verifying if duplicated method are generated. When
31: * duplicated method is found a warning is logged.
32: *
33: * @author S.Chassande-Barrioz
34: */
35: public class DuplicatedMethodVerifier extends LoggedClassAdapter {
36:
37: /**
38: * Set of methods already found.
39: */
40: private Set methods = new HashSet();
41:
42: public DuplicatedMethodVerifier(ClassVisitor classVisitor,
43: Logger logger, Personality p) {
44: super (classVisitor, p, logger);
45: }
46:
47: /**
48: * Internal representation of the method declaration
49: */
50: private static class Meth {
51: public String name;
52: public String desc;
53: public int access;
54:
55: public Meth(int a, String n, String d) {
56: access = a;
57: name = n;
58: desc = d;
59: }
60:
61: public boolean equals(Object o) {
62: return (o instanceof Meth) && ((Meth) o).name.equals(name)
63: && ((Meth) o).desc.equals(desc);
64: }
65:
66: public int hashCode() {
67: return name.hashCode();
68: }
69:
70: public String toString() {
71: return access + name + desc;
72: }
73: }
74:
75: public CodeVisitor visitMethod(final int access, final String name,
76: final String desc, final String[] exceptions,
77: final Attribute attrs) {
78: Meth m = new Meth(access, name, desc);
79: if (methods.contains(m)) {
80: logger.log(BasicLevel.WARN, "Duplicate method: '" + m);
81: } else {
82: methods.add(m);
83: }
84: return cv.visitMethod(access, name, desc, exceptions, attrs);
85: }
86: }
|