All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mogudiandian.util.javac.DynamicCompilerException Maven / Gradle / Ivy

There is a newer version: 1.0.19
Show newest version
package com.mogudiandian.util.javac;

import javax.tools.Diagnostic;
import javax.tools.JavaFileObject;
import java.util.List;

/**
 * 动态编译期间产生的异常
 * @author Joshua Sun
 * @since 1.0.0
 */
public final class DynamicCompilerException extends Exception {

    private List> diagnostics;

    public DynamicCompilerException(String message, List> diagnostics) {
        super(message);
        this.diagnostics = diagnostics;
    }

    public DynamicCompilerException(Throwable e, List> diagnostics) {
        super(e);
        this.diagnostics = diagnostics;
    }

    /**
     * 获取编译器诊断的错误
     * @return 错误信息
     */
    public String getDiagnosticsError() {
        StringBuilder builder = new StringBuilder();
        if (diagnostics != null) {
            for (Diagnostic diagnostic : diagnostics) {
                builder.append(String.format("Error on line %d: %s\n", diagnostic.getLineNumber(), diagnostic.getMessage(null)));
            }
        }
        return builder.toString();
    }

    @Override
    public String toString() {
        return getDiagnosticsError();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy