| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package com.google.dart.compiler.common; | 5 package com.google.dart.compiler.common; |
| 6 | 6 |
| 7 import com.google.common.base.Preconditions; | |
| 8 import com.google.dart.compiler.Source; | |
| 9 | |
| 10 /** | 7 /** |
| 11 * Abstract base class for nodes that carry source information. | 8 * Abstract base class for nodes that carry source information. |
| 12 */ | 9 */ |
| 13 public class AbstractNode implements SourceInfo, HasSourceInfo { | 10 public class AbstractNode implements HasSourceInfo { |
| 14 | 11 |
| 15 // TODO(johnlenz): All this source location data is wasteful. | 12 private SourceInfo sourceInfo = SourceInfo.UNKNOWN; |
| 16 // Move it into a common object, that can be shared between the ASTs | |
| 17 // or something. | |
| 18 protected Source source = null; | |
| 19 protected int sourceLine = -1; | |
| 20 protected int sourceColumn = -1; | |
| 21 protected int sourceStart = -1; | |
| 22 protected int sourceLength = -1; | |
| 23 | |
| 24 @Override | |
| 25 public Source getSource() { | |
| 26 return source; | |
| 27 } | |
| 28 | |
| 29 @Override | |
| 30 public int getSourceLine() { | |
| 31 return sourceLine; | |
| 32 } | |
| 33 | |
| 34 @Override | |
| 35 public int getSourceColumn() { | |
| 36 return sourceColumn; | |
| 37 } | |
| 38 | |
| 39 @Override | |
| 40 public int getSourceStart() { | |
| 41 return sourceStart; | |
| 42 } | |
| 43 | |
| 44 @Override | |
| 45 public int getSourceLength() { | |
| 46 return sourceLength; | |
| 47 } | |
| 48 | 13 |
| 49 @Override | 14 @Override |
| 50 public SourceInfo getSourceInfo() { | 15 public SourceInfo getSourceInfo() { |
| 51 return this; | 16 return sourceInfo; |
| 52 } | 17 } |
| 53 | 18 |
| 54 @Override | 19 @Override |
| 55 public void setSourceInfo(SourceInfo info) { | 20 public void setSourceInfo(SourceInfo info) { |
| 56 source = info.getSource(); | 21 sourceInfo = info; |
| 57 sourceStart = info.getSourceStart(); | |
| 58 sourceLength = info.getSourceLength(); | |
| 59 sourceLine = info.getSourceLine(); | |
| 60 sourceColumn = info.getSourceColumn(); | |
| 61 } | 22 } |
| 62 | |
| 63 @Override | |
| 64 public final void setSourceLocation( | |
| 65 Source source, int line, int column, int startPosition, int length) { | |
| 66 Preconditions.checkArgument(startPosition != -1 && length >= 0 | |
| 67 || startPosition == -1 && length == 0); | |
| 68 this.source = source; | |
| 69 this.sourceLine = line; | |
| 70 this.sourceColumn = column; | |
| 71 this.sourceStart = startPosition; | |
| 72 this.sourceLength = length; | |
| 73 } | |
| 74 | |
| 75 public final void setSourceRange(int startPosition, int length) { | |
| 76 Preconditions.checkArgument(startPosition != -1 && length >= 0 | |
| 77 || startPosition == -1 && length == 0); | |
| 78 this.sourceStart = startPosition; | |
| 79 this.sourceLength = length; | |
| 80 } | |
| 81 | |
| 82 } | 23 } |
| OLD | NEW |