bool SetFieldOrProperty(IAstAttribute aa, ExpressionPair p) { ReferenceExpression name = p.First as ReferenceExpression; if (null == name) { _context.Errors.Add(CompilerErrorFactory.NamedParameterMustBeIdentifier(p)); return(false); } else { Reflection.MemberInfo[] members = _type.FindMembers( Reflection.MemberTypes.Property | Reflection.MemberTypes.Field, Reflection.BindingFlags.Instance | Reflection.BindingFlags.Public, Type.FilterName, name.Name); if (members.Length > 0) { if (members.Length > 1) { _context.Errors.Add(CompilerErrorFactory.AmbiguousReference(name, members)); return(false); } else { Reflection.MemberInfo m = members[0]; Reflection.PropertyInfo property = m as Reflection.PropertyInfo; if (null != property) { property.SetValue(aa, p.Second, null); } else { Reflection.FieldInfo field = m as Reflection.FieldInfo; if (null != field) { field.SetValue(aa, p.Second); } else { throw new InvalidOperationException(); } } } } else { _context.Errors.Add(CompilerErrorFactory.NotAPublicFieldOrProperty(name, name.Name, _type.FullName)); return(false); } } return(true); }
bool SetFieldOrProperty(IAstAttribute aa, ExpressionPair p) { var name = p.First as ReferenceExpression; if (name == null) { _context.Errors.Add(CompilerErrorFactory.NamedParameterMustBeIdentifier(p)); return(false); } var members = FindMembers(name); if (members.Length <= 0) { _context.Errors.Add(CompilerErrorFactory.NotAPublicFieldOrProperty(name, name.Name, Type())); return(false); } if (members.Length > 1) { _context.Errors.Add(CompilerErrorFactory.AmbiguousReference(name, members)); return(false); } var member = members[0]; var property = member as PropertyInfo; if (property != null) { property.SetValue(aa, p.Second, null); return(true); } var field = (FieldInfo)member; field.SetValue(aa, p.Second); return(true); }
private IEntity AmbiguousReference(SimpleTypeReference node, Ambiguous entity) { CompilerErrors().Add(CompilerErrorFactory.AmbiguousReference(node, node.Name, entity.Entities)); return(TypeSystemServices.ErrorEntity); }
override public void OnAttribute(Ast.Attribute attribute) { if (null != attribute.Entity) { return; } var entity = NameResolutionService.ResolveQualifiedName(BuildAttributeName(attribute.Name, true)) ?? NameResolutionService.ResolveQualifiedName(BuildAttributeName(attribute.Name, false)) ?? NameResolutionService.ResolveQualifiedName(attribute.Name); if (entity == null) { var suggestion = NameResolutionService.GetMostSimilarTypeName(BuildAttributeName(attribute.Name, true)) ?? NameResolutionService.GetMostSimilarTypeName(BuildAttributeName(attribute.Name, false)); Error(attribute, CompilerErrorFactory.UnknownAttribute(attribute, attribute.Name, suggestion)); return; } if (entity.IsAmbiguous()) { Error(attribute, CompilerErrorFactory.AmbiguousReference( attribute, attribute.Name, ((Ambiguous)entity).Entities)); return; } if (EntityType.Type != entity.EntityType) { Error(attribute, CompilerErrorFactory.NameNotType(attribute, attribute.Name, entity, null)); return; } IType attributeType = ((ITypedEntity)entity).Type; if (IsAstAttribute(attributeType)) { ExternalType externalType = attributeType as ExternalType; if (null == externalType) { Error(attribute, CompilerErrorFactory.AstAttributeMustBeExternal(attribute, attributeType)); } else { ScheduleAttributeApplication(attribute, externalType.ActualType); RemoveCurrentNode(); } } else { if (!IsSystemAttribute(attributeType)) { Error(attribute, CompilerErrorFactory.TypeNotAttribute(attribute, attributeType)); } else { // remember the attribute's type attribute.Name = attributeType.FullName; attribute.Entity = entity; CheckAttributeParameters(attribute); } } }
override public void OnAttribute(Boo.Lang.Compiler.Ast.Attribute attribute) { if (null != attribute.Entity) { return; } _elements.Clear(); if (!NameResolutionService.ResolveQualifiedName(_elements, BuildAttributeName(attribute.Name))) { NameResolutionService.ResolveQualifiedName(_elements, attribute.Name); } if (_elements.Count > 0) { if (_elements.Count > 1) { Error(attribute, CompilerErrorFactory.AmbiguousReference( attribute, attribute.Name, _elements)); } else { IEntity tag = (IEntity)_elements[0]; if (EntityType.Type != tag.EntityType) { Error(attribute, CompilerErrorFactory.NameNotType(attribute, attribute.Name)); } else { 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; } } } } } else { Error(attribute, CompilerErrorFactory.UnknownAttribute(attribute, attribute.Name)); } }