com.greenpepper.annotation.ExceptionAnnotation Maven / Gradle / Ivy
The newest version!
package com.greenpepper.annotation;
import java.util.UUID;
import com.greenpepper.Text;
import com.greenpepper.util.ExceptionUtils;
/**
* ExceptionAnnotation class.
*
* @author oaouattara
* @version $Id: $Id
*/
public class ExceptionAnnotation implements Annotation {
private final Throwable error;
/**
* Constructor for ExceptionAnnotation.
*
* @param error a {@link java.lang.Throwable} object.
*/
public ExceptionAnnotation(Throwable error) {
this.error = error;
}
/** {@inheritDoc} */
public void writeDown(Text text) {
text.setStyle(Styles.BACKGROUND_COLOR, Colors.YELLOW);
text.setStatus( Status.ERROR );
StringBuilder textContent = new StringBuilder(text.getContent());
textContent.append("
")
.append(error.getClass().getSimpleName())
.append(": ")
.append(error.getMessage())
.append("");
UUID randomUUID = UUID.randomUUID();
String expandButtonID = randomUUID.toString() + "-show";
textContent.append("\n+");
String collapseButtonID = randomUUID.toString() + "-hide";
textContent.append("\n-");
textContent.append("\n")
.append(ExceptionUtils.stackTrace(error, "\n", 10))
.append("
");
text.setContent(textContent.toString());
}
/**
* toString.
*
* @return a {@link java.lang.String} object.
*/
public String toString() {
return ExceptionUtils.stackTrace(error, "\n", 10);
}
/**
* getExceptionMessage.
*
* @return a {@link java.lang.String} object.
*/
public String getExceptionMessage() {
return error.getMessage();
}
}