feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
179
jdkSrc/jdk8/javax/tools/Diagnostic.java
Normal file
179
jdkSrc/jdk8/javax/tools/Diagnostic.java
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Interface for diagnostics from tools. A diagnostic usually reports
|
||||
* a problem at a specific position in a source file. However, not
|
||||
* all diagnostics are associated with a position or a file.
|
||||
*
|
||||
* <p>A position is a zero-based character offset from the beginning of
|
||||
* a file. Negative values (except {@link #NOPOS}) are not valid
|
||||
* positions.
|
||||
*
|
||||
* <p>Line and column numbers begin at 1. Negative values (except
|
||||
* {@link #NOPOS}) and 0 are not valid line or column numbers.
|
||||
*
|
||||
* @param <S> the type of source object used by this diagnostic
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @author Jonathan Gibbons
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface Diagnostic<S> {
|
||||
|
||||
/**
|
||||
* Kinds of diagnostics, for example, error or warning.
|
||||
*
|
||||
* The kind of a diagnostic can be used to determine how the
|
||||
* diagnostic should be presented to the user. For example,
|
||||
* errors might be colored red or prefixed with the word "Error",
|
||||
* while warnings might be colored yellow or prefixed with the
|
||||
* word "Warning". There is no requirement that the Kind
|
||||
* should imply any inherent semantic meaning to the message
|
||||
* of the diagnostic: for example, a tool might provide an
|
||||
* option to report all warnings as errors.
|
||||
*/
|
||||
enum Kind {
|
||||
/**
|
||||
* Problem which prevents the tool's normal completion.
|
||||
*/
|
||||
ERROR,
|
||||
/**
|
||||
* Problem which does not usually prevent the tool from
|
||||
* completing normally.
|
||||
*/
|
||||
WARNING,
|
||||
/**
|
||||
* Problem similar to a warning, but is mandated by the tool's
|
||||
* specification. For example, the Java™ Language
|
||||
* Specification mandates warnings on certain
|
||||
* unchecked operations and the use of deprecated methods.
|
||||
*/
|
||||
MANDATORY_WARNING,
|
||||
/**
|
||||
* Informative message from the tool.
|
||||
*/
|
||||
NOTE,
|
||||
/**
|
||||
* Diagnostic which does not fit within the other kinds.
|
||||
*/
|
||||
OTHER,
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to signal that no position is available.
|
||||
*/
|
||||
public final static long NOPOS = -1;
|
||||
|
||||
/**
|
||||
* Gets the kind of this diagnostic, for example, error or
|
||||
* warning.
|
||||
* @return the kind of this diagnostic
|
||||
*/
|
||||
Kind getKind();
|
||||
|
||||
/**
|
||||
* Gets the source object associated with this diagnostic.
|
||||
*
|
||||
* @return the source object associated with this diagnostic.
|
||||
* {@code null} if no source object is associated with the
|
||||
* diagnostic.
|
||||
*/
|
||||
S getSource();
|
||||
|
||||
/**
|
||||
* Gets a character offset from the beginning of the source object
|
||||
* associated with this diagnostic that indicates the location of
|
||||
* the problem. In addition, the following must be true:
|
||||
*
|
||||
* <p>{@code getStartPostion() <= getPosition()}
|
||||
* <p>{@code getPosition() <= getEndPosition()}
|
||||
*
|
||||
* @return character offset from beginning of source; {@link
|
||||
* #NOPOS} if {@link #getSource()} would return {@code null} or if
|
||||
* no location is suitable
|
||||
*/
|
||||
long getPosition();
|
||||
|
||||
/**
|
||||
* Gets the character offset from the beginning of the file
|
||||
* associated with this diagnostic that indicates the start of the
|
||||
* problem.
|
||||
*
|
||||
* @return offset from beginning of file; {@link #NOPOS} if and
|
||||
* only if {@link #getPosition()} returns {@link #NOPOS}
|
||||
*/
|
||||
long getStartPosition();
|
||||
|
||||
/**
|
||||
* Gets the character offset from the beginning of the file
|
||||
* associated with this diagnostic that indicates the end of the
|
||||
* problem.
|
||||
*
|
||||
* @return offset from beginning of file; {@link #NOPOS} if and
|
||||
* only if {@link #getPosition()} returns {@link #NOPOS}
|
||||
*/
|
||||
long getEndPosition();
|
||||
|
||||
/**
|
||||
* Gets the line number of the character offset returned by
|
||||
* {@linkplain #getPosition()}.
|
||||
*
|
||||
* @return a line number or {@link #NOPOS} if and only if {@link
|
||||
* #getPosition()} returns {@link #NOPOS}
|
||||
*/
|
||||
long getLineNumber();
|
||||
|
||||
/**
|
||||
* Gets the column number of the character offset returned by
|
||||
* {@linkplain #getPosition()}.
|
||||
*
|
||||
* @return a column number or {@link #NOPOS} if and only if {@link
|
||||
* #getPosition()} returns {@link #NOPOS}
|
||||
*/
|
||||
long getColumnNumber();
|
||||
|
||||
/**
|
||||
* Gets a diagnostic code indicating the type of diagnostic. The
|
||||
* code is implementation-dependent and might be {@code null}.
|
||||
*
|
||||
* @return a diagnostic code
|
||||
*/
|
||||
String getCode();
|
||||
|
||||
/**
|
||||
* Gets a localized message for the given locale. The actual
|
||||
* message is implementation-dependent. If the locale is {@code
|
||||
* null} use the default locale.
|
||||
*
|
||||
* @param locale a locale; might be {@code null}
|
||||
* @return a localized message
|
||||
*/
|
||||
String getMessage(Locale locale);
|
||||
}
|
||||
58
jdkSrc/jdk8/javax/tools/DiagnosticCollector.java
Normal file
58
jdkSrc/jdk8/javax/tools/DiagnosticCollector.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides an easy way to collect diagnostics in a list.
|
||||
*
|
||||
* @param <S> the type of source objects used by diagnostics received
|
||||
* by this object
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @since 1.6
|
||||
*/
|
||||
public final class DiagnosticCollector<S> implements DiagnosticListener<S> {
|
||||
private List<Diagnostic<? extends S>> diagnostics =
|
||||
Collections.synchronizedList(new ArrayList<Diagnostic<? extends S>>());
|
||||
|
||||
public void report(Diagnostic<? extends S> diagnostic) {
|
||||
diagnostic.getClass(); // null check
|
||||
diagnostics.add(diagnostic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list view of diagnostics collected by this object.
|
||||
*
|
||||
* @return a list view of diagnostics
|
||||
*/
|
||||
public List<Diagnostic<? extends S>> getDiagnostics() {
|
||||
return Collections.unmodifiableList(diagnostics);
|
||||
}
|
||||
}
|
||||
49
jdkSrc/jdk8/javax/tools/DiagnosticListener.java
Normal file
49
jdkSrc/jdk8/javax/tools/DiagnosticListener.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
/**
|
||||
* Interface for receiving diagnostics from tools.
|
||||
*
|
||||
* @param <S> the type of source objects used by diagnostics received
|
||||
* by this listener
|
||||
*
|
||||
* @author Jonathan Gibbons
|
||||
* @author Peter von der Ahé
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface DiagnosticListener<S> {
|
||||
/**
|
||||
* Invoked when a problem is found.
|
||||
*
|
||||
* @param diagnostic a diagnostic representing the problem that
|
||||
* was found
|
||||
* @throws NullPointerException if the diagnostic argument is
|
||||
* {@code null} and the implementation cannot handle {@code null}
|
||||
* arguments
|
||||
*/
|
||||
void report(Diagnostic<? extends S> diagnostic);
|
||||
}
|
||||
183
jdkSrc/jdk8/javax/tools/DocumentationTool.java
Normal file
183
jdkSrc/jdk8/javax/tools/DocumentationTool.java
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package javax.tools;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Interface to invoke Java™ programming language documentation tools from
|
||||
* programs.
|
||||
*/
|
||||
public interface DocumentationTool extends Tool, OptionChecker {
|
||||
/**
|
||||
* Creates a future for a documentation task with the given
|
||||
* components and arguments. The task might not have
|
||||
* completed as described in the DocumentationTask interface.
|
||||
*
|
||||
* <p>If a file manager is provided, it must be able to handle all
|
||||
* locations defined in {@link DocumentationTool.Location},
|
||||
* as well as
|
||||
* {@link StandardLocation#SOURCE_PATH},
|
||||
* {@link StandardLocation#CLASS_PATH}, and
|
||||
* {@link StandardLocation#PLATFORM_CLASS_PATH}.
|
||||
*
|
||||
* @param out a Writer for additional output from the tool;
|
||||
* use {@code System.err} if {@code null}
|
||||
*
|
||||
* @param fileManager a file manager; if {@code null} use the
|
||||
* tool's standard filemanager
|
||||
*
|
||||
* @param diagnosticListener a diagnostic listener; if {@code null}
|
||||
* use the tool's default method for reporting diagnostics
|
||||
*
|
||||
* @param docletClass a class providing the necessary methods required
|
||||
* of a doclet
|
||||
*
|
||||
* @param options documentation tool options and doclet options,
|
||||
* {@code null} means no options
|
||||
*
|
||||
* @param compilationUnits the compilation units to compile, {@code
|
||||
* null} means no compilation units
|
||||
*
|
||||
* @return an object representing the compilation
|
||||
*
|
||||
* @throws RuntimeException if an unrecoverable error
|
||||
* occurred in a user supplied component. The
|
||||
* {@linkplain Throwable#getCause() cause} will be the error in
|
||||
* user code.
|
||||
*
|
||||
* @throws IllegalArgumentException if any of the given
|
||||
* compilation units are of other kind than
|
||||
* {@linkplain JavaFileObject.Kind#SOURCE source}
|
||||
*/
|
||||
DocumentationTask getTask(Writer out,
|
||||
JavaFileManager fileManager,
|
||||
DiagnosticListener<? super JavaFileObject> diagnosticListener,
|
||||
Class<?> docletClass,
|
||||
Iterable<String> options,
|
||||
Iterable<? extends JavaFileObject> compilationUnits);
|
||||
|
||||
/**
|
||||
* Gets a new instance of the standard file manager implementation
|
||||
* for this tool. The file manager will use the given diagnostic
|
||||
* listener for producing any non-fatal diagnostics. Fatal errors
|
||||
* will be signaled with the appropriate exceptions.
|
||||
*
|
||||
* <p>The standard file manager will be automatically reopened if
|
||||
* it is accessed after calls to {@code flush} or {@code close}.
|
||||
* The standard file manager must be usable with other tools.
|
||||
*
|
||||
* @param diagnosticListener a diagnostic listener for non-fatal
|
||||
* diagnostics; if {@code null} use the compiler's default method
|
||||
* for reporting diagnostics
|
||||
*
|
||||
* @param locale the locale to apply when formatting diagnostics;
|
||||
* {@code null} means the {@linkplain Locale#getDefault() default locale}.
|
||||
*
|
||||
* @param charset the character set used for decoding bytes; if
|
||||
* {@code null} use the platform default
|
||||
*
|
||||
* @return the standard file manager
|
||||
*/
|
||||
StandardJavaFileManager getStandardFileManager(
|
||||
DiagnosticListener<? super JavaFileObject> diagnosticListener,
|
||||
Locale locale,
|
||||
Charset charset);
|
||||
|
||||
/**
|
||||
* Interface representing a future for a documentation task. The
|
||||
* task has not yet started. To start the task, call
|
||||
* the {@linkplain #call call} method.
|
||||
*
|
||||
* <p>Before calling the call method, additional aspects of the
|
||||
* task can be configured, for example, by calling the
|
||||
* {@linkplain #setLocale setLocale} method.
|
||||
*/
|
||||
interface DocumentationTask extends Callable<Boolean> {
|
||||
/**
|
||||
* Set the locale to be applied when formatting diagnostics and
|
||||
* other localized data.
|
||||
*
|
||||
* @param locale the locale to apply; {@code null} means apply no
|
||||
* locale
|
||||
* @throws IllegalStateException if the task has started
|
||||
*/
|
||||
void setLocale(Locale locale);
|
||||
|
||||
/**
|
||||
* Performs this documentation task. The task may only
|
||||
* be performed once. Subsequent calls to this method throw
|
||||
* IllegalStateException.
|
||||
*
|
||||
* @return true if and only all the files were processed without errors;
|
||||
* false otherwise
|
||||
*
|
||||
* @throws RuntimeException if an unrecoverable error occurred
|
||||
* in a user-supplied component. The
|
||||
* {@linkplain Throwable#getCause() cause} will be the error
|
||||
* in user code.
|
||||
*
|
||||
* @throws IllegalStateException if called more than once
|
||||
*/
|
||||
Boolean call();
|
||||
}
|
||||
|
||||
/**
|
||||
* Locations specific to {@link DocumentationTool}.
|
||||
*
|
||||
* @see StandardLocation
|
||||
*/
|
||||
enum Location implements JavaFileManager.Location {
|
||||
/**
|
||||
* Location of new documentation files.
|
||||
*/
|
||||
DOCUMENTATION_OUTPUT,
|
||||
|
||||
/**
|
||||
* Location to search for doclets.
|
||||
*/
|
||||
DOCLET_PATH,
|
||||
|
||||
/**
|
||||
* Location to search for taglets.
|
||||
*/
|
||||
TAGLET_PATH;
|
||||
|
||||
public String getName() { return name(); }
|
||||
|
||||
public boolean isOutputLocation() {
|
||||
switch (this) {
|
||||
case DOCUMENTATION_OUTPUT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
159
jdkSrc/jdk8/javax/tools/FileObject.java
Normal file
159
jdkSrc/jdk8/javax/tools/FileObject.java
Normal file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* File abstraction for tools. In this context, <em>file</em> means
|
||||
* an abstraction of regular files and other sources of data. For
|
||||
* example, a file object can be used to represent regular files,
|
||||
* memory cache, or data in databases.
|
||||
*
|
||||
* <p>All methods in this interface might throw a SecurityException if
|
||||
* a security exception occurs.
|
||||
*
|
||||
* <p>Unless explicitly allowed, all methods in this interface might
|
||||
* throw a NullPointerException if given a {@code null} argument.
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @author Jonathan Gibbons
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface FileObject {
|
||||
|
||||
/**
|
||||
* Returns a URI identifying this file object.
|
||||
* @return a URI
|
||||
*/
|
||||
URI toUri();
|
||||
|
||||
/**
|
||||
* Gets a user-friendly name for this file object. The exact
|
||||
* value returned is not specified but implementations should take
|
||||
* care to preserve names as given by the user. For example, if
|
||||
* the user writes the filename {@code "BobsApp\Test.java"} on
|
||||
* the command line, this method should return {@code
|
||||
* "BobsApp\Test.java"} whereas the {@linkplain #toUri toUri}
|
||||
* method might return {@code
|
||||
* file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java}.
|
||||
*
|
||||
* @return a user-friendly name
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets an InputStream for this file object.
|
||||
*
|
||||
* @return an InputStream
|
||||
* @throws IllegalStateException if this file object was
|
||||
* opened for writing and does not support reading
|
||||
* @throws UnsupportedOperationException if this kind of file
|
||||
* object does not support byte access
|
||||
* @throws IOException if an I/O error occurred
|
||||
*/
|
||||
InputStream openInputStream() throws IOException;
|
||||
|
||||
/**
|
||||
* Gets an OutputStream for this file object.
|
||||
*
|
||||
* @return an OutputStream
|
||||
* @throws IllegalStateException if this file object was
|
||||
* opened for reading and does not support writing
|
||||
* @throws UnsupportedOperationException if this kind of
|
||||
* file object does not support byte access
|
||||
* @throws IOException if an I/O error occurred
|
||||
*/
|
||||
OutputStream openOutputStream() throws IOException;
|
||||
|
||||
/**
|
||||
* Gets a reader for this object. The returned reader will
|
||||
* replace bytes that cannot be decoded with the default
|
||||
* translation character. In addition, the reader may report a
|
||||
* diagnostic unless {@code ignoreEncodingErrors} is true.
|
||||
*
|
||||
* @param ignoreEncodingErrors ignore encoding errors if true
|
||||
* @return a Reader
|
||||
* @throws IllegalStateException if this file object was
|
||||
* opened for writing and does not support reading
|
||||
* @throws UnsupportedOperationException if this kind of
|
||||
* file object does not support character access
|
||||
* @throws IOException if an I/O error occurred
|
||||
*/
|
||||
Reader openReader(boolean ignoreEncodingErrors) throws IOException;
|
||||
|
||||
/**
|
||||
* Gets the character content of this file object, if available.
|
||||
* Any byte that cannot be decoded will be replaced by the default
|
||||
* translation character. In addition, a diagnostic may be
|
||||
* reported unless {@code ignoreEncodingErrors} is true.
|
||||
*
|
||||
* @param ignoreEncodingErrors ignore encoding errors if true
|
||||
* @return a CharSequence if available; {@code null} otherwise
|
||||
* @throws IllegalStateException if this file object was
|
||||
* opened for writing and does not support reading
|
||||
* @throws UnsupportedOperationException if this kind of
|
||||
* file object does not support character access
|
||||
* @throws IOException if an I/O error occurred
|
||||
*/
|
||||
CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException;
|
||||
|
||||
/**
|
||||
* Gets a Writer for this file object.
|
||||
*
|
||||
* @return a Writer
|
||||
* @throws IllegalStateException if this file object was
|
||||
* opened for reading and does not support writing
|
||||
* @throws UnsupportedOperationException if this kind of
|
||||
* file object does not support character access
|
||||
* @throws IOException if an I/O error occurred
|
||||
*/
|
||||
Writer openWriter() throws IOException;
|
||||
|
||||
/**
|
||||
* Gets the time this file object was last modified. The time is
|
||||
* measured in milliseconds since the epoch (00:00:00 GMT, January
|
||||
* 1, 1970).
|
||||
*
|
||||
* @return the time this file object was last modified; or 0 if
|
||||
* the file object does not exist, if an I/O error occurred, or if
|
||||
* the operation is not supported
|
||||
*/
|
||||
long getLastModified();
|
||||
|
||||
/**
|
||||
* Deletes this file object. In case of errors, returns false.
|
||||
* @return true if and only if this file object is successfully
|
||||
* deleted; false otherwise
|
||||
*/
|
||||
boolean delete();
|
||||
|
||||
}
|
||||
120
jdkSrc/jdk8/javax/tools/ForwardingFileObject.java
Normal file
120
jdkSrc/jdk8/javax/tools/ForwardingFileObject.java
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* Forwards calls to a given file object. Subclasses of this class
|
||||
* might override some of these methods and might also provide
|
||||
* additional fields and methods.
|
||||
*
|
||||
* @param <F> the kind of file object forwarded to by this object
|
||||
* @author Peter von der Ahé
|
||||
* @since 1.6
|
||||
*/
|
||||
public class ForwardingFileObject<F extends FileObject> implements FileObject {
|
||||
|
||||
/**
|
||||
* The file object which all methods are delegated to.
|
||||
*/
|
||||
protected final F fileObject;
|
||||
|
||||
/**
|
||||
* Creates a new instance of ForwardingFileObject.
|
||||
* @param fileObject delegate to this file object
|
||||
*/
|
||||
protected ForwardingFileObject(F fileObject) {
|
||||
fileObject.getClass(); // null check
|
||||
this.fileObject = fileObject;
|
||||
}
|
||||
|
||||
public URI toUri() {
|
||||
return fileObject.toUri();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return fileObject.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
* @throws UnsupportedOperationException {@inheritDoc}
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
public InputStream openInputStream() throws IOException {
|
||||
return fileObject.openInputStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
* @throws UnsupportedOperationException {@inheritDoc}
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
public OutputStream openOutputStream() throws IOException {
|
||||
return fileObject.openOutputStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
* @throws UnsupportedOperationException {@inheritDoc}
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
|
||||
return fileObject.openReader(ignoreEncodingErrors);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
* @throws UnsupportedOperationException {@inheritDoc}
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
|
||||
return fileObject.getCharContent(ignoreEncodingErrors);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
* @throws UnsupportedOperationException {@inheritDoc}
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
public Writer openWriter() throws IOException {
|
||||
return fileObject.openWriter();
|
||||
}
|
||||
|
||||
public long getLastModified() {
|
||||
return fileObject.getLastModified();
|
||||
}
|
||||
|
||||
public boolean delete() {
|
||||
return fileObject.delete();
|
||||
}
|
||||
}
|
||||
166
jdkSrc/jdk8/javax/tools/ForwardingJavaFileManager.java
Normal file
166
jdkSrc/jdk8/javax/tools/ForwardingJavaFileManager.java
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import javax.tools.JavaFileObject.Kind;
|
||||
|
||||
/**
|
||||
* Forwards calls to a given file manager. Subclasses of this class
|
||||
* might override some of these methods and might also provide
|
||||
* additional fields and methods.
|
||||
*
|
||||
* @param <M> the kind of file manager forwarded to by this object
|
||||
* @author Peter von der Ahé
|
||||
* @since 1.6
|
||||
*/
|
||||
public class ForwardingJavaFileManager<M extends JavaFileManager> implements JavaFileManager {
|
||||
|
||||
/**
|
||||
* The file manager which all methods are delegated to.
|
||||
*/
|
||||
protected final M fileManager;
|
||||
|
||||
/**
|
||||
* Creates a new instance of ForwardingJavaFileManager.
|
||||
* @param fileManager delegate to this file manager
|
||||
*/
|
||||
protected ForwardingJavaFileManager(M fileManager) {
|
||||
fileManager.getClass(); // null check
|
||||
this.fileManager = fileManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SecurityException {@inheritDoc}
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
*/
|
||||
public ClassLoader getClassLoader(Location location) {
|
||||
return fileManager.getClassLoader(location);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IOException {@inheritDoc}
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
*/
|
||||
public Iterable<JavaFileObject> list(Location location,
|
||||
String packageName,
|
||||
Set<Kind> kinds,
|
||||
boolean recurse)
|
||||
throws IOException
|
||||
{
|
||||
return fileManager.list(location, packageName, kinds, recurse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
*/
|
||||
public String inferBinaryName(Location location, JavaFileObject file) {
|
||||
return fileManager.inferBinaryName(location, file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
public boolean isSameFile(FileObject a, FileObject b) {
|
||||
return fileManager.isSameFile(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
*/
|
||||
public boolean handleOption(String current, Iterator<String> remaining) {
|
||||
return fileManager.handleOption(current, remaining);
|
||||
}
|
||||
|
||||
public boolean hasLocation(Location location) {
|
||||
return fileManager.hasLocation(location);
|
||||
}
|
||||
|
||||
public int isSupportedOption(String option) {
|
||||
return fileManager.isSupportedOption(option);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
*/
|
||||
public JavaFileObject getJavaFileForInput(Location location,
|
||||
String className,
|
||||
Kind kind)
|
||||
throws IOException
|
||||
{
|
||||
return fileManager.getJavaFileForInput(location, className, kind);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
*/
|
||||
public JavaFileObject getJavaFileForOutput(Location location,
|
||||
String className,
|
||||
Kind kind,
|
||||
FileObject sibling)
|
||||
throws IOException
|
||||
{
|
||||
return fileManager.getJavaFileForOutput(location, className, kind, sibling);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
*/
|
||||
public FileObject getFileForInput(Location location,
|
||||
String packageName,
|
||||
String relativeName)
|
||||
throws IOException
|
||||
{
|
||||
return fileManager.getFileForInput(location, packageName, relativeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
*/
|
||||
public FileObject getFileForOutput(Location location,
|
||||
String packageName,
|
||||
String relativeName,
|
||||
FileObject sibling)
|
||||
throws IOException
|
||||
{
|
||||
return fileManager.getFileForOutput(location, packageName, relativeName, sibling);
|
||||
}
|
||||
|
||||
public void flush() throws IOException {
|
||||
fileManager.flush();
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
fileManager.close();
|
||||
}
|
||||
}
|
||||
65
jdkSrc/jdk8/javax/tools/ForwardingJavaFileObject.java
Normal file
65
jdkSrc/jdk8/javax/tools/ForwardingJavaFileObject.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
import javax.lang.model.element.Modifier;
|
||||
import javax.lang.model.element.NestingKind;
|
||||
|
||||
/**
|
||||
* Forwards calls to a given file object. Subclasses of this class
|
||||
* might override some of these methods and might also provide
|
||||
* additional fields and methods.
|
||||
*
|
||||
* @param <F> the kind of file object forwarded to by this object
|
||||
* @author Peter von der Ahé
|
||||
* @since 1.6
|
||||
*/
|
||||
public class ForwardingJavaFileObject<F extends JavaFileObject>
|
||||
extends ForwardingFileObject<F>
|
||||
implements JavaFileObject
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates a new instance of ForwardingJavaFileObject.
|
||||
* @param fileObject delegate to this file object
|
||||
*/
|
||||
protected ForwardingJavaFileObject(F fileObject) {
|
||||
super(fileObject);
|
||||
}
|
||||
|
||||
public Kind getKind() {
|
||||
return fileObject.getKind();
|
||||
}
|
||||
|
||||
public boolean isNameCompatible(String simpleName, Kind kind) {
|
||||
return fileObject.isNameCompatible(simpleName, kind);
|
||||
}
|
||||
|
||||
public NestingKind getNestingKind() { return fileObject.getNestingKind(); }
|
||||
|
||||
public Modifier getAccessLevel() { return fileObject.getAccessLevel(); }
|
||||
|
||||
}
|
||||
335
jdkSrc/jdk8/javax/tools/JavaCompiler.java
Normal file
335
jdkSrc/jdk8/javax/tools/JavaCompiler.java
Normal file
@@ -0,0 +1,335 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Callable;
|
||||
import javax.annotation.processing.Processor;
|
||||
|
||||
/**
|
||||
* Interface to invoke Java™ programming language compilers from
|
||||
* programs.
|
||||
*
|
||||
* <p>The compiler might generate diagnostics during compilation (for
|
||||
* example, error messages). If a diagnostic listener is provided,
|
||||
* the diagnostics will be supplied to the listener. If no listener
|
||||
* is provided, the diagnostics will be formatted in an unspecified
|
||||
* format and written to the default output, which is {@code
|
||||
* System.err} unless otherwise specified. Even if a diagnostic
|
||||
* listener is supplied, some diagnostics might not fit in a {@code
|
||||
* Diagnostic} and will be written to the default output.
|
||||
*
|
||||
* <p>A compiler tool has an associated standard file manager, which
|
||||
* is the file manager that is native to the tool (or built-in). The
|
||||
* standard file manager can be obtained by calling {@linkplain
|
||||
* #getStandardFileManager getStandardFileManager}.
|
||||
*
|
||||
* <p>A compiler tool must function with any file manager as long as
|
||||
* any additional requirements as detailed in the methods below are
|
||||
* met. If no file manager is provided, the compiler tool will use a
|
||||
* standard file manager such as the one returned by {@linkplain
|
||||
* #getStandardFileManager getStandardFileManager}.
|
||||
*
|
||||
* <p>An instance implementing this interface must conform to
|
||||
* <cite>The Java™ Language Specification</cite>
|
||||
* and generate class files conforming to
|
||||
* <cite>The Java™ Virtual Machine Specification</cite>.
|
||||
* The versions of these
|
||||
* specifications are defined in the {@linkplain Tool} interface.
|
||||
*
|
||||
* Additionally, an instance of this interface supporting {@link
|
||||
* javax.lang.model.SourceVersion#RELEASE_6 SourceVersion.RELEASE_6}
|
||||
* or higher must also support {@linkplain javax.annotation.processing
|
||||
* annotation processing}.
|
||||
*
|
||||
* <p>The compiler relies on two services: {@linkplain
|
||||
* DiagnosticListener diagnostic listener} and {@linkplain
|
||||
* JavaFileManager file manager}. Although most classes and
|
||||
* interfaces in this package defines an API for compilers (and
|
||||
* tools in general) the interfaces {@linkplain DiagnosticListener},
|
||||
* {@linkplain JavaFileManager}, {@linkplain FileObject}, and
|
||||
* {@linkplain JavaFileObject} are not intended to be used in
|
||||
* applications. Instead these interfaces are intended to be
|
||||
* implemented and used to provide customized services for a
|
||||
* compiler and thus defines an SPI for compilers.
|
||||
*
|
||||
* <p>There are a number of classes and interfaces in this package
|
||||
* which are designed to ease the implementation of the SPI to
|
||||
* customize the behavior of a compiler:
|
||||
*
|
||||
* <dl>
|
||||
* <dt>{@link StandardJavaFileManager}</dt>
|
||||
* <dd>
|
||||
*
|
||||
* Every compiler which implements this interface provides a
|
||||
* standard file manager for operating on regular {@linkplain
|
||||
* java.io.File files}. The StandardJavaFileManager interface
|
||||
* defines additional methods for creating file objects from
|
||||
* regular files.
|
||||
*
|
||||
* <p>The standard file manager serves two purposes:
|
||||
*
|
||||
* <ul>
|
||||
* <li>basic building block for customizing how a compiler reads
|
||||
* and writes files</li>
|
||||
* <li>sharing between multiple compilation tasks</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>Reusing a file manager can potentially reduce overhead of
|
||||
* scanning the file system and reading jar files. Although there
|
||||
* might be no reduction in overhead, a standard file manager must
|
||||
* work with multiple sequential compilations making the following
|
||||
* example a recommended coding pattern:
|
||||
*
|
||||
* <pre>
|
||||
* File[] files1 = ... ; // input for first compilation task
|
||||
* File[] files2 = ... ; // input for second compilation task
|
||||
*
|
||||
* JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
* StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
|
||||
*
|
||||
* {@code Iterable<? extends JavaFileObject>} compilationUnits1 =
|
||||
* fileManager.getJavaFileObjectsFromFiles({@linkplain java.util.Arrays#asList Arrays.asList}(files1));
|
||||
* compiler.getTask(null, fileManager, null, null, null, compilationUnits1).call();
|
||||
*
|
||||
* {@code Iterable<? extends JavaFileObject>} compilationUnits2 =
|
||||
* fileManager.getJavaFileObjects(files2); // use alternative method
|
||||
* // reuse the same file manager to allow caching of jar files
|
||||
* compiler.getTask(null, fileManager, null, null, null, compilationUnits2).call();
|
||||
*
|
||||
* fileManager.close();</pre>
|
||||
*
|
||||
* </dd>
|
||||
*
|
||||
* <dt>{@link DiagnosticCollector}</dt>
|
||||
* <dd>
|
||||
* Used to collect diagnostics in a list, for example:
|
||||
* <pre>
|
||||
* {@code Iterable<? extends JavaFileObject>} compilationUnits = ...;
|
||||
* JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
* {@code DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();}
|
||||
* StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
|
||||
* compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits).call();
|
||||
*
|
||||
* for ({@code Diagnostic<? extends JavaFileObject>} diagnostic : diagnostics.getDiagnostics())
|
||||
* System.out.format("Error on line %d in %s%n",
|
||||
* diagnostic.getLineNumber(),
|
||||
* diagnostic.getSource().toUri());
|
||||
*
|
||||
* fileManager.close();</pre>
|
||||
* </dd>
|
||||
*
|
||||
* <dt>
|
||||
* {@link ForwardingJavaFileManager}, {@link ForwardingFileObject}, and
|
||||
* {@link ForwardingJavaFileObject}
|
||||
* </dt>
|
||||
* <dd>
|
||||
*
|
||||
* Subclassing is not available for overriding the behavior of a
|
||||
* standard file manager as it is created by calling a method on a
|
||||
* compiler, not by invoking a constructor. Instead forwarding
|
||||
* (or delegation) should be used. These classes makes it easy to
|
||||
* forward most calls to a given file manager or file object while
|
||||
* allowing customizing behavior. For example, consider how to
|
||||
* log all calls to {@linkplain JavaFileManager#flush}:
|
||||
*
|
||||
* <pre>
|
||||
* final {@linkplain java.util.logging.Logger Logger} logger = ...;
|
||||
* {@code Iterable<? extends JavaFileObject>} compilationUnits = ...;
|
||||
* JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
* StandardJavaFileManager stdFileManager = compiler.getStandardFileManager(null, null, null);
|
||||
* JavaFileManager fileManager = new ForwardingJavaFileManager(stdFileManager) {
|
||||
* public void flush() throws IOException {
|
||||
* logger.entering(StandardJavaFileManager.class.getName(), "flush");
|
||||
* super.flush();
|
||||
* logger.exiting(StandardJavaFileManager.class.getName(), "flush");
|
||||
* }
|
||||
* };
|
||||
* compiler.getTask(null, fileManager, null, null, null, compilationUnits).call();</pre>
|
||||
* </dd>
|
||||
*
|
||||
* <dt>{@link SimpleJavaFileObject}</dt>
|
||||
* <dd>
|
||||
*
|
||||
* This class provides a basic file object implementation which
|
||||
* can be used as building block for creating file objects. For
|
||||
* example, here is how to define a file object which represent
|
||||
* source code stored in a string:
|
||||
*
|
||||
* <pre>
|
||||
* /**
|
||||
* * A file object used to represent source coming from a string.
|
||||
* {@code *}/
|
||||
* public class JavaSourceFromString extends SimpleJavaFileObject {
|
||||
* /**
|
||||
* * The source code of this "file".
|
||||
* {@code *}/
|
||||
* final String code;
|
||||
*
|
||||
* /**
|
||||
* * Constructs a new JavaSourceFromString.
|
||||
* * {@code @}param name the name of the compilation unit represented by this file object
|
||||
* * {@code @}param code the source code for the compilation unit represented by this file object
|
||||
* {@code *}/
|
||||
* JavaSourceFromString(String name, String code) {
|
||||
* super({@linkplain java.net.URI#create URI.create}("string:///" + name.replace('.','/') + Kind.SOURCE.extension),
|
||||
* Kind.SOURCE);
|
||||
* this.code = code;
|
||||
* }
|
||||
*
|
||||
* {@code @}Override
|
||||
* public CharSequence getCharContent(boolean ignoreEncodingErrors) {
|
||||
* return code;
|
||||
* }
|
||||
* }</pre>
|
||||
* </dd>
|
||||
* </dl>
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @author Jonathan Gibbons
|
||||
* @see DiagnosticListener
|
||||
* @see Diagnostic
|
||||
* @see JavaFileManager
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface JavaCompiler extends Tool, OptionChecker {
|
||||
|
||||
/**
|
||||
* Creates a future for a compilation task with the given
|
||||
* components and arguments. The compilation might not have
|
||||
* completed as described in the CompilationTask interface.
|
||||
*
|
||||
* <p>If a file manager is provided, it must be able to handle all
|
||||
* locations defined in {@link StandardLocation}.
|
||||
*
|
||||
* <p>Note that annotation processing can process both the
|
||||
* compilation units of source code to be compiled, passed with
|
||||
* the {@code compilationUnits} parameter, as well as class
|
||||
* files, whose names are passed with the {@code classes}
|
||||
* parameter.
|
||||
*
|
||||
* @param out a Writer for additional output from the compiler;
|
||||
* use {@code System.err} if {@code null}
|
||||
* @param fileManager a file manager; if {@code null} use the
|
||||
* compiler's standard filemanager
|
||||
* @param diagnosticListener a diagnostic listener; if {@code
|
||||
* null} use the compiler's default method for reporting
|
||||
* diagnostics
|
||||
* @param options compiler options, {@code null} means no options
|
||||
* @param classes names of classes to be processed by annotation
|
||||
* processing, {@code null} means no class names
|
||||
* @param compilationUnits the compilation units to compile, {@code
|
||||
* null} means no compilation units
|
||||
* @return an object representing the compilation
|
||||
* @throws RuntimeException if an unrecoverable error
|
||||
* occurred in a user supplied component. The
|
||||
* {@linkplain Throwable#getCause() cause} will be the error in
|
||||
* user code.
|
||||
* @throws IllegalArgumentException if any of the options are invalid,
|
||||
* or if any of the given compilation units are of other kind than
|
||||
* {@linkplain JavaFileObject.Kind#SOURCE source}
|
||||
*/
|
||||
CompilationTask getTask(Writer out,
|
||||
JavaFileManager fileManager,
|
||||
DiagnosticListener<? super JavaFileObject> diagnosticListener,
|
||||
Iterable<String> options,
|
||||
Iterable<String> classes,
|
||||
Iterable<? extends JavaFileObject> compilationUnits);
|
||||
|
||||
/**
|
||||
* Gets a new instance of the standard file manager implementation
|
||||
* for this tool. The file manager will use the given diagnostic
|
||||
* listener for producing any non-fatal diagnostics. Fatal errors
|
||||
* will be signaled with the appropriate exceptions.
|
||||
*
|
||||
* <p>The standard file manager will be automatically reopened if
|
||||
* it is accessed after calls to {@code flush} or {@code close}.
|
||||
* The standard file manager must be usable with other tools.
|
||||
*
|
||||
* @param diagnosticListener a diagnostic listener for non-fatal
|
||||
* diagnostics; if {@code null} use the compiler's default method
|
||||
* for reporting diagnostics
|
||||
* @param locale the locale to apply when formatting diagnostics;
|
||||
* {@code null} means the {@linkplain Locale#getDefault() default locale}.
|
||||
* @param charset the character set used for decoding bytes; if
|
||||
* {@code null} use the platform default
|
||||
* @return the standard file manager
|
||||
*/
|
||||
StandardJavaFileManager getStandardFileManager(
|
||||
DiagnosticListener<? super JavaFileObject> diagnosticListener,
|
||||
Locale locale,
|
||||
Charset charset);
|
||||
|
||||
/**
|
||||
* Interface representing a future for a compilation task. The
|
||||
* compilation task has not yet started. To start the task, call
|
||||
* the {@linkplain #call call} method.
|
||||
*
|
||||
* <p>Before calling the call method, additional aspects of the
|
||||
* task can be configured, for example, by calling the
|
||||
* {@linkplain #setProcessors setProcessors} method.
|
||||
*/
|
||||
interface CompilationTask extends Callable<Boolean> {
|
||||
|
||||
/**
|
||||
* Sets processors (for annotation processing). This will
|
||||
* bypass the normal discovery mechanism.
|
||||
*
|
||||
* @param processors processors (for annotation processing)
|
||||
* @throws IllegalStateException if the task has started
|
||||
*/
|
||||
void setProcessors(Iterable<? extends Processor> processors);
|
||||
|
||||
/**
|
||||
* Set the locale to be applied when formatting diagnostics and
|
||||
* other localized data.
|
||||
*
|
||||
* @param locale the locale to apply; {@code null} means apply no
|
||||
* locale
|
||||
* @throws IllegalStateException if the task has started
|
||||
*/
|
||||
void setLocale(Locale locale);
|
||||
|
||||
/**
|
||||
* Performs this compilation task. The compilation may only
|
||||
* be performed once. Subsequent calls to this method throw
|
||||
* IllegalStateException.
|
||||
*
|
||||
* @return true if and only all the files compiled without errors;
|
||||
* false otherwise
|
||||
*
|
||||
* @throws RuntimeException if an unrecoverable error occurred
|
||||
* in a user-supplied component. The
|
||||
* {@linkplain Throwable#getCause() cause} will be the error
|
||||
* in user code.
|
||||
* @throws IllegalStateException if called more than once
|
||||
*/
|
||||
Boolean call();
|
||||
}
|
||||
}
|
||||
402
jdkSrc/jdk8/javax/tools/JavaFileManager.java
Normal file
402
jdkSrc/jdk8/javax/tools/JavaFileManager.java
Normal file
@@ -0,0 +1,402 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.Flushable;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import static javax.tools.JavaFileObject.Kind;
|
||||
|
||||
/**
|
||||
* File manager for tools operating on Java™ programming language
|
||||
* source and class files. In this context, <em>file</em> means an
|
||||
* abstraction of regular files and other sources of data.
|
||||
*
|
||||
* <p>When constructing new JavaFileObjects, the file manager must
|
||||
* determine where to create them. For example, if a file manager
|
||||
* manages regular files on a file system, it would most likely have a
|
||||
* current/working directory to use as default location when creating
|
||||
* or finding files. A number of hints can be provided to a file
|
||||
* manager as to where to create files. Any file manager might choose
|
||||
* to ignore these hints.
|
||||
*
|
||||
* <p>Some methods in this interface use class names. Such class
|
||||
* names must be given in the Java Virtual Machine internal form of
|
||||
* fully qualified class and interface names. For convenience '.'
|
||||
* and '/' are interchangeable. The internal form is defined in
|
||||
* chapter four of
|
||||
* <cite>The Java™ Virtual Machine Specification</cite>.
|
||||
|
||||
* <blockquote><p>
|
||||
* <i>Discussion:</i> this means that the names
|
||||
* "java/lang.package-info", "java/lang/package-info",
|
||||
* "java.lang.package-info", are valid and equivalent. Compare to
|
||||
* binary name as defined in
|
||||
* <cite>The Java™ Language Specification</cite>,
|
||||
* section 13.1 "The Form of a Binary".
|
||||
* </p></blockquote>
|
||||
*
|
||||
* <p>The case of names is significant. All names should be treated
|
||||
* as case-sensitive. For example, some file systems have
|
||||
* case-insensitive, case-aware file names. File objects representing
|
||||
* such files should take care to preserve case by using {@link
|
||||
* java.io.File#getCanonicalFile} or similar means. If the system is
|
||||
* not case-aware, file objects must use other means to preserve case.
|
||||
*
|
||||
* <p><em><a name="relative_name">Relative names</a>:</em> some
|
||||
* methods in this interface use relative names. A relative name is a
|
||||
* non-null, non-empty sequence of path segments separated by '/'.
|
||||
* '.' or '..' are invalid path segments. A valid relative name must
|
||||
* match the "path-rootless" rule of <a
|
||||
* href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>,
|
||||
* section 3.3. Informally, this should be true:
|
||||
*
|
||||
* <!-- URI.create(relativeName).normalize().getPath().equals(relativeName) -->
|
||||
* <pre> URI.{@linkplain java.net.URI#create create}(relativeName).{@linkplain java.net.URI#normalize normalize}().{@linkplain java.net.URI#getPath getPath}().equals(relativeName)</pre>
|
||||
*
|
||||
* <p>All methods in this interface might throw a SecurityException.
|
||||
*
|
||||
* <p>An object of this interface is not required to support
|
||||
* multi-threaded access, that is, be synchronized. However, it must
|
||||
* support concurrent access to different file objects created by this
|
||||
* object.
|
||||
*
|
||||
* <p><em>Implementation note:</em> a consequence of this requirement
|
||||
* is that a trivial implementation of output to a {@linkplain
|
||||
* java.util.jar.JarOutputStream} is not a sufficient implementation.
|
||||
* That is, rather than creating a JavaFileObject that returns the
|
||||
* JarOutputStream directly, the contents must be cached until closed
|
||||
* and then written to the JarOutputStream.
|
||||
*
|
||||
* <p>Unless explicitly allowed, all methods in this interface might
|
||||
* throw a NullPointerException if given a {@code null} argument.
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @author Jonathan Gibbons
|
||||
* @see JavaFileObject
|
||||
* @see FileObject
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface JavaFileManager extends Closeable, Flushable, OptionChecker {
|
||||
|
||||
/**
|
||||
* Interface for locations of file objects. Used by file managers
|
||||
* to determine where to place or search for file objects.
|
||||
*/
|
||||
interface Location {
|
||||
/**
|
||||
* Gets the name of this location.
|
||||
*
|
||||
* @return a name
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Determines if this is an output location. An output
|
||||
* location is a location that is conventionally used for
|
||||
* output.
|
||||
*
|
||||
* @return true if this is an output location, false otherwise
|
||||
*/
|
||||
boolean isOutputLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a class loader for loading plug-ins from the given
|
||||
* location. For example, to load annotation processors, a
|
||||
* compiler will request a class loader for the {@link
|
||||
* StandardLocation#ANNOTATION_PROCESSOR_PATH
|
||||
* ANNOTATION_PROCESSOR_PATH} location.
|
||||
*
|
||||
* @param location a location
|
||||
* @return a class loader for the given location; or {@code null}
|
||||
* if loading plug-ins from the given location is disabled or if
|
||||
* the location is not known
|
||||
* @throws SecurityException if a class loader can not be created
|
||||
* in the current security context
|
||||
* @throws IllegalStateException if {@link #close} has been called
|
||||
* and this file manager cannot be reopened
|
||||
*/
|
||||
ClassLoader getClassLoader(Location location);
|
||||
|
||||
/**
|
||||
* Lists all file objects matching the given criteria in the given
|
||||
* location. List file objects in "subpackages" if recurse is
|
||||
* true.
|
||||
*
|
||||
* <p>Note: even if the given location is unknown to this file
|
||||
* manager, it may not return {@code null}. Also, an unknown
|
||||
* location may not cause an exception.
|
||||
*
|
||||
* @param location a location
|
||||
* @param packageName a package name
|
||||
* @param kinds return objects only of these kinds
|
||||
* @param recurse if true include "subpackages"
|
||||
* @return an Iterable of file objects matching the given criteria
|
||||
* @throws IOException if an I/O error occurred, or if {@link
|
||||
* #close} has been called and this file manager cannot be
|
||||
* reopened
|
||||
* @throws IllegalStateException if {@link #close} has been called
|
||||
* and this file manager cannot be reopened
|
||||
*/
|
||||
Iterable<JavaFileObject> list(Location location,
|
||||
String packageName,
|
||||
Set<Kind> kinds,
|
||||
boolean recurse)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Infers a binary name of a file object based on a location. The
|
||||
* binary name returned might not be a valid binary name according to
|
||||
* <cite>The Java™ Language Specification</cite>.
|
||||
*
|
||||
* @param location a location
|
||||
* @param file a file object
|
||||
* @return a binary name or {@code null} the file object is not
|
||||
* found in the given location
|
||||
* @throws IllegalStateException if {@link #close} has been called
|
||||
* and this file manager cannot be reopened
|
||||
*/
|
||||
String inferBinaryName(Location location, JavaFileObject file);
|
||||
|
||||
/**
|
||||
* Compares two file objects and return true if they represent the
|
||||
* same underlying object.
|
||||
*
|
||||
* @param a a file object
|
||||
* @param b a file object
|
||||
* @return true if the given file objects represent the same
|
||||
* underlying object
|
||||
*
|
||||
* @throws IllegalArgumentException if either of the arguments
|
||||
* were created with another file manager and this file manager
|
||||
* does not support foreign file objects
|
||||
*/
|
||||
boolean isSameFile(FileObject a, FileObject b);
|
||||
|
||||
/**
|
||||
* Handles one option. If {@code current} is an option to this
|
||||
* file manager it will consume any arguments to that option from
|
||||
* {@code remaining} and return true, otherwise return false.
|
||||
*
|
||||
* @param current current option
|
||||
* @param remaining remaining options
|
||||
* @return true if this option was handled by this file manager,
|
||||
* false otherwise
|
||||
* @throws IllegalArgumentException if this option to this file
|
||||
* manager is used incorrectly
|
||||
* @throws IllegalStateException if {@link #close} has been called
|
||||
* and this file manager cannot be reopened
|
||||
*/
|
||||
boolean handleOption(String current, Iterator<String> remaining);
|
||||
|
||||
/**
|
||||
* Determines if a location is known to this file manager.
|
||||
*
|
||||
* @param location a location
|
||||
* @return true if the location is known
|
||||
*/
|
||||
boolean hasLocation(Location location);
|
||||
|
||||
/**
|
||||
* Gets a {@linkplain JavaFileObject file object} for input
|
||||
* representing the specified class of the specified kind in the
|
||||
* given location.
|
||||
*
|
||||
* @param location a location
|
||||
* @param className the name of a class
|
||||
* @param kind the kind of file, must be one of {@link
|
||||
* JavaFileObject.Kind#SOURCE SOURCE} or {@link
|
||||
* JavaFileObject.Kind#CLASS CLASS}
|
||||
* @return a file object, might return {@code null} if the
|
||||
* file does not exist
|
||||
* @throws IllegalArgumentException if the location is not known
|
||||
* to this file manager and the file manager does not support
|
||||
* unknown locations, or if the kind is not valid
|
||||
* @throws IOException if an I/O error occurred, or if {@link
|
||||
* #close} has been called and this file manager cannot be
|
||||
* reopened
|
||||
* @throws IllegalStateException if {@link #close} has been called
|
||||
* and this file manager cannot be reopened
|
||||
*/
|
||||
JavaFileObject getJavaFileForInput(Location location,
|
||||
String className,
|
||||
Kind kind)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Gets a {@linkplain JavaFileObject file object} for output
|
||||
* representing the specified class of the specified kind in the
|
||||
* given location.
|
||||
*
|
||||
* <p>Optionally, this file manager might consider the sibling as
|
||||
* a hint for where to place the output. The exact semantics of
|
||||
* this hint is unspecified. The JDK compiler, javac, for
|
||||
* example, will place class files in the same directories as
|
||||
* originating source files unless a class file output directory
|
||||
* is provided. To facilitate this behavior, javac might provide
|
||||
* the originating source file as sibling when calling this
|
||||
* method.
|
||||
*
|
||||
* @param location a location
|
||||
* @param className the name of a class
|
||||
* @param kind the kind of file, must be one of {@link
|
||||
* JavaFileObject.Kind#SOURCE SOURCE} or {@link
|
||||
* JavaFileObject.Kind#CLASS CLASS}
|
||||
* @param sibling a file object to be used as hint for placement;
|
||||
* might be {@code null}
|
||||
* @return a file object for output
|
||||
* @throws IllegalArgumentException if sibling is not known to
|
||||
* this file manager, or if the location is not known to this file
|
||||
* manager and the file manager does not support unknown
|
||||
* locations, or if the kind is not valid
|
||||
* @throws IOException if an I/O error occurred, or if {@link
|
||||
* #close} has been called and this file manager cannot be
|
||||
* reopened
|
||||
* @throws IllegalStateException {@link #close} has been called
|
||||
* and this file manager cannot be reopened
|
||||
*/
|
||||
JavaFileObject getJavaFileForOutput(Location location,
|
||||
String className,
|
||||
Kind kind,
|
||||
FileObject sibling)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Gets a {@linkplain FileObject file object} for input
|
||||
* representing the specified <a href="JavaFileManager.html#relative_name">relative
|
||||
* name</a> in the specified package in the given location.
|
||||
*
|
||||
* <p>If the returned object represents a {@linkplain
|
||||
* JavaFileObject.Kind#SOURCE source} or {@linkplain
|
||||
* JavaFileObject.Kind#CLASS class} file, it must be an instance
|
||||
* of {@link JavaFileObject}.
|
||||
*
|
||||
* <p>Informally, the file object returned by this method is
|
||||
* located in the concatenation of the location, package name, and
|
||||
* relative name. For example, to locate the properties file
|
||||
* "resources/compiler.properties" in the package
|
||||
* "com.sun.tools.javac" in the {@linkplain
|
||||
* StandardLocation#SOURCE_PATH SOURCE_PATH} location, this method
|
||||
* might be called like so:
|
||||
*
|
||||
* <pre>getFileForInput(SOURCE_PATH, "com.sun.tools.javac", "resources/compiler.properties");</pre>
|
||||
*
|
||||
* <p>If the call was executed on Windows, with SOURCE_PATH set to
|
||||
* <code>"C:\Documents and Settings\UncleBob\src\share\classes"</code>,
|
||||
* a valid result would be a file object representing the file
|
||||
* <code>"C:\Documents and Settings\UncleBob\src\share\classes\com\sun\tools\javac\resources\compiler.properties"</code>.
|
||||
*
|
||||
* @param location a location
|
||||
* @param packageName a package name
|
||||
* @param relativeName a relative name
|
||||
* @return a file object, might return {@code null} if the file
|
||||
* does not exist
|
||||
* @throws IllegalArgumentException if the location is not known
|
||||
* to this file manager and the file manager does not support
|
||||
* unknown locations, or if {@code relativeName} is not valid
|
||||
* @throws IOException if an I/O error occurred, or if {@link
|
||||
* #close} has been called and this file manager cannot be
|
||||
* reopened
|
||||
* @throws IllegalStateException if {@link #close} has been called
|
||||
* and this file manager cannot be reopened
|
||||
*/
|
||||
FileObject getFileForInput(Location location,
|
||||
String packageName,
|
||||
String relativeName)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Gets a {@linkplain FileObject file object} for output
|
||||
* representing the specified <a href="JavaFileManager.html#relative_name">relative
|
||||
* name</a> in the specified package in the given location.
|
||||
*
|
||||
* <p>Optionally, this file manager might consider the sibling as
|
||||
* a hint for where to place the output. The exact semantics of
|
||||
* this hint is unspecified. The JDK compiler, javac, for
|
||||
* example, will place class files in the same directories as
|
||||
* originating source files unless a class file output directory
|
||||
* is provided. To facilitate this behavior, javac might provide
|
||||
* the originating source file as sibling when calling this
|
||||
* method.
|
||||
*
|
||||
* <p>If the returned object represents a {@linkplain
|
||||
* JavaFileObject.Kind#SOURCE source} or {@linkplain
|
||||
* JavaFileObject.Kind#CLASS class} file, it must be an instance
|
||||
* of {@link JavaFileObject}.
|
||||
*
|
||||
* <p>Informally, the file object returned by this method is
|
||||
* located in the concatenation of the location, package name, and
|
||||
* relative name or next to the sibling argument. See {@link
|
||||
* #getFileForInput getFileForInput} for an example.
|
||||
*
|
||||
* @param location a location
|
||||
* @param packageName a package name
|
||||
* @param relativeName a relative name
|
||||
* @param sibling a file object to be used as hint for placement;
|
||||
* might be {@code null}
|
||||
* @return a file object
|
||||
* @throws IllegalArgumentException if sibling is not known to
|
||||
* this file manager, or if the location is not known to this file
|
||||
* manager and the file manager does not support unknown
|
||||
* locations, or if {@code relativeName} is not valid
|
||||
* @throws IOException if an I/O error occurred, or if {@link
|
||||
* #close} has been called and this file manager cannot be
|
||||
* reopened
|
||||
* @throws IllegalStateException if {@link #close} has been called
|
||||
* and this file manager cannot be reopened
|
||||
*/
|
||||
FileObject getFileForOutput(Location location,
|
||||
String packageName,
|
||||
String relativeName,
|
||||
FileObject sibling)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Flushes any resources opened for output by this file manager
|
||||
* directly or indirectly. Flushing a closed file manager has no
|
||||
* effect.
|
||||
*
|
||||
* @throws IOException if an I/O error occurred
|
||||
* @see #close
|
||||
*/
|
||||
void flush() throws IOException;
|
||||
|
||||
/**
|
||||
* Releases any resources opened by this file manager directly or
|
||||
* indirectly. This might render this file manager useless and
|
||||
* the effect of subsequent calls to methods on this object or any
|
||||
* objects obtained through this object is undefined unless
|
||||
* explicitly allowed. However, closing a file manager which has
|
||||
* already been closed has no effect.
|
||||
*
|
||||
* @throws IOException if an I/O error occurred
|
||||
* @see #flush
|
||||
*/
|
||||
void close() throws IOException;
|
||||
}
|
||||
130
jdkSrc/jdk8/javax/tools/JavaFileObject.java
Normal file
130
jdkSrc/jdk8/javax/tools/JavaFileObject.java
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
import javax.lang.model.element.NestingKind;
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
||||
/**
|
||||
* File abstraction for tools operating on Java™ programming language
|
||||
* source and class files.
|
||||
*
|
||||
* <p>All methods in this interface might throw a SecurityException if
|
||||
* a security exception occurs.
|
||||
*
|
||||
* <p>Unless explicitly allowed, all methods in this interface might
|
||||
* throw a NullPointerException if given a {@code null} argument.
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @author Jonathan Gibbons
|
||||
* @see JavaFileManager
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface JavaFileObject extends FileObject {
|
||||
|
||||
/**
|
||||
* Kinds of JavaFileObjects.
|
||||
*/
|
||||
enum Kind {
|
||||
/**
|
||||
* Source files written in the Java programming language. For
|
||||
* example, regular files ending with {@code .java}.
|
||||
*/
|
||||
SOURCE(".java"),
|
||||
|
||||
/**
|
||||
* Class files for the Java Virtual Machine. For example,
|
||||
* regular files ending with {@code .class}.
|
||||
*/
|
||||
CLASS(".class"),
|
||||
|
||||
/**
|
||||
* HTML files. For example, regular files ending with {@code
|
||||
* .html}.
|
||||
*/
|
||||
HTML(".html"),
|
||||
|
||||
/**
|
||||
* Any other kind.
|
||||
*/
|
||||
OTHER("");
|
||||
/**
|
||||
* The extension which (by convention) is normally used for
|
||||
* this kind of file object. If no convention exists, the
|
||||
* empty string ({@code ""}) is used.
|
||||
*/
|
||||
public final String extension;
|
||||
private Kind(String extension) {
|
||||
extension.getClass(); // null check
|
||||
this.extension = extension;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the kind of this file object.
|
||||
*
|
||||
* @return the kind
|
||||
*/
|
||||
Kind getKind();
|
||||
|
||||
/**
|
||||
* Checks if this file object is compatible with the specified
|
||||
* simple name and kind. A simple name is a single identifier
|
||||
* (not qualified) as defined in
|
||||
* <cite>The Java™ Language Specification</cite>,
|
||||
* section 6.2 "Names and Identifiers".
|
||||
*
|
||||
* @param simpleName a simple name of a class
|
||||
* @param kind a kind
|
||||
* @return {@code true} if this file object is compatible; false
|
||||
* otherwise
|
||||
*/
|
||||
boolean isNameCompatible(String simpleName, Kind kind);
|
||||
|
||||
/**
|
||||
* Provides a hint about the nesting level of the class
|
||||
* represented by this file object. This method may return
|
||||
* {@link NestingKind#MEMBER} to mean
|
||||
* {@link NestingKind#LOCAL} or {@link NestingKind#ANONYMOUS}.
|
||||
* If the nesting level is not known or this file object does not
|
||||
* represent a class file this method returns {@code null}.
|
||||
*
|
||||
* @return the nesting kind, or {@code null} if the nesting kind
|
||||
* is not known
|
||||
*/
|
||||
NestingKind getNestingKind();
|
||||
|
||||
/**
|
||||
* Provides a hint about the access level of the class represented
|
||||
* by this file object. If the access level is not known or if
|
||||
* this file object does not represent a class file this method
|
||||
* returns {@code null}.
|
||||
*
|
||||
* @return the access level
|
||||
*/
|
||||
Modifier getAccessLevel();
|
||||
|
||||
}
|
||||
46
jdkSrc/jdk8/javax/tools/OptionChecker.java
Normal file
46
jdkSrc/jdk8/javax/tools/OptionChecker.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
/**
|
||||
* Interface for recognizing options.
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface OptionChecker {
|
||||
|
||||
/**
|
||||
* Determines if the given option is supported and if so, the
|
||||
* number of arguments the option takes.
|
||||
*
|
||||
* @param option an option
|
||||
* @return the number of arguments the given option takes or -1 if
|
||||
* the option is not supported
|
||||
*/
|
||||
int isSupportedOption(String option);
|
||||
|
||||
}
|
||||
216
jdkSrc/jdk8/javax/tools/SimpleJavaFileObject.java
Normal file
216
jdkSrc/jdk8/javax/tools/SimpleJavaFileObject.java
Normal file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.nio.CharBuffer;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import javax.lang.model.element.NestingKind;
|
||||
import javax.tools.JavaFileObject.Kind;
|
||||
|
||||
/**
|
||||
* Provides simple implementations for most methods in JavaFileObject.
|
||||
* This class is designed to be subclassed and used as a basis for
|
||||
* JavaFileObject implementations. Subclasses can override the
|
||||
* implementation and specification of any method of this class as
|
||||
* long as the general contract of JavaFileObject is obeyed.
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @since 1.6
|
||||
*/
|
||||
public class SimpleJavaFileObject implements JavaFileObject {
|
||||
/**
|
||||
* A URI for this file object.
|
||||
*/
|
||||
protected final URI uri;
|
||||
|
||||
/**
|
||||
* The kind of this file object.
|
||||
*/
|
||||
protected final Kind kind;
|
||||
|
||||
/**
|
||||
* Construct a SimpleJavaFileObject of the given kind and with the
|
||||
* given URI.
|
||||
*
|
||||
* @param uri the URI for this file object
|
||||
* @param kind the kind of this file object
|
||||
*/
|
||||
protected SimpleJavaFileObject(URI uri, Kind kind) {
|
||||
// null checks
|
||||
uri.getClass();
|
||||
kind.getClass();
|
||||
if (uri.getPath() == null)
|
||||
throw new IllegalArgumentException("URI must have a path: " + uri);
|
||||
this.uri = uri;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
public URI toUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return toUri().getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation always throws {@linkplain
|
||||
* UnsupportedOperationException}. Subclasses can change this
|
||||
* behavior as long as the contract of {@link FileObject} is
|
||||
* obeyed.
|
||||
*/
|
||||
public InputStream openInputStream() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation always throws {@linkplain
|
||||
* UnsupportedOperationException}. Subclasses can change this
|
||||
* behavior as long as the contract of {@link FileObject} is
|
||||
* obeyed.
|
||||
*/
|
||||
public OutputStream openOutputStream() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the result of {@linkplain #getCharContent} in a Reader.
|
||||
* Subclasses can change this behavior as long as the contract of
|
||||
* {@link FileObject} is obeyed.
|
||||
*
|
||||
* @param ignoreEncodingErrors {@inheritDoc}
|
||||
* @return a Reader wrapping the result of getCharContent
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
* @throws UnsupportedOperationException {@inheritDoc}
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
|
||||
CharSequence charContent = getCharContent(ignoreEncodingErrors);
|
||||
if (charContent == null)
|
||||
throw new UnsupportedOperationException();
|
||||
if (charContent instanceof CharBuffer) {
|
||||
CharBuffer buffer = (CharBuffer)charContent;
|
||||
if (buffer.hasArray())
|
||||
return new CharArrayReader(buffer.array());
|
||||
}
|
||||
return new StringReader(charContent.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation always throws {@linkplain
|
||||
* UnsupportedOperationException}. Subclasses can change this
|
||||
* behavior as long as the contract of {@link FileObject} is
|
||||
* obeyed.
|
||||
*/
|
||||
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the result of openOutputStream in a Writer. Subclasses
|
||||
* can change this behavior as long as the contract of {@link
|
||||
* FileObject} is obeyed.
|
||||
*
|
||||
* @return a Writer wrapping the result of openOutputStream
|
||||
* @throws IllegalStateException {@inheritDoc}
|
||||
* @throws UnsupportedOperationException {@inheritDoc}
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
public Writer openWriter() throws IOException {
|
||||
return new OutputStreamWriter(openOutputStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation returns {@code 0L}. Subclasses can change
|
||||
* this behavior as long as the contract of {@link FileObject} is
|
||||
* obeyed.
|
||||
*
|
||||
* @return {@code 0L}
|
||||
*/
|
||||
public long getLastModified() {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation does nothing. Subclasses can change this
|
||||
* behavior as long as the contract of {@link FileObject} is
|
||||
* obeyed.
|
||||
*
|
||||
* @return {@code false}
|
||||
*/
|
||||
public boolean delete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code this.kind}
|
||||
*/
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation compares the path of its URI to the given
|
||||
* simple name. This method returns true if the given kind is
|
||||
* equal to the kind of this object, and if the path is equal to
|
||||
* {@code simpleName + kind.extension} or if it ends with {@code
|
||||
* "/" + simpleName + kind.extension}.
|
||||
*
|
||||
* <p>This method calls {@link #getKind} and {@link #toUri} and
|
||||
* does not access the fields {@link #uri} and {@link #kind}
|
||||
* directly.
|
||||
*
|
||||
* <p>Subclasses can change this behavior as long as the contract
|
||||
* of {@link JavaFileObject} is obeyed.
|
||||
*/
|
||||
public boolean isNameCompatible(String simpleName, Kind kind) {
|
||||
String baseName = simpleName + kind.extension;
|
||||
return kind.equals(getKind())
|
||||
&& (baseName.equals(toUri().getPath())
|
||||
|| toUri().getPath().endsWith("/" + baseName));
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation returns {@code null}. Subclasses can
|
||||
* change this behavior as long as the contract of
|
||||
* {@link JavaFileObject} is obeyed.
|
||||
*/
|
||||
public NestingKind getNestingKind() { return null; }
|
||||
|
||||
/**
|
||||
* This implementation returns {@code null}. Subclasses can
|
||||
* change this behavior as long as the contract of
|
||||
* {@link JavaFileObject} is obeyed.
|
||||
*/
|
||||
public Modifier getAccessLevel() { return null; }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getName() + "[" + toUri() + "]";
|
||||
}
|
||||
}
|
||||
239
jdkSrc/jdk8/javax/tools/StandardJavaFileManager.java
Normal file
239
jdkSrc/jdk8/javax/tools/StandardJavaFileManager.java
Normal file
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* File manager based on {@linkplain File java.io.File}. A common way
|
||||
* to obtain an instance of this class is using {@linkplain
|
||||
* JavaCompiler#getStandardFileManager
|
||||
* getStandardFileManager}, for example:
|
||||
*
|
||||
* <pre>
|
||||
* JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
* {@code DiagnosticCollector<JavaFileObject>} diagnostics =
|
||||
* new {@code DiagnosticCollector<JavaFileObject>()};
|
||||
* StandardJavaFileManager fm = compiler.getStandardFileManager(diagnostics, null, null);
|
||||
* </pre>
|
||||
*
|
||||
* This file manager creates file objects representing regular
|
||||
* {@linkplain File files},
|
||||
* {@linkplain java.util.zip.ZipEntry zip file entries}, or entries in
|
||||
* similar file system based containers. Any file object returned
|
||||
* from a file manager implementing this interface must observe the
|
||||
* following behavior:
|
||||
*
|
||||
* <ul>
|
||||
* <li>
|
||||
* File names need not be canonical.
|
||||
* </li>
|
||||
* <li>
|
||||
* For file objects representing regular files
|
||||
* <ul>
|
||||
* <li>
|
||||
* the method <code>{@linkplain FileObject#delete()}</code>
|
||||
* is equivalent to <code>{@linkplain File#delete()}</code>,
|
||||
* </li>
|
||||
* <li>
|
||||
* the method <code>{@linkplain FileObject#getLastModified()}</code>
|
||||
* is equivalent to <code>{@linkplain File#lastModified()}</code>,
|
||||
* </li>
|
||||
* <li>
|
||||
* the methods <code>{@linkplain FileObject#getCharContent(boolean)}</code>,
|
||||
* <code>{@linkplain FileObject#openInputStream()}</code>, and
|
||||
* <code>{@linkplain FileObject#openReader(boolean)}</code>
|
||||
* must succeed if the following would succeed (ignoring
|
||||
* encoding issues):
|
||||
* <blockquote>
|
||||
* <pre>new {@linkplain java.io.FileInputStream#FileInputStream(File) FileInputStream}(new {@linkplain File#File(java.net.URI) File}({@linkplain FileObject fileObject}.{@linkplain FileObject#toUri() toUri}()))</pre>
|
||||
* </blockquote>
|
||||
* </li>
|
||||
* <li>
|
||||
* and the methods
|
||||
* <code>{@linkplain FileObject#openOutputStream()}</code>, and
|
||||
* <code>{@linkplain FileObject#openWriter()}</code> must
|
||||
* succeed if the following would succeed (ignoring encoding
|
||||
* issues):
|
||||
* <blockquote>
|
||||
* <pre>new {@linkplain java.io.FileOutputStream#FileOutputStream(File) FileOutputStream}(new {@linkplain File#File(java.net.URI) File}({@linkplain FileObject fileObject}.{@linkplain FileObject#toUri() toUri}()))</pre>
|
||||
* </blockquote>
|
||||
* </li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* <li>
|
||||
* The {@linkplain java.net.URI URI} returned from
|
||||
* <code>{@linkplain FileObject#toUri()}</code>
|
||||
* <ul>
|
||||
* <li>
|
||||
* must be {@linkplain java.net.URI#isAbsolute() absolute} (have a schema), and
|
||||
* </li>
|
||||
* <li>
|
||||
* must have a {@linkplain java.net.URI#normalize() normalized}
|
||||
* {@linkplain java.net.URI#getPath() path component} which
|
||||
* can be resolved without any process-specific context such
|
||||
* as the current directory (file names must be absolute).
|
||||
* </li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* According to these rules, the following URIs, for example, are
|
||||
* allowed:
|
||||
* <ul>
|
||||
* <li>
|
||||
* <code>file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java</code>
|
||||
* </li>
|
||||
* <li>
|
||||
* <code>jar:///C:/Documents%20and%20Settings/UncleBob/lib/vendorA.jar!com/vendora/LibraryClass.class</code>
|
||||
* </li>
|
||||
* </ul>
|
||||
* Whereas these are not (reason in parentheses):
|
||||
* <ul>
|
||||
* <li>
|
||||
* <code>file:BobsApp/Test.java</code> (the file name is relative
|
||||
* and depend on the current directory)
|
||||
* </li>
|
||||
* <li>
|
||||
* <code>jar:lib/vendorA.jar!com/vendora/LibraryClass.class</code>
|
||||
* (the first half of the path depends on the current directory,
|
||||
* whereas the component after ! is legal)
|
||||
* </li>
|
||||
* <li>
|
||||
* <code>Test.java</code> (this URI depends on the current
|
||||
* directory and does not have a schema)
|
||||
* </li>
|
||||
* <li>
|
||||
* <code>jar:///C:/Documents%20and%20Settings/UncleBob/BobsApp/../lib/vendorA.jar!com/vendora/LibraryClass.class</code>
|
||||
* (the path is not normalized)
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface StandardJavaFileManager extends JavaFileManager {
|
||||
|
||||
/**
|
||||
* Compares two file objects and return true if they represent the
|
||||
* same canonical file, zip file entry, or entry in any file
|
||||
* system based container.
|
||||
*
|
||||
* @param a a file object
|
||||
* @param b a file object
|
||||
* @return true if the given file objects represent the same
|
||||
* canonical file or zip file entry; false otherwise
|
||||
*
|
||||
* @throws IllegalArgumentException if either of the arguments
|
||||
* were created with another file manager implementation
|
||||
*/
|
||||
boolean isSameFile(FileObject a, FileObject b);
|
||||
|
||||
/**
|
||||
* Gets file objects representing the given files.
|
||||
*
|
||||
* @param files a list of files
|
||||
* @return a list of file objects
|
||||
* @throws IllegalArgumentException if the list of files includes
|
||||
* a directory
|
||||
*/
|
||||
Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(
|
||||
Iterable<? extends File> files);
|
||||
|
||||
/**
|
||||
* Gets file objects representing the given files.
|
||||
* Convenience method equivalent to:
|
||||
*
|
||||
* <pre>
|
||||
* getJavaFileObjectsFromFiles({@linkplain java.util.Arrays#asList Arrays.asList}(files))
|
||||
* </pre>
|
||||
*
|
||||
* @param files an array of files
|
||||
* @return a list of file objects
|
||||
* @throws IllegalArgumentException if the array of files includes
|
||||
* a directory
|
||||
* @throws NullPointerException if the given array contains null
|
||||
* elements
|
||||
*/
|
||||
Iterable<? extends JavaFileObject> getJavaFileObjects(File... files);
|
||||
|
||||
/**
|
||||
* Gets file objects representing the given file names.
|
||||
*
|
||||
* @param names a list of file names
|
||||
* @return a list of file objects
|
||||
* @throws IllegalArgumentException if the list of file names
|
||||
* includes a directory
|
||||
*/
|
||||
Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(
|
||||
Iterable<String> names);
|
||||
|
||||
/**
|
||||
* Gets file objects representing the given file names.
|
||||
* Convenience method equivalent to:
|
||||
*
|
||||
* <pre>
|
||||
* getJavaFileObjectsFromStrings({@linkplain java.util.Arrays#asList Arrays.asList}(names))
|
||||
* </pre>
|
||||
*
|
||||
* @param names a list of file names
|
||||
* @return a list of file objects
|
||||
* @throws IllegalArgumentException if the array of file names
|
||||
* includes a directory
|
||||
* @throws NullPointerException if the given array contains null
|
||||
* elements
|
||||
*/
|
||||
Iterable<? extends JavaFileObject> getJavaFileObjects(String... names);
|
||||
|
||||
/**
|
||||
* Associates the given path with the given location. Any
|
||||
* previous value will be discarded.
|
||||
*
|
||||
* @param location a location
|
||||
* @param path a list of files, if {@code null} use the default
|
||||
* path for this location
|
||||
* @see #getLocation
|
||||
* @throws IllegalArgumentException if location is an output
|
||||
* location and path does not contain exactly one element
|
||||
* @throws IOException if location is an output location and path
|
||||
* does not represent an existing directory
|
||||
*/
|
||||
void setLocation(Location location, Iterable<? extends File> path)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Gets the path associated with the given location.
|
||||
*
|
||||
* @param location a location
|
||||
* @return a list of files or {@code null} if this location has no
|
||||
* associated path
|
||||
* @see #setLocation
|
||||
*/
|
||||
Iterable<? extends File> getLocation(Location location);
|
||||
|
||||
}
|
||||
115
jdkSrc/jdk8/javax/tools/StandardLocation.java
Normal file
115
jdkSrc/jdk8/javax/tools/StandardLocation.java
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
import javax.tools.JavaFileManager.Location;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* Standard locations of file objects.
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @since 1.6
|
||||
*/
|
||||
public enum StandardLocation implements Location {
|
||||
|
||||
/**
|
||||
* Location of new class files.
|
||||
*/
|
||||
CLASS_OUTPUT,
|
||||
|
||||
/**
|
||||
* Location of new source files.
|
||||
*/
|
||||
SOURCE_OUTPUT,
|
||||
|
||||
/**
|
||||
* Location to search for user class files.
|
||||
*/
|
||||
CLASS_PATH,
|
||||
|
||||
/**
|
||||
* Location to search for existing source files.
|
||||
*/
|
||||
SOURCE_PATH,
|
||||
|
||||
/**
|
||||
* Location to search for annotation processors.
|
||||
*/
|
||||
ANNOTATION_PROCESSOR_PATH,
|
||||
|
||||
/**
|
||||
* Location to search for platform classes. Sometimes called
|
||||
* the boot class path.
|
||||
*/
|
||||
PLATFORM_CLASS_PATH,
|
||||
|
||||
/**
|
||||
* Location of new native header files.
|
||||
* @since 1.8
|
||||
*/
|
||||
NATIVE_HEADER_OUTPUT;
|
||||
|
||||
/**
|
||||
* Gets a location object with the given name. The following
|
||||
* property must hold: {@code locationFor(x) ==
|
||||
* locationFor(y)} if and only if {@code x.equals(y)}.
|
||||
* The returned location will be an output location if and only if
|
||||
* name ends with {@code "_OUTPUT"}.
|
||||
*
|
||||
* @param name a name
|
||||
* @return a location
|
||||
*/
|
||||
public static Location locationFor(final String name) {
|
||||
if (locations.isEmpty()) {
|
||||
// can't use valueOf which throws IllegalArgumentException
|
||||
for (Location location : values())
|
||||
locations.putIfAbsent(location.getName(), location);
|
||||
}
|
||||
locations.putIfAbsent(name.toString(/* null-check */), new Location() {
|
||||
public String getName() { return name; }
|
||||
public boolean isOutputLocation() { return name.endsWith("_OUTPUT"); }
|
||||
});
|
||||
return locations.get(name);
|
||||
}
|
||||
//where
|
||||
private static final ConcurrentMap<String,Location> locations
|
||||
= new ConcurrentHashMap<String,Location>();
|
||||
|
||||
public String getName() { return name(); }
|
||||
|
||||
public boolean isOutputLocation() {
|
||||
switch (this) {
|
||||
case CLASS_OUTPUT:
|
||||
case SOURCE_OUTPUT:
|
||||
case NATIVE_HEADER_OUTPUT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
72
jdkSrc/jdk8/javax/tools/Tool.java
Normal file
72
jdkSrc/jdk8/javax/tools/Tool.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
import java.util.Set;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import javax.lang.model.SourceVersion;
|
||||
|
||||
/**
|
||||
* Common interface for tools that can be invoked from a program.
|
||||
* A tool is traditionally a command line program such as a compiler.
|
||||
* The set of tools available with a platform is defined by the
|
||||
* vendor.
|
||||
*
|
||||
* <p>Tools can be located using {@link
|
||||
* java.util.ServiceLoader#load(Class)}.
|
||||
*
|
||||
* @author Neal M Gafter
|
||||
* @author Peter von der Ahé
|
||||
* @author Jonathan Gibbons
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface Tool {
|
||||
|
||||
/**
|
||||
* Run the tool with the given I/O channels and arguments. By
|
||||
* convention a tool returns 0 for success and nonzero for errors.
|
||||
* Any diagnostics generated will be written to either {@code out}
|
||||
* or {@code err} in some unspecified format.
|
||||
*
|
||||
* @param in "standard" input; use System.in if null
|
||||
* @param out "standard" output; use System.out if null
|
||||
* @param err "standard" error; use System.err if null
|
||||
* @param arguments arguments to pass to the tool
|
||||
* @return 0 for success; nonzero otherwise
|
||||
* @throws NullPointerException if the array of arguments contains
|
||||
* any {@code null} elements.
|
||||
*/
|
||||
int run(InputStream in, OutputStream out, OutputStream err, String... arguments);
|
||||
|
||||
/**
|
||||
* Gets the source versions of the Java™ programming language
|
||||
* supported by this tool.
|
||||
* @return a set of supported source versions
|
||||
*/
|
||||
Set<SourceVersion> getSourceVersions();
|
||||
|
||||
}
|
||||
216
jdkSrc/jdk8/javax/tools/ToolProvider.java
Normal file
216
jdkSrc/jdk8/javax/tools/ToolProvider.java
Normal file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.tools;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import static java.util.logging.Level.*;
|
||||
|
||||
/**
|
||||
* Provides methods for locating tool providers, for example,
|
||||
* providers of compilers. This class complements the
|
||||
* functionality of {@link java.util.ServiceLoader}.
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @since 1.6
|
||||
*/
|
||||
public class ToolProvider {
|
||||
|
||||
private static final String propertyName = "sun.tools.ToolProvider";
|
||||
private static final String loggerName = "javax.tools";
|
||||
|
||||
/*
|
||||
* Define the system property "sun.tools.ToolProvider" to enable
|
||||
* debugging:
|
||||
*
|
||||
* java ... -Dsun.tools.ToolProvider ...
|
||||
*/
|
||||
static <T> T trace(Level level, Object reason) {
|
||||
// NOTE: do not make this method private as it affects stack traces
|
||||
try {
|
||||
if (System.getProperty(propertyName) != null) {
|
||||
StackTraceElement[] st = Thread.currentThread().getStackTrace();
|
||||
String method = "???";
|
||||
String cls = ToolProvider.class.getName();
|
||||
if (st.length > 2) {
|
||||
StackTraceElement frame = st[2];
|
||||
method = String.format((Locale)null, "%s(%s:%s)",
|
||||
frame.getMethodName(),
|
||||
frame.getFileName(),
|
||||
frame.getLineNumber());
|
||||
cls = frame.getClassName();
|
||||
}
|
||||
Logger logger = Logger.getLogger(loggerName);
|
||||
if (reason instanceof Throwable) {
|
||||
logger.logp(level, cls, method,
|
||||
reason.getClass().getName(), (Throwable)reason);
|
||||
} else {
|
||||
logger.logp(level, cls, method, String.valueOf(reason));
|
||||
}
|
||||
}
|
||||
} catch (SecurityException ex) {
|
||||
System.err.format((Locale)null, "%s: %s; %s%n",
|
||||
ToolProvider.class.getName(),
|
||||
reason,
|
||||
ex.getLocalizedMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final String defaultJavaCompilerName
|
||||
= "com.sun.tools.javac.api.JavacTool";
|
||||
|
||||
/**
|
||||
* Gets the Java™ programming language compiler provided
|
||||
* with this platform.
|
||||
* @return the compiler provided with this platform or
|
||||
* {@code null} if no compiler is provided
|
||||
*/
|
||||
public static JavaCompiler getSystemJavaCompiler() {
|
||||
return instance().getSystemTool(JavaCompiler.class, defaultJavaCompilerName);
|
||||
}
|
||||
|
||||
private static final String defaultDocumentationToolName
|
||||
= "com.sun.tools.javadoc.api.JavadocTool";
|
||||
|
||||
/**
|
||||
* Gets the Java™ programming language documentation tool provided
|
||||
* with this platform.
|
||||
* @return the documentation tool provided with this platform or
|
||||
* {@code null} if no documentation tool is provided
|
||||
*/
|
||||
public static DocumentationTool getSystemDocumentationTool() {
|
||||
return instance().getSystemTool(DocumentationTool.class, defaultDocumentationToolName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class loader for tools provided with this platform.
|
||||
* This does not include user-installed tools. Use the
|
||||
* {@linkplain java.util.ServiceLoader service provider mechanism}
|
||||
* for locating user installed tools.
|
||||
*
|
||||
* @return the class loader for tools provided with this platform
|
||||
* or {@code null} if no tools are provided
|
||||
*/
|
||||
public static ClassLoader getSystemToolClassLoader() {
|
||||
try {
|
||||
Class<? extends JavaCompiler> c =
|
||||
instance().getSystemToolClass(JavaCompiler.class, defaultJavaCompilerName);
|
||||
return c.getClassLoader();
|
||||
} catch (Throwable e) {
|
||||
return trace(WARNING, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static ToolProvider instance;
|
||||
|
||||
private static synchronized ToolProvider instance() {
|
||||
if (instance == null)
|
||||
instance = new ToolProvider();
|
||||
return instance;
|
||||
}
|
||||
|
||||
// Cache for tool classes.
|
||||
// Use weak references to avoid keeping classes around unnecessarily
|
||||
private Map<String, Reference<Class<?>>> toolClasses = new HashMap<String, Reference<Class<?>>>();
|
||||
|
||||
// Cache for tool classloader.
|
||||
// Use a weak reference to avoid keeping it around unnecessarily
|
||||
private Reference<ClassLoader> refToolClassLoader = null;
|
||||
|
||||
|
||||
private ToolProvider() { }
|
||||
|
||||
private <T> T getSystemTool(Class<T> clazz, String name) {
|
||||
Class<? extends T> c = getSystemToolClass(clazz, name);
|
||||
try {
|
||||
return c.asSubclass(clazz).newInstance();
|
||||
} catch (Throwable e) {
|
||||
trace(WARNING, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private <T> Class<? extends T> getSystemToolClass(Class<T> clazz, String name) {
|
||||
Reference<Class<?>> refClass = toolClasses.get(name);
|
||||
Class<?> c = (refClass == null ? null : refClass.get());
|
||||
if (c == null) {
|
||||
try {
|
||||
c = findSystemToolClass(name);
|
||||
} catch (Throwable e) {
|
||||
return trace(WARNING, e);
|
||||
}
|
||||
toolClasses.put(name, new WeakReference<Class<?>>(c));
|
||||
}
|
||||
return c.asSubclass(clazz);
|
||||
}
|
||||
|
||||
private static final String[] defaultToolsLocation = { "lib", "tools.jar" };
|
||||
|
||||
private Class<?> findSystemToolClass(String toolClassName)
|
||||
throws MalformedURLException, ClassNotFoundException
|
||||
{
|
||||
// try loading class directly, in case tool is on the bootclasspath
|
||||
try {
|
||||
return Class.forName(toolClassName, false, null);
|
||||
} catch (ClassNotFoundException e) {
|
||||
trace(FINE, e);
|
||||
|
||||
// if tool not on bootclasspath, look in default tools location (tools.jar)
|
||||
ClassLoader cl = (refToolClassLoader == null ? null : refToolClassLoader.get());
|
||||
if (cl == null) {
|
||||
File file = new File(System.getProperty("java.home"));
|
||||
if (file.getName().equalsIgnoreCase("jre"))
|
||||
file = file.getParentFile();
|
||||
for (String name : defaultToolsLocation)
|
||||
file = new File(file, name);
|
||||
|
||||
// if tools not found, no point in trying a URLClassLoader
|
||||
// so rethrow the original exception.
|
||||
if (!file.exists())
|
||||
throw e;
|
||||
|
||||
URL[] urls = { file.toURI().toURL() };
|
||||
trace(FINE, urls[0].toString());
|
||||
|
||||
cl = URLClassLoader.newInstance(urls);
|
||||
refToolClassLoader = new WeakReference<ClassLoader>(cl);
|
||||
}
|
||||
|
||||
return Class.forName(toolClassName, false, cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
78
jdkSrc/jdk8/javax/tools/package-info.java
Normal file
78
jdkSrc/jdk8/javax/tools/package-info.java
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides interfaces for tools which can be invoked from a program,
|
||||
* for example, compilers.
|
||||
*
|
||||
* <p>These interfaces and classes are required as part of the
|
||||
* Java™ Platform, Standard Edition (Java SE),
|
||||
* but there is no requirement to provide any tools implementing them.
|
||||
*
|
||||
* <p>Unless explicitly allowed, all methods in this package might
|
||||
* throw a {@linkplain java.lang.NullPointerException} if given a
|
||||
* {@code null} argument or if given a
|
||||
* {@linkplain java.lang.Iterable list or collection} containing
|
||||
* {@code null} elements. Similarly, no method may return
|
||||
* {@code null} unless explicitly allowed.
|
||||
*
|
||||
* <p>This package is the home of the Java programming language compiler framework. This
|
||||
* framework allows clients of the framework to locate and run
|
||||
* compilers from programs. The framework also provides Service
|
||||
* Provider Interfaces (SPI) for structured access to diagnostics
|
||||
* ({@linkplain javax.tools.DiagnosticListener}) as well as a file
|
||||
* abstraction for overriding file access ({@linkplain
|
||||
* javax.tools.JavaFileManager} and {@linkplain
|
||||
* javax.tools.JavaFileObject}). See {@linkplain
|
||||
* javax.tools.JavaCompiler} for more details on using the SPI.
|
||||
*
|
||||
* <p>There is no requirement for a compiler at runtime. However, if
|
||||
* a default compiler is provided, it can be located using the
|
||||
* {@linkplain javax.tools.ToolProvider}, for example:
|
||||
*
|
||||
* <p>{@code JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();}
|
||||
*
|
||||
* <p>It is possible to provide alternative compilers or tools
|
||||
* through the {@linkplain java.util.ServiceLoader service provider
|
||||
* mechanism}.
|
||||
*
|
||||
* <p>For example, if {@code com.vendor.VendorJavaCompiler} is a
|
||||
* provider of the {@code JavaCompiler} tool then its jar file
|
||||
* would contain the file {@code
|
||||
* META-INF/services/javax.tools.JavaCompiler}. This file would
|
||||
* contain the single line:
|
||||
*
|
||||
* <p>{@code com.vendor.VendorJavaCompiler}
|
||||
*
|
||||
* <p>If the jar file is on the class path, VendorJavaCompiler can be
|
||||
* located using code like this:
|
||||
*
|
||||
* <p>{@code JavaCompiler compiler = ServiceLoader.load(JavaCompiler.class).iterator().next();}
|
||||
*
|
||||
* @author Peter von der Ahé
|
||||
* @author Jonathan Gibbons
|
||||
* @since 1.6
|
||||
*/
|
||||
package javax.tools;
|
||||
Reference in New Issue
Block a user