Don't crash if there's no enclosing program.

Change-Id: If526d29a0fcbf9cc787127b73725088c05565efe
Reviewed-on: https://dart-review.googlesource.com/16544
Commit-Queue: Peter von der Ahé <ahe@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
This commit is contained in:
Peter von der Ahé 2017-10-26 15:38:11 +00:00 committed by commit-bot@chromium.org
parent 5c143d4353
commit a18358482e

View file

@ -417,7 +417,7 @@ class Library extends NamedNode implements Comparable<Library> {
String toString() => debugLibraryName(this);
Location _getLocationInEnclosingFile(int offset) {
return enclosingProgram.getLocation(fileUri, offset);
return _getLocationInProgram(enclosingProgram, fileUri, offset);
}
}
@ -891,7 +891,7 @@ class Class extends NamedNode {
}
Location _getLocationInEnclosingFile(int offset) {
return enclosingProgram.getLocation(fileUri, offset);
return _getLocationInProgram(enclosingProgram, fileUri, offset);
}
}
@ -1172,7 +1172,7 @@ class Field extends Member {
DartType get setterType => isMutable ? type : const BottomType();
Location _getLocationInEnclosingFile(int offset) {
return enclosingProgram.getLocation(fileUri, offset);
return _getLocationInProgram(enclosingProgram, fileUri, offset);
}
}
@ -1395,7 +1395,7 @@ class Procedure extends Member {
}
Location _getLocationInEnclosingFile(int offset) {
return enclosingProgram.getLocation(fileUri, offset);
return _getLocationInProgram(enclosingProgram, fileUri, offset);
}
}
@ -5268,3 +5268,11 @@ CanonicalName getCanonicalNameOfTypedef(Typedef typedef_) {
/// other words, if this information (or any information it refers to) changes,
/// static analysis and runtime behavior of the library are unaffected.
const informative = null;
Location _getLocationInProgram(Program program, String fileUri, int offset) {
if (program != null) {
return program.getLocation(fileUri, offset);
} else {
return new Location(fileUri, TreeNode.noOffset, TreeNode.noOffset);
}
}