langtools/src/jdk.compiler/share/classes/com/sun/tools/javah/JavahTask.java
author jjg
Tue, 21 Oct 2014 17:50:13 -0700
changeset 27226 53535e4e1b08
parent 27225 8369cde9152a
child 27852 2e6ad0e4fe20
permissions -rw-r--r--
8061723: 8060056 breaks tests on Windows Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
     1
/*
25690
b1dac768ab79 8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents: 22163
diff changeset
     2
 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
     4
 *
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5217
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5217
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    10
 *
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    15
 * accompanied this code).
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    16
 *
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5217
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5217
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5217
diff changeset
    23
 * questions.
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    24
 */
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    25
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    26
package com.sun.tools.javah;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    27
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    28
import java.io.File;
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
    29
import java.io.FileNotFoundException;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    30
import java.io.IOException;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    31
import java.io.OutputStream;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    32
import java.io.PrintWriter;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    33
import java.io.Writer;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    34
import java.text.MessageFormat;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    35
import java.util.ArrayList;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    36
import java.util.Arrays;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    37
import java.util.Collections;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    38
import java.util.HashMap;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    39
import java.util.Iterator;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    40
import java.util.LinkedHashSet;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    41
import java.util.List;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    42
import java.util.Locale;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    43
import java.util.Map;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    44
import java.util.MissingResourceException;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    45
import java.util.ResourceBundle;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    46
import java.util.Set;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    47
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    48
import javax.annotation.processing.AbstractProcessor;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    49
import javax.annotation.processing.Messager;
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
    50
import javax.annotation.processing.ProcessingEnvironment;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    51
import javax.annotation.processing.RoundEnvironment;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    52
import javax.annotation.processing.SupportedAnnotationTypes;
27226
53535e4e1b08 8061723: 8060056 breaks tests on Windows
jjg
parents: 27225
diff changeset
    53
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    54
import javax.lang.model.SourceVersion;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    55
import javax.lang.model.element.ExecutableElement;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    56
import javax.lang.model.element.TypeElement;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    57
import javax.lang.model.element.VariableElement;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    58
import javax.lang.model.type.ArrayType;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    59
import javax.lang.model.type.DeclaredType;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    60
import javax.lang.model.type.TypeMirror;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    61
import javax.lang.model.type.TypeVisitor;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    62
import javax.lang.model.util.ElementFilter;
25690
b1dac768ab79 8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents: 22163
diff changeset
    63
import javax.lang.model.util.SimpleTypeVisitor9;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    64
import javax.lang.model.util.Types;
27226
53535e4e1b08 8061723: 8060056 breaks tests on Windows
jjg
parents: 27225
diff changeset
    65
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    66
import javax.tools.Diagnostic;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    67
import javax.tools.DiagnosticListener;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    68
import javax.tools.JavaCompiler;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    69
import javax.tools.JavaCompiler.CompilationTask;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    70
import javax.tools.JavaFileManager;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    71
import javax.tools.JavaFileObject;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    72
import javax.tools.StandardJavaFileManager;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    73
import javax.tools.StandardLocation;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    74
import javax.tools.ToolProvider;
27226
53535e4e1b08 8061723: 8060056 breaks tests on Windows
jjg
parents: 27225
diff changeset
    75
import static javax.tools.Diagnostic.Kind.*;
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
    76
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
    77
import com.sun.tools.javac.code.Symbol.CompletionFailure;
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
    78
import com.sun.tools.javac.main.CommandLine;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    79
import com.sun.tools.javac.util.DefinedBy;
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    80
import com.sun.tools.javac.util.DefinedBy.Api;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    81
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    82
/**
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    83
 * Javah generates support files for native methods.
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13690
diff changeset
    84
 * Parse commandline options and invokes javadoc to execute those commands.
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    85
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5841
diff changeset
    86
 * <p><b>This is NOT part of any supported API.
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    87
 * If you write code that depends on this, you do so at your own
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    88
 * risk.  This code and its internal interfaces are subject to change
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    89
 * or deletion without notice.</b></p>
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    90
 *
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    91
 * @author Sucheta Dambalkar
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    92
 * @author Jonathan Gibbons
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    93
 */
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    94
public class JavahTask implements NativeHeaderTool.NativeHeaderTask {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    95
    public class BadArgs extends Exception {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    96
        private static final long serialVersionUID = 1479361270874789045L;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    97
        BadArgs(String key, Object... args) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    98
            super(JavahTask.this.getMessage(key, args));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    99
            this.key = key;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   100
            this.args = args;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   101
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   102
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   103
        BadArgs showUsage(boolean b) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   104
            showUsage = b;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   105
            return this;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   106
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   107
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   108
        final String key;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   109
        final Object[] args;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   110
        boolean showUsage;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   111
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   112
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   113
    static abstract class Option {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   114
        Option(boolean hasArg, String... aliases) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   115
            this.hasArg = hasArg;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   116
            this.aliases = aliases;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   117
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   118
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   119
        boolean isHidden() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   120
            return false;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   121
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   122
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   123
        boolean matches(String opt) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   124
            for (String a: aliases) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   125
                if (a.equals(opt))
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   126
                    return true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   127
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   128
            return false;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   129
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   130
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   131
        boolean ignoreRest() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   132
            return false;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   133
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   134
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   135
        abstract void process(JavahTask task, String opt, String arg) throws BadArgs;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   136
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   137
        final boolean hasArg;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   138
        final String[] aliases;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   139
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   140
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   141
    static abstract class HiddenOption extends Option {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   142
        HiddenOption(boolean hasArg, String... aliases) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   143
            super(hasArg, aliases);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   144
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   145
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   146
        @Override
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   147
        boolean isHidden() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   148
            return true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   149
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   150
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   151
14801
d66cab4ef397 8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents: 14362
diff changeset
   152
    static final Option[] recognizedOptions = {
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   153
        new Option(true, "-o") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   154
            void process(JavahTask task, String opt, String arg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   155
                task.ofile = new File(arg);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   156
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   157
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   158
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   159
        new Option(true, "-d") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   160
            void process(JavahTask task, String opt, String arg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   161
                task.odir = new File(arg);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   162
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   163
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   164
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   165
        new HiddenOption(true, "-td") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   166
            void process(JavahTask task, String opt, String arg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   167
                 // ignored; for backwards compatibility
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   168
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   169
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   170
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   171
        new HiddenOption(false, "-stubs") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   172
            void process(JavahTask task, String opt, String arg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   173
                 // ignored; for backwards compatibility
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   174
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   175
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   176
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   177
        new Option(false, "-v", "-verbose") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   178
            void process(JavahTask task, String opt, String arg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   179
                task.verbose = true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   180
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   181
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   182
6925
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents: 6715
diff changeset
   183
        new Option(false, "-h", "-help", "--help", "-?") {
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   184
            void process(JavahTask task, String opt, String arg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   185
                task.help = true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   186
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   187
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   188
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   189
        new HiddenOption(false, "-trace") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   190
            void process(JavahTask task, String opt, String arg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   191
                task.trace = true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   192
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   193
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   194
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   195
        new Option(false, "-version") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   196
            void process(JavahTask task, String opt, String arg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   197
                task.version = true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   198
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   199
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   200
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   201
        new HiddenOption(false, "-fullversion") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   202
            void process(JavahTask task, String opt, String arg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   203
                task.fullVersion = true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   204
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   205
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   206
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   207
        new Option(false, "-jni") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   208
            void process(JavahTask task, String opt, String arg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   209
                task.jni = true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   210
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   211
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   212
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   213
        new Option(false, "-force") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   214
            void process(JavahTask task, String opt, String arg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   215
                task.force = true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   216
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   217
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   218
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   219
        new HiddenOption(false, "-Xnew") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   220
            void process(JavahTask task, String opt, String arg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   221
                // we're already using the new javah
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   222
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   223
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   224
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   225
        new HiddenOption(false, "-llni", "-Xllni") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   226
            void process(JavahTask task, String opt, String arg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   227
                task.llni = true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   228
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   229
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   230
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   231
        new HiddenOption(false, "-llnidouble") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   232
            void process(JavahTask task, String opt, String arg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   233
                task.llni = true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   234
                task.doubleAlign = true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   235
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   236
        },
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   237
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   238
        new HiddenOption(false) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   239
            boolean matches(String opt) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   240
                return opt.startsWith("-XD");
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   241
            }
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   242
            void process(JavahTask task, String opt, String arg) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   243
                task.javac_extras.add(opt);
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   244
            }
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   245
        },
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   246
    };
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   247
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   248
    JavahTask() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   249
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   250
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   251
    JavahTask(Writer out,
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   252
            JavaFileManager fileManager,
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   253
            DiagnosticListener<? super JavaFileObject> diagnosticListener,
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   254
            Iterable<String> options,
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   255
            Iterable<String> classes) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   256
        this();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   257
        this.log = getPrintWriterForWriter(out);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   258
        this.fileManager = fileManager;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   259
        this.diagnosticListener = diagnosticListener;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   260
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   261
        try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   262
            handleOptions(options, false);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   263
        } catch (BadArgs e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   264
            throw new IllegalArgumentException(e.getMessage());
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   265
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   266
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   267
        this.classes = new ArrayList<>();
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents: 3996
diff changeset
   268
        if (classes != null) {
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents: 3996
diff changeset
   269
            for (String classname: classes) {
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents: 3996
diff changeset
   270
                classname.getClass(); // null-check
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents: 3996
diff changeset
   271
                this.classes.add(classname);
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents: 3996
diff changeset
   272
            }
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   273
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   274
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   275
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   276
    public void setLocale(Locale locale) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   277
        if (locale == null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   278
            locale = Locale.getDefault();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   279
        task_locale = locale;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   280
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   281
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   282
    public void setLog(PrintWriter log) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   283
        this.log = log;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   284
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   285
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   286
    public void setLog(OutputStream s) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   287
        setLog(getPrintWriterForStream(s));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   288
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   289
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   290
    static PrintWriter getPrintWriterForStream(OutputStream s) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   291
        return new PrintWriter(s, true);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   292
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   293
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   294
    static PrintWriter getPrintWriterForWriter(Writer w) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   295
        if (w == null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   296
            return getPrintWriterForStream(null);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   297
        else if (w instanceof PrintWriter)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   298
            return (PrintWriter) w;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   299
        else
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   300
            return new PrintWriter(w, true);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   301
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   302
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   303
    public void setDiagnosticListener(DiagnosticListener<? super JavaFileObject> dl) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   304
        diagnosticListener = dl;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   305
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   306
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   307
    public void setDiagnosticListener(OutputStream s) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   308
        setDiagnosticListener(getDiagnosticListenerForStream(s));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   309
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   310
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   311
    private DiagnosticListener<JavaFileObject> getDiagnosticListenerForStream(OutputStream s) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   312
        return getDiagnosticListenerForWriter(getPrintWriterForStream(s));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   313
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   314
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   315
    private DiagnosticListener<JavaFileObject> getDiagnosticListenerForWriter(Writer w) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   316
        final PrintWriter pw = getPrintWriterForWriter(w);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   317
        return new DiagnosticListener<JavaFileObject> () {
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   318
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   319
            public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   320
                if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   321
                    pw.print(getMessage("err.prefix"));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   322
                    pw.print(" ");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   323
                }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   324
                pw.println(diagnostic.getMessage(null));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   325
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   326
        };
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   327
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   328
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   329
    int run(String[] args) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   330
        try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   331
            handleOptions(args);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   332
            boolean ok = run();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   333
            return ok ? 0 : 1;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   334
        } catch (BadArgs e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   335
            diagnosticListener.report(createDiagnostic(e.key, e.args));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   336
            return 1;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   337
        } catch (InternalError e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   338
            diagnosticListener.report(createDiagnostic("err.internal.error", e.getMessage()));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   339
            return 1;
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   340
        } catch (Util.Exit e) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   341
            return e.exitValue;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   342
        } finally {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   343
            log.flush();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   344
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   345
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   346
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   347
    public void handleOptions(String[] args) throws BadArgs {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   348
        handleOptions(Arrays.asList(args), true);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   349
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   350
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   351
    private void handleOptions(Iterable<String> args, boolean allowClasses) throws BadArgs {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   352
        if (log == null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   353
            log = getPrintWriterForStream(System.out);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   354
            if (diagnosticListener == null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   355
              diagnosticListener = getDiagnosticListenerForStream(System.err);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   356
        } else {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   357
            if (diagnosticListener == null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   358
              diagnosticListener = getDiagnosticListenerForWriter(log);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   359
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   360
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   361
        if (fileManager == null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   362
            fileManager = getDefaultFileManager(diagnosticListener, log);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   363
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   364
        Iterator<String> iter = expandAtArgs(args).iterator();
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
   365
        noArgs = !iter.hasNext();
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   366
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   367
        while (iter.hasNext()) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   368
            String arg = iter.next();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   369
            if (arg.startsWith("-"))
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   370
                handleOption(arg, iter);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   371
            else if (allowClasses) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   372
                if (classes == null)
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   373
                    classes = new ArrayList<>();
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   374
                classes.add(arg);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   375
                while (iter.hasNext())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   376
                    classes.add(iter.next());
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   377
            } else
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   378
                throw new BadArgs("err.unknown.option", arg).showUsage(true);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   379
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   380
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   381
        if ((classes == null || classes.size() == 0) &&
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents: 3996
diff changeset
   382
                !(noArgs || help || version || fullVersion)) {
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   383
            throw new BadArgs("err.no.classes.specified");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   384
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   385
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   386
        if (jni && llni)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   387
            throw new BadArgs("jni.llni.mixed");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   388
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   389
        if (odir != null && ofile != null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   390
            throw new BadArgs("dir.file.mixed");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   391
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   392
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   393
    private void handleOption(String name, Iterator<String> rest) throws BadArgs {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   394
        for (Option o: recognizedOptions) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   395
            if (o.matches(name)) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   396
                if (o.hasArg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   397
                    if (rest.hasNext())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   398
                        o.process(this, name, rest.next());
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   399
                    else
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   400
                        throw new BadArgs("err.missing.arg", name).showUsage(true);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   401
                } else
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   402
                    o.process(this, name, null);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   403
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   404
                if (o.ignoreRest()) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   405
                    while (rest.hasNext())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   406
                        rest.next();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   407
                }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   408
                return;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   409
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   410
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   411
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   412
        if (fileManager.handleOption(name, rest))
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   413
            return;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   414
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   415
        throw new BadArgs("err.unknown.option", name).showUsage(true);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   416
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   417
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   418
    private Iterable<String> expandAtArgs(Iterable<String> args) throws BadArgs {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   419
        try {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   420
            List<String> l = new ArrayList<>();
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   421
            for (String arg: args) l.add(arg);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   422
            return Arrays.asList(CommandLine.parse(l.toArray(new String[l.size()])));
27226
53535e4e1b08 8061723: 8060056 breaks tests on Windows
jjg
parents: 27225
diff changeset
   423
        } catch (FileNotFoundException e) {
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   424
            throw new BadArgs("at.args.file.not.found", e.getLocalizedMessage());
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   425
        } catch (IOException e) {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   426
            throw new BadArgs("at.args.io.exception", e.getLocalizedMessage());
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   427
        }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   428
    }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   429
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   430
    public Boolean call() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   431
        return run();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   432
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   433
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   434
    public boolean run() throws Util.Exit {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   435
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   436
        Util util = new Util(log, diagnosticListener);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   437
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
   438
        if (noArgs || help) {
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   439
            showHelp();
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
   440
            return help; // treat noArgs as an error for purposes of exit code
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   441
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   442
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   443
        if (version || fullVersion) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   444
            showVersion(fullVersion);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   445
            return true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   446
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   447
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   448
        util.verbose = verbose;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   449
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   450
        Gen g;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   451
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   452
        if (llni)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   453
            g = new LLNI(doubleAlign, util);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   454
        else {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   455
//            if (stubs)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   456
//                throw new BadArgs("jni.no.stubs");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   457
            g = new JNI(util);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   458
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   459
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   460
        if (ofile != null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   461
            if (!(fileManager instanceof StandardJavaFileManager)) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   462
                diagnosticListener.report(createDiagnostic("err.cant.use.option.for.fm", "-o"));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   463
                return false;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   464
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   465
            Iterable<? extends JavaFileObject> iter =
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   466
                    ((StandardJavaFileManager) fileManager).getJavaFileObjectsFromFiles(Collections.singleton(ofile));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   467
            JavaFileObject fo = iter.iterator().next();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   468
            g.setOutFile(fo);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   469
        } else {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   470
            if (odir != null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   471
                if (!(fileManager instanceof StandardJavaFileManager)) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   472
                    diagnosticListener.report(createDiagnostic("err.cant.use.option.for.fm", "-d"));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   473
                    return false;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   474
                }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   475
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   476
                if (!odir.exists())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   477
                    if (!odir.mkdirs())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   478
                        util.error("cant.create.dir", odir.toString());
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   479
                try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   480
                    ((StandardJavaFileManager) fileManager).setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(odir));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   481
                } catch (IOException e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   482
                    Object msg = e.getLocalizedMessage();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   483
                    if (msg == null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   484
                        msg = e;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   485
                    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   486
                    diagnosticListener.report(createDiagnostic("err.ioerror", odir, msg));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   487
                    return false;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   488
                }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   489
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   490
            g.setFileManager(fileManager);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   491
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   492
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   493
        /*
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   494
         * Force set to false will turn off smarts about checking file
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   495
         * content before writing.
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   496
         */
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   497
        g.setForce(force);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   498
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   499
        if (fileManager instanceof JavahFileManager)
14362
598fd301e4de 8001229: refactor javac so that ct.sym is just used for javac, not all clients of JavacFileManager
jjg
parents: 13844
diff changeset
   500
            ((JavahFileManager) fileManager).setSymbolFileEnabled(false);
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   501
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   502
        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   503
        List<String> opts = new ArrayList<>();
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   504
        opts.add("-proc:only");
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   505
        opts.addAll(javac_extras);
13690
8be9ba21c4a9 7185778: javah error "Not a valid class name" on class names with dollar signs
jjh
parents: 10192
diff changeset
   506
        CompilationTask t = c.getTask(log, fileManager, diagnosticListener, opts, classes, null);
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   507
        JavahProcessor p = new JavahProcessor(g);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   508
        t.setProcessors(Collections.singleton(p));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   509
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   510
        boolean ok = t.call();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   511
        if (p.exit != null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   512
            throw new Util.Exit(p.exit);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   513
        return ok;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   514
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   515
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   516
    private List<File> pathToFiles(String path) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   517
        List<File> files = new ArrayList<>();
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   518
        for (String f: path.split(File.pathSeparator)) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   519
            if (f.length() > 0)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   520
                files.add(new File(f));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   521
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   522
        return files;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   523
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   524
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   525
    static StandardJavaFileManager getDefaultFileManager(final DiagnosticListener<? super JavaFileObject> dl, PrintWriter log) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   526
        return JavahFileManager.create(dl, log);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   527
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   528
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   529
    private void showHelp() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   530
        log.println(getMessage("main.usage", progname));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   531
        for (Option o: recognizedOptions) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   532
            if (o.isHidden())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   533
                continue;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   534
            String name = o.aliases[0].substring(1); // there must always be at least one name
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   535
            log.println(getMessage("main.opt." + name));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   536
        }
18898
0eab5f5e3d1d 8009924: some langtools tools do not accept -cp as an alias for -classpath
vromero
parents: 18655
diff changeset
   537
        String[] fmOptions = { "-classpath", "-cp", "-bootclasspath" };
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   538
        for (String o: fmOptions) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   539
            if (fileManager.isSupportedOption(o) == -1)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   540
                continue;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   541
            String name = o.substring(1);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   542
            log.println(getMessage("main.opt." + name));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   543
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   544
        log.println(getMessage("main.usage.foot"));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   545
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   546
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   547
    private void showVersion(boolean full) {
6715
9afc72714ca4 6890226: javah -version is broken
jjg
parents: 5847
diff changeset
   548
        log.println(version(full));
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   549
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   550
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   551
    private static final String versionRBName = "com.sun.tools.javah.resources.version";
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   552
    private static ResourceBundle versionRB;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   553
6715
9afc72714ca4 6890226: javah -version is broken
jjg
parents: 5847
diff changeset
   554
    private String version(boolean full) {
9afc72714ca4 6890226: javah -version is broken
jjg
parents: 5847
diff changeset
   555
        String msgKey = (full ? "javah.fullVersion" : "javah.version");
9afc72714ca4 6890226: javah -version is broken
jjg
parents: 5847
diff changeset
   556
        String versionKey = (full ? "full" : "release");
9afc72714ca4 6890226: javah -version is broken
jjg
parents: 5847
diff changeset
   557
        // versionKey=product:  mm.nn.oo[-milestone]
9afc72714ca4 6890226: javah -version is broken
jjg
parents: 5847
diff changeset
   558
        // versionKey=full:     mm.mm.oo[-milestone]-build
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   559
        if (versionRB == null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   560
            try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   561
                versionRB = ResourceBundle.getBundle(versionRBName);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   562
            } catch (MissingResourceException e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   563
                return getMessage("version.resource.missing", System.getProperty("java.version"));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   564
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   565
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   566
        try {
6715
9afc72714ca4 6890226: javah -version is broken
jjg
parents: 5847
diff changeset
   567
            return getMessage(msgKey, "javah", versionRB.getString(versionKey));
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   568
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   569
        catch (MissingResourceException e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   570
            return getMessage("version.unknown", System.getProperty("java.version"));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   571
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   572
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   573
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   574
    private Diagnostic<JavaFileObject> createDiagnostic(final String key, final Object... args) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   575
        return new Diagnostic<JavaFileObject>() {
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   576
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   577
            public Kind getKind() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   578
                return Diagnostic.Kind.ERROR;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   579
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   580
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   581
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   582
            public JavaFileObject getSource() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   583
                return null;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   584
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   585
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   586
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   587
            public long getPosition() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   588
                return Diagnostic.NOPOS;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   589
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   590
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   591
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   592
            public long getStartPosition() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   593
                return Diagnostic.NOPOS;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   594
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   595
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   596
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   597
            public long getEndPosition() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   598
                return Diagnostic.NOPOS;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   599
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   600
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   601
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   602
            public long getLineNumber() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   603
                return Diagnostic.NOPOS;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   604
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   605
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   606
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   607
            public long getColumnNumber() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   608
                return Diagnostic.NOPOS;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   609
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   610
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   611
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   612
            public String getCode() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   613
                return key;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   614
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   615
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   616
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   617
            public String getMessage(Locale locale) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   618
                return JavahTask.this.getMessage(locale, key, args);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   619
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   620
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   621
        };
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   622
    }
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   623
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   624
    private String getMessage(String key, Object... args) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   625
        return getMessage(task_locale, key, args);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   626
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   627
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   628
    private String getMessage(Locale locale, String key, Object... args) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   629
        if (bundles == null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   630
            // could make this a HashMap<Locale,SoftReference<ResourceBundle>>
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   631
            // and for efficiency, keep a hard reference to the bundle for the task
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   632
            // locale
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   633
            bundles = new HashMap<>();
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   634
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   635
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   636
        if (locale == null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   637
            locale = Locale.getDefault();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   638
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   639
        ResourceBundle b = bundles.get(locale);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   640
        if (b == null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   641
            try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   642
                b = ResourceBundle.getBundle("com.sun.tools.javah.resources.l10n", locale);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   643
                bundles.put(locale, b);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   644
            } catch (MissingResourceException e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   645
                throw new InternalError("Cannot find javah resource bundle for locale " + locale, e);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   646
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   647
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   648
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   649
        try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   650
            return MessageFormat.format(b.getString(key), args);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   651
        } catch (MissingResourceException e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   652
            return key;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   653
            //throw new InternalError(e, key);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   654
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   655
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   656
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   657
    File ofile;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   658
    File odir;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   659
    String bootcp;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   660
    String usercp;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   661
    List<String> classes;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   662
    boolean verbose;
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
   663
    boolean noArgs;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   664
    boolean help;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   665
    boolean trace;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   666
    boolean version;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   667
    boolean fullVersion;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   668
    boolean jni;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   669
    boolean llni;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   670
    boolean doubleAlign;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   671
    boolean force;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   672
    Set<String> javac_extras = new LinkedHashSet<>();
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   673
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   674
    PrintWriter log;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   675
    JavaFileManager fileManager;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   676
    DiagnosticListener<? super JavaFileObject> diagnosticListener;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   677
    Locale task_locale;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   678
    Map<Locale, ResourceBundle> bundles;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   679
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   680
    private static final String progname = "javah";
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   681
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   682
    @SupportedAnnotationTypes("*")
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   683
    class JavahProcessor extends AbstractProcessor {
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   684
        private Messager messager;
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   685
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   686
        JavahProcessor(Gen g) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   687
            this.g = g;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   688
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   689
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   690
        @Override @DefinedBy(Api.ANNOTATION_PROCESSING)
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   691
        public SourceVersion getSupportedSourceVersion() {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   692
            // since this is co-bundled with javac, we can assume it supports
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   693
            // the latest source version
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   694
            return SourceVersion.latest();
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   695
        }
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   696
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   697
        @Override @DefinedBy(Api.ANNOTATION_PROCESSING)
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   698
        public void init(ProcessingEnvironment pEnv) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   699
            super.init(pEnv);
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   700
            messager  = processingEnv.getMessager();
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   701
        }
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   702
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   703
        @DefinedBy(Api.ANNOTATION_PROCESSING)
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   704
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   705
            try {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   706
                Set<TypeElement> classes = getAllClasses(ElementFilter.typesIn(roundEnv.getRootElements()));
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   707
                if (classes.size() > 0) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   708
                    checkMethodParameters(classes);
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   709
                    g.setProcessingEnvironment(processingEnv);
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   710
                    g.setClasses(classes);
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   711
                    g.run();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   712
                }
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   713
            } catch (CompletionFailure cf) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   714
                messager.printMessage(ERROR, getMessage("class.not.found", cf.sym.getQualifiedName().toString()));
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   715
            } catch (ClassNotFoundException cnfe) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   716
                messager.printMessage(ERROR, getMessage("class.not.found", cnfe.getMessage()));
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   717
            } catch (IOException ioe) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   718
                messager.printMessage(ERROR, getMessage("io.exception", ioe.getMessage()));
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   719
            } catch (Util.Exit e) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   720
                exit = e;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   721
            }
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   722
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   723
            return true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   724
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   725
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   726
        private Set<TypeElement> getAllClasses(Set<? extends TypeElement> classes) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   727
            Set<TypeElement> allClasses = new LinkedHashSet<>();
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   728
            getAllClasses0(classes, allClasses);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   729
            return allClasses;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   730
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   731
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   732
        private void getAllClasses0(Iterable<? extends TypeElement> classes, Set<TypeElement> allClasses) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   733
            for (TypeElement c: classes) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   734
                allClasses.add(c);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   735
                getAllClasses0(ElementFilter.typesIn(c.getEnclosedElements()), allClasses);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   736
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   737
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   738
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   739
        // 4942232:
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   740
        // check that classes exist for all the parameters of native methods
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   741
        private void checkMethodParameters(Set<TypeElement> classes) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   742
            Types types = processingEnv.getTypeUtils();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   743
            for (TypeElement te: classes) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   744
                for (ExecutableElement ee: ElementFilter.methodsIn(te.getEnclosedElements())) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   745
                    for (VariableElement ve: ee.getParameters()) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   746
                        TypeMirror tm = ve.asType();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   747
                        checkMethodParametersVisitor.visit(tm, types);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   748
                    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   749
                }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   750
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   751
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   752
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   753
        private TypeVisitor<Void,Types> checkMethodParametersVisitor =
25690
b1dac768ab79 8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents: 22163
diff changeset
   754
                new SimpleTypeVisitor9<Void,Types>() {
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   755
            @Override @DefinedBy(Api.LANGUAGE_MODEL)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   756
            public Void visitArray(ArrayType t, Types types) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   757
                visit(t.getComponentType(), types);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   758
                return null;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   759
            }
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   760
            @Override @DefinedBy(Api.LANGUAGE_MODEL)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   761
            public Void visitDeclared(DeclaredType t, Types types) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   762
                t.asElement().getKind(); // ensure class exists
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   763
                for (TypeMirror st: types.directSupertypes(t))
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   764
                    visit(st, types);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   765
                return null;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   766
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   767
        };
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   768
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   769
        private Gen g;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   770
        private Util.Exit exit;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   771
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   772
}