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); }
public override void VisitConstructorDeclaration(ConstructorDeclaration methodDeclaration) { if (methodDeclaration.HasModifier(Modifiers.Static)) { base.VisitConstructorDeclaration(methodDeclaration); } }
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); }
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 })); } }
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")); } }
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); } }
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))); } } }
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; }
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; }
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); } }
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); } }
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(); } } } }
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); } )); }
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; }