예제 #1
0
        public static MethodSignature ReadSignature(ImperativeCodeModel codeModel, IMethodSymbol symbol)
        {
            var parameters = symbol.Parameters.Select((p, index) => new MethodParameter {
                Name     = p.Name,
                Position = index + 1,
                Type     = codeModel.TryGet <TypeMember>(p.Type),
                Modifier = p.GetParameterModifier(),
            });

            var hasReturnType = (
                symbol.MethodKind != MethodKind.Constructor &&
                symbol.MethodKind != MethodKind.StaticConstructor &&
                !symbol.ReturnsVoid);

            var returnValue = (
                hasReturnType
                    ? new MethodParameter {
                Name = "$retVal",
                Position = 0,
                Type = codeModel.TryGet <TypeMember>(symbol.ReturnType),
                Modifier = symbol.GetReturnValueModifier(),
            }
                    : null
                );

            return(new MethodSignature {
                IsAsync = symbol.IsAsync,
                ReturnValue = returnValue,
                Parameters = parameters.ToList()
            });
        }
예제 #2
0
 public static TypeMember TryGetMemberFromTypeof(this ImperativeCodeModel codeModel, AbstractExpression expression)
 {
     return(
         (expression as ConstantExpression)?.Value is INamedTypeSymbol typeSymbol
         ? codeModel.TryGet <TypeMember>(binding: typeSymbol)
         : null);
 }
예제 #3
0
 public ClrTypeReader(Type clrType, TypeMember typeMember, ImperativeCodeModel codeModel, int distance)
 {
     _clrType    = clrType;
     _typeMember = typeMember;
     _codeModel  = codeModel;
     _distance   = distance;
 }
예제 #4
0
        public void Complete(TypeMember existingType, ImperativeCodeModel codeModel)
        {
            var clrType = existingType.Bindings.First <System.Type>();
            var reader  = new ClrTypeReader(clrType, existingType, codeModel, distance: 0);

            reader.ReadAll();
        }
예제 #5
0
        public WebUIMetadata(ImperativeCodeModel imperativeCodeModel)
        {
            _imperativeCodeModel = imperativeCodeModel;

            this.Pages       = DiscoverWebPages(); // calls to GetApiMetadata made during web page discovery, populate _backendApiByType
            this.BackendApis = _backendApiByType.Values.ToImmutableArray();
        }
예제 #6
0
 public HyperappAdapter(ImperativeCodeModel codeModel, IComponentAdapterFactory componentAdapterFactory, ICodeGeneratorOutput output)
 {
     _codeModel = codeModel;
     _componentAdapterFactory = componentAdapterFactory;
     _output     = output;
     _codeWriter = new JavaScriptCodeWriter(output);
 }
예제 #7
0
        public WebApiMetadata(ImperativeCodeModel imperativeCodeModel, TypeMember interfaceType)
        {
            _imperativeCodeModel = imperativeCodeModel;

            this.InterfaceType = interfaceType;
            this.ServiceName   = interfaceType.Name.TrimPrefixFragment("I").TrimSuffixFragment("Service");
            this.ApiMethods    = DiscoverApiMethods();
        }
예제 #8
0
        public WebPageMetadata(ImperativeCodeModel imperativeCodeModel, IBackendApiRegistry apiRegistry, TypeMember pageClass)
        {
            _imperativeCodeModel = imperativeCodeModel;
            _apiRegistry         = apiRegistry;

            this.PageClass        = pageClass;
            this.StateClass       = pageClass.BaseType.GenericArguments[0];
            this.ControllerMethod = TryFindControllerMethod();
            this.ModelProperty    = FindModelProperty();
            this.Components       = DiscoverComponents();
            this.BackendApis      = DiscoverBackendApis();
            this.IsIndex          = pageClass.HasAttribute <WebUI.Semantic.IndexPageAttribute>();
        }
예제 #9
0
        public static TypeMember ResolveType(Type clrType, ImperativeCodeModel codeModel, int distance)
        {
            var typeMember = new TypeMember();
            var reader     = new ClrTypeReader(clrType, typeMember, codeModel, distance);

            codeModel.Add(typeMember, isTopLevel: !clrType.IsNested);

            if (distance > 0)
            {
                reader.ReadNameOnly();
            }
            else
            {
                reader.ReadAll();
            }

            return(typeMember);
        }
예제 #10
0
        public WebComponentMetadata(
            WebPageMetadata page,
            ImperativeCodeModel imperativeCodeModel,
            PropertyMember declaredProperty,
            MethodMember controllerMethod)
        {
            _imperativeCodeModel = imperativeCodeModel;

            this.Page             = page;
            this.DeclaredProperty = declaredProperty;
            this.ComponentClass   = declaredProperty.PropertyType;
            this.ModelClass       = ComponentClass.GenericArguments.FirstOrDefault();
            this.PropertyMap      = new Dictionary <IdentifierName, AbstractExpression>();
            this.EventMap         = new EventMapMetadata();
            this.ModelMetadata    = new ModelObjectMetadata(ModelClass);

            //TODO: add AbstractMember.HasAttribute<T>()/TryGetAttribute<T>()
            this.IsPredefined = (
                ComponentClass.Bindings.FirstOrDefault <Type>()?.GetCustomAttribute <ProgrammingModelAttribute>() != null);

            ParsePropertyValues();
            FindEventHandlers(controllerMethod);
        }
예제 #11
0
 public UnitSyntaxEmitter(ImperativeCodeModel codeModel, TypeMember type)
 {
     _codeModel = codeModel;
     _type      = type;
 }
예제 #12
0
 TypeMember IClrTypeResolver.Resolve(Type clrType, ImperativeCodeModel codeModel, int distance)
 {
     return(ResolveType(clrType, codeModel, distance));
 }
예제 #13
0
 public static TypeMember GetMemberFromTypeof(this ImperativeCodeModel codeModel, AbstractExpression expression)
 {
     return(
         TryGetMemberFromTypeof(codeModel, expression)
         ?? throw new Exception($"could not find TypeMember referred by typeof"));
 }
예제 #14
0
 public AspNetAdapter(ImperativeCodeModel codeModel, ICodeGeneratorOutput output)
 {
     _codeModel = codeModel;
     _output    = output;
 }
예제 #15
0
 public RoslynCodeModelWriter(ImperativeCodeModel codeModel, ICodeGeneratorOutput output)
 {
     _codeModel = codeModel;
     _output    = output;
 }