OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 20 matching lines...) Expand all Loading... |
31 * The state of the cached parsed (but not resolved) HTML unit. | 31 * The state of the cached parsed (but not resolved) HTML unit. |
32 */ | 32 */ |
33 private CacheState parsedUnitState = CacheState.INVALID; | 33 private CacheState parsedUnitState = CacheState.INVALID; |
34 | 34 |
35 /** | 35 /** |
36 * The parsed HTML unit, or {@code null} if the parsed HTML unit is not curren
tly cached. | 36 * The parsed HTML unit, or {@code null} if the parsed HTML unit is not curren
tly cached. |
37 */ | 37 */ |
38 private HtmlUnit parsedUnit; | 38 private HtmlUnit parsedUnit; |
39 | 39 |
40 /** | 40 /** |
| 41 * The state of the cached parse errors. |
| 42 */ |
| 43 private CacheState parseErrorsState = CacheState.INVALID; |
| 44 |
| 45 /** |
| 46 * The errors produced while scanning and parsing the HTML, or {@code null} if
the errors are not |
| 47 * currently cached. |
| 48 */ |
| 49 private AnalysisError[] parseErrors = AnalysisError.NO_ERRORS; |
| 50 |
| 51 /** |
41 * The state of the cached resolution errors. | 52 * The state of the cached resolution errors. |
42 */ | 53 */ |
43 private CacheState resolutionErrorsState = CacheState.INVALID; | 54 private CacheState resolutionErrorsState = CacheState.INVALID; |
44 | 55 |
45 /** | 56 /** |
46 * The errors produced while resolving the compilation unit, or {@code null} i
f the errors are not | 57 * The errors produced while resolving the HTML, or {@code null} if the errors
are not currently |
47 * currently cached. | 58 * cached. |
48 */ | 59 */ |
49 private AnalysisError[] resolutionErrors = AnalysisError.NO_ERRORS; | 60 private AnalysisError[] resolutionErrors = AnalysisError.NO_ERRORS; |
50 | 61 |
51 /** | 62 /** |
52 * The state of the cached list of referenced libraries. | 63 * The state of the cached list of referenced libraries. |
53 */ | 64 */ |
54 private CacheState referencedLibrariesState = CacheState.INVALID; | 65 private CacheState referencedLibrariesState = CacheState.INVALID; |
55 | 66 |
56 /** | 67 /** |
57 * The list of libraries referenced in the HTML, or {@code null} if the list i
s not currently | 68 * The list of libraries referenced in the HTML, or {@code null} if the list i
s not currently |
(...skipping 25 matching lines...) Expand all Loading... |
83 /** | 94 /** |
84 * Initialize a newly created cache entry to be empty. | 95 * Initialize a newly created cache entry to be empty. |
85 */ | 96 */ |
86 public HtmlEntryImpl() { | 97 public HtmlEntryImpl() { |
87 super(); | 98 super(); |
88 } | 99 } |
89 | 100 |
90 @Override | 101 @Override |
91 public AnalysisError[] getAllErrors() { | 102 public AnalysisError[] getAllErrors() { |
92 ArrayList<AnalysisError> errors = new ArrayList<AnalysisError>(); | 103 ArrayList<AnalysisError> errors = new ArrayList<AnalysisError>(); |
93 // for (AnalysisError error : parseErrors) { | 104 for (AnalysisError error : parseErrors) { |
94 // errors.add(error); | 105 errors.add(error); |
95 // } | 106 } |
96 for (AnalysisError error : resolutionErrors) { | 107 for (AnalysisError error : resolutionErrors) { |
97 errors.add(error); | 108 errors.add(error); |
98 } | 109 } |
99 for (AnalysisError error : hints) { | 110 for (AnalysisError error : hints) { |
100 errors.add(error); | 111 errors.add(error); |
101 } | 112 } |
102 if (errors.size() == 0) { | 113 if (errors.size() == 0) { |
103 return AnalysisError.NO_ERRORS; | 114 return AnalysisError.NO_ERRORS; |
104 } | 115 } |
105 return errors.toArray(new AnalysisError[errors.size()]); | 116 return errors.toArray(new AnalysisError[errors.size()]); |
106 } | 117 } |
107 | 118 |
108 @Override | 119 @Override |
109 public SourceKind getKind() { | 120 public SourceKind getKind() { |
110 return SourceKind.HTML; | 121 return SourceKind.HTML; |
111 } | 122 } |
112 | 123 |
113 @Override | 124 @Override |
114 public CacheState getState(DataDescriptor<?> descriptor) { | 125 public CacheState getState(DataDescriptor<?> descriptor) { |
115 if (descriptor == ELEMENT) { | 126 if (descriptor == ELEMENT) { |
116 return elementState; | 127 return elementState; |
| 128 } else if (descriptor == PARSE_ERRORS) { |
| 129 return parseErrorsState; |
117 } else if (descriptor == PARSED_UNIT) { | 130 } else if (descriptor == PARSED_UNIT) { |
118 return parsedUnitState; | 131 return parsedUnitState; |
119 } else if (descriptor == REFERENCED_LIBRARIES) { | 132 } else if (descriptor == REFERENCED_LIBRARIES) { |
120 return referencedLibrariesState; | 133 return referencedLibrariesState; |
121 } else if (descriptor == RESOLUTION_ERRORS) { | 134 } else if (descriptor == RESOLUTION_ERRORS) { |
122 return resolutionErrorsState; | 135 return resolutionErrorsState; |
123 } else if (descriptor == HINTS) { | 136 } else if (descriptor == HINTS) { |
124 return hintsState; | 137 return hintsState; |
125 } | 138 } |
126 return super.getState(descriptor); | 139 return super.getState(descriptor); |
127 } | 140 } |
128 | 141 |
129 @Override | 142 @Override |
130 @SuppressWarnings("unchecked") | 143 @SuppressWarnings("unchecked") |
131 public <E> E getValue(DataDescriptor<E> descriptor) { | 144 public <E> E getValue(DataDescriptor<E> descriptor) { |
132 if (descriptor == ELEMENT) { | 145 if (descriptor == ELEMENT) { |
133 return (E) element; | 146 return (E) element; |
| 147 } else if (descriptor == PARSE_ERRORS) { |
| 148 return (E) parseErrors; |
134 } else if (descriptor == PARSED_UNIT) { | 149 } else if (descriptor == PARSED_UNIT) { |
135 return (E) parsedUnit; | 150 return (E) parsedUnit; |
136 } else if (descriptor == REFERENCED_LIBRARIES) { | 151 } else if (descriptor == REFERENCED_LIBRARIES) { |
137 return (E) referencedLibraries; | 152 return (E) referencedLibraries; |
138 } else if (descriptor == RESOLUTION_ERRORS) { | 153 } else if (descriptor == RESOLUTION_ERRORS) { |
139 return (E) resolutionErrors; | 154 return (E) resolutionErrors; |
140 } else if (descriptor == HINTS) { | 155 } else if (descriptor == HINTS) { |
141 return (E) hints; | 156 return (E) hints; |
142 } | 157 } |
143 return super.getValue(descriptor); | 158 return super.getValue(descriptor); |
144 } | 159 } |
145 | 160 |
146 @Override | 161 @Override |
147 public HtmlEntryImpl getWritableCopy() { | 162 public HtmlEntryImpl getWritableCopy() { |
148 HtmlEntryImpl copy = new HtmlEntryImpl(); | 163 HtmlEntryImpl copy = new HtmlEntryImpl(); |
149 copy.copyFrom(this); | 164 copy.copyFrom(this); |
150 return copy; | 165 return copy; |
151 } | 166 } |
152 | 167 |
153 /** | 168 /** |
154 * Invalidate all of the information associated with the HTML file. | 169 * Invalidate all of the information associated with the HTML file. |
155 */ | 170 */ |
156 public void invalidateAllInformation() { | 171 public void invalidateAllInformation() { |
157 setState(LINE_INFO, CacheState.INVALID); | 172 setState(LINE_INFO, CacheState.INVALID); |
158 | 173 |
| 174 parseErrors = AnalysisError.NO_ERRORS; |
| 175 parseErrorsState = CacheState.INVALID; |
159 parsedUnit = null; | 176 parsedUnit = null; |
160 parsedUnitState = CacheState.INVALID; | 177 parsedUnitState = CacheState.INVALID; |
161 | 178 |
162 referencedLibraries = Source.EMPTY_ARRAY; | 179 referencedLibraries = Source.EMPTY_ARRAY; |
163 referencedLibrariesState = CacheState.INVALID; | 180 referencedLibrariesState = CacheState.INVALID; |
164 | 181 |
165 invalidateAllResolutionInformation(); | 182 invalidateAllResolutionInformation(); |
166 } | 183 } |
167 | 184 |
168 /** | 185 /** |
169 * Invalidate all of the resolution information associated with the HTML file. | 186 * Invalidate all of the resolution information associated with the HTML file. |
170 */ | 187 */ |
171 public void invalidateAllResolutionInformation() { | 188 public void invalidateAllResolutionInformation() { |
172 element = null; | 189 element = null; |
173 elementState = CacheState.INVALID; | 190 elementState = CacheState.INVALID; |
174 | 191 |
175 resolutionErrors = AnalysisError.NO_ERRORS; | 192 resolutionErrors = AnalysisError.NO_ERRORS; |
176 resolutionErrorsState = CacheState.INVALID; | 193 resolutionErrorsState = CacheState.INVALID; |
177 | 194 |
178 hints = AnalysisError.NO_ERRORS; | 195 hints = AnalysisError.NO_ERRORS; |
179 hintsState = CacheState.INVALID; | 196 hintsState = CacheState.INVALID; |
180 } | 197 } |
181 | 198 |
182 /** | 199 /** |
183 * Record that an error was encountered while attempting to parse the source a
ssociated with this | 200 * Record that an error was encountered while attempting to parse the source a
ssociated with this |
184 * entry. | 201 * entry. |
185 */ | 202 */ |
186 public void recordParseError() { | 203 public void recordParseError() { |
187 setState(SourceEntry.LINE_INFO, CacheState.ERROR); | 204 setState(SourceEntry.LINE_INFO, CacheState.ERROR); |
| 205 setState(HtmlEntry.PARSE_ERRORS, CacheState.ERROR); |
188 setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR); | 206 setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR); |
189 setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.ERROR); | 207 setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.ERROR); |
190 recordResolutionError(); | 208 recordResolutionError(); |
191 } | 209 } |
192 | 210 |
193 /** | 211 /** |
194 * Record that an error was encountered while attempting to resolve the source
associated with | 212 * Record that an error was encountered while attempting to resolve the source
associated with |
195 * this entry. | 213 * this entry. |
196 */ | 214 */ |
197 public void recordResolutionError() { | 215 public void recordResolutionError() { |
198 setState(HtmlEntry.ELEMENT, CacheState.ERROR); | 216 setState(HtmlEntry.ELEMENT, CacheState.ERROR); |
199 setState(HtmlEntry.RESOLUTION_ERRORS, CacheState.ERROR); | 217 setState(HtmlEntry.RESOLUTION_ERRORS, CacheState.ERROR); |
200 setState(HtmlEntry.HINTS, CacheState.ERROR); | 218 setState(HtmlEntry.HINTS, CacheState.ERROR); |
201 } | 219 } |
202 | 220 |
203 @Override | 221 @Override |
204 public void setState(DataDescriptor<?> descriptor, CacheState state) { | 222 public void setState(DataDescriptor<?> descriptor, CacheState state) { |
205 if (descriptor == ELEMENT) { | 223 if (descriptor == ELEMENT) { |
206 element = updatedValue(state, element, null); | 224 element = updatedValue(state, element, null); |
207 elementState = state; | 225 elementState = state; |
| 226 } else if (descriptor == PARSE_ERRORS) { |
| 227 parseErrors = updatedValue(state, parseErrors, null); |
| 228 parseErrorsState = state; |
208 } else if (descriptor == PARSED_UNIT) { | 229 } else if (descriptor == PARSED_UNIT) { |
209 parsedUnit = updatedValue(state, parsedUnit, null); | 230 parsedUnit = updatedValue(state, parsedUnit, null); |
210 parsedUnitState = state; | 231 parsedUnitState = state; |
211 } else if (descriptor == REFERENCED_LIBRARIES) { | 232 } else if (descriptor == REFERENCED_LIBRARIES) { |
212 referencedLibraries = updatedValue(state, referencedLibraries, Source.EMPT
Y_ARRAY); | 233 referencedLibraries = updatedValue(state, referencedLibraries, Source.EMPT
Y_ARRAY); |
213 referencedLibrariesState = state; | 234 referencedLibrariesState = state; |
214 } else if (descriptor == RESOLUTION_ERRORS) { | 235 } else if (descriptor == RESOLUTION_ERRORS) { |
215 resolutionErrors = updatedValue(state, resolutionErrors, AnalysisError.NO_
ERRORS); | 236 resolutionErrors = updatedValue(state, resolutionErrors, AnalysisError.NO_
ERRORS); |
216 resolutionErrorsState = state; | 237 resolutionErrorsState = state; |
217 } else if (descriptor == HINTS) { | 238 } else if (descriptor == HINTS) { |
218 hints = updatedValue(state, hints, AnalysisError.NO_ERRORS); | 239 hints = updatedValue(state, hints, AnalysisError.NO_ERRORS); |
219 hintsState = state; | 240 hintsState = state; |
220 } else { | 241 } else { |
221 super.setState(descriptor, state); | 242 super.setState(descriptor, state); |
222 } | 243 } |
223 } | 244 } |
224 | 245 |
225 @Override | 246 @Override |
226 public <E> void setValue(DataDescriptor<E> descriptor, E value) { | 247 public <E> void setValue(DataDescriptor<E> descriptor, E value) { |
227 if (descriptor == ELEMENT) { | 248 if (descriptor == ELEMENT) { |
228 element = (HtmlElement) value; | 249 element = (HtmlElement) value; |
229 elementState = CacheState.VALID; | 250 elementState = CacheState.VALID; |
| 251 } else if (descriptor == PARSE_ERRORS) { |
| 252 parseErrors = (AnalysisError[]) value; |
| 253 parseErrorsState = CacheState.VALID; |
230 } else if (descriptor == PARSED_UNIT) { | 254 } else if (descriptor == PARSED_UNIT) { |
231 parsedUnit = (HtmlUnit) value; | 255 parsedUnit = (HtmlUnit) value; |
232 parsedUnitState = CacheState.VALID; | 256 parsedUnitState = CacheState.VALID; |
233 } else if (descriptor == REFERENCED_LIBRARIES) { | 257 } else if (descriptor == REFERENCED_LIBRARIES) { |
234 referencedLibraries = value == null ? Source.EMPTY_ARRAY : (Source[]) valu
e; | 258 referencedLibraries = value == null ? Source.EMPTY_ARRAY : (Source[]) valu
e; |
235 referencedLibrariesState = CacheState.VALID; | 259 referencedLibrariesState = CacheState.VALID; |
236 } else if (descriptor == RESOLUTION_ERRORS) { | 260 } else if (descriptor == RESOLUTION_ERRORS) { |
237 resolutionErrors = (AnalysisError[]) value; | 261 resolutionErrors = (AnalysisError[]) value; |
238 resolutionErrorsState = CacheState.VALID; | 262 resolutionErrorsState = CacheState.VALID; |
239 } else if (descriptor == HINTS) { | 263 } else if (descriptor == HINTS) { |
240 hints = (AnalysisError[]) value; | 264 hints = (AnalysisError[]) value; |
241 hintsState = CacheState.VALID; | 265 hintsState = CacheState.VALID; |
242 } else { | 266 } else { |
243 super.setValue(descriptor, value); | 267 super.setValue(descriptor, value); |
244 } | 268 } |
245 } | 269 } |
246 | 270 |
247 @Override | 271 @Override |
248 protected void copyFrom(SourceEntryImpl entry) { | 272 protected void copyFrom(SourceEntryImpl entry) { |
249 super.copyFrom(entry); | 273 super.copyFrom(entry); |
250 HtmlEntryImpl other = (HtmlEntryImpl) entry; | 274 HtmlEntryImpl other = (HtmlEntryImpl) entry; |
| 275 parseErrorsState = other.parseErrorsState; |
| 276 parseErrors = other.parseErrors; |
251 parsedUnitState = other.parsedUnitState; | 277 parsedUnitState = other.parsedUnitState; |
252 parsedUnit = other.parsedUnit; | 278 parsedUnit = other.parsedUnit; |
253 referencedLibrariesState = other.referencedLibrariesState; | 279 referencedLibrariesState = other.referencedLibrariesState; |
254 referencedLibraries = other.referencedLibraries; | 280 referencedLibraries = other.referencedLibraries; |
255 resolutionErrors = other.resolutionErrors; | 281 resolutionErrors = other.resolutionErrors; |
256 resolutionErrorsState = other.resolutionErrorsState; | 282 resolutionErrorsState = other.resolutionErrorsState; |
257 elementState = other.elementState; | 283 elementState = other.elementState; |
258 element = other.element; | 284 element = other.element; |
259 hints = other.hints; | 285 hints = other.hints; |
260 hintsState = other.hintsState; | 286 hintsState = other.hintsState; |
261 } | 287 } |
262 | 288 |
263 @Override | 289 @Override |
264 protected void writeOn(StringBuilder builder) { | 290 protected void writeOn(StringBuilder builder) { |
265 builder.append("Html: "); | 291 builder.append("Html: "); |
266 super.writeOn(builder); | 292 super.writeOn(builder); |
| 293 builder.append("; parseErrors = "); |
| 294 builder.append(parseErrorsState); |
267 builder.append("; parsedUnit = "); | 295 builder.append("; parsedUnit = "); |
268 builder.append(parsedUnitState); | 296 builder.append(parsedUnitState); |
269 builder.append("; resolutionErrors = "); | 297 builder.append("; resolutionErrors = "); |
270 builder.append(resolutionErrorsState); | 298 builder.append(resolutionErrorsState); |
271 builder.append("; referencedLibraries = "); | 299 builder.append("; referencedLibraries = "); |
272 builder.append(referencedLibrariesState); | 300 builder.append(referencedLibrariesState); |
273 builder.append("; element = "); | 301 builder.append("; element = "); |
274 builder.append(elementState); | 302 builder.append(elementState); |
275 } | 303 } |
276 } | 304 } |
OLD | NEW |