~ubuntu-branches/ubuntu/maverick/proguard/maverick

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Sam Clegg, Onkar Shinde, Sam Clegg
  • Date: 2009-10-09 16:17:49 UTC
  • mfrom: (1.2.3 upstream) (3.1.6 karmic)
  • Revision ID: james.westby@ubuntu.com-20091009161749-qjk059y5r792co7c
Tags: 4.4-1
[ Onkar Shinde ]
* Merge from Ubuntu. (Closes: #534029, #548810)

[ Sam Clegg ]
* Thanks Onkar for the above fixes!
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * ProGuard -- shrinking, optimization, obfuscation, and preverification
3
3
 *             of Java bytecode.
4
4
 *
5
 
 * Copyright (c) 2002-2008 Eric Lafortune (eric@graphics.cornell.edu)
 
5
 * Copyright (c) 2002-2009 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
63
63
{
64
64
    private final ClassPool      programClassPool;
65
65
    private final ClassPool      libraryClassPool;
66
 
    private final WarningPrinter missingWarningPrinter;
 
66
    private final WarningPrinter missingClassWarningPrinter;
 
67
    private final WarningPrinter missingMemberWarningPrinter;
67
68
    private final WarningPrinter dependencyWarningPrinter;
68
69
 
69
70
    private final MemberFinder memberFinder = new MemberFinder();
72
73
    /**
73
74
     * Creates a new ClassReferenceInitializer that initializes the references
74
75
     * of all visited class files, optionally printing warnings if some classes
75
 
     * can't be found or if they are in the program class pool.
 
76
     * or class members can't be found or if they are in the program class pool.
76
77
     */
77
78
    public ClassReferenceInitializer(ClassPool      programClassPool,
78
79
                                     ClassPool      libraryClassPool,
79
 
                                     WarningPrinter missingWarningPrinter,
 
80
                                     WarningPrinter missingClassWarningPrinter,
 
81
                                     WarningPrinter missingMemberWarningPrinter,
80
82
                                     WarningPrinter dependencyWarningPrinter)
81
83
    {
82
 
        this.programClassPool         = programClassPool;
83
 
        this.libraryClassPool         = libraryClassPool;
84
 
        this.missingWarningPrinter    = missingWarningPrinter;
85
 
        this.dependencyWarningPrinter = dependencyWarningPrinter;
 
84
        this.programClassPool            = programClassPool;
 
85
        this.libraryClassPool            = libraryClassPool;
 
86
        this.missingClassWarningPrinter  = missingClassWarningPrinter;
 
87
        this.missingMemberWarningPrinter = missingMemberWarningPrinter;
 
88
        this.dependencyWarningPrinter    = dependencyWarningPrinter;
86
89
    }
87
90
 
88
91
 
189
192
                                                                   isFieldRef);
190
193
            refConstant.referencedClass  = memberFinder.correspondingClass();
191
194
 
192
 
            if (refConstant.referencedMember == null &&
193
 
                missingWarningPrinter != null)
 
195
            if (refConstant.referencedMember == null)
194
196
            {
195
197
                // We've haven't found the class member anywhere in the hierarchy.
196
 
                missingWarningPrinter.print("Warning: " +
197
 
                                     ClassUtil.externalClassName(clazz.getName()) +
198
 
                                     ": can't find referenced " +
199
 
                                     (isFieldRef ?
200
 
                                         "field '"  + ClassUtil.externalFullFieldDescription(0, name, type) :
201
 
                                         "method '" + ClassUtil.externalFullMethodDescription(className, 0, name, type)) +
202
 
                                     "' in class " +
203
 
                                     ClassUtil.externalClassName(className));
 
198
                missingMemberWarningPrinter.print(clazz.getName(),
 
199
                                                  className,
 
200
                                                  "Warning: " +
 
201
                                                  ClassUtil.externalClassName(clazz.getName()) +
 
202
                                                  ": can't find referenced " +
 
203
                                                  (isFieldRef ?
 
204
                                                      "field '"  + ClassUtil.externalFullFieldDescription(0, name, type) :
 
205
                                                      "method '" + ClassUtil.externalFullMethodDescription(className, 0, name, type)) +
 
206
                                                  "' in class " +
 
207
                                                  ClassUtil.externalClassName(className));
204
208
            }
205
209
        }
206
210
    }
236
240
        if (referencedClass == null)
237
241
        {
238
242
            // We couldn't find the enclosing class.
239
 
            if (missingWarningPrinter != null)
240
 
            {
241
 
                missingWarningPrinter.print("Warning: " +
242
 
                                     ClassUtil.externalClassName(className) +
243
 
                                     ": can't find enclosing class " +
244
 
                                     ClassUtil.externalClassName(enclosingClassName));
245
 
            }
246
 
 
 
243
            missingClassWarningPrinter.print(className,
 
244
                                             enclosingClassName,
 
245
                                             "Warning: " +
 
246
                                             ClassUtil.externalClassName(className) +
 
247
                                             ": can't find enclosing class " +
 
248
                                             ClassUtil.externalClassName(enclosingClassName));
247
249
            return;
248
250
        }
249
251
 
262
264
        if (referencedMethod == null)
263
265
        {
264
266
            // We couldn't find the enclosing method.
265
 
            if (missingWarningPrinter != null)
266
 
            {
267
 
                missingWarningPrinter.print("Warning: " +
268
 
                                     ClassUtil.externalClassName(className) +
269
 
                                     ": can't find enclosing method '" +
270
 
                                     ClassUtil.externalFullMethodDescription(enclosingClassName, 0, name, type) +
271
 
                                     "' in class " +
272
 
                                     ClassUtil.externalClassName(enclosingClassName));
273
 
            }
274
 
 
 
267
            missingMemberWarningPrinter.print(className,
 
268
                                              enclosingClassName,
 
269
                                              "Warning: " +
 
270
                                              ClassUtil.externalClassName(className) +
 
271
                                              ": can't find enclosing method '" +
 
272
                                              ClassUtil.externalFullMethodDescription(enclosingClassName, 0, name, type) +
 
273
                                              "' in class " +
 
274
                                              ClassUtil.externalClassName(enclosingClassName));
275
275
            return;
276
276
        }
277
277
 
517
517
            clazz = libraryClassPool.getClass(name);
518
518
 
519
519
            if (clazz == null &&
520
 
                missingWarningPrinter != null)
 
520
                missingClassWarningPrinter != null)
521
521
            {
522
522
                // We didn't find the superclass or interface. Print a warning.
523
 
                missingWarningPrinter.print("Warning: " +
524
 
                                            ClassUtil.externalClassName(referencingClassName) +
525
 
                                            ": can't find referenced class " +
526
 
                                            ClassUtil.externalClassName(name));
 
523
                missingClassWarningPrinter.print(referencingClassName,
 
524
                                                 name,
 
525
                                                 "Warning: " +
 
526
                                                 ClassUtil.externalClassName(referencingClassName) +
 
527
                                                 ": can't find referenced class " +
 
528
                                                 ClassUtil.externalClassName(name));
527
529
            }
528
530
        }
529
531
        else if (dependencyWarningPrinter != null)
530
532
        {
531
533
            // The superclass or interface was found in the program class pool.
532
534
            // Print a warning.
533
 
            dependencyWarningPrinter.print("Warning: library class " +
 
535
            dependencyWarningPrinter.print(referencingClassName,
 
536
                                           name,
 
537
                                           "Warning: library class " +
534
538
                                           ClassUtil.externalClassName(referencingClassName) +
535
539
                                           " depends on program class " +
536
540
                                           ClassUtil.externalClassName(name));