public override void ExtendDeclaration(IDeclarationModel declaration, CompilationModel model) { // this only applies to properties var propDecl = declaration as PropertyDeclaration; if (propDecl == null || propDecl.Container == null) return; var container = propDecl.Container; container.RemoveMember(propDecl); var field = new FieldDeclaration { Container = container, OriginatingNode = propDecl.OriginatingNode, OriginatingTree = propDecl.OriginatingTree, Definition = new FieldDefinition { Name = propDecl.Name, ContainingType = propDecl.Definition.ContainingType, Kind = DefinitionKind.Member, MemberKind = MemberDefinitionKind.Field, Type = propDecl.Definition.Type } }; field.Definition.Modifiers.Apply(propDecl.Definition.Modifiers); container.AddMember(field); }
public override void ExtendDeclaration(IDeclarationModel declaration, CompilationModel model) { // this only applies to properties var propDecl = declaration as PropertyDeclaration; if (propDecl == null || propDecl.Container == null) { return; } var container = propDecl.Container; container.RemoveMember(propDecl); var field = new FieldDeclaration { Container = container, OriginatingNode = propDecl.OriginatingNode, OriginatingTree = propDecl.OriginatingTree, Definition = new FieldDefinition { Name = propDecl.Name, ContainingType = propDecl.Definition.ContainingType, Type = propDecl.Definition.Type } }; field.Definition.Modifiers.Apply(propDecl.Definition.Modifiers); container.AddMember(field); }
public override void ExtendDeclaration(IDeclarationModel declaration, CompilationModel model) { if (declaration.Definition == null) { return; } switch (declaration.Definition.Kind) { case DefinitionKind.Type: var typeDecl = declaration as ITypeDeclarationModel; if (typeDecl != null) { model.RemoveType(typeDecl); } break; case DefinitionKind.Member: var memberDecl = declaration as IMemberDeclarationModel; if (memberDecl != null && memberDecl.Container != null) { memberDecl.Container.RemoveMember(memberDecl); } break; } }
public override void ExtendDeclaration(IDeclarationModel declaration, CompilationModel model) { var classDecl = declaration as ClassDeclaration; if (classDecl.Definition == null) throw new CompilationException("A script object literal attribute may only be applied to a class.", declaration); ValidateClass(classDecl); // remove from the model, this produces no declaration model.RemoveType(classDecl); }
public override void ExtendDeclaration(IDeclarationModel declaration, CompilationModel model) { // this only applies to methods var methodDecl = declaration as MethodDeclaration; if (methodDecl == null || methodDecl.Container == null) return; if (!methodDecl.Definition.Symbol.IsExtensionMethod) throw new CompilationException("The ScriptMixin attribute can only be applied to extension methods.", declaration); // remove the function from the container methodDecl.Container.RemoveMember(methodDecl); // get the extension target info var extTarget = methodDecl.Parameters[0]; var extType = extTarget.Definition.Type; // rewrite first param as a local declaration to this context var thisDecl = new LocalDeclarationStatement { VariableDeclaration = new VariableDeclaration() }; thisDecl.VariableDeclaration.Variables.Add(new VariableDeclarator { Definition = new LocalDefinition { Name = extTarget.Name, Type = extType }, EqualsValueExpression = new LiteralExpression { Text = "this" } }); // add the declaration to the method body methodDecl.Body.Statements.Insert(0, thisDecl); // create a lambda using the method body. var lambdaExpression = new LambdaExpression(); lambdaExpression.Body = methodDecl.Body; for (int i = 1; i < methodDecl.Parameters.Count; i++) lambdaExpression.Parameters.Add(methodDecl.Parameters[i]); // create a global statement to set the prototype value var target = extType.GetFullName() + ".prototype." + methodDecl.Definition.Name; model.GlobalStatements.Add(new ExpressionStatement { Expression = new BinaryExpression { LeftExpression = new LiteralExpression { Text = target }, RightExpression = lambdaExpression, Operator = "=" } }); }
public override void ExtendDeclaration(IDeclarationModel declaration, CompilationModel model) { var classDecl = declaration as ClassDeclaration; if (classDecl.Definition == null) { throw new CompilationException("A script object literal attribute may only be applied to a class.", declaration); } ValidateClass(classDecl); // remove from the model, this produces no declaration model.RemoveType(classDecl); }
public override void ExtendDeclaration(IDeclarationModel declaration, CompilationModel model) { if (declaration.Definition == null) return; switch (declaration.Definition.Kind) { case DefinitionKind.Type: var typeDecl = declaration as ITypeDeclarationModel; if (typeDecl != null) model.RemoveType(typeDecl); break; case DefinitionKind.Member: var memberDecl = declaration as IMemberDeclarationModel; if (memberDecl != null && memberDecl.Container != null) memberDecl.Container.RemoveMember(memberDecl); break; } }
/// <summary> /// Extends a declaration. /// </summary> /// <param name="declaration">The target declaration.</param> /// <param name="model">The containing compilation model.</param> public virtual void ExtendDeclaration(IDeclarationModel declaration, CompilationModel model) { }
public static IEnumerable <T> FindReferencesInGraph <T>(this IGraphModel self, IDeclarationModel variableDeclarationModel) where T : IHasDeclarationModel { return(self.FindReferencesInGraph(variableDeclarationModel).OfType <T>()); }
public static IEnumerable <IHasDeclarationModel> FindReferencesInGraph(this IGraphModel self, IDeclarationModel variableDeclarationModel) { return(self.NodeModels.OfType <IHasDeclarationModel>().Where(v => v.DeclarationModel != null && variableDeclarationModel.Guid == v.DeclarationModel.Guid)); }
public override void ExtendDeclaration(IDeclarationModel declaration, CompilationModel model) { // this only applies to methods var methodDecl = declaration as MethodDeclaration; if (methodDecl == null || methodDecl.Container == null) { return; } if (!methodDecl.Definition.Symbol.IsExtensionMethod) { throw new CompilationException("The ScriptMixin attribute can only be applied to extension methods.", declaration); } // remove the function from the container methodDecl.Container.RemoveMember(methodDecl); // get the extension target info var extTarget = methodDecl.Parameters[0]; var extType = extTarget.Definition.Type; // rewrite first param as a local declaration to this context var thisDecl = new LocalDeclarationStatement { VariableDeclaration = new VariableDeclaration() }; thisDecl.VariableDeclaration.Variables.Add(new VariableDeclarator { Definition = new LocalDefinition { Name = extTarget.Name, Type = extType }, EqualsValueExpression = new LiteralExpression { Text = "this" } }); // add the declaration to the method body methodDecl.Body.Statements.Insert(0, thisDecl); // create a lambda using the method body. var lambdaExpression = new LambdaExpression(); lambdaExpression.Body = methodDecl.Body; for (int i = 1; i < methodDecl.Parameters.Count; i++) { lambdaExpression.Parameters.Add(methodDecl.Parameters[i]); } // create a global statement to set the prototype value var target = extType.GetFullName() + ".prototype." + methodDecl.Definition.Name; model.GlobalStatements.Add(new ExpressionStatement { Expression = new BinaryExpression { LeftExpression = new LiteralExpression { Text = target }, RightExpression = lambdaExpression, Operator = "=" } }); }