protected virtual void EmitMethodParameters(IEnumerable <ParameterDeclaration> declarations, AstNode context, bool skipClose) { this.WriteOpenParentheses(); bool needComma = false; foreach (var p in declarations) { var name = this.Emitter.GetEntityName(p); if (needComma) { this.WriteComma(); } needComma = true; this.Write(name); this.WriteColon(); name = BridgeTypes.ToJsName(p.Type, this.Emitter); name = EmitBlock.HandleType(name); this.Write(name); } if (!skipClose) { this.WriteCloseParentheses(); } }
private void WriteProp(TypeConfigItem ev, string name, bool getter) { this.Write(getter ? "get" : "set"); this.Write(name); this.WriteOpenParentheses(); if (!getter) { this.Write("value"); this.WriteColon(); string typeName = BridgeTypes.ToJsName(ev.Entity.ReturnType, this.Emitter); typeName = EmitBlock.HandleType(typeName); this.Write(typeName); } this.WriteCloseParentheses(); this.WriteColon(); if (!getter) { this.Write("void"); } else { string typeName = BridgeTypes.ToJsName(ev.Entity.ReturnType, this.Emitter); typeName = EmitBlock.HandleType(typeName); this.Write(typeName); } this.WriteSemiColon(); this.WriteNewLine(); }
protected virtual void EmitIndexerMethod(IndexerDeclaration indexerDeclaration, Accessor accessor, bool setter) { if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null) { var overloads = OverloadsCollection.Create(this.Emitter, indexerDeclaration, setter); string name = overloads.GetOverloadName(); this.Write((setter ? "set" : "get") + name); this.EmitMethodParameters(indexerDeclaration.Parameters, indexerDeclaration, setter); if (setter) { this.Write(", value"); this.WriteColon(); name = BridgeTypes.ToJsName(indexerDeclaration.ReturnType, this.Emitter); name = EmitBlock.HandleType(name); this.Write(name); this.WriteCloseParentheses(); this.WriteColon(); this.Write("void"); } else { this.WriteColon(); name = BridgeTypes.ToJsName(indexerDeclaration.ReturnType, this.Emitter); name = EmitBlock.HandleType(name); this.Write(name); } this.WriteSemiColon(); this.WriteNewLine(); } }
protected void EmitOperatorDeclaration(OperatorDeclaration operatorDeclaration) { var typeDef = this.Emitter.GetTypeDefinition(); var overloads = OverloadsCollection.Create(this.Emitter, operatorDeclaration); if (overloads.HasOverloads) { string name = overloads.GetOverloadName(); this.Write(name); } else { this.Write(this.Emitter.GetEntityName(operatorDeclaration)); } this.EmitMethodParameters(operatorDeclaration.Parameters, operatorDeclaration); this.WriteColon(); var retType = BridgeTypes.ToJsName(operatorDeclaration.ReturnType, this.Emitter); retType = EmitBlock.HandleType(retType); this.Write(retType); this.WriteSemiColon(); this.WriteNewLine(); }
protected virtual void EmitFields(TypeConfigInfo info) { if (info.Fields.Count > 0) { foreach (var field in info.Fields) { if (field.Entity.HasModifier(Modifiers.Public)) { this.Write(field.GetName(this.Emitter)); this.WriteColon(); string typeName = BridgeTypes.ToJsName(field.Entity.ReturnType, this.Emitter); typeName = EmitBlock.HandleType(typeName); this.Write(typeName); this.WriteSemiColon(); this.WriteNewLine(); } } } if (info.Events.Count > 0) { foreach (var ev in info.Events) { if (ev.Entity.HasModifier(Modifiers.Public)) { var name = ev.GetName(this.Emitter); if (name.StartsWith("$")) { name = name.Substring(1); } this.WriteEvent(ev, "add" + name); this.WriteEvent(ev, "remove" + name); } } } if (info.Properties.Count > 0) { foreach (var prop in info.Properties) { if (prop.Entity.HasModifier(Modifiers.Public)) { var name = prop.GetName(this.Emitter); if (name.StartsWith("$")) { name = name.Substring(1); } this.WriteProp(prop, name, true); this.WriteProp(prop, name, false); } } } new MethodsBlock(this.Emitter, this.TypeInfo, this.StaticBlock).Emit(); }
private void WriteEvent(TypeConfigItem ev, string name) { this.Write(name); this.WriteOpenParentheses(); this.Write("value"); this.WriteColon(); string typeName = BridgeTypes.ToJsName(ev.Entity.ReturnType, this.Emitter); typeName = EmitBlock.HandleType(typeName); this.Write(typeName); this.WriteCloseParentheses(); this.WriteColon(); this.Write("void"); this.WriteSemiColon(); this.WriteNewLine(); }
protected virtual void EmitPropertyMethod(PropertyDeclaration propertyDeclaration, Accessor accessor, bool setter) { var memberResult = this.Emitter.Resolver.ResolveNode(propertyDeclaration, this.Emitter) as MemberResolveResult; if (memberResult != null && (memberResult.Member.Attributes.Any(a => a.AttributeType.FullName == "Bridge.FieldPropertyAttribute") || (propertyDeclaration.Getter.IsNull && propertyDeclaration.Setter.IsNull))) { return; } if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null) { var p = (PropertyDeclaration)accessor.Parent; var overloads = OverloadsCollection.Create(this.Emitter, propertyDeclaration, setter); string name = overloads.GetOverloadName(); this.Write((setter ? "set" : "get") + name); this.WriteOpenParentheses(); if (setter) { this.Write("value"); this.WriteColon(); name = BridgeTypes.ToJsName(p.ReturnType, this.Emitter); name = EmitBlock.HandleType(name); this.Write(name); } this.WriteCloseParentheses(); this.WriteColon(); if (setter) { this.Write("void"); } else { name = BridgeTypes.ToJsName(p.ReturnType, this.Emitter); name = EmitBlock.HandleType(name); this.Write(name); } this.WriteSemiColon(); this.WriteNewLine(); } }
protected virtual void EmitPropertyMethod(CustomEventDeclaration customEventDeclaration, Accessor accessor, bool remover) { if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null) { var overloads = OverloadsCollection.Create(this.Emitter, customEventDeclaration, remover); this.Write((remover ? "remove" : "add") + overloads.GetOverloadName()); this.WriteOpenParentheses(); this.Write("value"); this.WriteColon(); var retType = BridgeTypes.ToJsName(customEventDeclaration.ReturnType, this.Emitter); retType = EmitBlock.HandleType(retType); this.Write(retType); this.WriteCloseParentheses(); this.WriteColon(); this.Write("void"); this.WriteSemiColon(); this.WriteNewLine(); } }
protected void VisitMethodDeclaration(MethodDeclaration methodDeclaration) { var typeDef = this.Emitter.GetTypeDefinition(); var overloads = OverloadsCollection.Create(this.Emitter, methodDeclaration); if (overloads.HasOverloads) { string name = overloads.GetOverloadName(); this.Write(name); } else { this.Write(this.Emitter.GetEntityName(methodDeclaration)); } var isGeneric = methodDeclaration.TypeParameters.Count > 0; if (isGeneric) { bool needComma = false; this.Write("<"); foreach (var p in methodDeclaration.TypeParameters) { if (needComma) { this.WriteComma(); } needComma = true; this.Write(p.Name); } this.Write(">"); this.WriteOpenParentheses(); var comma = false; foreach (var p in methodDeclaration.TypeParameters) { if (comma) { this.WriteComma(); } this.Write(p.Name); this.WriteColon(); this.WriteOpenBrace(); this.Write("prototype"); this.WriteColon(); this.Write(p.Name); this.WriteCloseBrace(); comma = true; } this.WriteCloseParentheses(); this.WriteColon(); this.WriteOpenBrace(); this.WriteSpace(); } this.EmitMethodParameters(methodDeclaration.Parameters, methodDeclaration); this.WriteColon(); var retType = BridgeTypes.ToJsName(methodDeclaration.ReturnType, this.Emitter); retType = EmitBlock.HandleType(retType); this.Write(retType); if (isGeneric) { this.WriteSpace(); this.WriteCloseBrace(); } this.WriteSemiColon(); this.WriteNewLine(); }
protected virtual void EmitCtorForInstantiableClass() { var typeDef = this.Emitter.GetTypeDefinition(); string name = this.Emitter.Validator.GetCustomTypeName(typeDef); if (name.IsEmpty()) { name = BridgeTypes.ToJsName(this.TypeInfo.Type, this.Emitter, false, true); } name = EmitBlock.HandleType(name); if (this.TypeInfo.Ctors.Count == 0) { this.Write("new "); this.WriteOpenCloseParentheses(); this.WriteColon(); this.Write(name); this.WriteSemiColon(); this.WriteNewLine(); } else if (this.TypeInfo.Ctors.Count == 1) { var ctor = this.TypeInfo.Ctors.First(); if (!ctor.HasModifier(Modifiers.Public)) { return; } this.Write("new "); this.EmitMethodParameters(ctor.Parameters, ctor); this.WriteColon(); this.Write(name); this.WriteSemiColon(); this.WriteNewLine(); } else { var isGeneric = typeDef.GenericParameters.Count > 0; foreach (var ctor in this.TypeInfo.Ctors) { if (!ctor.HasModifier(Modifiers.Public)) { continue; } var ctorName = "$constructor"; if (this.TypeInfo.Ctors.Count > 1 && ctor.Parameters.Count > 0) { var overloads = OverloadsCollection.Create(this.Emitter, ctor); ctorName = overloads.GetOverloadName(); } if (!isGeneric) { this.Write(ctorName); this.WriteColon(); this.BeginBlock(); } this.WriteNew(); this.EmitMethodParameters(ctor.Parameters, ctor); this.WriteColon(); this.Write(name); if (!isGeneric) { this.WriteNewLine(); this.EndBlock(); } this.WriteSemiColon(); this.WriteNewLine(); } } }