APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.tools.jdeprscan.scan

public Class Scan

extends Object
Class Inheritance
Imports
java.io.IOException, .PrintStream, java.lang.classfile.AccessFlags, .ClassFile, .ClassModel, java.lang.classfile.constantpool.FieldRefEntry, .NameAndTypeEntry, java.lang.constant.MethodTypeDesc, java.lang.reflect.AccessFlag, java.nio.file.Files, .NoSuchFileException, .Path, .Paths, java.util.ArrayDeque, .Deque, .Enumeration, .HashSet, .List, .Set, java.util.jar.JarEntry, .JarFile, java.util.regex.Matcher, .Pattern, java.util.stream.Stream, com.sun.tools.jdeprscan.DeprData, .DeprDB, .Messages

An object that represents the scanning phase of deprecation usage checking. Given a deprecation database, scans the targeted directory hierarchy, jar file, or individual class for uses of deprecated APIs.

Field Summary

Modifier and TypeField and Description
pack-priv final Set<String>
pack-priv final List<String>
pack-priv final DeprDB
pack-priv Pattern
pack-priv final PrintStream
pack-priv boolean
pack-priv final ClassFinder
pack-priv final PrintStream
pack-priv Pattern
pack-priv final boolean

Constructor Summary

AccessConstructor and Description
public
Scan(PrintStream out, PrintStream err, List<String> classPath, DeprDB db, boolean verbose)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addInterfaces(Deque<String>
the deque of interfaces
intfs
,
ClassModel
the ClassModel of this class @ if a constant pool entry cannot be found
cf
)

Adds all interfaces from this class to the deque of interfaces.

pack-priv void
checkClasses(ClassModel
the ClassModel of this class
cf
,
CPEntries
constant pool entries collected from this class @ if a constant pool entry cannot be found
entries
)

Checks Class_info entries in the constant pool.

pack-priv void
checkFieldRef(ClassModel
the ClassModel of this class @ if a constant pool entry cannot be found
cf
,
FieldRefEntry fri)

Checks fields referred to from the constant pool.

pack-priv void
checkFields(ClassModel
the ClassModel of this class @ if a constant pool entry cannot be found
cf
)

Checks the fields declared in this class.

pack-priv void
checkInterfaces(ClassModel
the ClassModel of this class @ if a constant pool entry cannot be found
cf
)

Checks the interfaces of this class.

pack-priv void
checkMethodRef(ClassModel
the ClassModel of this class
cf
,
String
the class name
clname
,
NameAndTypeEntry
the NameAndType_info from a MethodRef or InterfaceMethodRef entry
nti
,
String
message key for localization @ if a constant pool entry cannot be found
msgKey
)

Checks methods referred to from the constant pool.

pack-priv void
checkMethods(ClassModel
the ClassModel object of this class @ if a constant pool entry cannot be found
cf
)

Checks the methods declared in this class.

pack-priv void
checkSuper(ClassModel
the ClassModel of this class @ if a constant pool entry cannot be found
cf
)

Checks the superclass of this class.

pack-priv String
dep(boolean forRemoval)

pack-priv void
pack-priv void
errorNoClass(String className)

pack-priv void
errorNoFile(String fileName)

pack-priv void
errorNoMethod(String className, String methodName, String desc)

pack-priv boolean

Returns:

boolean indicating whether the member is present @ if a constant pool entry cannot be found
isMemberPresent
(ClassModel
the ClassModel of the class to search
targetClass
,
String
the method or field's name
targetName
,
String
the methods descriptor (ignored if checkMethod is false)
targetDesc
,
boolean
true if checking for method, false if checking for field
checkMethod
)

Checks whether a member (method or field) is present in a class.

pack-priv String

Returns:

the extracted class name, or null
nameFromDescType
(String
the type from a descriptor
descType
)

Given a descriptor type, extracts and returns the class name from it, if any.

pack-priv String

Returns:

the extracted class name, or null
nameFromRefType
(String
a reference type name
refType
)

Given a ref type name, extracts and returns the class name from it, if any.

pack-priv void
printField(String key, ClassModel cf, String cname, String fname, boolean r)

pack-priv void
printFieldType(String key, ClassModel cf, String cname, String fname, String type, boolean r)

pack-priv void
printHasField(ClassModel cf, String fname, String type, boolean r)

pack-priv void
printHasMethodParmType(ClassModel cf, String mname, String parmType, boolean r)

pack-priv void
printHasMethodRetType(ClassModel cf, String mname, String retType, boolean r)

pack-priv void
printHasOverriddenMethod(ClassModel cf, String overridden, String mname, String desc, boolean r)

pack-priv void
printMethod(String key, ClassModel cf, String cname, String mname, String rtype, boolean r)

pack-priv void
printType(String key, ClassModel cf, String cname, boolean r)

pack-priv void
processClass(ClassModel
the ClassModel of the class @ if a constant pool entry cannot be found
cf
)

Processes a single class file.

public boolean

Returns:

true on success, false on failure
processClassFile
(String
the class file to scan
fileName
)

Scans the named class file for uses of deprecated APIs.

public boolean

Returns:

true on success, false on failure
processClassName
(String
the class to scan
className
)

Scans the named class for uses of deprecated APIs.

pack-priv String

Returns:

the name of the class where the member resolved, or null @ if a constant pool entry cannot be found
resolveMember
(ClassModel
the ClassModel of this class
cf
,
String
the name of the class at which to start searching
startClassName
,
String
the member name to search for
findName
,
String
the method descriptor to search for (ignored for fields)
findDesc
,
boolean
true if resolving a method, false if resolving a field
resolveMethod
,
boolean
true if the start class should be searched, false if it should be skipped
checkStartClass
)

Resolves a member by searching this class and all its superclasses and implemented interfaces.

public boolean

Returns:

true on success, false on failure
scanDir
(String
the directory hierarchy to process
dirname
)

Scans class files in the named directory hierarchy for uses of deprecated APIs.

public boolean

Returns:

true on success, false on failure
scanJar
(String
the jar file to process
jarname
)

Scans a jar file for uses of deprecated APIs.

pack-priv String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classesNotFoundback to summary
pack-priv final Set<String> classesNotFound
classPathback to summary
pack-priv final List<String> classPath
dbback to summary
pack-priv final DeprDB db
descTypePatternback to summary
pack-priv Pattern descTypePattern
errback to summary
pack-priv final PrintStream err
errorOccurredback to summary
pack-priv boolean errorOccurred
finderback to summary
pack-priv final ClassFinder finder
outback to summary
pack-priv final PrintStream out
refTypePatternback to summary
pack-priv Pattern refTypePattern
verboseback to summary
pack-priv final boolean verbose

Constructor Detail

Scanback to summary
public Scan(PrintStream out, PrintStream err, List<String> classPath, DeprDB db, boolean verbose)

Method Detail

addInterfacesback to summary
pack-priv void addInterfaces(Deque<String> intfs, ClassModel cf)

Adds all interfaces from this class to the deque of interfaces.

Parameters
intfs:Deque<String>

the deque of interfaces

cf:ClassModel

the ClassModel of this class @ if a constant pool entry cannot be found

checkClassesback to summary
pack-priv void checkClasses(ClassModel cf, CPEntries entries)

Checks Class_info entries in the constant pool.

Parameters
cf:ClassModel

the ClassModel of this class

entries:CPEntries

constant pool entries collected from this class @ if a constant pool entry cannot be found

checkFieldRefback to summary
pack-priv void checkFieldRef(ClassModel cf, FieldRefEntry fri)

Checks fields referred to from the constant pool.

Parameters
cf:ClassModel

the ClassModel of this class @ if a constant pool entry cannot be found

checkFieldsback to summary
pack-priv void checkFields(ClassModel cf)

Checks the fields declared in this class.

Parameters
cf:ClassModel

the ClassModel of this class @ if a constant pool entry cannot be found

checkInterfacesback to summary
pack-priv void checkInterfaces(ClassModel cf)

Checks the interfaces of this class.

Parameters
cf:ClassModel

the ClassModel of this class @ if a constant pool entry cannot be found

checkMethodRefback to summary
pack-priv void checkMethodRef(ClassModel cf, String clname, NameAndTypeEntry nti, String msgKey)

Checks methods referred to from the constant pool.

Parameters
cf:ClassModel

the ClassModel of this class

clname:String

the class name

nti:NameAndTypeEntry

the NameAndType_info from a MethodRef or InterfaceMethodRef entry

msgKey:String

message key for localization @ if a constant pool entry cannot be found

checkMethodsback to summary
pack-priv void checkMethods(ClassModel cf)

Checks the methods declared in this class.

Parameters
cf:ClassModel

the ClassModel object of this class @ if a constant pool entry cannot be found

checkSuperback to summary
pack-priv void checkSuper(ClassModel cf)

Checks the superclass of this class.

Parameters
cf:ClassModel

the ClassModel of this class @ if a constant pool entry cannot be found

depback to summary
pack-priv String dep(boolean forRemoval)
errorExceptionback to summary
pack-priv void errorException(Exception ex)
errorNoClassback to summary
pack-priv void errorNoClass(String className)
errorNoFileback to summary
pack-priv void errorNoFile(String fileName)
errorNoMethodback to summary
pack-priv void errorNoMethod(String className, String methodName, String desc)
isMemberPresentback to summary
pack-priv boolean isMemberPresent(ClassModel targetClass, String targetName, String targetDesc, boolean checkMethod)

Checks whether a member (method or field) is present in a class. The checkMethod parameter determines whether this checks for a method or for a field.

Parameters
targetClass:ClassModel

the ClassModel of the class to search

targetName:String

the method or field's name

targetDesc:String

the methods descriptor (ignored if checkMethod is false)

checkMethod:boolean

true if checking for method, false if checking for field

Returns:boolean

boolean indicating whether the member is present @ if a constant pool entry cannot be found

nameFromDescTypeback to summary
pack-priv String nameFromDescType(String descType)

Given a descriptor type, extracts and returns the class name from it, if any. These types are obtained from field descriptors (JVMS 4.3.2) and method descriptors (JVMS 4.3.3). They have one of the following forms: I // or any other primitive, or V for void [I // array of primitives, including multi-dimensional Lname; // the named class [Lname; // array whose component is the named class (also multi-d) This method extracts and returns the class name, or returns empty for primitives, void, or array of primitives. Returns nullable reference instead of Optional because downstream processing can throw checked exceptions.

Parameters
descType:String

the type from a descriptor

Returns:String

the extracted class name, or null

nameFromRefTypeback to summary
pack-priv String nameFromRefType(String refType)

Given a ref type name, extracts and returns the class name from it, if any. Ref type names are obtained from a Class_info structure (JVMS 4.4.1) and from Fieldref_info, Methodref_info, and InterfaceMethodref_info structures (JVMS 4.4.2). They represent named classes or array classes mentioned by name, and they represent class or interface types that have the referenced field or method as a member. They have one of the following forms: [I // array of primitives, including multi-dimensional name // the named class [Lname; // array whose component is the named class (also multi-d) Notably, a plain class name doesn't have the L prefix and ; suffix, and primitives and void do not occur. Returns nullable reference instead of Optional because downstream processing can throw checked exceptions.

Parameters
refType:String

a reference type name

Returns:String

the extracted class name, or null

printFieldback to summary
pack-priv void printField(String key, ClassModel cf, String cname, String fname, boolean r)
printFieldTypeback to summary
pack-priv void printFieldType(String key, ClassModel cf, String cname, String fname, String type, boolean r)
printHasFieldback to summary
pack-priv void printHasField(ClassModel cf, String fname, String type, boolean r)
printHasMethodParmTypeback to summary
pack-priv void printHasMethodParmType(ClassModel cf, String mname, String parmType, boolean r)
printHasMethodRetTypeback to summary
pack-priv void printHasMethodRetType(ClassModel cf, String mname, String retType, boolean r)
printHasOverriddenMethodback to summary
pack-priv void printHasOverriddenMethod(ClassModel cf, String overridden, String mname, String desc, boolean r)
printMethodback to summary
pack-priv void printMethod(String key, ClassModel cf, String cname, String mname, String rtype, boolean r)
printTypeback to summary
pack-priv void printType(String key, ClassModel cf, String cname, boolean r)
processClassback to summary
pack-priv void processClass(ClassModel cf)

Processes a single class file.

Parameters
cf:ClassModel

the ClassModel of the class @ if a constant pool entry cannot be found

processClassFileback to summary
public boolean processClassFile(String fileName)

Scans the named class file for uses of deprecated APIs.

Parameters
fileName:String

the class file to scan

Returns:boolean

true on success, false on failure

processClassNameback to summary
public boolean processClassName(String className)

Scans the named class for uses of deprecated APIs.

Parameters
className:String

the class to scan

Returns:boolean

true on success, false on failure

resolveMemberback to summary
pack-priv String resolveMember(ClassModel cf, String startClassName, String findName, String findDesc, boolean resolveMethod, boolean checkStartClass)

Resolves a member by searching this class and all its superclasses and implemented interfaces.

Todo

handles a few too many cases; needs cleanup.

Todo

refine error handling

Parameters
cf:ClassModel

the ClassModel of this class

startClassName:String

the name of the class at which to start searching

findName:String

the member name to search for

findDesc:String

the method descriptor to search for (ignored for fields)

resolveMethod:boolean

true if resolving a method, false if resolving a field

checkStartClass:boolean

true if the start class should be searched, false if it should be skipped

Returns:String

the name of the class where the member resolved, or null @ if a constant pool entry cannot be found

scanDirback to summary
public boolean scanDir(String dirname)

Scans class files in the named directory hierarchy for uses of deprecated APIs.

Parameters
dirname:String

the directory hierarchy to process

Returns:boolean

true on success, false on failure

scanJarback to summary
public boolean scanJar(String jarname)

Scans a jar file for uses of deprecated APIs.

Parameters
jarname:String

the jar file to process

Returns:boolean

true on success, false on failure

typeKindback to summary
pack-priv String typeKind(ClassModel cf)