private XElement GenerateFieldMarkup(string formHtmlId, ModelFieldMetadata field) { var element = new XElement( "Form.field", GenerateScopeSelectorAttribute(), new XAttribute("formId", formHtmlId), new XAttribute("propName", field.Property.Name.ToString(CasingStyle.Camel))); if (field.Label != null) { var labelText = new IdentifierName(field.Label, LanguageInfo.Entries.JavaScript(), style: CasingStyle.Pascal); element.Add(new XAttribute("label", labelText.ToString(CasingStyle.UserFriendly) + ":")); } element.Add(new JsxExpressionAttribute( "getter", LAMBDA(@m => IIF(@m, whenTrue: @m.DOT(field.Property), whenFalse: ANY("???"))))); if (field.Direction == FieldDirection.Input) { element.Add(new JsxExpressionAttribute( "setter", LAMBDA((@m, @v) => @m.DOT(field.Property).ASSIGN(@v)))); } element.Add(new JsxExpressionAttribute("validation", GenerateValidationObject(field))); return(element); }
public override Node VisitWriteHostIntent(WriteHostIntent intent) { var consoleClass = new IdentifierName("Console"); var memberAccess = new MemberAccess(consoleClass, "WriteLine"); return(new Invocation(memberAccess, new ArgumentList(new Argument(intent.Object)))); }
public override int GetHashCode() { unchecked { return(((IdentifierName != null ? IdentifierName.GetHashCode() : 0) * 397) ^ (Identifier != null ? Identifier.GetHashCode() : 0)); } }
public override IdentifierInfo VisitInvocation([NotNull] IInvocationOperation operation, [CanBeNull] object argument) { var name = new IdentifierName(operation.TargetMethod.Name, operation.TargetMethod.ToDisplayString(SymbolDisplayFormat.CSharpShortErrorMessageFormat)); return(new IdentifierInfo(name, operation.TargetMethod.ReturnType, operation.TargetMethod.Kind.ToString())); }
public MemberQuery(string memberName, int parameterCount, BindingFlags flags, Type[] parameterTypes) { this.memberName = new IdentifierName(memberName); this.parameterCount = parameterCount; this.flags = flags; this.parameterTypes = parameterTypes; }
protected void GenerateEventHandlerActionKey(IdentifierName eventName, IReadOnlyList <IFunctionContext> handlerList) { KEY(GetEventActionKeyName(eventName), LAMBDA(@model => DO.RETURN(ASYNC.LAMBDA((@state, @actions) => { LOCAL("newModel", out var @newModel, USE("Object").DOT("assign").INVOKE(INITOBJECT(), @model)); var modelMemberAccessRewriter = new ModelMemberAccessRewriter(Metadata.Page, @newModel); var apiMemberAccessRewriter = new BackendApiProxyAccessRewriter(Metadata.Page); var actionBlock = CodeGeneratorContext.GetContextOrThrow().GetCurrentBlock(); foreach (var handler in handlerList) { var rewrittenHandlerBody = apiMemberAccessRewriter.RewriteBlockStatement( modelMemberAccessRewriter.RewriteBlockStatement(handler.Body)); foreach (var statement in rewrittenHandlerBody.Statements) { actionBlock.AppendStatement(statement); } } actions.DOT("replaceModel").INVOKE(@newModel); })) )); }
public override IdentifierInfo VisitLocalReferenceExpression([NotNull] ILocalReferenceExpression operation, [CanBeNull] object argument) { var name = new IdentifierName(operation.Local.Name, operation.Local.ToDisplayString(SymbolDisplayFormat.CSharpShortErrorMessageFormat)); return(new IdentifierInfo(name, operation.Local.Type, "Variable")); }
public override void VisitForEachStatement(ForEachStatementSyntax node) { var expression = VisitSyntaxNode(node.Expression); var statement = VisitSyntaxNode(node.Statement); var identifier = new IdentifierName(node.Identifier.Text); _currentNode = new ForEachStatement(identifier, expression, statement); }
private IdentifierInfo CreateForMemberReferenceExpression([NotNull] IMemberReferenceExpression operation, [NotNull] ITypeSymbol memberType) { var name = new IdentifierName(operation.Member.Name, operation.Member.ToDisplayString(SymbolDisplayFormat.CSharpShortErrorMessageFormat)); return(new IdentifierInfo(name, memberType, operation.Member.Kind.ToString())); }
public IReadOnlyList <IFunctionContext> GetHandlers(IdentifierName eventName) { if (_eventMap.TryGetValue(eventName, out var list)) { return(list); } return(new IFunctionContext[0]); }
protected MemberGenerator(CodeGeneratorContext context, IdentifierName name, Action body) { this.Context = context; this.Name = name; this.Body = body; this.Traits = context.PopStateOrThrow <MemberTraitsContext>();; this.DeclaringModule = context.TryGetCurrentModule(); this.DeclaringType = context.TryGetCurrentType(); }
public override IdentifierInfo VisitParameterReference([NotNull] IParameterReferenceOperation operation, [CanBeNull] object argument) { var name = new IdentifierName(operation.Parameter.Name, /* CSharpShortErrorMessageFormat returns 'int', ie. without parameter name */ operation.Parameter.Name); return(new IdentifierInfo(name, operation.Parameter.Type)); }
public static MemberExpression Create(AbstractExpression target, IdentifierName memberName) { return(BlockContext.GetBlockOrThrow().PushExpression(new MemberExpression { Type = target.Type, Target = target, Member = null, MemberName = memberName })); }
public bool Matches(string candidateName) { string baseName = candidateName.Contains(".") ? MatchName : new GracefulName(MatchName).IdentifierName.ToString(); var typeIdentifier = new IdentifierName(baseName); var typeFixtureIdentifier = new IdentifierName(baseName + "fixture"); return(typeIdentifier.Matches(candidateName) || typeFixtureIdentifier.Matches(candidateName)); }
public void AddHandler(IdentifierName eventName, IFunctionContext handler) { if (!_eventMap.TryGetValue(eventName, out var list)) { list = new List <IFunctionContext>(); _eventMap.Add(eventName, list); } list.Add(handler); }
public static RuntimeMember GetInstance(TypedValue instance, IdentifierName memberName, int parameterCount) { RuntimeMember runtimeMember = FindInstance(instance.Value, memberName, parameterCount); if (runtimeMember == null) { throw new MemberMissingException(instance.Type, memberName.SourceName, parameterCount); } return(runtimeMember); }
public override IdentifierInfo VisitParameterReferenceExpression([NotNull] IParameterReferenceExpression operation, [CanBeNull] object argument) { var name = new IdentifierName(operation.Parameter.Name, #pragma warning disable AV2310 // Code blocks should not contain inline comments /* CSharpShortErrorMessageFormat returns 'ref int', ie. without parameter name */ #pragma warning restore AV2310 // Code blocks should not contain inline comments operation.Parameter.Name); return(new IdentifierInfo(name, operation.Parameter.Type, operation.Parameter.Kind.ToString())); }
/// <inheritdoc/> protected override bool Implements(IInterfaceExposable member) { if (ReferenceEquals(member, this)) { return(false); } return((member.DeclarationType == DeclarationType.PropertyGet || member.DeclarationType == DeclarationType.Variable) && member.IsInterfaceMember && ((ClassModuleDeclaration)member.ParentDeclaration).Subtypes.Any(implementation => ReferenceEquals(implementation, ParentDeclaration)) && IdentifierName.Equals(member.ImplementingIdentifierName)); }
public override int GetHashCode() { unchecked { var hash = 17; hash = hash * 23 + QualifiedName.QualifiedModuleName.GetHashCode(); hash = hash * 23 + IdentifierName.GetHashCode(); hash = hash * 23 + DeclarationType.GetHashCode(); hash = hash * 23 + Scope.GetHashCode(); hash = hash * 23 + ParentScope.GetHashCode(); hash = hash * 23 + Selection.GetHashCode(); return(hash); } }
public bool MatchesGetSetName(string name) { var identifier = new IdentifierName(memberName.Name); if (identifier.Matches(name)) { return(true); } if (!identifier.MatchName.StartsWith("set") && !identifier.MatchName.StartsWith("get")) { return(false); } return(new IdentifierName(identifier.MatchName.Substring(3)).Matches(name)); }
private string CodeBuilderUDTResult(string inputCode, DeclarationType declarationType, params string[] prototypes) { var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _).Object; var state = MockParser.CreateAndParse(vbe); using (state) { var targets = state.DeclarationFinder.DeclarationsWithType(declarationType) .Where(d => prototypes.Contains(d.IdentifierName)) .Select(prototype => (prototype, prototype.IdentifierName.CapitalizeFirstLetter())); return(CreateCodeBuilder().TryBuildUserDefinedTypeDeclaration(_defaultUDTIdentifier, targets, out string declaration) ? declaration : string.Empty); } }
public override Node VisitWriteFileIntent(WriteFileIntent intent) { var fileClass = new IdentifierName("File"); var method = "WriteAllText"; var arguments = new List <Argument>(); if (intent.Append != null) { method = "AppendAllText"; } var memberAccess = new MemberAccess(fileClass, method); arguments.Add(new Argument(intent.FilePath)); arguments.Add(new Argument(intent.Content)); return(new Invocation(memberAccess, new ArgumentList(arguments))); }
object[] GetNamedParameterList(TypedValue instance, Tree <T> parameters, RuntimeMember member, IList <string> parameterNames) { var result = new object[parameterNames.Count]; for (int i = 0; i < parameterNames.Count; i++) { for (int j = 0; j < parameterNames.Count; j++) { var parameterNameId = new IdentifierName(parameterNames[j]); if (!parameterNameId.Matches(member.GetParameterName(i))) { continue; } result[i] = ParseParameterValue(member, instance, parameters.Branches[2 * j + 1], i); } } return(result); }
public RuntimeMember Find(IdentifierName memberName, int parameterCount, Func <KeyValuePair <string, Accessor>, bool> filter) { foreach (KeyValuePair <string, Accessor> accessor in accessors) { if (!filter(accessor)) { continue; } if (parameterCount == 1) { return(new SetterMember(accessor.Value)); } if (parameterCount == 0) { return(new GetterMember(accessor.Value)); } } throw new ArgumentException(string.Format("Missing member '{0}'", memberName.SourceName)); }
public RuntimeMember Find(IdentifierName memberName, int parameterCount, IList <Type> parameterTypes) { return(columnAccessors.Find(memberName, parameterCount, accessor => { string accessorName = accessor.Key.EndsWith("=") ? accessor.Key.Substring(0, accessor.Key.Length - 1) : accessor.Key; if (!memberName.Matches(accessorName)) { return false; } if (currentHeader != null && currentHeader.Text.EndsWith("=") && !accessor.Key.EndsWith("=")) { return false; } if (currentHeader != null && !currentHeader.Text.EndsWith("=") && accessor.Key.EndsWith("=")) { return false; } return true; })); }
public static ModuleMember MODULE(string[] folderPath, IdentifierName name, Action body) { var context = GetContextOrThrow(); var module = new ModuleMember() { FolderPath = folderPath ?? new string[0], Name = name, Status = MemberStatus.Incomplete, Visibility = MemberVisibility.Public, GloalBlock = new BlockStatement() }; using (context.PushState(module)) { using (context.PushState(new BlockContext(module.GloalBlock))) { body?.Invoke(); } } module.Status = MemberStatus.Generator; return(module); }
public static TypeMember BuildTypeMember(TypeMemberKind typeKind, IdentifierName name, Action body) { var context = CodeGeneratorContext.GetContextOrThrow(); var module = context.TryLookupState <ModuleMember>(); var namespaceContext = context.TryLookupState <NamespaceContext>(); var traits = context.PopStateOrThrow <MemberTraitsContext>(); var containingType = context.TryLookupState <TypeMember>(); var type = new TypeMember(); type.Name = name; type.Namespace = namespaceContext?.Name; type.TypeKind = typeKind; type.DeclaringModule = module; type.DeclaringType = containingType; type.Modifier = traits.Modifier; type.Visibility = traits.Visibility; type.IsDefaultExport = traits.IsDefaultExport; if (containingType != null) { containingType.Members.Add(type); } context.AddGeneratedMember(type, isTopLevel: containingType == null); if (module != null) { module.Members.Add(type); } using (context.PushState(type)) { body?.Invoke(); } return(type); }
public RuntimeMember Find(IdentifierName memberName, int parameterCount, IList <Type> parameterTypes) { return(columnAccessors.Find(memberName, parameterCount, accessor => memberName.Matches(accessor.Key))); }
Argument(IdentifierName(_apiKeyPropertyName !)))))));
public static string ToCamelCase(IdentifierName identifier) { return(identifier.GetSealedOrCased( CasingStyle.Camel, sealLanguage: LanguageInfo.Entries.JavaScript())); }