2
* ProGuard -- shrinking, optimization, obfuscation, and preverification
5
* Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
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)
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
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
21
package proguard.optimize.peephole;
23
import proguard.classfile.*;
24
import proguard.classfile.util.*;
25
import proguard.classfile.visitor.*;
26
import proguard.optimize.KeepMarker;
29
* This <code>MemberVisitor</code> makes the program methods that it visits
32
* @author Eric Lafortune
34
public class MethodFinalizer
35
extends SimplifiedVisitor
36
implements MemberVisitor
38
private final MemberVisitor extraMemberVisitor;
40
private final MemberFinder memberFinder = new MemberFinder();
44
* Creates a new ClassFinalizer.
46
public MethodFinalizer()
53
* Creates a new ClassFinalizer.
54
* @param extraMemberVisitor an optional extra visitor for all finalized
57
public MethodFinalizer(MemberVisitor extraMemberVisitor)
59
this.extraMemberVisitor = extraMemberVisitor;
63
// Implementations for MemberVisitor.
65
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
67
String name = programMethod.getName(programClass);
69
// If the method is not already private/static/final/abstract,
70
// and it is not a constructor,
71
// and its class is final,
72
// or it is not being kept and it is not overridden,
73
// then make it final.
74
if ((programMethod.u2accessFlags & (ClassConstants.INTERNAL_ACC_PRIVATE |
75
ClassConstants.INTERNAL_ACC_STATIC |
76
ClassConstants.INTERNAL_ACC_FINAL |
77
ClassConstants.INTERNAL_ACC_ABSTRACT)) == 0 &&
78
!name.equals(ClassConstants.INTERNAL_METHOD_NAME_INIT) &&
79
((programClass.u2accessFlags & ClassConstants.INTERNAL_ACC_FINAL) != 0 ||
80
(!KeepMarker.isKept(programMethod) &&
81
(programClass.subClasses == null ||
82
!memberFinder.isOverriden(programClass, programMethod)))))
84
programMethod.u2accessFlags |= ClassConstants.INTERNAL_ACC_FINAL;
86
// Visit the method, if required.
87
if (extraMemberVisitor != null)
89
extraMemberVisitor.visitProgramMethod(programClass, programMethod);
b'\\ No newline at end of file'