1 52 53 package com.go.teaservlet; 54 55 import com.go.tea.compiler.ErrorEvent; 56 57 63 public class TemplateError { 64 private String mErrorMessage; 65 private String mDetailedErrorMessage; 66 private String mSourceInfoMessage; 67 private String mSourceLine; 68 private int mErrorStartPos; 69 private int mDetailPos; 70 private int mErrorEndPos; 71 72 public TemplateError(ErrorEvent errorEvent, String sourceLine, 73 int errorStartPos, int detailPos, int errorEndPos) { 74 mErrorMessage = errorEvent.getErrorMessage(); 75 mSourceInfoMessage = errorEvent.getSourceInfoMessage(); 76 mDetailedErrorMessage = errorEvent.getDetailedErrorMessage(); 77 mSourceLine = sourceLine; 78 79 int length = sourceLine.length(); 80 if ((mErrorStartPos = errorStartPos) > length) { 81 mErrorStartPos = length - 1; 82 } 83 if ((mDetailPos = detailPos) > length) { 84 mDetailPos = length - 1; 85 } 86 if ((mErrorEndPos = errorEndPos) > length) { 87 mErrorEndPos = length - 1; 88 } 89 } 90 91 public String getErrorMessage() { 92 return mErrorMessage; 93 } 94 95 public String getDetailedErrorMessage() { 96 return mDetailedErrorMessage; 97 } 98 99 public String getSourceInfoMessage() { 100 return mSourceInfoMessage; 101 } 102 103 public String getSourceLine() { 104 return mSourceLine; 105 } 106 107 public String getLineStart() { 108 try { 109 return mSourceLine.substring(0, mErrorStartPos); 110 } 111 catch (IndexOutOfBoundsException e) { 112 return ""; 113 } 114 } 115 116 public String getErrorStart() { 117 try { 118 return mSourceLine.substring(mErrorStartPos, mDetailPos); 119 } 120 catch (IndexOutOfBoundsException e) { 121 return ""; 122 } 123 } 124 125 public String getDetail() { 126 try { 127 return mSourceLine.substring(mDetailPos, mDetailPos + 1); 128 } 129 catch (IndexOutOfBoundsException e) { 130 return ""; 131 } 132 } 133 134 public String getErrorEnd() { 135 try { 136 return mSourceLine.substring(mDetailPos + 1, mErrorEndPos + 1); 137 } 138 catch (IndexOutOfBoundsException e) { 139 return ""; 140 } 141 } 142 143 public String getLineEnd() { 144 try { 145 return mSourceLine.substring 146 (mErrorEndPos + 1, mSourceLine.length()); 147 } 148 catch (IndexOutOfBoundsException e) { 149 return ""; 150 } 151 } 152 } 153 | Popular Tags |