linkifyConstantValue method

String linkifyConstantValue(
  1. String original
)

Implementation

String linkifyConstantValue(String original) {
  if (constantInitializer is! InstanceCreationExpression) return original;
  var creationExpression = constantInitializer as InstanceCreationExpression;
  var constructorName = creationExpression.constructorName.toString();
  Element staticElement = creationExpression.constructorName.staticElement;
  if (staticElement == null) {
    warn(PackageWarning.missingConstantConstructor, message: constructorName);
    return original;
  }
  Constructor target = ModelElement.fromElement(staticElement, packageGraph);
  Class targetClass = target.enclosingElement;
  // TODO(jcollins-g): this logic really should be integrated into Constructor,
  // but that's not trivial because of linkedName's usage.
  if (targetClass.name == target.name) {
    return original.replaceAll(constructorName, '${target.linkedName}');
  }
  return original.replaceAll('${targetClass.name}.${target.name}',
      '${targetClass.linkedName}.${target.linkedName}');
}