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.pc;
18:
19: import org.objectweb.asm.Attribute;
20: import org.objectweb.asm.ClassVisitor;
21: import org.objectweb.asm.Constants;
22: import org.objectweb.speedo.generation.enhancer.common.LoggedClassAdapter;
23: import org.objectweb.speedo.lib.Personality;
24: import org.objectweb.speedo.metadata.SpeedoClass;
25: import org.objectweb.speedo.metadata.SpeedoField;
26: import org.objectweb.util.monolog.api.Logger;
27:
28: /**
29: * This visistor removes the persistent fields of a persistent class because
30: * they have been moved into the XXXFields class.
31: *
32: * @author S.Chassande-Barrioz
33: */
34: public class FieldRemover extends LoggedClassAdapter {
35:
36: /**
37: * is Speedo Meta Object representing the persistent class.
38: */
39: private final SpeedoClass clazz;
40:
41: public FieldRemover(final ClassVisitor classVisitor,
42: final SpeedoClass sClass, final Logger logger,
43: final Personality p) {
44: super (classVisitor, p, logger);
45: this .clazz = sClass;
46: }
47:
48: public void visitField(final int access, final String name,
49: final String desc, final Object value, final Attribute attrs) {
50: boolean keepfield = (access & Constants.ACC_STATIC) != 0;
51: if (!keepfield) {
52: SpeedoField sf = (SpeedoField) clazz.fields.get(name);
53: keepfield = sf == null;
54: if (!keepfield) {
55: keepfield = sf.persistenceStatus == SpeedoField.NONE;
56: }
57: }
58: if (keepfield) {
59: super.visitField(access, name, desc, value, attrs);
60: }
61: }
62: }
|