langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/scan/Scan.java
author smarks
Tue, 01 Nov 2016 11:28:16 -0700
changeset 41863 98b049c8b848
parent 40596 43b19b36e8e6
child 44877 1ab95a256567
permissions -rw-r--r--
8165646: (jdeprscan) adjust tool output to improve clarity Reviewed-by: jjg, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     1
/*
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     4
 *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    10
 *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    15
 * accompanied this code).
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    16
 *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    20
 *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    23
 * questions.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    24
 */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    25
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    26
package com.sun.tools.jdeprscan.scan;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    27
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    28
import java.io.IOException;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    29
import java.io.PrintStream;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    30
import java.nio.file.Files;
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    31
import java.nio.file.NoSuchFileException;
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    32
import java.nio.file.Path;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    33
import java.nio.file.Paths;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    34
import java.util.ArrayDeque;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    35
import java.util.Deque;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    36
import java.util.Enumeration;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    37
import java.util.List;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    38
import java.util.jar.JarEntry;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    39
import java.util.jar.JarFile;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    40
import java.util.regex.Matcher;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    41
import java.util.regex.Pattern;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    42
import java.util.stream.Collectors;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    43
import java.util.stream.Stream;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    44
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    45
import com.sun.tools.classfile.*;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    46
import com.sun.tools.jdeprscan.DeprData;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    47
import com.sun.tools.jdeprscan.DeprDB;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    48
import com.sun.tools.jdeprscan.Messages;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    49
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    50
import static com.sun.tools.classfile.AccessFlags.*;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    51
import static com.sun.tools.classfile.ConstantPool.*;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    52
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    53
/**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    54
 * An object that represents the scanning phase of deprecation usage checking.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    55
 * Given a deprecation database, scans the targeted directory hierarchy, jar
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    56
 * file, or individual class for uses of deprecated APIs.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    57
 */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    58
public class Scan {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    59
    final PrintStream out;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    60
    final PrintStream err;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    61
    final List<String> classPath;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    62
    final DeprDB db;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    63
    final boolean verbose;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    64
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    65
    final ClassFinder finder;
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    66
    boolean errorOccurred = false;
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    67
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    68
    public Scan(PrintStream out,
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    69
                PrintStream err,
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    70
                List<String> classPath,
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    71
                DeprDB db,
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    72
                boolean verbose) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    73
        this.out = out;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    74
        this.err = err;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    75
        this.classPath = classPath;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    76
        this.db = db;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    77
        this.verbose = verbose;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    78
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    79
        ClassFinder f = new ClassFinder(verbose);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    80
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    81
        // TODO: this isn't quite right. If we've specified a release other than the current
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    82
        // one, we should instead add a reference to the symbol file for that release instead
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    83
        // of the current image. The problems are a) it's unclear how to get from a release
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    84
        // to paths that reference the symbol files, as this might be internal to the file
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    85
        // manager; and b) the symbol file includes .sig files, not class files, which ClassFile
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    86
        // might not be able to handle.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    87
        f.addJrt();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    88
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    89
        for (String name : classPath) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    90
            if (name.endsWith(".jar")) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    91
                f.addJar(name);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    92
            } else {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    93
                f.addDir(name);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    94
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    95
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    96
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    97
        finder = f;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    98
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    99
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   100
    Pattern typePattern = Pattern.compile("\\[*L(.*);");
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   101
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   102
    // "flattens" an array type name to its component type
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   103
    // and a reference type "Lpkg/pkg/pkg/name;" to its base name
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   104
    // "pkg/pkg/pkg/name".
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   105
    // TODO: deal with primitive types
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   106
    String flatten(String typeName) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   107
        Matcher matcher = typePattern.matcher(typeName);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   108
        if (matcher.matches()) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   109
            return matcher.group(1);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   110
        } else {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   111
            return typeName;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   112
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   113
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   114
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   115
    String typeKind(ClassFile cf) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   116
        AccessFlags flags = cf.access_flags;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   117
        if (flags.is(ACC_ENUM)) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   118
            return "enum";
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   119
        } else if (flags.is(ACC_ANNOTATION)) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   120
            return "@interface";
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   121
        } else if (flags.is(ACC_INTERFACE)) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   122
            return "interface";
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   123
        } else {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   124
            return "class";
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   125
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   126
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   127
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   128
    String dep(boolean forRemoval) {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   129
        return Messages.get(forRemoval ? "scan.dep.removal" : "scan.dep.normal");
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   130
    }
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   131
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   132
    void printType(String key, ClassFile cf, String cname, boolean r)
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   133
            throws ConstantPoolException {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   134
        out.println(Messages.get(key, typeKind(cf), cf.getName(), cname, dep(r)));
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   135
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   136
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   137
    void printMethod(String key, ClassFile cf, String cname, String mname, String rtype,
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   138
                     boolean r) throws ConstantPoolException {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   139
        out.println(Messages.get(key, typeKind(cf), cf.getName(), cname, mname, rtype, dep(r)));
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   140
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   141
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   142
    void printField(String key, ClassFile cf, String cname, String fname,
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   143
                     boolean r) throws ConstantPoolException {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   144
        out.println(Messages.get(key, typeKind(cf), cf.getName(), cname, fname, dep(r)));
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   145
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   146
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   147
    void printFieldType(String key, ClassFile cf, String cname, String fname, String type,
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   148
                     boolean r) throws ConstantPoolException {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   149
        out.println(Messages.get(key, typeKind(cf), cf.getName(), cname, fname, type, dep(r)));
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   150
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   151
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   152
    void printHasField(ClassFile cf, String fname, String type, boolean r)
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   153
            throws ConstantPoolException {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   154
        out.println(Messages.get("scan.out.hasfield", typeKind(cf), cf.getName(), fname, type, dep(r)));
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   155
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   156
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   157
    void printHasMethodParmType(ClassFile cf, String mname, String parmType, boolean r)
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   158
            throws ConstantPoolException {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   159
        out.println(Messages.get("scan.out.methodparmtype", typeKind(cf), cf.getName(), mname, parmType, dep(r)));
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   160
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   161
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   162
    void printHasMethodRetType(ClassFile cf, String mname, String retType, boolean r)
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   163
            throws ConstantPoolException {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   164
        out.println(Messages.get("scan.out.methodrettype", typeKind(cf), cf.getName(), mname, retType, dep(r)));
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   165
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   166
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   167
    void printHasOverriddenMethod(ClassFile cf, String overridden, String mname, String desc, boolean r)
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   168
            throws ConstantPoolException {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   169
        out.println(Messages.get("scan.out.methodoverride", typeKind(cf), cf.getName(), overridden,
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   170
                                 mname, desc, dep(r)));
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   171
    }
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   172
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   173
    void errorException(Exception ex) {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   174
        errorOccurred = true;
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   175
        err.println(Messages.get("scan.err.exception", ex.toString()));
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   176
        if (verbose) {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   177
            ex.printStackTrace(err);
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   178
        }
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   179
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   180
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   181
    void errorNoClass(String className) {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   182
        errorOccurred = true;
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   183
        err.println(Messages.get("scan.err.noclass", className));
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   184
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   185
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   186
    void errorNoFile(String fileName) {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   187
        errorOccurred = true;
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   188
        err.println(Messages.get("scan.err.nofile", fileName));
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   189
    }
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   190
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   191
    void errorNoMethod(String className, String methodName, String desc) {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   192
        errorOccurred = true;
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   193
        err.println(Messages.get("scan.err.nomethod", className, methodName, desc));
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   194
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   195
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   196
    /**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   197
     * Checks whether a member (method or field) is present in a class.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   198
     * The checkMethod parameter determines whether this checks for a method
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   199
     * or for a field.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   200
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   201
     * @param targetClass the ClassFile of the class to search
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   202
     * @param targetName the method or field's name
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   203
     * @param targetDesc the methods descriptor (ignored if checkMethod is false)
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   204
     * @param checkMethod true if checking for method, false if checking for field
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   205
     * @return boolean indicating whether the member is present
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   206
     * @throws ConstantPoolException if a constant pool entry cannot be found
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   207
     */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   208
    boolean isMemberPresent(ClassFile targetClass,
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   209
                            String targetName,
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   210
                            String targetDesc,
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   211
                            boolean checkMethod)
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   212
            throws ConstantPoolException {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   213
        if (checkMethod) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   214
            for (Method m : targetClass.methods) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   215
                String mname = m.getName(targetClass.constant_pool);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   216
                String mdesc = targetClass.constant_pool.getUTF8Value(m.descriptor.index);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   217
                if (targetName.equals(mname) && targetDesc.equals(mdesc)) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   218
                    return true;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   219
                }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   220
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   221
        } else {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   222
            for (Field f : targetClass.fields) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   223
                String fname = f.getName(targetClass.constant_pool);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   224
                if (targetName.equals(fname)) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   225
                    return true;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   226
                }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   227
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   228
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   229
        return false;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   230
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   231
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   232
    /**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   233
     * Adds all interfaces from this class to the deque of interfaces.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   234
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   235
     * @param intfs the deque of interfaces
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   236
     * @param cf the ClassFile of this class
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   237
     * @throws ConstantPoolException if a constant pool entry cannot be found
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   238
     */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   239
    void addInterfaces(Deque<String> intfs, ClassFile cf)
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   240
            throws ConstantPoolException {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   241
        int count = cf.interfaces.length;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   242
        for (int i = 0; i < count; i++) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   243
            intfs.addLast(cf.getInterfaceName(i));
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   244
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   245
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   246
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   247
    /**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   248
     * Resolves a member by searching this class and all its superclasses and
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   249
     * implemented interfaces.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   250
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   251
     * TODO: handles a few too many cases; needs cleanup.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   252
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   253
     * TODO: refine error handling
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   254
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   255
     * @param cf the ClassFile of this class
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   256
     * @param startClassName the name of the class at which to start searching
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   257
     * @param findName the member name to search for
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   258
     * @param findDesc the method descriptor to search for (ignored for fields)
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   259
     * @param resolveMethod true if resolving a method, false if resolving a field
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   260
     * @param checkStartClass true if the start class should be searched, false if
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   261
     *                        it should be skipped
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   262
     * @return the name of the class where the member resolved, or null
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   263
     * @throws ConstantPoolException if a constant pool entry cannot be found
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   264
     */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   265
    String resolveMember(
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   266
            ClassFile cf, String startClassName, String findName, String findDesc,
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   267
            boolean resolveMethod, boolean checkStartClass)
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   268
            throws ConstantPoolException {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   269
        ClassFile startClass;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   270
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   271
        if (cf.getName().equals(startClassName)) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   272
            startClass = cf;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   273
        } else {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   274
            startClass = finder.find(startClassName);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   275
            if (startClass == null) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   276
                errorNoClass(startClassName);
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   277
                return startClassName;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   278
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   279
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   280
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   281
        // follow super_class until it's 0, meaning we've reached Object
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   282
        // accumulate interfaces of superclasses as we go along
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   283
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   284
        ClassFile curClass = startClass;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   285
        Deque<String> intfs = new ArrayDeque<>();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   286
        while (true) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   287
            if ((checkStartClass || curClass != startClass) &&
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   288
                    isMemberPresent(curClass, findName, findDesc, resolveMethod)) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   289
                break;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   290
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   291
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   292
            if (curClass.super_class == 0) { // reached Object
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   293
                curClass = null;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   294
                break;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   295
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   296
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   297
            String superName = curClass.getSuperclassName();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   298
            curClass = finder.find(superName);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   299
            if (curClass == null) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   300
                errorNoClass(superName);
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   301
                break;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   302
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   303
            addInterfaces(intfs, curClass);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   304
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   305
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   306
        // search interfaces: add all interfaces and superinterfaces to queue
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   307
        // search until it's empty
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   308
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   309
        if (curClass == null) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   310
            addInterfaces(intfs, startClass);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   311
            while (intfs.size() > 0) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   312
                String intf = intfs.removeFirst();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   313
                curClass = finder.find(intf);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   314
                if (curClass == null) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   315
                    errorNoClass(intf);
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   316
                    break;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   317
                }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   318
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   319
                if (isMemberPresent(curClass, findName, findDesc, resolveMethod)) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   320
                    break;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   321
                }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   322
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   323
                addInterfaces(intfs, curClass);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   324
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   325
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   326
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   327
        if (curClass == null) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   328
            if (checkStartClass) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   329
                errorNoMethod(startClassName, findName, findDesc);
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   330
                return startClassName;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   331
            } else {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   332
                // TODO: refactor this
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   333
                // checkStartClass == false means we're checking for overrides
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   334
                // so not being able to resolve a method simply means there's
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   335
                // no overriding, which isn't an error
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   336
                return null;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   337
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   338
        } else {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   339
            String foundClassName = curClass.getName();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   340
            return foundClassName;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   341
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   342
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   343
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   344
    /**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   345
     * Checks the superclass of this class.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   346
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   347
     * @param cf the ClassFile of this class
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   348
     * @throws ConstantPoolException if a constant pool entry cannot be found
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   349
     */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   350
    void checkSuper(ClassFile cf) throws ConstantPoolException {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   351
        String sname = cf.getSuperclassName();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   352
        DeprData dd = db.getTypeDeprecated(sname);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   353
        if (dd != null) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   354
            printType("scan.out.extends", cf, sname, dd.isForRemoval());
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   355
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   356
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   357
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   358
    /**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   359
     * Checks the interfaces of this class.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   360
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   361
     * @param cf the ClassFile of this class
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   362
     * @throws ConstantPoolException if a constant pool entry cannot be found
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   363
     */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   364
    void checkInterfaces(ClassFile cf) throws ConstantPoolException {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   365
        int ni = cf.interfaces.length;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   366
        for (int i = 0; i < ni; i++) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   367
            String iname = cf.getInterfaceName(i);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   368
            DeprData dd = db.getTypeDeprecated(iname);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   369
            if (dd != null) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   370
                printType("scan.out.implements", cf, iname, dd.isForRemoval());
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   371
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   372
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   373
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   374
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   375
    /**
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   376
     * Checks Class_info entries in the constant pool.
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   377
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   378
     * @param cf the ClassFile of this class
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   379
     * @param entries constant pool entries collected from this class
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   380
     * @throws ConstantPoolException if a constant pool entry cannot be found
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   381
     */
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   382
    void checkClasses(ClassFile cf, CPEntries entries) throws ConstantPoolException {
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   383
        for (ConstantPool.CONSTANT_Class_info ci : entries.classes) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   384
            String className = ci.getName();
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   385
            DeprData dd = db.getTypeDeprecated(flatten(className));
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   386
            if (dd != null) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   387
                printType("scan.out.usesclass", cf, className, dd.isForRemoval());
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   388
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   389
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   390
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   391
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   392
    /**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   393
     * Checks methods referred to from the constant pool.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   394
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   395
     * @param cf the ClassFile of this class
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   396
     * @param nti the NameAndType_info from a MethodRef or InterfaceMethodRef entry
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   397
     * @param clname the class name
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   398
     * @param msgKey message key for localization
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   399
     * @throws ConstantPoolException if a constant pool entry cannot be found
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   400
     */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   401
    void checkMethodRef(ClassFile cf,
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   402
                        String clname,
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   403
                        CONSTANT_NameAndType_info nti,
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   404
                        String msgKey) throws ConstantPoolException {
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   405
        String name = nti.getName();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   406
        String type = nti.getType();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   407
        clname = resolveMember(cf, flatten(clname), name, type, true, true);
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   408
        DeprData dd = db.getMethodDeprecated(clname, name, type);
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   409
        if (dd != null) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   410
            printMethod(msgKey, cf, clname, name, type, dd.isForRemoval());
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   411
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   412
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   413
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   414
    /**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   415
     * Checks fields referred to from the constant pool.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   416
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   417
     * @param cf the ClassFile of this class
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   418
     * @throws ConstantPoolException if a constant pool entry cannot be found
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   419
     */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   420
    void checkFieldRef(ClassFile cf,
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   421
                       ConstantPool.CONSTANT_Fieldref_info fri) throws ConstantPoolException {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   422
        String clname = fri.getClassName();
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   423
        CONSTANT_NameAndType_info nti = fri.getNameAndTypeInfo();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   424
        String name = nti.getName();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   425
        String type = nti.getType();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   426
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   427
        clname = resolveMember(cf, flatten(clname), name, type, false, true);
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   428
        DeprData dd = db.getFieldDeprecated(clname, name);
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   429
        if (dd != null) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   430
            printField("scan.out.usesfield", cf, clname, name, dd.isForRemoval());
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   431
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   432
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   433
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   434
    /**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   435
     * Checks the fields declared in this class.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   436
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   437
     * @param cf the ClassFile of this class
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   438
     * @throws ConstantPoolException if a constant pool entry cannot be found
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   439
     */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   440
    void checkFields(ClassFile cf) throws ConstantPoolException {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   441
        for (Field f : cf.fields) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   442
            String type = cf.constant_pool.getUTF8Value(f.descriptor.index);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   443
            DeprData dd = db.getTypeDeprecated(flatten(type));
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   444
            if (dd != null) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   445
                printHasField(cf, f.getName(cf.constant_pool), type, dd.isForRemoval());
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   446
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   447
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   448
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   449
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   450
    /**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   451
     * Checks the methods declared in this class.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   452
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   453
     * @param cf the ClassFile object of this class
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   454
     * @throws ConstantPoolException if a constant pool entry cannot be found
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   455
     */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   456
    void checkMethods(ClassFile cf) throws ConstantPoolException {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   457
        for (Method m : cf.methods) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   458
            String mname = m.getName(cf.constant_pool);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   459
            String desc = cf.constant_pool.getUTF8Value(m.descriptor.index);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   460
            MethodSig sig = MethodSig.fromDesc(desc);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   461
            DeprData dd;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   462
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   463
            for (String parm : sig.getParameters()) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   464
                dd = db.getTypeDeprecated(flatten(parm));
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   465
                if (dd != null) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   466
                    printHasMethodParmType(cf, mname, parm, dd.isForRemoval());
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   467
                }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   468
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   469
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   470
            String ret = sig.getReturnType();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   471
            dd = db.getTypeDeprecated(flatten(ret));
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   472
            if (dd != null) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   473
                printHasMethodRetType(cf, mname, ret, dd.isForRemoval());
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   474
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   475
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   476
            // check overrides
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   477
            String overridden = resolveMember(cf, cf.getName(), mname, desc, true, false);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   478
            if (overridden != null) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   479
                dd = db.getMethodDeprecated(overridden, mname, desc);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   480
                if (dd != null) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   481
                    printHasOverriddenMethod(cf, overridden, mname, desc, dd.isForRemoval());
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   482
                }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   483
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   484
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   485
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   486
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   487
    /**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   488
     * Processes a single class file.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   489
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   490
     * @param cf the ClassFile of the class
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   491
     * @throws ConstantPoolException if a constant pool entry cannot be found
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   492
     */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   493
    void processClass(ClassFile cf) throws ConstantPoolException {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   494
        if (verbose) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   495
            out.println(Messages.get("scan.process.class", cf.getName()));
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   496
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   497
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   498
        CPEntries entries = CPEntries.loadFrom(cf);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   499
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   500
        checkSuper(cf);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   501
        checkInterfaces(cf);
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   502
        checkClasses(cf, entries);
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   503
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   504
        for (ConstantPool.CONSTANT_Methodref_info mri : entries.methodRefs) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   505
            String clname = mri.getClassName();
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   506
            CONSTANT_NameAndType_info nti = mri.getNameAndTypeInfo();
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   507
            checkMethodRef(cf, clname, nti, "scan.out.usesmethod");
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   508
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   509
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   510
        for (ConstantPool.CONSTANT_InterfaceMethodref_info imri : entries.intfMethodRefs) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   511
            String clname = imri.getClassName();
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   512
            CONSTANT_NameAndType_info nti = imri.getNameAndTypeInfo();
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   513
            checkMethodRef(cf, clname, nti, "scan.out.usesintfmethod");
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   514
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   515
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   516
        for (ConstantPool.CONSTANT_Fieldref_info fri : entries.fieldRefs) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   517
            checkFieldRef(cf, fri);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   518
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   519
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   520
        checkFields(cf);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   521
        checkMethods(cf);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   522
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   523
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   524
    /**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   525
     * Scans a jar file for uses of deprecated APIs.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   526
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   527
     * @param jarname the jar file to process
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   528
     * @return true on success, false on failure
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   529
     */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   530
    public boolean scanJar(String jarname) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   531
        try (JarFile jf = new JarFile(jarname)) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   532
            out.println(Messages.get("scan.head.jar", jarname));
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   533
            finder.addJar(jarname);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   534
            Enumeration<JarEntry> entries = jf.entries();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   535
            while (entries.hasMoreElements()) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   536
                JarEntry entry = entries.nextElement();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   537
                String name = entry.getName();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   538
                if (name.endsWith(".class")
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   539
                        && !name.endsWith("package-info.class")
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   540
                        && !name.endsWith("module-info.class")) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   541
                    processClass(ClassFile.read(jf.getInputStream(entry)));
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   542
                }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   543
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   544
            return true;
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   545
        } catch (NoSuchFileException nsfe) {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   546
            errorNoFile(jarname);
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   547
        } catch (IOException | ConstantPoolException ex) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   548
            errorException(ex);
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   549
        }
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   550
        return false;
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   551
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   552
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   553
    /**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   554
     * Scans class files in the named directory hierarchy for uses of deprecated APIs.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   555
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   556
     * @param dirname the directory hierarchy to process
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   557
     * @return true on success, false on failure
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   558
     */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   559
    public boolean scanDir(String dirname) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   560
        Path base = Paths.get(dirname);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   561
        int baseCount = base.getNameCount();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   562
        finder.addDir(dirname);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   563
        try (Stream<Path> paths = Files.walk(Paths.get(dirname))) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   564
            List<Path> classes =
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   565
                paths.filter(p -> p.getNameCount() > baseCount)
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   566
                     .filter(path -> path.toString().endsWith(".class"))
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   567
                     .filter(path -> !path.toString().endsWith("package-info.class"))
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   568
                     .filter(path -> !path.toString().endsWith("module-info.class"))
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   569
                     .collect(Collectors.toList());
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   570
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   571
            out.println(Messages.get("scan.head.dir", dirname));
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   572
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   573
            for (Path p : classes) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   574
                processClass(ClassFile.read(p));
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   575
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   576
            return true;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   577
        } catch (IOException | ConstantPoolException ex) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   578
            errorException(ex);
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   579
            return false;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   580
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   581
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   582
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   583
    /**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   584
     * Scans the named class for uses of deprecated APIs.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   585
     *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   586
     * @param className the class to scan
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   587
     * @return true on success, false on failure
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   588
     */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   589
    public boolean processClassName(String className) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   590
        try {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   591
            ClassFile cf = finder.find(className);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   592
            if (cf == null) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   593
                errorNoClass(className);
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   594
                return false;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   595
            } else {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   596
                processClass(cf);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   597
                return true;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   598
            }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   599
        } catch (ConstantPoolException ex) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   600
            errorException(ex);
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   601
            return false;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   602
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   603
    }
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   604
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   605
    /**
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   606
     * Scans the named class file for uses of deprecated APIs.
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   607
     *
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   608
     * @param fileName the class file to scan
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   609
     * @return true on success, false on failure
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   610
     */
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   611
    public boolean processClassFile(String fileName) {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   612
        Path path = Paths.get(fileName);
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   613
        try {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   614
            ClassFile cf = ClassFile.read(path);
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   615
            processClass(cf);
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   616
            return true;
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   617
        } catch (NoSuchFileException nsfe) {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   618
            errorNoFile(fileName);
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   619
        } catch (IOException | ConstantPoolException ex) {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   620
            errorException(ex);
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   621
        }
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   622
        return false;
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
   623
    }
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
   624
}