Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 44 additions & 10 deletions lib/src/markdown_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ class _MarkdownCommentReference {
// Squelch ambiguous doc reference warnings for parameters, because we
// don't link those anyway.
if (!results.every((r) => r is Parameter)) {
var elementNames = results.map((r) => "'${r.fullyQualifiedName}'");
element.warn(PackageWarning.ambiguousDocReference,
message:
"[$codeRef] => ${results.map((r) => "'${r.fullyQualifiedName}'").join(", ")}");
message: '[$codeRef] => ${elementNames.join(', ')}');
}
result = results.first;
}
Expand Down Expand Up @@ -683,17 +683,51 @@ class _MarkdownCommentReference {

void _findAnalyzerReferences() {
var refElement = _getRefElementFromCommentRefs(commentRefs, codeRef);
if (refElement != null) {
var refModelElement = ModelElement.fromElement(
_getRefElementFromCommentRefs(commentRefs, codeRef),
if (refElement == null) return;

ModelElement refModelElement;
if (refElement is MultiplyDefinedElement) {
var elementNames = refElement.conflictingElements
.map((e) => "'${_fullyQualifiedElementName(e)}'");
element.warn(PackageWarning.ambiguousDocReference,
message: '[$codeRef] => [${elementNames.join(', ')}]');
refModelElement = ModelElement.fromElement(
// Continue; just use the first conflicting element.
refElement.conflictingElements.first,
element.packageGraph);
if (refModelElement is Accessor) {
refModelElement = (refModelElement as Accessor).enclosingCombo;
}
} else {
refModelElement =
refModelElement.canonicalModelElement ?? refModelElement;
results.add(refModelElement);
ModelElement.fromElement(refElement, element.packageGraph);
}
if (refModelElement is Accessor) {
refModelElement = (refModelElement as Accessor).enclosingCombo;
}
refModelElement = refModelElement.canonicalModelElement ?? refModelElement;
results.add(refModelElement);
}

/// Generates a fully-qualified name, similar to that of
/// [ModelElement.fullyQualifiedName], for an Element.
static String _fullyQualifiedElementName(Element element) {
var enclosingElement = element.enclosingElement;

var enclosingName = enclosingElement == null
? null
: _fullyQualifiedElementName(enclosingElement);
var name = element.name;
if (name == null) {
if (element is ExtensionElement) {
name = '<unnamed extension>';
} else if (element is LibraryElement) {
name = '<unnamed library>';
} else if (element is CompilationUnitElement) {
return enclosingName;
} else {
name = '<unnamed ${element.runtimeType}>';
}
}

return enclosingName == null ? name : '$enclosingName.$name';
}

// Add a result, but make it canonical.
Expand Down
1 change: 1 addition & 0 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ abstract class ModelElement extends Canonicalization
return resolveMultiplyInheritedElement(
e, library, packageGraph, enclosingContainer);
}
assert(e is! MultiplyDefinedElement);
if (e is LibraryElement) {
return Library(e, packageGraph);
}
Expand Down