OLD | NEW |
(Empty) | |
| 1 package com.google.dart.engine.internal.index.file; |
| 2 |
| 3 import com.google.dart.engine.context.AnalysisContext; |
| 4 import com.google.dart.engine.element.Element; |
| 5 import com.google.dart.engine.index.Location; |
| 6 |
| 7 /** |
| 8 * A container with information about a {@link Location}. |
| 9 * |
| 10 * @coverage dart.engine.index |
| 11 */ |
| 12 public class LocationData { |
| 13 final int elementId; |
| 14 final int offset; |
| 15 final int length; |
| 16 |
| 17 public LocationData(ElementCodec elementCodec, Location location) { |
| 18 Element element = location.getElement(); |
| 19 this.elementId = elementCodec.encode(element); |
| 20 this.offset = location.getOffset(); |
| 21 this.length = location.getLength(); |
| 22 } |
| 23 |
| 24 public LocationData(int elementId, int offset, int length) { |
| 25 this.elementId = elementId; |
| 26 this.offset = offset; |
| 27 this.length = length; |
| 28 } |
| 29 |
| 30 @Override |
| 31 public boolean equals(Object obj) { |
| 32 if (!(obj instanceof LocationData)) { |
| 33 return false; |
| 34 } |
| 35 LocationData other = (LocationData) obj; |
| 36 return other.elementId == elementId && other.offset == offset && other.lengt
h == length; |
| 37 } |
| 38 |
| 39 /** |
| 40 * Returns a {@link Location} that is represented by this {@link LocationData}
. |
| 41 */ |
| 42 public Location getLocation(AnalysisContext context, ElementCodec elementCodec
) { |
| 43 Element element = elementCodec.decode(context, elementId); |
| 44 if (element == null) { |
| 45 return null; |
| 46 } |
| 47 return new Location(element, offset, length); |
| 48 } |
| 49 |
| 50 @Override |
| 51 public int hashCode() { |
| 52 return 31 * (31 * elementId + offset) + length; |
| 53 } |
| 54 } |
OLD | NEW |