~ubuntu-branches/ubuntu/gutsy/proguard/gutsy

« back to all changes in this revision

Viewing changes to src/proguard/classfile/util/ClassFileReferenceInitializer.java

  • Committer: Bazaar Package Importer
  • Author(s): Sam Clegg
  • Date: 2007-01-13 12:27:45 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070113122745-9nq3v1qcdr02o8xd
Tags: 3.7-1
* New upstream release
* debian/control: make Arch: all (Closes: #360115)
* use "$@" rather then $* in shell startup scripts (Closes: #364962)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: ClassFileReferenceInitializer.java,v 1.31 2005/06/25 22:07:51 eric Exp $
 
1
/* $Id: ClassFileReferenceInitializer.java,v 1.31.2.4 2006/11/25 16:56:11 eric Exp $
2
2
 *
3
3
 * ProGuard -- shrinking, optimization, and obfuscation of Java class files.
4
4
 *
5
 
 * Copyright (c) 2002-2005 Eric Lafortune (eric@graphics.cornell.edu)
 
5
 * Copyright (c) 2002-2006 Eric Lafortune (eric@graphics.cornell.edu)
6
6
 *
7
7
 * This program is free software; you can redistribute it and/or modify it
8
8
 * under the terms of the GNU General Public License as published by the Free
25
25
import proguard.classfile.attribute.annotation.*;
26
26
import proguard.classfile.visitor.*;
27
27
 
28
 
 
29
28
/**
30
29
 * This ClassFileVisitor initializes the references of all class files that
31
30
 * it visits.
58
57
{
59
58
    private MemberFinder memberFinder = new MemberFinder();
60
59
 
61
 
    private ClassPool programClassPool;
62
 
    private ClassPool libraryClassPool;
63
 
    private boolean   warn;
64
 
 
65
 
    // Counter for warnings.
66
 
    private int warningCount;
67
 
 
68
 
 
69
 
    /**
70
 
     * Creates a new ClassFileReferenceInitializer that initializes the hierarchy
71
 
     * of all visited class files, printing warnings if some classes can't be found.
72
 
     */
73
 
    public ClassFileReferenceInitializer(ClassPool programClassPool,
74
 
                                         ClassPool libraryClassPool)
75
 
    {
76
 
        this(programClassPool, libraryClassPool, true);
77
 
    }
78
 
 
79
 
 
80
 
    /**
81
 
     * Creates a new ClassFileReferenceInitializer that initializes the hierarchy
82
 
     * of all visited class files, optionally printing warnings if some classes
83
 
     * can't be found.
84
 
     */
85
 
    public ClassFileReferenceInitializer(ClassPool programClassPool,
86
 
                                         ClassPool libraryClassPool,
87
 
                                         boolean   warn)
 
60
    private ClassPool      programClassPool;
 
61
    private ClassPool      libraryClassPool;
 
62
    private WarningPrinter warningPrinter;
 
63
 
 
64
 
 
65
    /**
 
66
     * Creates a new ClassFileReferenceInitializer that initializes the
 
67
     * references of all visited class files, optionally printing warnings if
 
68
     * some classes can't be found.
 
69
     */
 
70
    public ClassFileReferenceInitializer(ClassPool      programClassPool,
 
71
                                         ClassPool      libraryClassPool,
 
72
                                         WarningPrinter warningPrinter)
88
73
    {
89
74
        this.programClassPool = programClassPool;
90
75
        this.libraryClassPool = libraryClassPool;
91
 
        this.warn             = warn;
92
 
    }
93
 
 
94
 
 
95
 
    /**
96
 
     * Returns the number of warnings printed about unresolved references to
97
 
     * class members in program class files.
98
 
     */
99
 
    public int getWarningCount()
100
 
    {
101
 
        return warningCount;
 
76
        this.warningPrinter   = warningPrinter;
102
77
    }
103
78
 
104
79
 
207
182
 
208
183
            // See if we can find the referenced class member somewhere in the
209
184
            // hierarchy.
210
 
            refCpInfo.referencedMemberInfo = memberFinder.findMember(referencedClassFile,
 
185
            refCpInfo.referencedMemberInfo = memberFinder.findMember(classFile,
 
186
                                                                     referencedClassFile,
211
187
                                                                     name,
212
188
                                                                     type,
213
189
                                                                     isFieldRef);
214
190
            refCpInfo.referencedClassFile  = memberFinder.correspondingClassFile();
215
191
 
216
 
            if (warn && refCpInfo.referencedMemberInfo == null)
 
192
            // Check if we haven't found the class member anywhere in the
 
193
            // hierarchy.
 
194
            if (refCpInfo.referencedMemberInfo == null &&
 
195
                warningPrinter != null)
217
196
            {
218
 
                // We've haven't found the class member anywhere in the hierarchy.
219
 
                warningCount++;
220
 
                System.err.println("Warning: " +
221
 
                                   ClassUtil.externalClassName(classFile.getName()) +
222
 
                                   ": can't find referenced " +
223
 
                                   (isFieldRef ?
224
 
                                    "field '"  + ClassUtil.externalFullFieldDescription(0, name, type) :
225
 
                                    "method '" + ClassUtil.externalFullMethodDescription(className, 0, name, type)) +
226
 
                                   "' in class " +
227
 
                                   ClassUtil.externalClassName(className));
 
197
                warningPrinter.print("Warning: " +
 
198
                                     ClassUtil.externalClassName(classFile.getName()) +
 
199
                                     ": can't find referenced " +
 
200
                                     (isFieldRef ?
 
201
                                         "field '"  + ClassUtil.externalFullFieldDescription(0, name, type) :
 
202
                                         "method '" + ClassUtil.externalFullMethodDescription(className, 0, name, type)) +
 
203
                                     "' in class " +
 
204
                                     ClassUtil.externalClassName(className));
228
205
            }
229
206
        }
230
207
    }
260
237
        if (referencedClassFile == null)
261
238
        {
262
239
            // We couldn't find the enclosing class.
263
 
            if (warn)
 
240
            if (warningPrinter != null)
264
241
            {
265
 
                warningCount++;
266
 
                System.err.println("Warning: " +
267
 
                                   ClassUtil.externalClassName(classFile.getName()) +
268
 
                                   ": can't find enclosing class " +
269
 
                                   ClassUtil.externalClassName(className));
 
242
                warningPrinter.print("Warning: " +
 
243
                                     ClassUtil.externalClassName(classFile.getName()) +
 
244
                                     ": can't find enclosing class " +
 
245
                                     ClassUtil.externalClassName(className));
270
246
            }
271
247
 
272
248
            return;
287
263
        if (referencedMethodInfo == null)
288
264
        {
289
265
            // We couldn't find the enclosing method.
290
 
            if (warn)
 
266
            if (warningPrinter != null)
291
267
            {
292
 
                warningCount++;
293
 
                System.err.println("Warning: " +
294
 
                                   ClassUtil.externalClassName(classFile.getName()) +
295
 
                                   ": can't find enclosing method '" +
296
 
                                   ClassUtil.externalFullMethodDescription(className, 0, name, type) +
297
 
                                   "' in class " +
298
 
                                   ClassUtil.externalClassName(className));
 
268
                warningPrinter.print("Warning: " +
 
269
                                     ClassUtil.externalClassName(classFile.getName()) +
 
270
                                     ": can't find enclosing method '" +
 
271
                                     ClassUtil.externalFullMethodDescription(className, 0, name, type) +
 
272
                                     "' in class " +
 
273
                                     ClassUtil.externalClassName(className));
299
274
            }
300
275
 
301
276
            return;
458
433
            // (ignoring the descriptor).
459
434
            String name = classFile.getCpString(elementValue.u2elementName);
460
435
 
461
 
            elementValue.referencedMethodInfo =
462
 
                annotation.referencedClassFiles[0].findMethod(name, null);
 
436
            ClassFile referencedClassFile = annotation.referencedClassFiles[0];
 
437
            elementValue.referencedClassFile  = referencedClassFile;
 
438
            elementValue.referencedMethodInfo = referencedClassFile.findMethod(name, null);
463
439
        }
464
440
    }
465
441