public SourceFieldSymbol( SourceTypeSymbol type, string name, Location location, Accessibility accessibility, PHPDocBlock phpdoc, PhpPropertyKind kind, BoundExpression initializer = null, ImmutableArray <AttributeData> attributes = default) { Contract.ThrowIfNull(type); Contract.ThrowIfNull(name); _containingType = type; _fieldName = name; _fieldKind = kind; _accessibility = accessibility; _initializer = initializer; _location = location; _attributes = attributes.IsDefault ? ImmutableArray <AttributeData> .Empty : attributes; PHPDocBlock = phpdoc; // implicit attributes from PHPDoc var deprecated = phpdoc?.GetElement <PHPDocBlock.DeprecatedTag>(); if (deprecated != null) { // [ObsoleteAttribute(message, false)] _attributes = _attributes.Add(DeclaringCompilation.CreateObsoleteAttribute(deprecated)); } }
public override ImmutableArray <AttributeData> GetAttributes() { var attrs = _customAttributes; // attributes from syntax node if (attrs.IsDefaultOrEmpty) { attrs = ImmutableArray <AttributeData> .Empty; } else { // initialize attribute data if necessary: attrs .OfType <SourceCustomAttribute>() .ForEach(x => x.Bind(this, _containingType.ContainingFile)); } // attributes from PHPDoc if (_phpDoc != null) { var deprecated = _phpDoc.GetElement <PHPDocBlock.DeprecatedTag>(); if (deprecated != null) { // [ObsoleteAttribute(message, false)] attrs = attrs.Add(DeclaringCompilation.CreateObsoleteAttribute(deprecated)); } // ... } // return(attrs); }
/// <summary> /// Add field as a property with getter & setter /// </summary> private CodeMemberProperty GenerateFieldCode(PHPDocBlock cmt, string name) { CodeMemberProperty prop = new CodeMemberProperty(); var vartag = cmt.GetElement <PHPDocBlock.VarTag>(); if (vartag != null) { prop.Type = ParseType(vartag.TypeNamesArray); } else { prop.Type = new CodeTypeReference(typeof(object)); } prop.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(DuckNameAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(name)))); var summary = cmt.Summary; if (!string.IsNullOrEmpty(summary)) { prop.Comments.Add(new CodeCommentStatement("<summary>\n " + summary + "\n </summary>", true)); } prop.HasGet = prop.HasSet = true; prop.Name = MakeCSharpName(name); return(prop); }
internal override TypeSymbol GetFieldType(ConsList <FieldSymbol> fieldsBeingBound) { var vartag = _phpdoc?.GetElement <PHPDocBlock.VarTag>(); if (vartag != null && vartag.TypeNamesArray.Length != 0) { var typectx = TypeRefFactory.CreateTypeRefContext(_type); var tmask = PHPDoc.GetTypeMask(typectx, vartag.TypeNamesArray); var t = DeclaringCompilation.GetTypeFromTypeRef(typectx, tmask); return(t); } // TODO: analysed PHP type return(DeclaringCompilation.CoreTypes.PhpValue); }
internal override TypeSymbol GetFieldType(ConsList <FieldSymbol> fieldsBeingBound) { // TODO: HHVM TypeHint // if ((IsConst || IsReadOnly) && Initializer != null) { // resolved type symbol if possible if (Initializer.ResultType != null) { return(Initializer.ResultType); } // resolved value type if possible var cvalue = Initializer.ConstantValue; if (cvalue.HasValue) { var specialType = (cvalue.Value != null) ? cvalue.ToConstantValueOrNull()?.SpecialType : SpecialType.System_Object; // NULL if (specialType.HasValue && specialType != SpecialType.None) { return(DeclaringCompilation.GetSpecialType(specialType.Value)); } } // //return DeclaringCompilation.GetTypeFromTypeRef(typectx, Initializer.TypeRefMask); } // PHPDoc @var type if ((DeclaringCompilation.Options.PhpDocTypes & PhpDocTypes.FieldTypes) != 0) { var vartag = _phpDoc?.GetElement <PHPDocBlock.VarTag>(); if (vartag != null && vartag.TypeNamesArray.Length != 0) { var dummyctx = TypeRefFactory.CreateTypeRefContext(_containingType); var tmask = PHPDoc.GetTypeMask(dummyctx, vartag.TypeNamesArray, NameUtils.GetNamingContext(_containingType.Syntax)); return(DeclaringCompilation.GetTypeFromTypeRef(dummyctx, tmask)); } } // default return(DeclaringCompilation.CoreTypes.PhpValue); }
/// <summary> /// Add field as a property with getter & setter /// </summary> private CodeMemberProperty GenerateFieldCode(PHPDocBlock cmt, string name) { CodeMemberProperty prop = new CodeMemberProperty(); var vartag = cmt.GetElement<PHPDocBlock.VarTag>(); if (vartag != null) prop.Type = ParseType(vartag.TypeNamesArray); else prop.Type = new CodeTypeReference(typeof(object)); prop.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(DuckNameAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(name)))); var summary = cmt.Summary; if (!string.IsNullOrEmpty(summary)) { prop.Comments.Add(new CodeCommentStatement("<summary>\n " + summary + "\n </summary>", true)); } prop.HasGet = prop.HasSet = true; prop.Name = MakeCSharpName(name); return prop; }