public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration)
 {
     if (!constructorDeclaration.HasModifier(Modifiers.Static))
     {
         return;
     }
     if (constructorDeclaration.HasModifier(Modifiers.Public) ||
         constructorDeclaration.HasModifier(Modifiers.Private) ||
         constructorDeclaration.HasModifier(Modifiers.Protected))
     {
         AddIssue(constructorDeclaration, ctx.TranslateString("Static constructor cannot take access modifier"));
     }
 }
            public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration)
            {
                CheckStaticRequired(constructorDeclaration);

                if (constructorDeclaration.HasModifier(Modifiers.Static))
                {
                    if ((constructorDeclaration.Modifiers & Modifiers.Static) != 0)
                    {
                        foreach (var mod in constructorDeclaration.ModifierTokens)
                        {
                            if (mod.Modifier == Modifiers.Static)
                            {
                                continue;
                            }
                            AddIssue(new CodeIssue(
                                         mod,
                                         ctx.TranslateString("Static constructors can't have any other modifier"),
                                         ctx.TranslateString("Remove prohibited modifier"),
                                         s => {
                                s.ChangeModifier(constructorDeclaration, Modifiers.Static);
                            }
                                         ));
                        }
                    }
                }
                base.VisitConstructorDeclaration(constructorDeclaration);
            }
예제 #3
0
 public override void VisitConstructorDeclaration(ConstructorDeclaration methodDeclaration)
 {
     if (methodDeclaration.HasModifier(Modifiers.Static))
     {
         base.VisitConstructorDeclaration(methodDeclaration);
     }
 }
예제 #4
0
 public override void VisitConstructorDeclaration(ConstructorDeclaration methodDeclaration)
 {
     if (methodDeclaration.HasModifier(Modifiers.Static))
     {
         base.VisitConstructorDeclaration(methodDeclaration);
     }
 }
 public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration)
 {
     if (constructorDeclaration.HasModifier(Modifiers.Public))
     {
         AddIssue(constructorDeclaration.NameToken, ctx.TranslateString("Convert public to protected"), script =>
                  script.Replace(constructorDeclaration.ModifierTokens.First(t => t.Modifier == Modifiers.Public), new CSharpModifierToken(TextLocation.Empty, Modifiers.Protected)));
     }
 }
 public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration)
 {
     if (constructorDeclaration.HasModifier(Modifiers.Static))
     {
         return;
     }
     base.VisitConstructorDeclaration(constructorDeclaration);
 }
예제 #7
0
            public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration)
            {
                if (constructorDeclaration.HasModifier(Modifiers.Public))
                {
                    var makeProtected = new CodeAction(ctx.TranslateString("Make constructor protected"), script => script.Replace(constructorDeclaration.ModifierTokens.First(t => t.Modifier == Modifiers.Public), new CSharpModifierToken(TextLocation.Empty, Modifiers.Protected)), constructorDeclaration.NameToken);
                    var makePrivate   = new CodeAction(ctx.TranslateString("Make constructor private"), script => script.Remove(constructorDeclaration.ModifierTokens.First(t => t.Modifier == Modifiers.Public)), constructorDeclaration.NameToken);

                    AddIssue(new CodeIssue(constructorDeclaration.NameToken, ctx.TranslateString("Constructor in Abstract Class should not be public"), new[] { makeProtected, makePrivate }));
                }
            }
예제 #8
0
 public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration)
 {
     if (!constructorDeclaration.HasModifier(Modifiers.Static))
     {
         return;
     }
     if (constructorDeclaration.Parameters.Count != 0)
     {
         AddIssue(constructorDeclaration, ctx.TranslateString("Static constructor cannot take parameters"));
     }
 }
예제 #9
0
        public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration)
        {
            if (this.HasInline(constructorDeclaration) || constructorDeclaration.HasModifier(Modifiers.Extern) && !this.HasScript(constructorDeclaration))
            {
                return;
            }

            bool isStatic = constructorDeclaration.HasModifier(Modifiers.Static);

            this.FixMethodParameters(constructorDeclaration.Parameters, constructorDeclaration.Body);

            if (isStatic)
            {
                this.CurrentType.StaticCtor = constructorDeclaration;
            }
            else
            {
                this.CurrentType.Ctors.Add(constructorDeclaration);
            }
        }
예제 #10
0
            public void Run(AstNode node)
            {
                ConstructorDeclaration ctor = node as ConstructorDeclaration;

                if (ctor != null)
                {
                    if (ctor.HasModifier(Modifiers.Static))
                    {
                        ctor.Remove();
                    }
                }
            }
            public override void VisitConstructorDeclaration(ConstructorDeclaration declaration)
            {
                base.VisitConstructorDeclaration(declaration);

                if (declaration.Initializer.IsNull && !declaration.HasModifier(Modifiers.Static))
                {
                    // Check if parameterless ctor is available:
                    if (!BaseTypeHasUsableParameterlessConstructor())
                    {
                        AddIssue(new CodeIssue(declaration.NameToken, GetIssueText(baseType)));
                    }
                }
            }
예제 #12
0
 private OverloadsCollection(IEmitter emitter, ConstructorDeclaration constructorDeclaration)
 {
     this.Emitter        = emitter;
     this.Name           = constructorDeclaration.Name;
     this.JsName         = this.Emitter.GetEntityName(constructorDeclaration, false, true);
     this.Inherit        = false;
     this.Constructor    = true;
     this.Static         = constructorDeclaration.HasModifier(Modifiers.Static);
     this.Member         = this.FindMember(constructorDeclaration);
     this.TypeDefinition = this.Member.DeclaringTypeDefinition;
     this.Type           = this.Member.DeclaringType;
     this.InitMembers();
     //this.Emitter.OverloadsCache[constructorDeclaration.GetHashCode().ToString()] = this;
 }
예제 #13
0
 private OverloadsCollection(IEmitter emitter, ConstructorDeclaration constructorDeclaration)
 {
     this.Emitter        = emitter;
     this.Name           = constructorDeclaration.Name;
     this.JsName         = this.Emitter.GetEntityName(constructorDeclaration, false, true);
     this.Inherit        = false;
     this.Constructor    = true;
     this.Static         = constructorDeclaration.HasModifier(Modifiers.Static);
     this.Member         = this.FindMember(constructorDeclaration);
     this.TypeDefinition = this.Member.DeclaringTypeDefinition;
     this.Type           = this.Member.DeclaringType;
     this.InitMembers();
     this.Emitter.OverloadsCacheNodes[new Tuple <AstNode, bool>(constructorDeclaration, false)] = this;
 }
예제 #14
0
        public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration)
        {
            bool isStatic = constructorDeclaration.HasModifier(Modifiers.Static);

            this.FixMethodParameters(constructorDeclaration.Parameters, constructorDeclaration.Body);

            if (isStatic)
            {
                this.CurrentType.StaticCtor = constructorDeclaration;
            }
            else
            {
                this.CurrentType.Ctors.Add(constructorDeclaration);
            }
        }
예제 #15
0
        public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration)
        {
            bool isStatic = constructorDeclaration.HasModifier(Modifiers.Static);

            this.FixMethodParameters(constructorDeclaration.Parameters, constructorDeclaration.Body);

            if (isStatic)
            {
                this.CurrentType.StaticCtor = constructorDeclaration;
            }
            else
            {
                this.CurrentType.Ctors.Add(constructorDeclaration);
            }
        }
예제 #16
0
            public void Run(AstNode compilationUnit)
            {
                ConstructorDeclaration ctorDecl = null;

                foreach (var node in compilationUnit.Children)
                {
                    ConstructorDeclaration ctor = node as ConstructorDeclaration;
                    if (ctor != null)
                    {
                        if (ctor.Annotation <MethodDefinition>() == ctorDef)
                        {
                            ctorDecl = ctor;
                        }
                        else
                        {
                            // remove other ctors
                            ctor.Remove();
                        }

                        if (ctor.HasModifier(Modifiers.Static))
                        {
                            ctor.Remove();
                        }
                    }


                    // Remove any fields without initializers
                    FieldDeclaration fd = node as FieldDeclaration;
                    if (fd != null && fd.Variables.All(v => v.Initializer.IsNull))
                    {
                        fd.Remove();
                    }
                }
                if (ctorDecl.Initializer.ConstructorInitializerType == ConstructorInitializerType.This)
                {
                    // remove all fields
                    foreach (var node in compilationUnit.Children)
                    {
                        if (node is FieldDeclaration)
                        {
                            node.Remove();
                        }
                    }
                }
            }
예제 #17
0
 public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration)
 {
     if (!constructorDeclaration.HasModifier(Modifiers.Static) || !constructorDeclaration.Parameters.Any())
     {
         return;
     }
     AddIssue(new CodeIssue(
                  constructorDeclaration.Parameters.First().StartLocation,
                  constructorDeclaration.Parameters.Last().EndLocation,
                  ctx.TranslateString("Static constructor cannot take parameters"),
                  ctx.TranslateString("Remove parameters"),
                  s => {
         int o1 = ctx.GetOffset(constructorDeclaration.LParToken.EndLocation);
         int o2 = ctx.GetOffset(constructorDeclaration.RParToken.StartLocation);
         s.RemoveText(o1, o2 - o1);
     }
                  ));
 }
예제 #18
0
 private OverloadsCollection(IEmitter emitter, ConstructorDeclaration constructorDeclaration)
 {
     this.Emitter = emitter;
     this.Name = constructorDeclaration.Name;
     this.JsName = this.Emitter.GetEntityName(constructorDeclaration, false, true);
     this.Inherit = false;
     this.Constructor = true;
     this.Static = constructorDeclaration.HasModifier(Modifiers.Static);
     this.Member = this.FindMember(constructorDeclaration);
     this.TypeDefinition = this.Member.DeclaringTypeDefinition;
     this.Type = this.Member.DeclaringType;
     this.InitMembers();
     this.Emitter.OverloadsCache[constructorDeclaration.GetHashCode().ToString()] = this;
 }