Пример #1
0
        /// <summary>
        /// Create the binding object (association) for the pool in the global name scope (system dictionary).
        /// </summary>
        /// <param name="installer">Context within which the binding is to be created.</param>
        /// <returns>Returns true if successful, otherwise false.</returns>
        protected internal override bool CreateGlobalBinding(IDefinitionInstallerContext installer)
        {
            if (installer == null)
            {
                throw new ArgumentNullException();
            }
            // 1. Check if the name is not complete garbage.
            if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(this.Name.Value))
            {
                return(installer.ReportError(this.Name, InstallerErrors.PoolInvalidName));
            }
            // 2. Check if there is already a global with that name in the inner name scope
            Symbol name = installer.Runtime.GetSymbol(this.Name.Value);
            IDiscreteGlobalBinding existingBinding = installer.GetLocalGlobalBinding(name);

            if (existingBinding != null)
            {
                return(installer.ReportError(this.Name, InstallerErrors.PoolNameNotUnique));
            }
            // 3. No global defined in the inner scope, but check the scopes (inner or outer) for protected names like Object etc.
            if (installer.IsProtectedName(name))
            {
                return(installer.ReportError(this.Name, InstallerErrors.PoolNameProtected));
            }
            if (IronSmalltalk.Common.GlobalConstants.ReservedIdentifiers.Contains(this.Name.Value))
            {
                return(installer.ReportError(this.Name, InstallerErrors.PoolReservedName));
            }

            // 4. OK ... create a binding - so far pointing to null.
            installer.AddPoolBinding(new PoolBinding(name));
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Add annotations the the object being created.
        /// </summary>
        /// <param name="installer">Context which is performing the installation.</param>
        /// <returns>Returns true if successful, otherwise false.</returns>
        protected internal override bool AnnotateObject(IDefinitionInstallerContext installer)
        {
            if (installer == null)
            {
                throw new ArgumentNullException();
            }

            if (!this.Annotations.Any())
            {
                return(true);
            }

            Symbol name = installer.Runtime.GetSymbol(this.Name.Value);

            Runtime.Bindings.IDiscreteGlobalBinding binding = installer.GetLocalGlobalBinding(name);
            if (binding == null)
            {
                return(true); // An error, but we don't see the annotations as critical.
            }
            installer.AnnotateObject(binding, this.Annotations);

            return(true);
        }