Java Doc for JavaCompiler.java in  » 6.0-JDK-Modules-sun » javac-compiler » javax » tools » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules sun » javac compiler » javax.tools 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


javax.tools.JavaCompiler

All known Subclasses:   com.sun.tools.javac.api.JavacTool,
JavaCompiler
public interface JavaCompiler extends Tool,OptionChecker(Code)
Interface to invoke Java™ programming language compilers from programs.

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 System.err unless otherwise specified. Even if a diagnostic listener is supplied, some diagnostics might not fit in a Diagnostic and will be written to the default output.

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 .

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 .

An instance implementing this interface must conform to the Java Language Specification and generate class files conforming to the Java Virtual Machine specification. The versions of these specifications are defined in the interface. Additionally, an instance of this interface supporting javax.lang.model.SourceVersion.RELEASE_6 SourceVersion.RELEASE_6 or higher must also support .

The compiler relies on two services: and . Although most classes and interfaces in this package defines an API for compilers (and tools in general) the interfaces , , , and 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.

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:

StandardJavaFileManager
Every compiler which implements this interface provides a standard file manager for operating on regular . The StandardJavaFileManager interface defines additional methods for creating file objects from regular files.

The standard file manager serves two purposes:

  • basic building block for customizing how a compiler reads and writes files
  • sharing between multiple compilation tasks

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:

 Files[] files1 = ... ; // input for first compilation task
 Files[] files2 = ... ; // input for second compilation task
 JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
 StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
  Iterable   compilationUnits1 =
 fileManager.getJavaFileObjectsFromFiles(
 (files1));
 compiler.getTask(null, fileManager, null, null, null, compilationUnits1).call();
  Iterable   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();
DiagnosticCollector
Used to collect diagnostics in a list, for example:
  Iterable   compilationUnits = ...;
 JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  DiagnosticCollector diagnostics = new DiagnosticCollector();  StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
 compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits).call();
 for (Diagnostic diagnostic : diagnostics.getDiagnostics())
 System.out.format("Error on line %d in %d%n",
 diagnostic.getLineNumber()
 diagnostic.getSource().toUri());
 fileManager.close();
ForwardingJavaFileManager , ForwardingFileObject , and ForwardingJavaFileObject
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 :
 final 
  logger = ...;
  Iterable   compilationUnits = ...;
 JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
 StandardJavaFileManager stdFileManager = compiler.getStandardFileManager(null, null, null);
 JavaFileManager fileManager = new ForwardingJavaFileManager(stdFileManager) {
 public void flush() {
 logger.entering(StandardJavaFileManager.class.getName(), "flush");
 super.flush();
 logger.exiting(StandardJavaFileManager.class.getName(), "flush");
 }
 };
 compiler.getTask(null, fileManager, null, null, null, compilationUnits).call();
SimpleJavaFileObject
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:
 /**
 A file object used to represent source coming from a string.
  *  /
 public class JavaSourceFromString extends SimpleJavaFileObject {
 /**
 The source code of this "file".
  *  /
 final String code;
 /**
 Constructs a new JavaSourceFromString.
  @  param name the name of the compilation unit represented by this file object
  @  param code the source code for the compilation unit represented by this file object
  *  /
 JavaSourceFromString(String name, String code) {
 super(
 ("string:///" + name.replace('.','/') + Kind.SOURCE.extension),
 Kind.SOURCE);
 this.code = code;
 }
  @  Override
 public CharSequence getCharContent(boolean ignoreEncodingErrors) {
 return code;
 }
 }

author:
   Peter von der Ahé
author:
   Jonathan Gibbons
See Also:   DiagnosticListener
See Also:   Diagnostic
See Also:   JavaFileManager
since:
   1.6

Inner Class :interface CompilationTask extends Callable<Boolean>



Method Summary
 StandardJavaFileManagergetStandardFileManager(DiagnosticListener<? super JavaFileObject> diagnosticListener, Locale locale, Charset charset)
     Gets a new instance of the standard file manager implementation for this tool.
 CompilationTaskgetTask(Writer out, JavaFileManager fileManager, DiagnosticListener<? super JavaFileObject> diagnosticListener, Iterable<String> options, Iterable<String> classes, Iterable<? extends JavaFileObject> compilationUnits)
     Creates a future for a compilation task with the given components and arguments.



Method Detail
getStandardFileManager
StandardJavaFileManager getStandardFileManager(DiagnosticListener<? super JavaFileObject> diagnosticListener, Locale locale, Charset charset)(Code)
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 signalled with the appropriate exceptions.

The standard file manager will be automatically reopened if it is accessed after calls to flush or close . The standard file manager must be usable with other tools.
Parameters:
  diagnosticListener - a diagnostic listener for non-fataldiagnostics; if null use the compiler's default methodfor reporting diagnostics
Parameters:
  locale - the locale to apply when formatting diagnostics; null means the .
Parameters:
  charset - the character set used for decoding bytes; if null use the platform default the standard file manager




getTask
CompilationTask getTask(Writer out, JavaFileManager fileManager, DiagnosticListener<? super JavaFileObject> diagnosticListener, Iterable<String> options, Iterable<String> classes, Iterable<? extends JavaFileObject> compilationUnits)(Code)
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.

If a file manager is provided, it must be able to handle all locations defined in StandardLocation .
Parameters:
  out - a Writer for additional output from the compiler;use System.err if null
Parameters:
  fileManager - a file manager; if null use thecompiler's standard filemanager
Parameters:
  diagnosticListener - a diagnostic listener; if null use the compiler's default method for reportingdiagnostics
Parameters:
  options - compiler options, null means no options
Parameters:
  classes - class names (for annotation processing), null means no class names
Parameters:
  compilationUnits - the compilation units to compile, null means no compilation units an object representing the compilation
throws:
  RuntimeException - if an unrecoverable erroroccurred in a user supplied component. The will be the error inuser code.
throws:
  IllegalArgumentException - if any of the givencompilation units are of other kind than




www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.