Example #1
0
        private void CompleteInterfaces(
            ICompletionContext context,
            ObjectTypeDefinition definition)
        {
            if (ClrType != typeof(object))
            {
                foreach (Type interfaceType in ClrType.GetInterfaces())
                {
                    if (context.TryGetType(
                            new ClrTypeReference(interfaceType, TypeContext.Output),
                            out InterfaceType type))
                    {
                        _interfaces[type.Name] = type;
                    }
                }
            }

            foreach (ITypeReference interfaceRef in definition.Interfaces)
            {
                if (!context.TryGetType(interfaceRef, out InterfaceType type))
                {
                    // TODO : resources
                    context.ReportError(SchemaErrorBuilder.New()
                                        .SetMessage(
                                            "COULD NOT RESOLVE INTERFACE")
                                        .SetCode(ErrorCodes.Schema.MissingType)
                                        .SetTypeSystemObject(this)
                                        .AddSyntaxNode(SyntaxNode)
                                        .Build());
                }

                _interfaces[type.Name] = type;
            }
        }
Example #2
0
 private void TryInferInterfaceUsageFromClrType(
     ICompletionContext context,
     Type clrType)
 {
     foreach (Type interfaceType in clrType.GetInterfaces())
     {
         if (context.TryGetType(
                 new ClrTypeReference(interfaceType, TypeContext.Output),
                 out InterfaceType type) &&
             !_interfaces.Contains(type))
         {
             _interfaces.Add(type);
         }
     }
 }
Example #3
0
        public static void Complete(
            ICompletionContext context,
            IComplexOutputTypeDefinition definition,
            Type clrType,
            ICollection <InterfaceType> interfaces,
            ITypeSystemObject interfaceOrObject,
            ISyntaxNode?node)
        {
            if (clrType != typeof(object))
            {
                TryInferInterfaceUsageFromClrType(context, clrType, interfaces);
            }

            if (definition.KnownClrTypes.Count > 0)
            {
                definition.KnownClrTypes.Remove(typeof(object));

                foreach (Type type in definition.KnownClrTypes.Distinct())
                {
                    TryInferInterfaceUsageFromClrType(context, type, interfaces);
                }
            }

            foreach (ITypeReference interfaceRef in definition.Interfaces)
            {
                if (!context.TryGetType(interfaceRef, out InterfaceType type))
                {
                    // TODO : resources
                    context.ReportError(SchemaErrorBuilder.New()
                                        .SetMessage("COULD NOT RESOLVE INTERFACE")
                                        .SetCode(ErrorCodes.Schema.MissingType)
                                        .SetTypeSystemObject(interfaceOrObject)
                                        .AddSyntaxNode(node)
                                        .Build());
                }

                if (!interfaces.Contains(type))
                {
                    interfaces.Add(type);
                }
            }
        }
Example #4
0
        private void CompleteInterfaces(
            ICompletionContext context,
            ObjectTypeDefinition definition)
        {
            if (definition.Name == "Some")
            {
            }
            if (ClrType != typeof(object))
            {
                TryInferInterfaceUsageFromClrType(context, ClrType);
            }

            if (definition.KnownClrTypes.Count > 0)
            {
                definition.KnownClrTypes.Remove(typeof(object));

                foreach (Type clrType in definition.KnownClrTypes.Distinct())
                {
                    TryInferInterfaceUsageFromClrType(context, clrType);
                }
            }

            foreach (ITypeReference interfaceRef in definition.Interfaces)
            {
                if (!context.TryGetType(interfaceRef, out InterfaceType type))
                {
                    // TODO : resources
                    context.ReportError(SchemaErrorBuilder.New()
                                        .SetMessage("COULD NOT RESOLVE INTERFACE")
                                        .SetCode(ErrorCodes.Schema.MissingType)
                                        .SetTypeSystemObject(this)
                                        .AddSyntaxNode(SyntaxNode)
                                        .Build());
                }

                if (!_interfaces.Contains(type))
                {
                    _interfaces.Add(type);
                }
            }
        }
Example #5
0
 protected virtual void OnCompleteTypeSet(
     ICompletionContext context,
     UnionTypeDefinition definition,
     ISet <ObjectType> typeSet)
 {
     foreach (ITypeReference typeReference in definition.Types)
     {
         if (context.TryGetType(typeReference, out ObjectType ot))
         {
             typeSet.Add(ot);
         }
         else
         {
             context.ReportError(SchemaErrorBuilder.New()
                                 .SetMessage(TypeResources.UnionType_UnableToResolveType)
                                 .SetCode(TypeErrorCodes.MissingType)
                                 .SetTypeSystemObject(this)
                                 .SetExtension(_typeReference, typeReference)
                                 .AddSyntaxNode(SyntaxNode)
                                 .Build());
         }
     }
 }