/sitebricks/src/main/java/com/google/sitebricks/compiler/AnalysisError.java
http://github.com/dhanji/sitebricks · Java · 104 lines · 71 code · 26 blank · 7 comment · 0 complexity · 5f9e1eba18aafa3b1b564abea058a5e9 MD5 · raw file
- package com.google.sitebricks.compiler;
- import org.mvel2.ErrorDetail;
- /**
- * Represents a static analysis error or warning due to a
- * sitebricks static check failure.
- *
- * @author Dhanji R. Prasanna (dhanji@gmail.com)
- */
- public abstract class AnalysisError {
- public abstract CompileErrors getReason();
- public static CompileErrorBuilder in(String fragment) {
- return new Builder(fragment);
- }
- public static interface CompileErrorBuilder {
- CompileErrorBuilder near(int line);
- AnalysisError causedBy(ExpressionCompileException e);
- AnalysisError causedBy(CompileErrors reason);
- AnalysisError causedBy(CompileErrors reason, ExpressionCompileException e);
- AnalysisError causedBy(CompileErrors reason, String cause);
- }
- private static class Builder implements CompileErrorBuilder {
- private final String fragment;
- private int line;
- private Builder(String fragment) {
- this.fragment = fragment;
- }
- public CompileErrorBuilder near(int line) {
- this.line = line;
- return this;
- }
- public AnalysisError causedBy(ExpressionCompileException e) {
- return new AnalysisErrorImpl(fragment, line, e.getError());
- }
- public AnalysisError causedBy(CompileErrors reason) {
- return new AnalysisErrorImpl(fragment, line, reason);
- }
- public AnalysisError causedBy(CompileErrors reason, ExpressionCompileException e) {
- return new AnalysisErrorImpl(fragment, line, e.getError(), reason);
- }
- public AnalysisError causedBy(CompileErrors reason, String cause) {
- return new AnalysisErrorImpl(fragment, line,
- new EvaluatorCompiler.CompileErrorDetail(cause, new ErrorDetail(fragment.toCharArray(), line, true, cause)), reason);
- }
- }
- private static class AnalysisErrorImpl extends AnalysisError {
- private final String fragment;
- private final int line;
- private final EvaluatorCompiler.CompileErrorDetail error;
- private final CompileErrors reason;
- public AnalysisErrorImpl(String fragment, int line, EvaluatorCompiler.CompileErrorDetail error) {
- this.fragment = fragment;
- this.line = line;
- this.error = error;
- this.reason = CompileErrors.ILLEGAL_EXPRESSION;
- }
- public AnalysisErrorImpl(String fragment, int line, CompileErrors reason) {
- this.fragment = fragment;
- this.line = line;
- this.reason = reason;
- this.error = null;
- }
- public AnalysisErrorImpl(String fragment, int line, EvaluatorCompiler.CompileErrorDetail error,
- CompileErrors reason) {
- this.fragment = fragment;
- this.line = line;
- this.error = error;
- this.reason = reason;
- }
- @Override
- public String toString() {
- //TODO make this nicer?
- return reason.toString();
- }
- public CompileErrors getReason() {
- return null;
- }
- }
- }