If canonicalLibrary (or canonicalEnclosingElement, for Inheritable subclasses) is null, href should be null.
Source
@override
String get href {
String retval;
if (canonicalLibrary == null) return null;
if (enclosingElement is Class) {
if (canonicalEnclosingElement == null) return null;
retval =
'${canonicalEnclosingElement.canonicalLibrary.dirName}/${canonicalEnclosingElement.name}/$_fileName';
} else if (enclosingElement is Library) {
retval = '${canonicalLibrary.dirName}/$_fileName';
} else {
throw new StateError(
'$name is not in a class or library, instead it is a ${enclosingElement.element}');
}
return retval;
}