src/share/classes/com/sun/tools/javah/JavahTool.java

Wed, 23 Sep 2009 19:15:04 -0700

author
jjg
date
Wed, 23 Sep 2009 19:15:04 -0700
changeset 416
c287d51c57da
child 554
9d9f26857129
permissions
-rw-r--r--

6572945: javah should be written as an annotation processor, not a doclet
Reviewed-by: darcy

     1 /*
     2  * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    26 package com.sun.tools.javah;
    28 import java.io.InputStream;
    29 import java.io.OutputStream;
    30 import java.io.Writer;
    31 import java.nio.charset.Charset;
    32 import java.util.Arrays;
    33 import java.util.EnumSet;
    34 import java.util.Locale;
    35 import java.util.Set;
    36 import javax.lang.model.SourceVersion;
    37 import javax.tools.DiagnosticListener;
    38 import javax.tools.JavaFileManager;
    39 import javax.tools.JavaFileObject;
    40 import javax.tools.StandardJavaFileManager;
    42 /*
    43  * <p><b>This is NOT part of any API supported by Sun Microsystems.
    44  * If you write code that depends on this, you do so at your own
    45  * risk.  This code and its internal interfaces are subject to change
    46  * or deletion without notice.</b></p>
    47  */
    48 public class JavahTool implements NativeHeaderTool {
    50     public NativeHeaderTask getTask(Writer out,
    51             JavaFileManager fileManager,
    52             DiagnosticListener<? super JavaFileObject> diagnosticListener,
    53             Iterable<String> options,
    54             Iterable<String> classes) {
    55         return new JavahTask(out, fileManager, diagnosticListener, options, classes);
    56     }
    58     public StandardJavaFileManager getStandardFileManager(DiagnosticListener<? super JavaFileObject> diagnosticListener, Locale locale, Charset charset) {
    59         return JavahTask.getDefaultFileManager(diagnosticListener, null);
    60     }
    62     public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) {
    63         JavahTask t = new JavahTask(
    64                 JavahTask.getPrintWriterForStream(out),
    65                 null,
    66                 null,
    67                 Arrays.asList(arguments),
    68                 null);
    69         return (t.run() ? 0 : 1);
    70     }
    72     public Set<SourceVersion> getSourceVersions() {
    73         return EnumSet.allOf(SourceVersion.class);
    74     }
    76     public int isSupportedOption(String option) {
    77         JavahTask.Option[] options = JavahTask.recognizedOptions;
    78         for (int i = 0; i < options.length; i++) {
    79             if (options[i].matches(option))
    80                 return (options[i].hasArg ? 1 : 0);
    81         }
    82         return -1;
    83     }
    84 }

mercurial