public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { AddMethod(true, constructorDeclaration, constructorDeclaration.Parameters); // call base to forward execution base.VisitConstructorDeclaration(constructorDeclaration); }
public override void VisitConstructorDeclaration(ConstructorDeclaration declaration) { Tupel t = new Tupel(declaration.StartLocation.Line, declaration.EndLocation.Line); addToMap(declaration.Name, t); //_methodRanges.Add(constructorDeclaration.Name, new Tupel(constructorDeclaration.StartLocation.Line, // constructorDeclaration.EndLocation.Line)); }
public override object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) { if (!constructorDeclaration.Initializer.IsNull && constructorDeclaration.Initializer.ConstructorInitializerType == ConstructorInitializerType.Base) UnlockWith(constructorDeclaration); return base.VisitConstructorDeclaration(constructorDeclaration, data); }
public override object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) { Push(); object result = base.VisitConstructorDeclaration(constructorDeclaration, data); Pop(); return result; }
public IEnumerable<CodeAction> GetActions(RefactoringContext context) { var createExpression = context.GetNode<Expression>() as ObjectCreateExpression; if (createExpression == null) yield break; var resolveResult = context.Resolve(createExpression) as CSharpInvocationResolveResult; if (resolveResult == null || !resolveResult.IsError || resolveResult.Member.DeclaringTypeDefinition == null || resolveResult.Member.DeclaringTypeDefinition.IsSealed || resolveResult.Member.DeclaringTypeDefinition.Region.IsEmpty) yield break; yield return new CodeAction(context.TranslateString("Create constructor"), script => { var decl = new ConstructorDeclaration() { Name = resolveResult.Member.DeclaringTypeDefinition.Name, Modifiers = Modifiers.Public, Body = new BlockStatement() { new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException"))) } }; decl.Parameters.AddRange(CreateMethodDeclarationAction.GenerateParameters(context, createExpression.Arguments)); script.InsertWithCursor( context.TranslateString("Create constructor"), resolveResult.Member.DeclaringTypeDefinition, decl ); }, createExpression); }
public override void VisitConstructorDeclaration(ConstructorDeclaration methodDeclaration) { if (methodDeclaration.HasModifier(Modifiers.Static)) { base.VisitConstructorDeclaration(methodDeclaration); } }
public override object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) { if(constructorDeclaration.Parameters.Count > 0) UnlockWith(constructorDeclaration); return base.VisitConstructorDeclaration(constructorDeclaration, data); }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { string prefix = ""; if ((constructorDeclaration.Modifiers & Modifiers.Static) == Modifiers.Static) prefix = "static."; VisitMember(prefix + constructorDeclaration.Name, constructorDeclaration.Parameters.Select(p => p.Type.ToString())); base.VisitConstructorDeclaration(constructorDeclaration); }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { if (isSealedType) return; var body = constructorDeclaration.Body; if (body == null || body.IsNull) return; body.AcceptVisitor(CallFinder); }
public static OverloadsCollection Create(IEmitter emitter, ConstructorDeclaration constructorDeclaration) { string key = constructorDeclaration.GetHashCode().ToString(); if (emitter.OverloadsCache.ContainsKey(key)) { return emitter.OverloadsCache[key]; } return new OverloadsCollection(emitter, constructorDeclaration); }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { if (isSealedType) return; var body = constructorDeclaration.Body; if (body == null || body.IsNull) return; var callFinder = new VirtualCallFinderVisitor(context); body.AcceptVisitor(callFinder); FoundIssues.AddRange(callFinder.FoundIssues); }
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; }
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) { FixAttributesAndDocComment(constructorDeclaration); ForceSpacesBefore(constructorDeclaration.LParToken, policy.SpaceBeforeConstructorDeclarationParentheses); if (constructorDeclaration.Parameters.Any()) { ForceSpacesAfter(constructorDeclaration.LParToken, policy.SpaceWithinConstructorDeclarationParentheses); FormatArguments(constructorDeclaration); } else { ForceSpacesAfter(constructorDeclaration.LParToken, policy.SpaceBetweenEmptyConstructorDeclarationParentheses); ForceSpacesBefore(constructorDeclaration.RParToken, policy.SpaceBetweenEmptyConstructorDeclarationParentheses); } if (!constructorDeclaration.Body.IsNull) { FixOpenBrace(policy.ConstructorBraceStyle, constructorDeclaration.Body.LBraceToken); VisitBlockWithoutFixingBraces(constructorDeclaration.Body, policy.IndentMethodBody); FixClosingBrace(policy.ConstructorBraceStyle, constructorDeclaration.Body.RBraceToken); } }
private void TransformToClass() { if (transformerDefinition.TransformResults == null) throw new TransformCompilationException("Cannot compile a transformer without a transformer function"); try { CSharpSafeName = "Transformer_" + Regex.Replace(Name, @"[^\w\d]", "_"); var type = new TypeDeclaration { Modifiers = Modifiers.Public, BaseTypes = { new SimpleType(typeof (AbstractTransformer).FullName) }, Name = CSharpSafeName, ClassType = ClassType.Class }; var body = new BlockStatement(); // this.ViewText = "96E65595-1C9E-4BFB-A0E5-80BF2D6FC185"; // Will be replaced later var viewText = new ExpressionStatement( new AssignmentExpression( new MemberReferenceExpression(new ThisReferenceExpression(), "ViewText"), AssignmentOperatorType.Assign, new StringLiteralExpression(uniqueTextToken))); body.Statements.Add(viewText); var ctor = new ConstructorDeclaration { Name = CSharpSafeName, Modifiers = Modifiers.Public, Body = body }; type.Members.Add(ctor); VariableInitializer translatorDeclaration; if (transformerDefinition.TransformResults.Trim().StartsWith("from")) { translatorDeclaration = QueryParsingUtils.GetVariableDeclarationForLinqQuery(transformerDefinition.TransformResults, requiresSelectNewAnonymousType: false); } else { translatorDeclaration = QueryParsingUtils.GetVariableDeclarationForLinqMethods(transformerDefinition.TransformResults, requiresSelectNewAnonymousType: false); } translatorDeclaration.AcceptVisitor(new ThrowOnInvalidMethodCallsForTransformResults(), null); // this.Translator = (results) => from doc in results ...; ctor.Body.Statements.Add(new ExpressionStatement( new AssignmentExpression( new MemberReferenceExpression(new ThisReferenceExpression(), "TransformResultsDefinition"), AssignmentOperatorType.Assign, new LambdaExpression { Parameters = { new ParameterDeclaration(null, "results") }, Body = translatorDeclaration.Initializer.Clone() }))); CompiledQueryText = QueryParsingUtils.GenerateText(type, extensions); var sb = new StringBuilder("@\""); sb.AppendLine(transformerDefinition.TransformResults.Replace("\"", "\"\"")); sb.Append("\""); CompiledQueryText = CompiledQueryText.Replace('"' + uniqueTextToken + '"', sb.ToString()); } catch (Exception ex) { throw new TransformCompilationException(ex.Message, ex); } }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { FormatAttributedNode(constructorDeclaration); ForceSpacesBefore(constructorDeclaration.LParToken, policy.SpaceBeforeConstructorDeclarationParentheses); if (constructorDeclaration.Parameters.Any()) { ForceSpacesAfter(constructorDeclaration.LParToken, policy.SpaceWithinConstructorDeclarationParentheses); ForceSpacesBefore(constructorDeclaration.RParToken, policy.SpaceWithinConstructorDeclarationParentheses); } else { ForceSpacesAfter(constructorDeclaration.LParToken, policy.SpaceBetweenEmptyConstructorDeclarationParentheses); ForceSpacesBefore(constructorDeclaration.RParToken, policy.SpaceBetweenEmptyConstructorDeclarationParentheses); } FormatCommas(constructorDeclaration, policy.SpaceBeforeConstructorDeclarationParameterComma, policy.SpaceAfterConstructorDeclarationParameterComma); if (!constructorDeclaration.Body.IsNull) { EnforceBraceStyle(policy.ConstructorBraceStyle, constructorDeclaration.Body.LBraceToken, constructorDeclaration.Body.RBraceToken); VisitBlockWithoutFixingBraces(constructorDeclaration.Body, policy.IndentMethodBody); } if (IsMember(constructorDeclaration.NextSibling)) { EnsureBlankLinesAfter(constructorDeclaration, policy.BlankLinesBetweenMembers); } }
private void EmitExternalBaseCtor(ConstructorDeclaration ctor, ref bool requireNewLine) { if (ctor.Initializer != null && !ctor.Initializer.IsNull) { var member = ((InvocationResolveResult)this.Emitter.Resolver.ResolveNode(ctor.Initializer, this.Emitter)).Member; var inlineCode = this.Emitter.GetInline(member); if (!string.IsNullOrEmpty(inlineCode)) { if (requireNewLine) { this.WriteNewLine(); requireNewLine = false; } this.Write(JS.Types.Bridge.APPLY); this.WriteOpenParentheses(); this.Write("this, "); var argsInfo = new ArgumentsInfo(this.Emitter, ctor.Initializer); new InlineArgumentsBlock(this.Emitter, argsInfo, inlineCode).Emit(); this.WriteCloseParentheses(); this.WriteSemiColon(); this.WriteNewLine(); } else { if (requireNewLine) { this.WriteNewLine(); requireNewLine = false; } var baseType = this.Emitter.GetBaseTypeDefinition(); string name = null; if (this.TypeInfo.GetBaseTypes(this.Emitter).Any()) { name = BridgeTypes.ToJsName(this.TypeInfo.GetBaseClass(this.Emitter), this.Emitter); } else { name = BridgeTypes.ToJsName(baseType, this.Emitter); } this.Write(name); this.WriteCall(); int openPos = this.Emitter.Output.Length; this.WriteOpenParentheses(); this.Write("this"); if (ctor.Initializer.Arguments.Count > 0) { this.Write(", "); var argsInfo = new ArgumentsInfo(this.Emitter, ctor.Initializer); var argsExpressions = argsInfo.ArgumentsExpressions; var paramsArg = argsInfo.ParamsExpression; new ExpressionListBlock(this.Emitter, argsExpressions, paramsArg, ctor.Initializer, openPos).Emit(); } this.WriteCloseParentheses(); this.WriteSemiColon(); this.WriteNewLine(); } } }
PythonConstructorInfo(ConstructorDeclaration constructor, List <FieldDeclaration> fields) { this.constructor = constructor; this.fields = fields; }
public StringBuilder VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, int data) { throw new NotSupportedException(); }
public JsNode VisitConstructorDeclaration(ConstructorDeclaration node) { throw new NotImplementedException(); }
public void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { throw new NotImplementedException(); }
private void GenerateDefaultConstructor(ClassDeclaration c) { var cd = new ConstructorDeclaration(c); }
private void AddEnumerator(ClassDeclaration c, FieldDeclaration data, MethodDeclaration close) { c.Interfaces.Add(typeof(IEnumerable)); // create subclass ClassDeclaration en = c.AddClass("Enumerator"); // add wrapped field FieldDeclaration wrapped = en.AddField( c, "wrapped" ); ITypeDeclaration enumeratorType = new TypeTypeDeclaration(typeof(IEnumerator)); ITypeDeclaration disposableType = new TypeTypeDeclaration(typeof(IDisposable)); // add IEnumerator en.Interfaces.Add(enumeratorType); en.Interfaces.Add(disposableType); // add constructor ConstructorDeclaration cs = en.AddConstructor(); ParameterDeclaration collection = cs.Signature.Parameters.Add(c, "collection", true); cs.Body.AddAssign(Expr.This.Field(wrapped), Expr.Arg(collection)); // add current PropertyDeclaration current = en.AddProperty(data.Type, "Current"); current.Get.Return( Expr.This.Field(wrapped).Prop("Data") ); // add explicit interface implementation PropertyDeclaration currentEn = en.AddProperty(typeof(Object), "Current"); currentEn.Get.Return(Expr.This.Prop(current)); currentEn.PrivateImplementationType = enumeratorType; // add reset MethodDeclaration reset = en.AddMethod("Reset"); reset.ImplementationTypes.Add(wrapped.Type); reset.Body.Add(Stm.Throw(typeof(InvalidOperationException), Expr.Prim("Not supported"))); // add movenext MethodDeclaration movenext = en.AddMethod("MoveNext"); movenext.ImplementationTypes.Add(wrapped.Type); movenext.Signature.ReturnType = new TypeTypeDeclaration(typeof(bool)); movenext.Body.Return(Expr.This.Field(wrapped).Method("Read").Invoke()); // add dispose MethodDeclaration disposeEn = en.AddMethod("Dispose"); disposeEn.ImplementationTypes.Add(disposableType); disposeEn.Body.Add( Expr.This.Field(wrapped).Method(close).Invoke() ); disposeEn.Body.AddAssign(Expr.This.Field(wrapped), Expr.Null); // add get enuemrator MethodDeclaration geten = c.AddMethod("GetEnumerator"); geten.Signature.ReturnType = en; geten.Body.Return(Expr.New(en, Expr.This)); MethodDeclaration igeten = c.AddMethod("GetEnumerator"); igeten.PrivateImplementationType = new TypeTypeDeclaration(typeof(IEnumerable)); igeten.Signature.ReturnType = new TypeTypeDeclaration(typeof(IEnumerator)); igeten.Body.Return(Expr.This.Method("GetEnumerator").Invoke()); }
public void ConstructorDeclarationTest1() { ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember <ConstructorDeclaration>("MyClass() {}"); Assert.IsTrue(cd.Initializer.IsNull); }
public override object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) { WriteLine("VisitConstructorDeclaration"); return(base.VisitConstructorDeclaration(constructorDeclaration, data)); }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { currentMethodName = constructorDeclaration.Name; skip = true; base.VisitConstructorDeclaration(constructorDeclaration); }
public virtual object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) { throw new global::System.NotImplementedException("ConstructorDeclaration"); }
private void HandleReduceDefinition(ConstructorDeclaration ctor) { if (!indexDefinition.IsMapReduce) { return; } VariableInitializer reduceDefinition; AstNode groupBySource; string groupByParameter; string groupByIdentifier; if (indexDefinition.Reduce.Trim().StartsWith("from")) { reduceDefinition = QueryParsingUtils.GetVariableDeclarationForLinqQuery(indexDefinition.Reduce, RequiresSelectNewAnonymousType); var queryExpression = ((QueryExpression)reduceDefinition.Initializer); var queryContinuationClause = queryExpression.Clauses.OfType <QueryContinuationClause>().First(); var queryGroupClause = queryContinuationClause.PrecedingQuery.Clauses.OfType <QueryGroupClause>().First(); groupByIdentifier = queryContinuationClause.Identifier; groupBySource = queryGroupClause.Key; groupByParameter = queryContinuationClause.PrecedingQuery.Clauses.OfType <QueryFromClause>().First().Identifier; } else { reduceDefinition = QueryParsingUtils.GetVariableDeclarationForLinqMethods(indexDefinition.Reduce, RequiresSelectNewAnonymousType); var initialInvocation = ((InvocationExpression)reduceDefinition.Initializer); var invocation = initialInvocation; var target = (MemberReferenceExpression)invocation.Target; while (target.MemberName != "GroupBy") { invocation = (InvocationExpression)target.Target; target = (MemberReferenceExpression)invocation.Target; } var lambdaExpression = GetLambdaExpression(invocation); groupByParameter = lambdaExpression.Parameters.First().Name; groupBySource = lambdaExpression.Body; groupByIdentifier = null; } var mapFields = captureSelectNewFieldNamesVisitor.FieldNames.ToList(); captureSelectNewFieldNamesVisitor.Clear(); // reduce override the map fields reduceDefinition.Initializer.AcceptVisitor(captureSelectNewFieldNamesVisitor, null); reduceDefinition.Initializer.AcceptVisitor(captureQueryParameterNamesVisitorForReduce, null); reduceDefinition.Initializer.AcceptVisitor(new ThrowOnInvalidMethodCalls(groupByIdentifier), null); ValidateMapReduceFields(mapFields); // this.ReduceDefinition = from result in results...; ctor.Body.Statements.Add(new ExpressionStatement( new AssignmentExpression( new MemberReferenceExpression(new ThisReferenceExpression(), "ReduceDefinition"), AssignmentOperatorType.Assign, new LambdaExpression { Parameters = { new ParameterDeclaration(null, "results") }, Body = reduceDefinition.Initializer.Clone() }))); ctor.Body.Statements.Add(new ExpressionStatement( new AssignmentExpression( new MemberReferenceExpression(new ThisReferenceExpression(), "GroupByExtraction"), AssignmentOperatorType.Assign, new LambdaExpression { Parameters = { new ParameterDeclaration(null, groupByParameter) }, Body = groupBySource.Clone() }))); }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { _constructorDeclarations.Add(Tuple.Create(constructorDeclaration, _resolver)); }
public virtual T VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { return(VisitChildren(constructorDeclaration)); }
private void TransformQueryToClass() { CSharpSafeName = "Index_" + Regex.Replace(Name, @"[^\w\d]", "_"); var type = new TypeDeclaration { Modifiers = Modifiers.Public, BaseTypes = { new SimpleType(typeof(AbstractViewGenerator).FullName) }, Name = CSharpSafeName, ClassType = ClassType.Class }; var body = new BlockStatement(); // this.ViewText = "96E65595-1C9E-4BFB-A0E5-80BF2D6FC185"; // Will be replaced later var viewText = new ExpressionStatement( new AssignmentExpression( new MemberReferenceExpression(new ThisReferenceExpression(), "ViewText"), AssignmentOperatorType.Assign, new StringLiteralExpression(mapReduceTextToken))); body.Statements.Add(viewText); var ctor = new ConstructorDeclaration { Name = CSharpSafeName, Modifiers = Modifiers.Public, Body = body }; type.Members.Add(ctor); foreach (var map in indexDefinition.Maps) { HandleMapFunction(ctor, map); } HandleTransformResults(ctor); HandleReduceDefinition(ctor); AddAdditionalInformation(ctor); CompiledQueryText = QueryParsingUtils.GenerateText(type, extensions); var sb = new StringBuilder("@\""); foreach (var map in indexDefinition.Maps) { sb.AppendLine(map.Replace("\"", "\"\"")); } if (indexDefinition.Reduce != null) { sb.AppendLine(indexDefinition.Reduce.Replace("\"", "\"\"")); } if (indexDefinition.TransformResults != null) { sb.AppendLine(indexDefinition.TransformResults.Replace("\"", "\"\"")); } sb.Length = sb.Length - 2; sb.Append("\""); CompiledQueryText = CompiledQueryText.Replace('"' + mapReduceTextToken + '"', sb.ToString()); }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { base.VisitConstructorDeclaration(constructorDeclaration); AddMethod(constructorDeclaration, constructorDeclaration.Body); }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { // skip }
private void MaybeCompileAndAddConstructorToType(JsClass jsClass, ConstructorDeclaration node, IMethod constructor, ConstructorScriptSemantics options) { if (options.GenerateCode) { var mc = CreateMethodCompiler(); var compiled = mc.CompileConstructor(node, constructor, TryGetInstanceInitStatements(jsClass), options); OnMethodCompiled(constructor, compiled, mc); AddCompiledConstructorToType(jsClass, constructor, options, compiled); } }
public JsFunctionDefinitionExpression CompileConstructor(ConstructorDeclaration ctor, IMethod constructor, List <JsStatement> instanceInitStatements, ConstructorScriptSemantics impl) { var region = _errorReporter.Region = ctor != null?ctor.GetRegion() : constructor.DeclaringTypeDefinition.Region; try { CreateCompilationContext(ctor, constructor, constructor.DeclaringTypeDefinition, (impl.Type == ConstructorScriptSemantics.ImplType.StaticMethod ? _namer.ThisAlias : null)); IList <JsStatement> body = new List <JsStatement>(); body.AddRange(PrepareParameters(constructor.Parameters, variables, expandParams: impl.ExpandParams, staticMethodWithThisAsFirstArgument: false)); if (impl.Type == ConstructorScriptSemantics.ImplType.StaticMethod) { if (ctor != null && !ctor.Initializer.IsNull) { body.AddRange(_statementCompiler.CompileConstructorInitializer(ctor.Initializer, true)); } else { body.AddRange(_statementCompiler.CompileImplicitBaseConstructorCall(constructor.DeclaringTypeDefinition, true)); } } if (ctor == null || ctor.Initializer.IsNull || ctor.Initializer.ConstructorInitializerType != ConstructorInitializerType.This) { if (impl.Type == ConstructorScriptSemantics.ImplType.StaticMethod) { // The compiler one step up has created the statements as "this.a = b;", but we need to replace that with "$this.a = b;" (or whatever name the this alias has). var replacer = new ThisReplacer(JsExpression.Identifier(_namer.ThisAlias)); instanceInitStatements = instanceInitStatements.Select(s => replacer.VisitStatement(s, null)).ToList(); } body.AddRange(instanceInitStatements); // Don't initialize fields when we are chaining, but do it when we 1) compile the default constructor, 2) don't have an initializer, or 3) when the initializer is not this(...). } if (impl.Type != ConstructorScriptSemantics.ImplType.StaticMethod) { if (ctor != null && !ctor.Initializer.IsNull) { body.AddRange(_statementCompiler.CompileConstructorInitializer(ctor.Initializer, false)); } else { body.AddRange(_statementCompiler.CompileImplicitBaseConstructorCall(constructor.DeclaringTypeDefinition, false)); } } if (ctor != null) { body.AddRange(_statementCompiler.Compile(ctor.Body).Statements); } if (impl.Type == ConstructorScriptSemantics.ImplType.StaticMethod) { if (body.Count == 0 || !(body[body.Count - 1] is JsReturnStatement)) { body.Add(new JsReturnStatement()); } body = StaticMethodConstructorReturnPatcher.Process(body, _namer.ThisAlias).AsReadOnly(); } var compiled = JsExpression.FunctionDefinition(constructor.Parameters.Where((p, i) => i != constructor.Parameters.Count - 1 || !impl.ExpandParams).Select(p => variables[p].Name), new JsBlockStatement(body)); return(_statementCompiler.StateMachineRewriteNormalMethod(compiled)); } catch (Exception ex) { _errorReporter.Region = region; _errorReporter.InternalError(ex); return(JsExpression.FunctionDefinition(new string[0], JsBlockStatement.EmptyStatement)); } }
ConstructorDeclaration ConvertConstructor(IMethod ctor) { ConstructorDeclaration decl = new ConstructorDeclaration(); decl.Modifiers = GetMemberModifiers(ctor); if (ctor.DeclaringTypeDefinition != null) decl.Name = ctor.DeclaringTypeDefinition.Name; foreach (IParameter p in ctor.Parameters) { decl.Parameters.Add(ConvertParameter(p)); } decl.Body = GenerateBodyBlock(); return decl; }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { HandleConstructorOrDestructor(constructorDeclaration); }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { CheckNode(constructorDeclaration); }
protected virtual void EmitBaseConstructor(ConstructorDeclaration ctor, string ctorName, bool isObjectLiteral) { var initializer = ctor.Initializer != null && !ctor.Initializer.IsNull ? ctor.Initializer : new ConstructorInitializer() { ConstructorInitializerType = ConstructorInitializerType.Base }; bool appendScope = false; bool isBaseObjectLiteral = false; if (initializer.ConstructorInitializerType == ConstructorInitializerType.Base) { var baseType = this.Emitter.GetBaseTypeDefinition(); var baseName = JS.Funcs.CONSTRUCTOR; isBaseObjectLiteral = this.Emitter.Validator.IsObjectLiteral(baseType); if (ctor.Initializer != null && !ctor.Initializer.IsNull) { var member = ((InvocationResolveResult)this.Emitter.Resolver.ResolveNode(ctor.Initializer, this.Emitter)).Member; var overloads = OverloadsCollection.Create(this.Emitter, member); if (overloads.HasOverloads) { baseName = overloads.GetOverloadName(); } } string name = null; if (this.TypeInfo.GetBaseTypes(this.Emitter).Any()) { name = BridgeTypes.ToJsName(this.TypeInfo.GetBaseClass(this.Emitter), this.Emitter); } else { name = BridgeTypes.ToJsName(baseType, this.Emitter); } if (!isObjectLiteral && isBaseObjectLiteral) { this.Write(JS.Types.Bridge.COPY_PROPERTIES); this.WriteOpenParentheses(); this.Write("this, "); } this.Write(name, "."); this.Write(baseName); if (!isObjectLiteral) { this.WriteCall(); appendScope = true; } } else { // this.WriteThis(); string name = BridgeTypes.ToJsName(this.TypeInfo.Type, this.Emitter); this.Write(name); this.WriteDot(); var baseName = JS.Funcs.CONSTRUCTOR; var member = ((InvocationResolveResult)this.Emitter.Resolver.ResolveNode(ctor.Initializer, this.Emitter)).Member; var overloads = OverloadsCollection.Create(this.Emitter, member); if (overloads.HasOverloads) { baseName = overloads.GetOverloadName(); } this.Write(baseName); if (!isObjectLiteral) { this.WriteCall(); appendScope = true; } } int openPos = this.Emitter.Output.Length; this.WriteOpenParentheses(); if (appendScope) { this.WriteThis(); if (initializer.Arguments.Count > 0) { this.WriteComma(); } } if (initializer.Arguments.Count > 0) { var argsInfo = new ArgumentsInfo(this.Emitter, ctor.Initializer); var argsExpressions = argsInfo.ArgumentsExpressions; var paramsArg = argsInfo.ParamsExpression; new ExpressionListBlock(this.Emitter, argsExpressions, paramsArg, ctor.Initializer, openPos).Emit(); } if (!isObjectLiteral && isBaseObjectLiteral) { this.WriteCloseParentheses(); } this.WriteCloseParentheses(); this.WriteSemiColon(); if (!isObjectLiteral) { this.WriteNewLine(); } }
public virtual UstNode Visit(ConstructorDeclaration constructorDeclaration) { return(VisitChildren(constructorDeclaration)); }
protected virtual void EmitBaseConstructor(ConstructorDeclaration ctor, string ctorName) { var initializer = ctor.Initializer != null && !ctor.Initializer.IsNull ? ctor.Initializer : new ConstructorInitializer() { ConstructorInitializerType = ConstructorInitializerType.Base }; bool appendScope = false; if (initializer.ConstructorInitializerType == ConstructorInitializerType.Base) { var baseType = this.Emitter.GetBaseTypeDefinition(); var baseName = "constructor"; if (ctor.Initializer != null && !ctor.Initializer.IsNull) { var member = ((InvocationResolveResult)this.Emitter.Resolver.ResolveNode(ctor.Initializer, this.Emitter)).Member; var overloads = OverloadsCollection.Create(this.Emitter, member); if (overloads.HasOverloads) { baseName = overloads.GetOverloadName(); } } if (baseName == "constructor") { baseName = "$constructor"; } string name = null; if (this.TypeInfo.TypeDeclaration.BaseTypes.Any()) { name = BridgeTypes.ToJsName(this.TypeInfo.TypeDeclaration.BaseTypes.First(), this.Emitter); } else { name = BridgeTypes.ToJsName(baseType, this.Emitter); } this.Write(name, ".prototype."); this.Write(baseName); this.Write(".call"); appendScope = true; } else { this.WriteThis(); this.WriteDot(); var baseName = "constructor"; var member = ((InvocationResolveResult)this.Emitter.Resolver.ResolveNode(ctor.Initializer, this.Emitter)).Member; var overloads = OverloadsCollection.Create(this.Emitter, member); if (overloads.HasOverloads) { baseName = overloads.GetOverloadName(); } if (baseName == "constructor") { baseName = "$constructor"; } this.Write(baseName); } this.WriteOpenParentheses(); if (appendScope) { this.WriteThis(); if (initializer.Arguments.Count > 0) { this.WriteComma(); } } var args = new List<Expression>(initializer.Arguments); for (int i = 0; i < args.Count; i++) { args[i].AcceptVisitor(this.Emitter); if (i != (args.Count - 1)) { this.WriteComma(); } } this.WriteCloseParentheses(); this.WriteSemiColon(); this.WriteNewLine(); }
public override void Visit (Constructor c) { ConstructorDeclaration newConstructor = new ConstructorDeclaration (); var location = LocationsBag.GetMemberLocation (c); AddModifiers (newConstructor, location); newConstructor.AddChild (new Identifier (c.MemberName.Name, Convert (c.MemberName.Location)), AbstractNode.Roles.Identifier); if (location != null) { newConstructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar); newConstructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar); } if (c.Block != null) newConstructor.AddChild ((INode)c.Block.Accept (this), ConstructorDeclaration.Roles.Body); typeStack.Peek ().AddChild (newConstructor, TypeDeclaration.Roles.Member); }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { FixAttributesAndDocComment(constructorDeclaration); ForceSpacesBefore(constructorDeclaration.LParToken, policy.SpaceBeforeConstructorDeclarationParentheses); if (constructorDeclaration.Parameters.Any()) { ForceSpacesAfter(constructorDeclaration.LParToken, policy.SpaceWithinConstructorDeclarationParentheses); FormatArguments(constructorDeclaration); } else { ForceSpacesAfter(constructorDeclaration.LParToken, policy.SpaceBetweenEmptyConstructorDeclarationParentheses); ForceSpacesBefore(constructorDeclaration.RParToken, policy.SpaceBetweenEmptyConstructorDeclarationParentheses); } var initializer = constructorDeclaration.Initializer; if (!initializer.IsNull) { curIndent.Push(IndentType.Block); PlaceOnNewLine(policy.NewLineBeforeConstructorInitializerColon, constructorDeclaration.ColonToken); PlaceOnNewLine(policy.NewLineAfterConstructorInitializerColon, initializer); initializer.AcceptVisitor(this); curIndent.Pop(); } if (!constructorDeclaration.Body.IsNull) { FixOpenBrace(policy.ConstructorBraceStyle, constructorDeclaration.Body.LBraceToken); VisitBlockWithoutFixingBraces(constructorDeclaration.Body, policy.IndentMethodBody); FixClosingBrace(policy.ConstructorBraceStyle, constructorDeclaration.Body.RBraceToken); } }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { inConstructor = true; base.VisitConstructorDeclaration(constructorDeclaration); inConstructor = false; }
public virtual void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { if (this.ThrowException) { throw (Exception)this.CreateException(constructorDeclaration); } }
private void TransformQueryToClass() { string entityName; var mapDefinition = TransformMapDefinition(out entityName); CSharpSafeName = "Index_" + Regex.Replace(Name, @"[^\w\d]", "_"); var type = new TypeDeclaration(Modifiers.Public, new List <AttributeSection>()) { BaseTypes = { new TypeReference("AbstractViewGenerator") }, Name = CSharpSafeName, Type = ClassType.Class }; var ctor = new ConstructorDeclaration(CSharpSafeName, Modifiers.Public, new List <ParameterDeclarationExpression>(), null); type.Children.Add(ctor); ctor.Body = new BlockStatement(); //this.ForEntityName = entityName; ctor.Body.AddChild(new ExpressionStatement( new AssignmentExpression( new MemberReferenceExpression(new ThisReferenceExpression(), "ForEntityName"), AssignmentOperatorType.Assign, new PrimitiveExpression(entityName, entityName)))); // this.ViewText = "96E65595-1C9E-4BFB-A0E5-80BF2D6FC185"; // Will be replaced later ctor.Body.AddChild(new ExpressionStatement( new AssignmentExpression( new MemberReferenceExpression(new ThisReferenceExpression(), "ViewText"), AssignmentOperatorType.Assign, new PrimitiveExpression(mapReduceTextToken, mapReduceTextToken)))); // this.MapDefinition = from doc in docs ...; ctor.Body.AddChild(new ExpressionStatement( new AssignmentExpression( new MemberReferenceExpression(new ThisReferenceExpression(), "MapDefinition"), AssignmentOperatorType.Assign, new LambdaExpression { Parameters = { new ParameterDeclarationExpression(null, "docs") }, ExpressionBody = mapDefinition.Initializer }))); mapDefinition.Initializer.AcceptVisitor(captureSelectNewFieldNamesVisitor, null); mapDefinition.Initializer.AcceptVisitor(captureQueryParameterNamesVisitorForMap, null); HandleTransformResults(ctor); HandleReduceDefintion(ctor); AddAdditionalInformation(ctor); CompiledQueryText = QueryParsingUtils.GenerateText(type, extensions); var compiledQueryText = "@\"" + indexDefinition.Map.Replace("\"", "\"\""); if (indexDefinition.Reduce != null) { compiledQueryText += Environment.NewLine + indexDefinition.Reduce.Replace("\"", "\"\""); } if (indexDefinition.TransformResults != null) { compiledQueryText += Environment.NewLine + indexDefinition.TransformResults.Replace("\"", "\"\""); } compiledQueryText += "\""; CompiledQueryText = CompiledQueryText.Replace("\"" + mapReduceTextToken + "\"", compiledQueryText); }
private void HandleConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { var resolveResult = _resolver.Resolve(constructorDeclaration); if (!(resolveResult is MemberResolveResult)) { _errorReporter.Region = constructorDeclaration.GetRegion(); _errorReporter.InternalError("Method declaration " + constructorDeclaration.Name + " does not resolve to a member."); return; } var method = ((MemberResolveResult)resolveResult).Member as IMethod; if (method == null) { _errorReporter.Region = constructorDeclaration.GetRegion(); _errorReporter.InternalError("Method declaration " + constructorDeclaration.Name + " does not resolve to a method (resolves to " + resolveResult.ToString() + ")"); return; } var jsClass = GetJsClass(method.DeclaringTypeDefinition); if (jsClass == null) return; if (method.IsStatic) { jsClass.StaticInitStatements.AddRange(CompileMethod(constructorDeclaration, constructorDeclaration.Body, method, MethodScriptSemantics.NormalMethod("X")).Body.Statements); } else { MaybeCompileAndAddConstructorToType(jsClass, constructorDeclaration, method, _metadataImporter.GetConstructorSemantics(method)); } }
public override void Generate() { // generate data this.Data.NamespaceDeclaration = this.NamespaceDeclaration; this.Data.Generate(); // generate the rest this.NamespaceDeclaration.Imports.Add("System.Data"); // create class ClassDeclaration c = this.NamespaceDeclaration.AddClass(this.DataReaderName); // IDisposable c.Interfaces.Add(typeof(IDisposable)); // add datareader field FieldDeclaration dr = c.AddField(typeof(IDataReader), "dr"); // add data field FieldDeclaration data = c.AddField( this.Data.DataName , "data"); data.InitExpression = Expr.New(data.Type); PropertyDeclaration datap = c.AddProperty(data, true, false, false); // foreach field values, add get property foreach (DictionaryEntry de in this.Data.Properties) { DictionaryEntry dde = (DictionaryEntry)de.Key; PropertyDeclaration pd = (PropertyDeclaration)de.Value; PropertyDeclaration pcd = c.AddProperty(pd.Type, pd.Name); pcd.Get.Return( Expr.This.Field(data).Prop(pd) ); } // add constructor ConstructorDeclaration cs = c.AddConstructor(); ParameterDeclaration drp = cs.Signature.Parameters.Add(dr.Type, "dr", false); cs.Body.Add(Stm.ThrowIfNull(drp)); cs.Body.Add( Stm.Assign( Expr.This.Field(dr), Expr.Arg(drp) ) ); // add close method MethodDeclaration close = c.AddMethod("Close"); // if dr ==null return; close.Body.Add( Stm.IfNull(Expr.This.Field(dr), Stm.Return()) ); // dr.Close(); close.Body.Add( Expr.This.Field(dr).Method("Close").Invoke() ); // dr = null; close.Body.AddAssign(Expr.This.Field(dr), Expr.Null); // data = null close.Body.AddAssign(Expr.This.Field(data), Expr.Null); // add read method MethodDeclaration read = c.AddMethod("Read"); read.Signature.ReturnType = new TypeTypeDeclaration(typeof(bool)); // if (!dr.Read()){close and return) ConditionStatement ifnotread = Stm.IfIdentity( Expr.This.Field(dr).Method("Read").Invoke(), Expr.False, Stm.ToStm(Expr.This.Method(close).Invoke()), Stm.Return(Expr.False) ); read.Body.Add(ifnotread); // foreach field values foreach (DictionaryEntry de in this.Data.Properties) { DictionaryEntry dde = (DictionaryEntry)de.Key; PropertyDeclaration pd = (PropertyDeclaration)de.Value; read.Body.AddAssign( Expr.This.Field(data).Prop(pd), ( Expr.This.Field(dr).Item(Expr.Prim(dde.Key.ToString())) ).Cast(dde.Value.ToString()) ); } // return true read.Body.Return(Expr.True); // add dispose method MethodDeclaration dispose = c.AddMethod("Dispose"); dispose.ImplementationTypes.Add(typeof(IDisposable)); // Close(); dispose.Body.Add( Expr.This.Method(close).Invoke() ); if (this.Enumerator) { AddEnumerator(c, data, close); } }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { VisitXmlChildren(constructorDeclaration); }
public override void Visit (Constructor c) { ConstructorDeclaration newConstructor = new ConstructorDeclaration (); AddAttributeSection (newConstructor, c); var location = LocationsBag.GetMemberLocation (c); AddModifiers (newConstructor, location); newConstructor.AddChild (Identifier.Create (c.MemberName.Name, Convert (c.MemberName.Location)), AstNode.Roles.Identifier); if (location != null) newConstructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar); AddParameter (newConstructor, c.ParameterInfo); if (location != null) newConstructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar); if (c.Initializer != null) { var initializer = new ConstructorInitializer (); initializer.ConstructorInitializerType = c.Initializer is ConstructorBaseInitializer ? ConstructorInitializerType.Base : ConstructorInitializerType.This; var initializerLocation = LocationsBag.GetLocations (c.Initializer); if (initializerLocation != null) newConstructor.AddChild (new CSharpTokenNode (Convert (initializerLocation[0]), 1), ConstructorDeclaration.Roles.Colon); // this and base has the same length initializer.AddChild (new CSharpTokenNode (Convert (c.Initializer.Location), "this".Length), ConstructorDeclaration.Roles.Keyword); if (initializerLocation != null) initializer.AddChild (new CSharpTokenNode (Convert (initializerLocation[1]), 1), ConstructorDeclaration.Roles.LPar); AddArguments (initializer, LocationsBag.GetLocations (c.Initializer.Arguments), c.Initializer.Arguments); if (initializerLocation != null) initializer.AddChild (new CSharpTokenNode (Convert (initializerLocation[2]), 1), ConstructorDeclaration.Roles.RPar); newConstructor.AddChild (initializer, ConstructorDeclaration.InitializerRole); } if (c.Block != null) newConstructor.AddChild ((BlockStatement)c.Block.Accept (this), ConstructorDeclaration.Roles.Body); typeStack.Peek ().AddChild (newConstructor, TypeDeclaration.MemberRole); }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { currentMethodName = constructorDeclaration.Name; base.VisitConstructorDeclaration(constructorDeclaration); }
public override void Visit(Constructor c) { var newConstructor = new ConstructorDeclaration(); AddAttributeSection(newConstructor, c); var location = LocationsBag.GetMemberLocation(c); AddModifiers(newConstructor, location); newConstructor.AddChild(Identifier.Create(c.MemberName.Name, Convert(c.MemberName.Location)), Roles.Identifier); if (location != null && location.Count > 0) newConstructor.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.LPar), Roles.LPar); AddParameter(newConstructor, c.ParameterInfo); if (location != null && location.Count > 1) newConstructor.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.RPar), Roles.RPar); if (c.Initializer != null) { var initializer = new ConstructorInitializer(); initializer.ConstructorInitializerType = c.Initializer is ConstructorBaseInitializer ? ConstructorInitializerType.Base : ConstructorInitializerType.This; var initializerLocation = LocationsBag.GetLocations(c.Initializer); if (initializerLocation != null) newConstructor.AddChild(new CSharpTokenNode(Convert(initializerLocation [0]), Roles.Colon), Roles.Colon); if (initializerLocation != null && initializerLocation.Count > 1) { // this and base has the same length var r = initializer.ConstructorInitializerType == ConstructorInitializerType.This ? ConstructorInitializer.ThisKeywordRole : ConstructorInitializer.BaseKeywordRole; initializer.AddChild(new CSharpTokenNode(Convert(c.Initializer.Location), r), r); initializer.AddChild(new CSharpTokenNode(Convert(initializerLocation [1]), Roles.LPar), Roles.LPar); AddArguments(initializer, c.Initializer.Arguments); initializer.AddChild(new CSharpTokenNode(Convert(initializerLocation [2]), Roles.RPar), Roles.RPar); newConstructor.AddChild(initializer, ConstructorDeclaration.InitializerRole); } } if (c.Block != null) newConstructor.AddChild((BlockStatement)c.Block.Accept(this), Roles.Body); typeStack.Peek().AddChild(newConstructor, Roles.TypeMemberRole); }
private void HandleMapFunction(ConstructorDeclaration ctor, string map) { string entityName; VariableDeclaration mapDefinition = map.Trim().StartsWith("from") ? TransformMapDefinitionFromLinqQuerySyntax(map, out entityName) : TransformMapDefinitionFromLinqMethodSyntax(map, out entityName); if (string.IsNullOrEmpty(entityName) == false) { //this.ForEntityNames.Add(entityName); ctor.Body.AddChild(new ExpressionStatement( new InvocationExpression( new MemberReferenceExpression( new MemberReferenceExpression(new ThisReferenceExpression(), "ForEntityNames"), "Add"), new List <Expression> { new PrimitiveExpression(entityName, entityName) }) )); } // this.AddMapDefinition(from doc in docs ...); ctor.Body.AddChild(new ExpressionStatement( new InvocationExpression(new MemberReferenceExpression(new ThisReferenceExpression(), "AddMapDefinition"), new List <Expression> { new LambdaExpression { Parameters = { new ParameterDeclarationExpression(null, "docs") }, ExpressionBody = mapDefinition.Initializer } } ))); if (firstMap) { mapDefinition.Initializer.AcceptVisitor(captureSelectNewFieldNamesVisitor, null); firstMap = false; } else { var secondMapFieldNames = new CaptureSelectNewFieldNamesVisitor(); mapDefinition.Initializer.AcceptVisitor(secondMapFieldNames, null); if (secondMapFieldNames.FieldNames.SetEquals(captureSelectNewFieldNamesVisitor.FieldNames) == false) { var message = string.Format(@"Map functions defined as part of a multi map index must return identical types. Baseline map : {0} Non matching map : {1} Common fields : {2} Missing fields : {3} Additional fields : {4}" , indexDefinition.Maps.First(), map, string.Join(", ", captureSelectNewFieldNamesVisitor.FieldNames.Intersect(secondMapFieldNames.FieldNames)), string.Join(", ", captureSelectNewFieldNamesVisitor.FieldNames.Except(secondMapFieldNames.FieldNames)), string.Join(", ", secondMapFieldNames.FieldNames.Except(captureSelectNewFieldNamesVisitor.FieldNames)) ); throw new InvalidOperationException(message); } } mapDefinition.Initializer.AcceptVisitor(new ThrowOnInvalidMethodCalls(), null); mapDefinition.Initializer.AcceptVisitor(captureQueryParameterNamesVisitorForMap, null); }
private void EmitExternalBaseCtor(ConstructorDeclaration ctor, ref bool requireNewLine) { IMember member = null; var hasInitializer = ctor.Initializer != null && !ctor.Initializer.IsNull; var baseType = this.Emitter.GetBaseTypeDefinition(); if (hasInitializer) { member = ((InvocationResolveResult)this.Emitter.Resolver.ResolveNode(ctor.Initializer, this.Emitter)).Member; } if (member != null) { var inlineCode = this.Emitter.GetInline(member); if (!string.IsNullOrEmpty(inlineCode)) { if (requireNewLine) { this.WriteNewLine(); requireNewLine = false; } this.Write(JS.Types.Bridge.APPLY); this.WriteOpenParentheses(); this.Write("this, "); var argsInfo = new ArgumentsInfo(this.Emitter, ctor.Initializer); new InlineArgumentsBlock(this.Emitter, argsInfo, inlineCode).Emit(); this.WriteCloseParentheses(); this.WriteSemiColon(); this.WriteNewLine(); return; } } if (hasInitializer || (baseType.FullName != "System.Object" && baseType.FullName != "System.ValueType" && baseType.FullName != "System.Enum" && !baseType.CustomAttributes.Any(a => a.AttributeType.FullName == "Bridge.NonScriptableAttribute") && !baseType.IsInterface)) { if (requireNewLine) { this.WriteNewLine(); requireNewLine = false; } string name = null; if (this.TypeInfo.GetBaseTypes(this.Emitter).Any()) { name = BridgeTypes.ToJsName(this.TypeInfo.GetBaseClass(this.Emitter), this.Emitter); } else { name = BridgeTypes.ToJsName(baseType, this.Emitter); } this.Write(name); this.WriteCall(); int openPos = this.Emitter.Output.Length; this.WriteOpenParentheses(); this.Write("this"); if (hasInitializer && ctor.Initializer.Arguments.Count > 0) { this.Write(", "); var argsInfo = new ArgumentsInfo(this.Emitter, ctor.Initializer); var argsExpressions = argsInfo.ArgumentsExpressions; var paramsArg = argsInfo.ParamsExpression; new ExpressionListBlock(this.Emitter, argsExpressions, paramsArg, ctor.Initializer, openPos).Emit(); } this.WriteCloseParentheses(); this.WriteSemiColon(); this.WriteNewLine(); } }
public override void VisitConstructorDeclaration (ConstructorDeclaration constructorDeclaration) { if (!constructorDeclaration.Body.IsNull) AddFolding (GetEndOfPrev(constructorDeclaration.Body.LBraceToken), constructorDeclaration.Body.RBraceToken.EndLocation, true); base.VisitConstructorDeclaration (constructorDeclaration); }
public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { base.VisitConstructorDeclaration(constructorDeclaration); }
public virtual void VisitConstructorDeclaration (ConstructorDeclaration constructorDeclaration) { VisitChildren (constructorDeclaration); }
private void HandleReduceDefintion(ConstructorDeclaration ctor) { if (!indexDefinition.IsMapReduce) { return; } VariableDeclaration reduceDefiniton; Expression groupBySource; string groupByParamter; if (indexDefinition.Reduce.Trim().StartsWith("from")) { reduceDefiniton = QueryParsingUtils.GetVariableDeclarationForLinqQuery(indexDefinition.Reduce, RequiresSelectNewAnonymousType); var sourceSelect = (QueryExpression)((QueryExpression)reduceDefiniton.Initializer).FromClause.InExpression; groupBySource = ((QueryExpressionGroupClause)sourceSelect.SelectOrGroupClause).GroupBy; groupByParamter = sourceSelect.FromClause.Identifier; } else { reduceDefiniton = QueryParsingUtils.GetVariableDeclarationForLinqMethods(indexDefinition.Reduce); var invocation = ((InvocationExpression)reduceDefiniton.Initializer); var target = (MemberReferenceExpression)invocation.TargetObject; while (target.MemberName != "GroupBy") { invocation = (InvocationExpression)target.TargetObject; target = (MemberReferenceExpression)invocation.TargetObject; } var lambdaExpression = ((LambdaExpression)invocation.Arguments[0]); groupByParamter = lambdaExpression.Parameters[0].ParameterName; groupBySource = lambdaExpression.ExpressionBody; } var mapFields = captureSelectNewFieldNamesVisitor.FieldNames.ToList(); captureSelectNewFieldNamesVisitor.FieldNames.Clear(); // reduce override the map fields reduceDefiniton.Initializer.AcceptVisitor(captureSelectNewFieldNamesVisitor, null); reduceDefiniton.Initializer.AcceptChildren(captureQueryParameterNamesVisitorForReduce, null); //ValidateMapReduceFields(mapFields); // this.ReduceDefinition = from result in results...; ctor.Body.AddChild(new ExpressionStatement( new AssignmentExpression( new MemberReferenceExpression(new ThisReferenceExpression(), "ReduceDefinition"), AssignmentOperatorType.Assign, new LambdaExpression { Parameters = { new ParameterDeclarationExpression(null, "results") }, ExpressionBody = reduceDefiniton.Initializer }))); ctor.Body.AddChild(new ExpressionStatement( new AssignmentExpression( new MemberReferenceExpression(new ThisReferenceExpression(), "GroupByExtraction"), AssignmentOperatorType.Assign, new LambdaExpression { Parameters = { new ParameterDeclarationExpression(null, groupByParamter) }, ExpressionBody = groupBySource }))); }
public void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) { StartNode(constructorDeclaration); WriteAttributes(constructorDeclaration.Attributes); WriteModifiers(constructorDeclaration.ModifierTokens); TypeDeclaration type = constructorDeclaration.Parent as TypeDeclaration; StartNode(constructorDeclaration.NameToken); WriteIdentifier(type != null ? type.Name : constructorDeclaration.Name); EndNode(constructorDeclaration.NameToken); Space(policy.SpaceBeforeConstructorDeclarationParentheses); WriteCommaSeparatedListInParenthesis(constructorDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses); if (!constructorDeclaration.Initializer.IsNull) { Space(); constructorDeclaration.Initializer.AcceptVisitor(this); } WriteMethodBody(constructorDeclaration.Body); EndNode(constructorDeclaration); }
private void AddAdditionalInformation(ConstructorDeclaration ctor) { AddInformation(ctor, captureSelectNewFieldNamesVisitor.FieldNames, "AddField"); AddInformation(ctor, captureQueryParameterNamesVisitorForMap.QueryParameters, "AddQueryParameterForMap"); AddInformation(ctor, captureQueryParameterNamesVisitorForMap.QueryParameters, "AddQueryParameterForReduce"); }