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

play.exceptions.PlayExceptionWithJavaSource Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package play.exceptions;

import play.Play;

import java.util.Collections;
import java.util.List;

import static java.util.Arrays.asList;
import static play.classloading.ApplicationClasses.ApplicationClass;

public abstract class PlayExceptionWithJavaSource extends PlayException implements SourceAttachment {
    ApplicationClass applicationClass;
    Integer line;

    protected PlayExceptionWithJavaSource() {
    }

    protected PlayExceptionWithJavaSource(String message) {
        super(message);
    }

    protected PlayExceptionWithJavaSource(String message, Throwable cause, ApplicationClass applicationClass, Integer line) {
        super(message, cause);
        this.applicationClass = applicationClass;
        this.line = line;
    }

    protected PlayExceptionWithJavaSource(String message, Throwable cause) {
        super(message, cause);

        StackTraceElement element = getInterestingStrackTraceElement(cause);
        if (element != null) {
            applicationClass = Play.classes.getApplicationClass(element.getClassName());
            line = element.getLineNumber();
        }
    }

    @Override
    public String getSourceFile() {
        return isSourceAvailable() && applicationClass.javaFile != null ? applicationClass.javaFile.relativePath() : null;
    }

    @Override
    public List getSource() {
        return isSourceAvailable() ? asList(applicationClass.javaSource.split("\n")) : Collections.emptyList();
    }

    @Override
    public Integer getLineNumber() {
        return line;
    }

    @Override
    public boolean isSourceAvailable() {
        return applicationClass != null && applicationClass.javaSource != null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy