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