本文整理汇总了Java中javax.tools.DiagnosticListener类的典型用法代码示例。如果您正苦于以下问题:Java DiagnosticListener类的具体用法?Java DiagnosticListener怎么用?Java DiagnosticListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DiagnosticListener类属于javax.tools包,在下文中一共展示了DiagnosticListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createJavacTask
import javax.tools.DiagnosticListener; //导入依赖的package包/类
public static JavacTaskImpl createJavacTask (
@NonNull final ClasspathInfo cpInfo,
@NullAllowed final DiagnosticListener<? super JavaFileObject> diagnosticListener,
@NullAllowed final String sourceLevel,
@NullAllowed final SourceLevelQuery.Profile sourceProfile,
@NullAllowed FQN2Files fqn2Files,
@NullAllowed final CancelService cancelService,
@NullAllowed final APTUtils aptUtils,
@NullAllowed final CompilerOptionsQuery.Result compilerOptions,
@NonNull Iterable<? extends JavaFileObject> files) {
return createJavacTask(
cpInfo,
diagnosticListener,
sourceLevel,
sourceProfile,
EnumSet.of(ConfigFlags.BACKGROUND_COMPILATION, ConfigFlags.MULTI_SOURCE),
fqn2Files,
cancelService,
aptUtils,
compilerOptions,
Collections.emptySet(),
files);
}
示例2: CompilationInfoImpl
import javax.tools.DiagnosticListener; //导入依赖的package包/类
/**
* Creates a new CompilationInfoImpl for given source file
* @param parser used to parse the file
* @param file to be parsed
* @param root the owner of the parsed file
* @param javacTask used javac or null if new one should be created
* @param snapshot rendered content of the file
* @param detached true if the CompilationInfoImpl is detached from parsing infrastructure.
* @throws java.io.IOException
*/
CompilationInfoImpl (final JavacParser parser,
final FileObject file,
final FileObject root,
final JavacTaskImpl javacTask,
final DiagnosticListener<JavaFileObject> diagnosticListener,
final Snapshot snapshot,
final boolean detached) throws IOException {
assert parser != null;
this.parser = parser;
this.cpInfo = parser.getClasspathInfo();
assert cpInfo != null;
this.file = file;
this.root = root;
this.snapshot = snapshot;
assert file == null || snapshot != null;
this.jfo = file != null ?
FileObjects.sourceFileObject(file, root, JavaFileFilterQuery.getFilter(file), snapshot.getText()) :
null;
this.javacTask = javacTask;
this.diagnosticListener = diagnosticListener;
this.isClassFile = false;
this.isDetached = detached;
}
示例3: getSourceFileForInput
import javax.tools.DiagnosticListener; //导入依赖的package包/类
public JavaFileObject getSourceFileForInput( Location location, String fqn, JavaFileObject.Kind kind, DiagnosticListener<JavaFileObject> errorHandler )
{
try
{
JavaFileObject file = super.getJavaFileForInput( location, fqn, kind );
if( file != null )
{
return file;
}
}
catch( IOException ignore )
{
}
return findGeneratedFile( fqn.replace( '$', '.' ), ManifoldHost.getCurrentModule(), errorHandler );
}
示例4: compileJava
import javax.tools.DiagnosticListener; //导入依赖的package包/类
public static int compileJava(Context context, JavaProjectFolder projectFile, @Nullable DiagnosticListener listener) {
try {
String[] args = new String[]{
"-verbose",
"-cp", projectFile.getJavaClassPath(context),
"-sourcepath", projectFile.getSourcePath(), //sourcepath
"-d", projectFile.getDirBuildClasses().getPath(), //output dir
projectFile.getMainClass().getPath(projectFile) //main class
};
DLog.d(TAG, "compileJava args = " + Arrays.toString(args));
int compileStatus;
compileStatus = Javac.compile(args, listener);
return compileStatus;
} catch (Throwable e) {
e.printStackTrace();
}
return Main.EXIT_ERROR;
}
示例5: JavapTask
import javax.tools.DiagnosticListener; //导入依赖的package包/类
public JavapTask(Writer out,
JavaFileManager fileManager,
DiagnosticListener<? super JavaFileObject> diagnosticListener,
Iterable<String> options,
Iterable<String> classes) {
this(out, fileManager, diagnosticListener);
this.classes = new ArrayList<String>();
for (String classname: classes) {
classname.getClass(); // null-check
this.classes.add(classname);
}
try {
if (options != null)
handleOptions(options, false);
} catch (BadArgs e) {
throw new IllegalArgumentException(e.getMessage());
}
}
示例6: getDiagnosticListenerForWriter
import javax.tools.DiagnosticListener; //导入依赖的package包/类
private DiagnosticListener<JavaFileObject> getDiagnosticListenerForWriter(Writer w) {
final PrintWriter pw = getPrintWriterForWriter(w);
return new DiagnosticListener<JavaFileObject> () {
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
switch (diagnostic.getKind()) {
case ERROR:
pw.print(getMessage("err.prefix"));
break;
case WARNING:
pw.print(getMessage("warn.prefix"));
break;
case NOTE:
pw.print(getMessage("note.prefix"));
break;
}
pw.print(" ");
pw.println(diagnostic.getMessage(null));
}
};
}
示例7: JavahTask
import javax.tools.DiagnosticListener; //导入依赖的package包/类
JavahTask(Writer out,
JavaFileManager fileManager,
DiagnosticListener<? super JavaFileObject> diagnosticListener,
Iterable<String> options,
Iterable<String> classes) {
this();
this.log = getPrintWriterForWriter(out);
this.fileManager = fileManager;
this.diagnosticListener = diagnosticListener;
try {
handleOptions(options, false);
} catch (BadArgs e) {
throw new IllegalArgumentException(e.getMessage());
}
this.classes = new ArrayList<String>();
if (classes != null) {
for (String classname: classes) {
classname.getClass(); // null-check
this.classes.add(classname);
}
}
}
示例8: Log
import javax.tools.DiagnosticListener; //导入依赖的package包/类
/** Construct a log with given I/O redirections.
*/
protected Log(Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) {
super(JCDiagnostic.Factory.instance(context));
context.put(logKey, this);
this.errWriter = errWriter;
this.warnWriter = warnWriter;
this.noticeWriter = noticeWriter;
@SuppressWarnings("unchecked") // FIXME
DiagnosticListener<? super JavaFileObject> dl =
context.get(DiagnosticListener.class);
this.diagListener = dl;
diagnosticHandler = new DefaultDiagnosticHandler();
messages = JavacMessages.instance(context);
messages.add(Main.javacBundleName);
final Options options = Options.instance(context);
initOptions(options);
options.addListener(new Runnable() {
public void run() {
initOptions(options);
}
});
}
示例9: JavapTask
import javax.tools.DiagnosticListener; //导入依赖的package包/类
public JavapTask(Writer out,
JavaFileManager fileManager,
DiagnosticListener<? super JavaFileObject> diagnosticListener,
Iterable<String> options,
Iterable<String> classes) {
this(out, fileManager, diagnosticListener);
this.classes = new ArrayList<>();
for (String classname: classes) {
Objects.requireNonNull(classname);
this.classes.add(classname);
}
try {
if (options != null)
handleOptions(options, false);
} catch (BadArgs e) {
throw new IllegalArgumentException(e.getMessage());
}
}
示例10: getDiagnosticListenerForWriter
import javax.tools.DiagnosticListener; //导入依赖的package包/类
private DiagnosticListener<JavaFileObject> getDiagnosticListenerForWriter(Writer w) {
final PrintWriter pw = getPrintWriterForWriter(w);
return diagnostic -> {
switch (diagnostic.getKind()) {
case ERROR:
pw.print(getMessage("err.prefix"));
break;
case WARNING:
pw.print(getMessage("warn.prefix"));
break;
case NOTE:
pw.print(getMessage("note.prefix"));
break;
}
pw.print(" ");
pw.println(diagnostic.getMessage(null));
};
}
示例11: report
import javax.tools.DiagnosticListener; //导入依赖的package包/类
void report( DiagnosticListener<JavaFileObject> errorHandler )
{
if( errorHandler == null )
{
return;
}
List<IIssue> issues = getIssues();
if( issues.isEmpty() )
{
return;
}
JavaFileObject file = new SourceJavaFileObject( getFile().toURI() );
for( IIssue issue : issues )
{
Diagnostic.Kind kind = issue.getKind() == IIssue.Kind.Error ? Diagnostic.Kind.ERROR : Diagnostic.Kind.WARNING;
errorHandler.report( new JavacDiagnostic( file, kind, issue.getStartOffset(), issue.getLine(), issue.getColumn(), issue.getMessage() ) );
}
}
示例12: JavahTask
import javax.tools.DiagnosticListener; //导入依赖的package包/类
JavahTask(Writer out,
JavaFileManager fileManager,
DiagnosticListener<? super JavaFileObject> diagnosticListener,
Iterable<String> options,
Iterable<String> classes) {
this();
this.log = getPrintWriterForWriter(out);
this.fileManager = fileManager;
this.diagnosticListener = diagnosticListener;
try {
handleOptions(options, false);
} catch (BadArgs e) {
throw new IllegalArgumentException(e.getMessage());
}
this.classes = new ArrayList<>();
if (classes != null) {
for (String classname: classes) {
Objects.requireNonNull(classname);
this.classes.add(classname);
}
}
}
示例13: Log
import javax.tools.DiagnosticListener; //导入依赖的package包/类
/**
* Creates a log.
* @param context the context in which the log should be registered
* @param writers a map of writers that can be accessed by the kind of writer required
*/
private Log(Context context, Map<WriterKind, PrintWriter> writers) {
super(JCDiagnostic.Factory.instance(context));
context.put(logKey, this);
this.writers = writers;
@SuppressWarnings("unchecked") // FIXME
DiagnosticListener<? super JavaFileObject> dl =
context.get(DiagnosticListener.class);
this.diagListener = dl;
diagnosticHandler = new DefaultDiagnosticHandler();
messages = JavacMessages.instance(context);
messages.add(Main.javacBundleName);
final Options options = Options.instance(context);
initOptions(options);
options.addListener(() -> initOptions(options));
}
示例14: clear
import javax.tools.DiagnosticListener; //导入依赖的package包/类
void clear() {
drop(Arguments.argsKey);
drop(DiagnosticListener.class);
drop(Log.outKey);
drop(Log.errKey);
drop(JavaFileManager.class);
drop(JavacTask.class);
if (ht.get(Log.logKey) instanceof ReusableLog) {
//log already inited - not first round
((ReusableLog)Log.instance(this)).clear();
Enter.instance(this).newRound();
((ReusableJavaCompiler)ReusableJavaCompiler.instance(this)).clear();
Types.instance(this).newRound();
Check.instance(this).newRound();
Modules.instance(this).newRound();
Annotate.instance(this).newRound();
CompileStates.instance(this).clear();
MultiTaskListener.instance(this).clear();
//find if any of the roots have redefined java.* classes
Symtab syms = Symtab.instance(this);
pollutionScanner.scan(roots, syms);
roots.clear();
}
}
示例15: getTask
import javax.tools.DiagnosticListener; //导入依赖的package包/类
@Override
public JavaCompiler.CompilationTask getTask(Writer out, JavaFileManager fileManager,
DiagnosticListener<? super JavaFileObject> diagnosticListener,
Iterable<String> options, Iterable<String> classes,
Iterable<? extends JavaFileObject> compilationUnits) {
return compiler.getTask(out, fileManager, diagnosticListener, options, classes, compilationUnits);
}