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 $
3
3
* ProGuard -- shrinking, optimization, and obfuscation of Java class files.
5
* Copyright (c) 2002-2005 Eric Lafortune (eric@graphics.cornell.edu)
5
* Copyright (c) 2002-2006 Eric Lafortune (eric@graphics.cornell.edu)
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
59
58
private MemberFinder memberFinder = new MemberFinder();
61
private ClassPool programClassPool;
62
private ClassPool libraryClassPool;
65
// Counter for warnings.
66
private int warningCount;
70
* Creates a new ClassFileReferenceInitializer that initializes the hierarchy
71
* of all visited class files, printing warnings if some classes can't be found.
73
public ClassFileReferenceInitializer(ClassPool programClassPool,
74
ClassPool libraryClassPool)
76
this(programClassPool, libraryClassPool, true);
81
* Creates a new ClassFileReferenceInitializer that initializes the hierarchy
82
* of all visited class files, optionally printing warnings if some classes
85
public ClassFileReferenceInitializer(ClassPool programClassPool,
86
ClassPool libraryClassPool,
60
private ClassPool programClassPool;
61
private ClassPool libraryClassPool;
62
private WarningPrinter warningPrinter;
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.
70
public ClassFileReferenceInitializer(ClassPool programClassPool,
71
ClassPool libraryClassPool,
72
WarningPrinter warningPrinter)
89
74
this.programClassPool = programClassPool;
90
75
this.libraryClassPool = libraryClassPool;
96
* Returns the number of warnings printed about unresolved references to
97
* class members in program class files.
99
public int getWarningCount()
76
this.warningPrinter = warningPrinter;
208
183
// See if we can find the referenced class member somewhere in the
210
refCpInfo.referencedMemberInfo = memberFinder.findMember(referencedClassFile,
185
refCpInfo.referencedMemberInfo = memberFinder.findMember(classFile,
214
190
refCpInfo.referencedClassFile = memberFinder.correspondingClassFile();
216
if (warn && refCpInfo.referencedMemberInfo == null)
192
// Check if we haven't found the class member anywhere in the
194
if (refCpInfo.referencedMemberInfo == null &&
195
warningPrinter != null)
218
// We've haven't found the class member anywhere in the hierarchy.
220
System.err.println("Warning: " +
221
ClassUtil.externalClassName(classFile.getName()) +
222
": can't find referenced " +
224
"field '" + ClassUtil.externalFullFieldDescription(0, name, type) :
225
"method '" + ClassUtil.externalFullMethodDescription(className, 0, name, type)) +
227
ClassUtil.externalClassName(className));
197
warningPrinter.print("Warning: " +
198
ClassUtil.externalClassName(classFile.getName()) +
199
": can't find referenced " +
201
"field '" + ClassUtil.externalFullFieldDescription(0, name, type) :
202
"method '" + ClassUtil.externalFullMethodDescription(className, 0, name, type)) +
204
ClassUtil.externalClassName(className));
260
237
if (referencedClassFile == null)
262
239
// We couldn't find the enclosing class.
240
if (warningPrinter != null)
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));
287
263
if (referencedMethodInfo == null)
289
265
// We couldn't find the enclosing method.
266
if (warningPrinter != null)
293
System.err.println("Warning: " +
294
ClassUtil.externalClassName(classFile.getName()) +
295
": can't find enclosing method '" +
296
ClassUtil.externalFullMethodDescription(className, 0, name, type) +
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) +
273
ClassUtil.externalClassName(className));
458
433
// (ignoring the descriptor).
459
434
String name = classFile.getCpString(elementValue.u2elementName);
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);