Beispiel #1
0
        public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
        {
            if (CurrentType != null)
            {
                NestedTypes = NestedTypes ?? new List <Tuple <TypeDeclaration, ITypeInfo> >();
                NestedTypes.Add(new Tuple <TypeDeclaration, ITypeInfo>(typeDeclaration, CurrentType));
                return;
            }

            ValidateNamespace(typeDeclaration);

            var rr          = Resolver.ResolveNode(typeDeclaration);
            var fullName    = rr.Type.ReflectionName;
            var partialType = Types.FirstOrDefault(t => t.Key == fullName);
            var add         = true;
            var ignored     = IgnoredTypes.Contains(fullName);
            var external    = HasExternal(typeDeclaration);

            if (!external)
            {
                var resolveResult = Resolver.ResolveNode(typeDeclaration);
                if (resolveResult != null && resolveResult.Type != null)
                {
                    var def = resolveResult.Type.GetDefinition();

                    external = def != null && (Validator.IsTypeFromH5Core(def.FullName) || def.ParentAssembly.AssemblyAttributes.Any(a => a.AttributeType.FullName == "H5.ExternalAttribute"));
                }
            }

            if ((external || ignored || IsNonScriptable(typeDeclaration)) && !IsObjectLiteral(typeDeclaration))
            {
                if (partialType != null)
                {
                    Types.Remove(partialType);
                }

                if (!ignored)
                {
                    IgnoredTypes.Add(fullName);
                }

                return;
            }

            if (partialType == null)
            {
                ITypeInfo parentTypeInfo        = null;
                var       parentTypeDeclaration = typeDeclaration.GetParent <TypeDeclaration>();
                if (parentTypeDeclaration != null)
                {
                    var rr1        = Resolver.ResolveNode(parentTypeDeclaration);
                    var parentName = rr1.Type.ReflectionName;
                    parentTypeInfo = Types.FirstOrDefault(t => t.Key == parentName);
                }

                CurrentType = new TypeInfo()
                {
                    Key             = rr.Type.ReflectionName,
                    TypeDeclaration = typeDeclaration,
                    ParentType      = parentTypeInfo,
                    Name            = typeDeclaration.Name,
                    ClassType       = typeDeclaration.ClassType,
                    Namespace       = Namespace,
                    IsEnum          = typeDeclaration.ClassType == ClassType.Enum,
                    IsStatic        = typeDeclaration.ClassType == ClassType.Enum || typeDeclaration.HasModifier(Modifiers.Static),
                    IsObjectLiteral = IsObjectLiteral(typeDeclaration),
                    Type            = rr.Type
                };
            }
            else
            {
                CurrentType = partialType;
                CurrentType.PartialTypeDeclarations.Add(typeDeclaration);
                add = false;
            }

            if (typeDeclaration.ClassType != ClassType.Interface)
            {
                typeDeclaration.AcceptChildren(this);
            }
            else
            {
                typeDeclaration.AcceptChildren(this);
            }

            if (add)
            {
                Types.Add(CurrentType);
            }

            if (typeDeclaration.ClassType != ClassType.Interface)
            {
                AddMissingAliases(typeDeclaration);
            }

            CurrentType = null;

            while (NestedTypes != null && NestedTypes.Count > 0)
            {
                var types = NestedTypes;
                NestedTypes = null;
                foreach (var nestedType in types)
                {
                    VisitTypeDeclaration(nestedType.Item1);
                }
            }
        }