langtools/src/jdk.compiler/share/classes/com/sun/tools/javah/JavahTask.java
author mcimadamore
Fri, 16 Dec 2016 15:27:34 +0000
changeset 42827 36468b5fa7f4
parent 40308 274367a99f98
permissions -rw-r--r--
8181370: Convert anonymous inner classes into lambdas/method references Reviewed-by: jjg, rfield, mchung
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
/*
36153
ed5063b304be 8149600: javac, remove unused options, step 2
vromero
parents: 29291
diff changeset
     2
 * Copyright (c) 2002, 2016, 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;
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    34
import java.nio.file.NoSuchFileException;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    35
import java.text.MessageFormat;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    36
import java.util.ArrayList;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    37
import java.util.Arrays;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    38
import java.util.Collections;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    39
import java.util.HashMap;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    40
import java.util.Iterator;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    41
import java.util.LinkedHashSet;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    42
import java.util.List;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    43
import java.util.Locale;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    44
import java.util.Map;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    45
import java.util.MissingResourceException;
29291
076c277565f7 8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents: 27852
diff changeset
    46
import java.util.Objects;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    47
import java.util.ResourceBundle;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    48
import java.util.Set;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    49
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    50
import javax.annotation.processing.AbstractProcessor;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    51
import javax.annotation.processing.Messager;
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
    52
import javax.annotation.processing.ProcessingEnvironment;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    53
import javax.annotation.processing.RoundEnvironment;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    54
import javax.annotation.processing.SupportedAnnotationTypes;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    55
import javax.lang.model.SourceVersion;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    56
import javax.lang.model.element.ExecutableElement;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    57
import javax.lang.model.element.TypeElement;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    58
import javax.lang.model.element.VariableElement;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    59
import javax.lang.model.type.ArrayType;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    60
import javax.lang.model.type.DeclaredType;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    61
import javax.lang.model.type.TypeMirror;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    62
import javax.lang.model.type.TypeVisitor;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    63
import javax.lang.model.util.ElementFilter;
25690
b1dac768ab79 8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents: 22163
diff changeset
    64
import javax.lang.model.util.SimpleTypeVisitor9;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    65
import javax.lang.model.util.Types;
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;
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
    75
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
    76
import com.sun.tools.javac.code.Symbol.CompletionFailure;
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
    77
import com.sun.tools.javac.main.CommandLine;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    78
import com.sun.tools.javac.util.DefinedBy;
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    79
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
    80
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    81
import static javax.tools.Diagnostic.Kind.*;
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    82
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    83
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    84
/**
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    85
 * Javah generates support files for native methods.
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13690
diff changeset
    86
 * 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
    87
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5841
diff changeset
    88
 * <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
    89
 * 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
    90
 * 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
    91
 * or deletion without notice.</b></p>
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    92
 *
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    93
 * @author Sucheta Dambalkar
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    94
 * @author Jonathan Gibbons
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    95
 */
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    96
public class JavahTask implements NativeHeaderTool.NativeHeaderTask {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    97
    public class BadArgs extends Exception {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    98
        private static final long serialVersionUID = 1479361270874789045L;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    99
        BadArgs(String key, Object... args) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   100
            super(JavahTask.this.getMessage(key, args));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   101
            this.key = key;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   102
            this.args = args;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   103
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   104
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   105
        BadArgs showUsage(boolean b) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   106
            showUsage = b;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   107
            return this;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   108
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   109
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   110
        final String key;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   111
        final Object[] args;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   112
        boolean showUsage;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   113
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   114
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   115
    static abstract class Option {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   116
        Option(boolean hasArg, String... aliases) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   117
            this.hasArg = hasArg;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   118
            this.aliases = aliases;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   119
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   120
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   121
        boolean isHidden() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   122
            return false;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   123
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   124
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   125
        boolean matches(String opt) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   126
            for (String a: aliases) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   127
                if (a.equals(opt))
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   128
                    return true;
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
            return false;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   131
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   132
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   133
        boolean ignoreRest() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   134
            return false;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   135
        }
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
        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
   138
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   139
        final boolean hasArg;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   140
        final String[] aliases;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   141
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   142
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   143
    static abstract class HiddenOption extends Option {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   144
        HiddenOption(boolean hasArg, String... aliases) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   145
            super(hasArg, aliases);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   146
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   147
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   148
        @Override
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   149
        boolean isHidden() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   150
            return true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   151
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   152
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   153
14801
d66cab4ef397 8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents: 14362
diff changeset
   154
    static final Option[] recognizedOptions = {
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   155
        new Option(true, "-o") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   156
            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
   157
                task.ofile = new File(arg);
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
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   160
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   161
        new Option(true, "-d") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   162
            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
   163
                task.odir = new File(arg);
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
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   166
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   167
        new HiddenOption(true, "-td") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   168
            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
   169
                 // ignored; for backwards compatibility
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
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   172
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   173
        new Option(false, "-v", "-verbose") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   174
            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
   175
                task.verbose = true;
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
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   178
6925
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents: 6715
diff changeset
   179
        new Option(false, "-h", "-help", "--help", "-?") {
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   180
            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
   181
                task.help = true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   182
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   183
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   184
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   185
        new HiddenOption(false, "-trace") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   186
            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
   187
                task.trace = true;
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
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   190
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   191
        new Option(false, "-version") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   192
            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
   193
                task.version = true;
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
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   196
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   197
        new HiddenOption(false, "-fullversion") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   198
            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
   199
                task.fullVersion = true;
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
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   202
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   203
        new Option(false, "-jni") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   204
            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
   205
                task.jni = true;
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
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   208
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   209
        new Option(false, "-force") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   210
            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
   211
                task.force = true;
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
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   214
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   215
        new HiddenOption(false, "-Xnew") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   216
            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
   217
                // we're already using the new javah
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
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   220
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   221
        new HiddenOption(false, "-llni", "-Xllni") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   222
            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
   223
                task.llni = true;
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
        },
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   226
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   227
        new HiddenOption(false, "-llnidouble") {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   228
            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
   229
                task.llni = true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   230
                task.doubleAlign = true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   231
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   232
        },
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   233
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   234
        new HiddenOption(false) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   235
            boolean matches(String opt) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   236
                return opt.startsWith("-XD");
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
            void process(JavahTask task, String opt, String arg) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   239
                task.javac_extras.add(opt);
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   240
            }
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   241
        },
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   242
    };
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   243
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   244
    JavahTask() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   245
    }
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
    JavahTask(Writer out,
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   248
            JavaFileManager fileManager,
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   249
            DiagnosticListener<? super JavaFileObject> diagnosticListener,
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   250
            Iterable<String> options,
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   251
            Iterable<String> classes) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   252
        this();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   253
        this.log = getPrintWriterForWriter(out);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   254
        this.fileManager = fileManager;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   255
        this.diagnosticListener = diagnosticListener;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   256
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   257
        try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   258
            handleOptions(options, false);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   259
        } catch (BadArgs e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   260
            throw new IllegalArgumentException(e.getMessage());
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   261
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   262
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   263
        this.classes = new ArrayList<>();
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents: 3996
diff changeset
   264
        if (classes != null) {
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents: 3996
diff changeset
   265
            for (String classname: classes) {
29291
076c277565f7 8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents: 27852
diff changeset
   266
                Objects.requireNonNull(classname);
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents: 3996
diff changeset
   267
                this.classes.add(classname);
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents: 3996
diff changeset
   268
            }
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   269
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   270
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   271
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   272
    public void setLocale(Locale locale) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   273
        if (locale == null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   274
            locale = Locale.getDefault();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   275
        task_locale = locale;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   276
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   277
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   278
    public void setLog(PrintWriter log) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   279
        this.log = log;
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(OutputStream s) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   283
        setLog(getPrintWriterForStream(s));
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
    static PrintWriter getPrintWriterForStream(OutputStream s) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   287
        return new PrintWriter(s, true);
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 getPrintWriterForWriter(Writer w) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   291
        if (w == null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   292
            return getPrintWriterForStream(null);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   293
        else if (w instanceof PrintWriter)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   294
            return (PrintWriter) w;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   295
        else
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   296
            return new PrintWriter(w, true);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   297
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   298
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   299
    public void setDiagnosticListener(DiagnosticListener<? super JavaFileObject> dl) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   300
        diagnosticListener = dl;
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(OutputStream s) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   304
        setDiagnosticListener(getDiagnosticListenerForStream(s));
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
    private DiagnosticListener<JavaFileObject> getDiagnosticListenerForStream(OutputStream s) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   308
        return getDiagnosticListenerForWriter(getPrintWriterForStream(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> getDiagnosticListenerForWriter(Writer w) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   312
        final PrintWriter pw = getPrintWriterForWriter(w);
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40308
diff changeset
   313
        return diagnostic -> {
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40308
diff changeset
   314
            if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40308
diff changeset
   315
                pw.print(getMessage("err.prefix"));
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40308
diff changeset
   316
                pw.print(" ");
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   317
            }
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40308
diff changeset
   318
            pw.println(diagnostic.getMessage(null));
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   319
        };
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   320
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   321
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   322
    int run(String[] args) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   323
        try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   324
            handleOptions(args);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   325
            boolean ok = run();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   326
            return ok ? 0 : 1;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   327
        } catch (BadArgs e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   328
            diagnosticListener.report(createDiagnostic(e.key, e.args));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   329
            return 1;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   330
        } catch (InternalError e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   331
            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
   332
            return 1;
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   333
        } catch (Util.Exit e) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   334
            return e.exitValue;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   335
        } finally {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   336
            log.flush();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   337
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   338
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   339
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   340
    public void handleOptions(String[] args) throws BadArgs {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   341
        handleOptions(Arrays.asList(args), true);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   342
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   343
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   344
    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
   345
        if (log == null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   346
            log = getPrintWriterForStream(System.out);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   347
            if (diagnosticListener == null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   348
              diagnosticListener = getDiagnosticListenerForStream(System.err);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   349
        } else {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   350
            if (diagnosticListener == null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   351
              diagnosticListener = getDiagnosticListenerForWriter(log);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   352
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   353
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   354
        if (fileManager == null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   355
            fileManager = getDefaultFileManager(diagnosticListener, log);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   356
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   357
        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
   358
        noArgs = !iter.hasNext();
3996
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
        while (iter.hasNext()) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   361
            String arg = iter.next();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   362
            if (arg.startsWith("-"))
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   363
                handleOption(arg, iter);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   364
            else if (allowClasses) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   365
                if (classes == null)
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   366
                    classes = new ArrayList<>();
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   367
                classes.add(arg);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   368
                while (iter.hasNext())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   369
                    classes.add(iter.next());
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   370
            } else
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   371
                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
   372
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   373
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   374
        if ((classes == null || classes.size() == 0) &&
5005
b9ecef751d2c 6893943: exit code from javah with no args is 0
jjg
parents: 3996
diff changeset
   375
                !(noArgs || help || version || fullVersion)) {
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   376
            throw new BadArgs("err.no.classes.specified");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   377
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   378
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   379
        if (jni && llni)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   380
            throw new BadArgs("jni.llni.mixed");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   381
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   382
        if (odir != null && ofile != null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   383
            throw new BadArgs("dir.file.mixed");
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
    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
   387
        for (Option o: recognizedOptions) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   388
            if (o.matches(name)) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   389
                if (o.hasArg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   390
                    if (rest.hasNext())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   391
                        o.process(this, name, rest.next());
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   392
                    else
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   393
                        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
   394
                } else
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   395
                    o.process(this, name, null);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   396
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   397
                if (o.ignoreRest()) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   398
                    while (rest.hasNext())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   399
                        rest.next();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   400
                }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   401
                return;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   402
            }
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
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   405
        if (fileManager.handleOption(name, rest))
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   406
            return;
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
        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
   409
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   410
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   411
    private Iterable<String> expandAtArgs(Iterable<String> args) throws BadArgs {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   412
        try {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   413
            List<String> l = new ArrayList<>();
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   414
            for (String arg: args) l.add(arg);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   415
            return Arrays.asList(CommandLine.parse(l.toArray(new String[l.size()])));
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   416
        } catch (FileNotFoundException | NoSuchFileException e) {
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   417
            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
   418
        } catch (IOException e) {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   419
            throw new BadArgs("at.args.io.exception", e.getLocalizedMessage());
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   420
        }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   421
    }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   422
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   423
    public Boolean call() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   424
        return run();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   425
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   426
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   427
    public boolean run() throws Util.Exit {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   428
38605
72ca5671f3e6 8152360: deprecate javah
vromero
parents: 36526
diff changeset
   429
        if (!javac_extras.contains("-XDsuppress-tool-removal-message")) {
72ca5671f3e6 8152360: deprecate javah
vromero
parents: 36526
diff changeset
   430
            log.println(getMessage("javah.misc.Deprecation"));
72ca5671f3e6 8152360: deprecate javah
vromero
parents: 36526
diff changeset
   431
        }
72ca5671f3e6 8152360: deprecate javah
vromero
parents: 36526
diff changeset
   432
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   433
        Util util = new Util(log, diagnosticListener);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   434
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
   435
        if (noArgs || help) {
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   436
            showHelp();
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
   437
            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
   438
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   439
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   440
        if (version || fullVersion) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   441
            showVersion(fullVersion);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   442
            return true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   443
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   444
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   445
        util.verbose = verbose;
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
        Gen g;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   448
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   449
        if (llni)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   450
            g = new LLNI(doubleAlign, util);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   451
        else {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   452
            g = new JNI(util);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   453
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   454
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   455
        if (ofile != null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   456
            if (!(fileManager instanceof StandardJavaFileManager)) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   457
                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
   458
                return false;
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
            Iterable<? extends JavaFileObject> iter =
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   461
                    ((StandardJavaFileManager) fileManager).getJavaFileObjectsFromFiles(Collections.singleton(ofile));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   462
            JavaFileObject fo = iter.iterator().next();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   463
            g.setOutFile(fo);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   464
        } else {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   465
            if (odir != null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   466
                if (!(fileManager instanceof StandardJavaFileManager)) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   467
                    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
   468
                    return false;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   469
                }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   470
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   471
                if (!odir.exists())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   472
                    if (!odir.mkdirs())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   473
                        util.error("cant.create.dir", odir.toString());
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   474
                try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   475
                    ((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
   476
                } catch (IOException e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   477
                    Object msg = e.getLocalizedMessage();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   478
                    if (msg == null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   479
                        msg = e;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   480
                    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   481
                    diagnosticListener.report(createDiagnostic("err.ioerror", odir, msg));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   482
                    return false;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   483
                }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   484
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   485
            g.setFileManager(fileManager);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   486
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   487
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
         * 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
   490
         * content before writing.
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
        g.setForce(force);
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
        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
   495
            ((JavahFileManager) fileManager).setSymbolFileEnabled(false);
3996
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
        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   498
        List<String> opts = new ArrayList<>();
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   499
        opts.add("-proc:only");
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   500
        opts.addAll(javac_extras);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36153
diff changeset
   501
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36153
diff changeset
   502
        CompilationTask t;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36153
diff changeset
   503
        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36153
diff changeset
   504
            t = c.getTask(log, fileManager, diagnosticListener, opts, classes, null);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36153
diff changeset
   505
        } catch (IllegalArgumentException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36153
diff changeset
   506
            util.error("bad.arg", e.getMessage());
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36153
diff changeset
   507
            return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36153
diff changeset
   508
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36153
diff changeset
   509
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   510
        JavahProcessor p = new JavahProcessor(g);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   511
        t.setProcessors(Collections.singleton(p));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   512
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   513
        boolean ok = t.call();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   514
        if (p.exit != null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   515
            throw new Util.Exit(p.exit);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   516
        return ok;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   517
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   518
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   519
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   520
    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
   521
        return JavahFileManager.create(dl, log);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   522
    }
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
    private void showHelp() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   525
        log.println(getMessage("main.usage", progname));
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38605
diff changeset
   526
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   527
        for (Option o: recognizedOptions) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   528
            if (o.isHidden())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   529
                continue;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   530
            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
   531
            log.println(getMessage("main.opt." + name));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   532
        }
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38605
diff changeset
   533
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38605
diff changeset
   534
        String[] fmOptions = {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38605
diff changeset
   535
            "--module-path", "--system",
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38605
diff changeset
   536
            "--class-path", "-classpath", "-cp",
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38605
diff changeset
   537
            "-bootclasspath"
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38605
diff changeset
   538
        };
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38605
diff changeset
   539
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   540
        for (String o: fmOptions) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   541
            if (fileManager.isSupportedOption(o) == -1)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   542
                continue;
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38605
diff changeset
   543
            String name = o.replaceAll("^-+", "").replaceAll("-+", "_");
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   544
            log.println(getMessage("main.opt." + name));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   545
        }
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38605
diff changeset
   546
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   547
        log.println(getMessage("main.usage.foot"));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   548
    }
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
    private void showVersion(boolean full) {
6715
9afc72714ca4 6890226: javah -version is broken
jjg
parents: 5847
diff changeset
   551
        log.println(version(full));
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   552
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   553
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   554
    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
   555
    private static ResourceBundle versionRB;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   556
6715
9afc72714ca4 6890226: javah -version is broken
jjg
parents: 5847
diff changeset
   557
    private String version(boolean full) {
9afc72714ca4 6890226: javah -version is broken
jjg
parents: 5847
diff changeset
   558
        String msgKey = (full ? "javah.fullVersion" : "javah.version");
9afc72714ca4 6890226: javah -version is broken
jjg
parents: 5847
diff changeset
   559
        String versionKey = (full ? "full" : "release");
9afc72714ca4 6890226: javah -version is broken
jjg
parents: 5847
diff changeset
   560
        // versionKey=product:  mm.nn.oo[-milestone]
9afc72714ca4 6890226: javah -version is broken
jjg
parents: 5847
diff changeset
   561
        // 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
   562
        if (versionRB == null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   563
            try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   564
                versionRB = ResourceBundle.getBundle(versionRBName);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   565
            } catch (MissingResourceException e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   566
                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
   567
            }
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
        try {
6715
9afc72714ca4 6890226: javah -version is broken
jjg
parents: 5847
diff changeset
   570
            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
   571
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   572
        catch (MissingResourceException e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   573
            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
   574
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   575
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   576
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   577
    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
   578
        return new Diagnostic<JavaFileObject>() {
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   579
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   580
            public Kind getKind() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   581
                return Diagnostic.Kind.ERROR;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   582
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   583
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   584
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   585
            public JavaFileObject getSource() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   586
                return null;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   587
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   588
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   589
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   590
            public long getPosition() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   591
                return Diagnostic.NOPOS;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   592
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   593
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   594
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   595
            public long getStartPosition() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   596
                return Diagnostic.NOPOS;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   597
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   598
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   599
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   600
            public long getEndPosition() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   601
                return Diagnostic.NOPOS;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   602
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   603
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   604
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   605
            public long getLineNumber() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   606
                return Diagnostic.NOPOS;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   607
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   608
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   609
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   610
            public long getColumnNumber() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   611
                return Diagnostic.NOPOS;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   612
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   613
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   614
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   615
            public String getCode() {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   616
                return key;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   617
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   618
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   619
            @DefinedBy(Api.COMPILER)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   620
            public String getMessage(Locale locale) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   621
                return JavahTask.this.getMessage(locale, key, args);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   622
            }
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
        };
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents: 6930
diff changeset
   625
    }
3996
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
    private String getMessage(String key, Object... args) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   628
        return getMessage(task_locale, key, args);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   629
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   630
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   631
    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
   632
        if (bundles == null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   633
            // 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
   634
            // 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
   635
            // locale
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   636
            bundles = new HashMap<>();
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   637
        }
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
        if (locale == null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   640
            locale = Locale.getDefault();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   641
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   642
        ResourceBundle b = bundles.get(locale);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   643
        if (b == null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   644
            try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   645
                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
   646
                bundles.put(locale, b);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   647
            } catch (MissingResourceException e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   648
                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
   649
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   650
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   651
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   652
        try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   653
            return MessageFormat.format(b.getString(key), args);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   654
        } catch (MissingResourceException e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   655
            return key;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   656
            //throw new InternalError(e, key);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   657
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   658
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   659
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   660
    File ofile;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   661
    File odir;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   662
    String bootcp;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   663
    String usercp;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   664
    List<String> classes;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   665
    boolean verbose;
5217
e20e20050405 6937318: jdk7 b86: javah and javah -help is no output for these commands
jjg
parents: 5005
diff changeset
   666
    boolean noArgs;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   667
    boolean help;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   668
    boolean trace;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   669
    boolean version;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   670
    boolean fullVersion;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   671
    boolean jni;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   672
    boolean llni;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   673
    boolean doubleAlign;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   674
    boolean force;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   675
    Set<String> javac_extras = new LinkedHashSet<>();
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   676
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   677
    PrintWriter log;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   678
    JavaFileManager fileManager;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   679
    DiagnosticListener<? super JavaFileObject> diagnosticListener;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   680
    Locale task_locale;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   681
    Map<Locale, ResourceBundle> bundles;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   682
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   683
    private static final String progname = "javah";
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   684
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   685
    @SupportedAnnotationTypes("*")
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   686
    class JavahProcessor extends AbstractProcessor {
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   687
        private Messager messager;
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   688
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   689
        JavahProcessor(Gen g) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   690
            this.g = g;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   691
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   692
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   693
        @Override @DefinedBy(Api.ANNOTATION_PROCESSING)
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   694
        public SourceVersion getSupportedSourceVersion() {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   695
            // 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
   696
            // the latest source version
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   697
            return SourceVersion.latest();
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   698
        }
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   699
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   700
        @Override @DefinedBy(Api.ANNOTATION_PROCESSING)
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   701
        public void init(ProcessingEnvironment pEnv) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   702
            super.init(pEnv);
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   703
            messager  = processingEnv.getMessager();
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   704
        }
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   705
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   706
        @DefinedBy(Api.ANNOTATION_PROCESSING)
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   707
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   708
            try {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   709
                Set<TypeElement> classes = getAllClasses(ElementFilter.typesIn(roundEnv.getRootElements()));
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   710
                if (classes.size() > 0) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   711
                    checkMethodParameters(classes);
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   712
                    g.setProcessingEnvironment(processingEnv);
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   713
                    g.setClasses(classes);
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   714
                    g.run();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   715
                }
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   716
            } catch (CompletionFailure cf) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   717
                messager.printMessage(ERROR, getMessage("class.not.found", cf.sym.getQualifiedName().toString()));
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   718
            } catch (ClassNotFoundException cnfe) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   719
                messager.printMessage(ERROR, getMessage("class.not.found", cnfe.getMessage()));
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   720
            } catch (IOException ioe) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   721
                messager.printMessage(ERROR, getMessage("io.exception", ioe.getMessage()));
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   722
            } catch (Util.Exit e) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   723
                exit = e;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   724
            }
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 6925
diff changeset
   725
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   726
            return true;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   727
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   728
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   729
        private Set<TypeElement> getAllClasses(Set<? extends TypeElement> classes) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18898
diff changeset
   730
            Set<TypeElement> allClasses = new LinkedHashSet<>();
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   731
            getAllClasses0(classes, allClasses);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   732
            return allClasses;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   733
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   734
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   735
        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
   736
            for (TypeElement c: classes) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   737
                allClasses.add(c);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   738
                getAllClasses0(ElementFilter.typesIn(c.getEnclosedElements()), allClasses);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   739
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   740
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   741
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   742
        // 4942232:
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   743
        // 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
   744
        private void checkMethodParameters(Set<TypeElement> classes) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   745
            Types types = processingEnv.getTypeUtils();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   746
            for (TypeElement te: classes) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   747
                for (ExecutableElement ee: ElementFilter.methodsIn(te.getEnclosedElements())) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   748
                    for (VariableElement ve: ee.getParameters()) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   749
                        TypeMirror tm = ve.asType();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   750
                        checkMethodParametersVisitor.visit(tm, types);
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
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   754
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   755
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   756
        private TypeVisitor<Void,Types> checkMethodParametersVisitor =
25690
b1dac768ab79 8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents: 22163
diff changeset
   757
                new SimpleTypeVisitor9<Void,Types>() {
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   758
            @Override @DefinedBy(Api.LANGUAGE_MODEL)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   759
            public Void visitArray(ArrayType t, Types types) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   760
                visit(t.getComponentType(), types);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   761
                return null;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   762
            }
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   763
            @Override @DefinedBy(Api.LANGUAGE_MODEL)
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   764
            public Void visitDeclared(DeclaredType t, Types types) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   765
                t.asElement().getKind(); // ensure class exists
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   766
                for (TypeMirror st: types.directSupertypes(t))
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   767
                    visit(st, types);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   768
                return null;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   769
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   770
        };
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
        private Gen g;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   773
        private Util.Exit exit;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   774
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   775
}