1/*
2 * ProGuard -- shrinking, optimization, obfuscation, and preverification
3 *             of Java bytecode.
4 *
5 * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21package proguard.classfile.editor;
22
23import proguard.classfile.*;
24import proguard.classfile.attribute.visitor.InnerClassesInfoVisitor;
25import proguard.classfile.attribute.InnerClassesInfo;
26import proguard.classfile.constant.*;
27import proguard.classfile.constant.visitor.ConstantVisitor;
28import proguard.classfile.util.*;
29import proguard.classfile.visitor.*;
30
31/**
32 * This InnerClassesInfoVisitor fixes the inner class access flags of the
33 * inner classes information that it visits.
34 *
35 * @author Eric Lafortune
36 */
37public class InnerClassesAccessFixer
38extends      SimplifiedVisitor
39implements   InnerClassesInfoVisitor,
40             ConstantVisitor,
41             ClassVisitor
42{
43    private int innerClassAccessFlags;
44
45
46    // Implementations for InnerClassesInfoVisitor.
47
48    public void visitInnerClassesInfo(Clazz clazz, InnerClassesInfo innerClassesInfo)
49    {
50        // The current access flags are the default.
51        innerClassAccessFlags = innerClassesInfo.u2innerClassAccessFlags;
52
53        // See if we can find new access flags.
54        innerClassesInfo.innerClassConstantAccept(clazz, this);
55
56        // Update the access flags.
57        innerClassesInfo.u2innerClassAccessFlags = innerClassAccessFlags;
58    }
59
60
61    // Implementations for ConstantVisitor.
62
63    public void visitAnyConstant(Clazz clazz, Constant constant) {}
64
65
66    public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
67    {
68        classConstant.referencedClassAccept(this);
69    }
70
71
72    // Implementations for ClassVisitor.
73
74    public void visitLibraryClass(LibraryClass libraryClass) {}
75
76
77    public void visitProgramClass(ProgramClass programClass)
78    {
79        innerClassAccessFlags =
80            AccessUtil.replaceAccessFlags(innerClassAccessFlags,
81                                          programClass.u2accessFlags);
82    }
83}