public override void OnAttribute(Boo.Lang.Compiler.Ast.Attribute attribute)
{
if (null != attribute.Entity)
{
return;
}
_elements.Clear();
if (!NameResolutionService.ResolveQualifiedName(_elements, BuildAttributeName(attribute.Name, true)))
{
if (!NameResolutionService.ResolveQualifiedName(_elements, BuildAttributeName(attribute.Name, false)))
{
NameResolutionService.ResolveQualifiedName(_elements, attribute.Name);
}
}
if (_elements.Count == 0)
{
string suggestion = NameResolutionService.GetMostSimilarTypeName(BuildAttributeName(attribute.Name, true));
if (null == suggestion)
suggestion = NameResolutionService.GetMostSimilarTypeName(BuildAttributeName(attribute.Name, false));
Error(attribute, CompilerErrorFactory.UnknownAttribute(attribute, attribute.Name, suggestion));
return;
}
if (_elements.Count > 1)
{
Error(attribute, CompilerErrorFactory.AmbiguousReference(
attribute,
attribute.Name,
_elements));
return;
}
// if _elements.Count == 1
IEntity tag = (IEntity)_elements[0];
if (EntityType.Type != tag.EntityType)
{
Error(attribute, CompilerErrorFactory.NameNotType(attribute, attribute.Name, null));
return;
}
IType attributeType = ((ITypedEntity)tag).Type;
if (IsAstAttribute(attributeType))
{
ExternalType externalType = attributeType as ExternalType;
if (null == externalType)
{
Error(attribute, CompilerErrorFactory.AstAttributeMustBeExternal(attribute, attributeType.FullName));
}
else
{
ScheduleAttributeApplication(attribute, externalType.ActualType);
RemoveCurrentNode();
}
}
else
{
if (!IsSystemAttribute(attributeType))
{
Error(attribute, CompilerErrorFactory.TypeNotAttribute(attribute, attributeType.FullName));
}
else
{
// remember the attribute's type
attribute.Name = attributeType.FullName;
attribute.Entity = attributeType;
CheckAttributeParameters(attribute);
}
}
}