/// <summary> /// Initializes a new instance of the <see cref="PropertyASTWalker"/> class. /// </summary> /// <param name="node"></param> /// <param name="propertyDeclaration"></param> /// <param name="semanticModel">The semantic model.</param> protected PropertyASTWalker(CSharpSyntaxNode node, PropertyDeclarationTranslationUnit propertyDeclaration, SemanticModel semanticModel) : base(node, semanticModel) { var propertyDeclarationSyntaxNode = node as PropertyDeclarationSyntax; if (propertyDeclarationSyntaxNode == null) { throw new ArgumentException( string.Format("Specified node is not of type {0}", typeof(PropertyDeclarationSyntax).Name)); } if (propertyDeclaration == null) { throw new ArgumentNullException(nameof(propertyDeclaration)); } this.propertyDeclaration = propertyDeclaration; // Going through accessors in the node and filling the translation unit with initial data this.VisitNode(propertyDeclarationSyntaxNode); }
/// <summary> /// /// </summary> /// <param name="visibility"></param> /// <param name="returnType"></param> /// <param name="name"></param> /// <param name="getStatements"></param> /// <param name="setStatements"></param> /// <returns></returns> public static ITranslationUnit BuildPropertyTranslationUnit(ModifierTokens modifiers, string returnType, string name, ITranslationUnit[] getStatements = null, ITranslationUnit[] setStatements = null) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (returnType == null) { throw new ArgumentNullException(nameof(returnType)); } PropertyDeclarationTranslationUnit translationUnit = PropertyDeclarationTranslationUnit.Create( modifiers, TypeIdentifierTranslationUnit.Create(returnType), IdentifierTranslationUnit.Create(name), true, true); if (getStatements != null) { var statementsGroup = StatementsGroupTranslationUnit.Create(); foreach (ITranslationUnit statement in getStatements) { statementsGroup.AddStatement(statement); } translationUnit.SetGetAccessor(statementsGroup); } if (setStatements != null) { var statementsGroup = StatementsGroupTranslationUnit.Create(); foreach (ITranslationUnit statement in setStatements) { statementsGroup.AddStatement(statement); } translationUnit.SetSetAccessor(statementsGroup); } return(translationUnit); }
/// <summary> /// Creates the translation unit. /// </summary> /// <param name="modifiers"></param> /// <param name="type"></param> /// <param name="name"></param> /// <param name="hasGet"></param> /// <param name="hasSet"></param> /// <returns></returns> protected virtual ITranslationUnit CreateTranslationUnit( ModifierTokens modifiers, ITranslationUnit type, ITranslationUnit name, bool hasGet, bool hasSet) { return(PropertyDeclarationTranslationUnit.Create(modifiers, type, name, hasGet, hasSet)); }
/// <summary> /// Copy initializes a new instance of the <see cref="PropertyASTWalker"/> class. /// </summary> /// <param name="other"></param> /// <remarks> /// For testability. /// </remarks> public PropertyASTWalker(PropertyASTWalker other) : base(other) { this.propertyDeclaration = other.propertyDeclaration; }
/// <summary> /// Creates the translation unit. /// </summary> /// <param name="visibility"></param> /// <param name="type"></param> /// <param name="name"></param> /// <param name="hasGet"></param> /// <param name="hasSet"></param> /// <returns></returns> protected virtual ITranslationUnit CreateTranslationUnit( VisibilityToken visibility, ITranslationUnit type, ITranslationUnit name, bool hasGet, bool hasSet) { return(PropertyDeclarationTranslationUnit.Create(visibility, type, name, hasGet, hasSet)); }