Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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))));
        }
Esempio n. 3
0
 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()));
            }
Esempio n. 5
0
 public MemberQuery(string memberName, int parameterCount, BindingFlags flags, Type[] parameterTypes)
 {
     this.memberName     = new IdentifierName(memberName);
     this.parameterCount = parameterCount;
     this.flags          = flags;
     this.parameterTypes = parameterTypes;
 }
Esempio n. 6
0
        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"));
            }
Esempio n. 8
0
        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()));
            }
Esempio n. 10
0
        public IReadOnlyList <IFunctionContext> GetHandlers(IdentifierName eventName)
        {
            if (_eventMap.TryGetValue(eventName, out var list))
            {
                return(list);
            }

            return(new IFunctionContext[0]);
        }
Esempio n. 11
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));
            }
Esempio n. 13
0
 public static MemberExpression Create(AbstractExpression target, IdentifierName memberName)
 {
     return(BlockContext.GetBlockOrThrow().PushExpression(new MemberExpression {
         Type = target.Type,
         Target = target,
         Member = null,
         MemberName = memberName
     }));
 }
Esempio n. 14
0
            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));
            }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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));
        }
Esempio n. 19
0
 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);
     }
 }
Esempio n. 20
0
        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));
        }
Esempio n. 21
0
        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);
            }
        }
Esempio n. 22
0
        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)));
        }
Esempio n. 23
0
        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);
        }
Esempio n. 24
0
 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));
 }
Esempio n. 25
0
 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;
     }));
 }
Esempio n. 26
0
        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);
        }
Esempio n. 27
0
        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);
        }
Esempio n. 28
0
 public RuntimeMember Find(IdentifierName memberName, int parameterCount, IList <Type> parameterTypes)
 {
     return(columnAccessors.Find(memberName, parameterCount, accessor => memberName.Matches(accessor.Key)));
 }
 Argument(IdentifierName(_apiKeyPropertyName !)))))));
Esempio n. 30
0
 public static string ToCamelCase(IdentifierName identifier)
 {
     return(identifier.GetSealedOrCased(
                CasingStyle.Camel,
                sealLanguage: LanguageInfo.Entries.JavaScript()));
 }