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

Wed, 02 Jun 2010 19:08:47 -0700

author
darcy
date
Wed, 02 Jun 2010 19:08:47 -0700
changeset 575
9a7c998bf2fc
parent 554
9d9f26857129
child 581
f2fdd52e4e87
permissions
-rw-r--r--

6933147: Provided new utility visitors supporting SourceVersion.RELEASE_7
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 2009, Oracle and/or its affiliates. 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.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * 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