Exemple #1
0
        private static async Task <ImmutableArray <DependentProject> > GetDependentProjectsCoreAsync(
            ISymbol symbol,
            Solution solution,
            Project sourceProject,
            SymbolVisibility visibility,
            CancellationToken cancellationToken)
        {
            var dependentProjects = new HashSet <DependentProject>();

            // If a symbol was defined in source, then it is always visible to the project it
            // was defined in.
            if (sourceProject != null)
            {
                dependentProjects.Add(new DependentProject(sourceProject.Id, hasInternalsAccess: true));
            }

            cancellationToken.ThrowIfCancellationRequested();

            // If it's not private, then we need to find possible references.
            if (visibility != SymbolVisibility.Private)
            {
                await AddNonSubmissionDependentProjectsAsync(symbol.ContainingAssembly, solution, sourceProject, dependentProjects, cancellationToken).ConfigureAwait(false);
            }

            // submission projects are special here. The fields generated inside the Script object
            // is private, but further submissions can bind to them.
            await AddSubmissionDependentProjectsAsync(solution, sourceProject, dependentProjects, cancellationToken).ConfigureAwait(false);

            return(dependentProjects.ToImmutableArray());
        }
Exemple #2
0
 /// <summary>
 /// Determines whether <paramref name="typeVisibility"/> is at least as visible as <paramref name="comparisonVisibility"/>.
 /// </summary>
 /// <param name="typeVisibility">The visibility to compare against.</param>
 /// <param name="comparisonVisibility">The visibility to compare with.</param>
 /// <returns>True if one can say that <paramref name="typeVisibility"/> is at least as visible as <paramref name="comparisonVisibility"/>.</returns>
 /// <remarks>
 /// For example, <see cref="SymbolVisibility.Public"/> is at least as visible as <see cref="SymbolVisibility.Internal"/>, but <see cref="SymbolVisibility.Private"/> is not as visible as <see cref="SymbolVisibility.Public"/>.
 /// </remarks>
 public static bool IsAtLeastAsVisibleAs(this SymbolVisibility typeVisibility, SymbolVisibility comparisonVisibility)
 {
     return(typeVisibility switch
     {
         SymbolVisibility.Public => true,
         SymbolVisibility.Internal => comparisonVisibility != SymbolVisibility.Public,
         SymbolVisibility.Private => comparisonVisibility == SymbolVisibility.Private,
         _ => throw new ArgumentOutOfRangeException(nameof(typeVisibility), typeVisibility, null),
     });
Exemple #3
0
 public SymbolEntry(string name, T value, T size, SymbolVisibility visibility,
                    SymbolBinding binding, SymbolType type, ELF <T> elf, ushort sectionIdx)
 {
     Name                = name;
     Value               = value;
     Size                = size;
     Binding             = binding;
     Type                = type;
     Visibility          = visibility;
     this.elf            = elf;
     PointedSectionIndex = sectionIdx;
 }
        public static SymbolVisibility GetResultantVisibility(this ISymbol symbol)
        {
            // Start by assuming it's visible.
            SymbolVisibility visibility = SymbolVisibility.Public;

            switch (symbol.Kind)
            {
            case SymbolKind.Alias:
                // Aliases are uber private.  They're only visible in the same file that they
                // were declared in.
                return(SymbolVisibility.Private);

            case SymbolKind.Parameter:
                // Parameters are only as visible as their containing symbol
                return(GetResultantVisibility(symbol.ContainingSymbol));

            case SymbolKind.TypeParameter:
                // Type Parameters are private.
                return(SymbolVisibility.Private);
            }

            while (symbol != null && symbol.Kind != SymbolKind.Namespace)
            {
                switch (symbol.DeclaredAccessibility)
                {
                // If we see anything private, then the symbol is private.
                case Accessibility.NotApplicable:
                case Accessibility.Private:
                    return(SymbolVisibility.Private);

                // If we see anything internal, then knock it down from public to
                // internal.
                case Accessibility.Internal:
                case Accessibility.ProtectedAndInternal:
                    visibility = SymbolVisibility.Internal;
                    break;

                    // For anything else (Public, Protected, ProtectedOrInternal), the
                    // symbol stays at the level we've gotten so far.
                }

                symbol = symbol.ContainingSymbol;
            }

            return(visibility);
        }
Exemple #5
0
        /// <summary>
        /// Determines whether <paramref name="typeVisibility"/> is at least as visible as <paramref name="comparisonVisibility"/>.
        /// </summary>
        /// <param name="typeVisibility">The visibility to compare against.</param>
        /// <param name="comparisonVisibility">The visibility to compare with.</param>
        /// <returns>True if one can say that <paramref name="typeVisibility"/> is at least as visible as <paramref name="comparisonVisibility"/>.</returns>
        /// <remarks>
        /// For example, <see cref="SymbolVisibility.Public"/> is at least as visible as <see cref="SymbolVisibility.Internal"/>, but <see cref="SymbolVisibility.Private"/> is not as visible as <see cref="SymbolVisibility.Public"/>.
        /// </remarks>
        public static bool IsAtLeastAsVisibleAs(this SymbolVisibility typeVisibility, SymbolVisibility comparisonVisibility)
        {
            switch (typeVisibility)
            {
            case SymbolVisibility.Public:
                return(true);

            case SymbolVisibility.Internal:
                return(comparisonVisibility != SymbolVisibility.Public);

            case SymbolVisibility.Private:
                return(comparisonVisibility == SymbolVisibility.Private);

            default:
                throw new ArgumentOutOfRangeException(nameof(typeVisibility), typeVisibility, null);
            }
        }
Exemple #6
0
        public static SymbolVisibilityGroup ToSymbolVisibilityGroup(this SymbolVisibility symbolVisibility)
        {
            switch (symbolVisibility)
            {
            case SymbolVisibility.Public:
                return(SymbolVisibilityGroup.Public);

            case SymbolVisibility.Internal:
                return(SymbolVisibilityGroup.Internal);

            case SymbolVisibility.Private:
                return(SymbolVisibilityGroup.Private);

            default:
                throw new ArgumentOutOfRangeException(nameof(symbolVisibility), symbolVisibility, null);
            }
        }
Exemple #7
0
        private static ImmutableArray <Project> FilterDependentProjectsByVisibility(
            Solution solution,
            ImmutableArray <DependentProject> dependentProjects,
            SymbolVisibility visibility)
        {
            // Filter out dependent projects based on symbol visibility.
            switch (visibility)
            {
            case SymbolVisibility.Internal:
                // Retain dependent projects that have internals access.
                dependentProjects = dependentProjects.WhereAsArray(dp => dp.HasInternalsAccess);
                break;
            }

            var projectIds = dependentProjects.SelectAsArray(dp => dp.ProjectId);

            return(GetProjects(solution, projectIds));
        }
        private static IEnumerable<Project> FilterDependentProjectsByVisibility(
            Solution solution,
            IEnumerable<DependentProject> dependentProjects,
            SymbolVisibility visibility)
        {
            // Filter out dependent projects based on symbol visibility.
            switch (visibility)
            {
                case SymbolVisibility.Internal:
                    // Retain dependent projects that have internals access.
                    dependentProjects = dependentProjects.Where(dp => dp.HasInternalsAccess);
                    break;
            }

            var projectIds = dependentProjects.Select(dp => dp.ProjectId);
            return GetProjects(solution, projectIds);
        }
        private static async Task<IEnumerable<DependentProject>> GetDependentProjectsCoreAsync(
            ISymbol symbol,
            Solution solution,
            Project sourceProject,
            SymbolVisibility visibility,
            CancellationToken cancellationToken)
        {
            var dependentProjects = new HashSet<DependentProject>();

            // If a symbol was defined in source, then it is always visible to the project it
            // was defined in.
            if (sourceProject != null)
            {
                dependentProjects.Add(new DependentProject(sourceProject.Id, hasInternalsAccess: true));
            }

            cancellationToken.ThrowIfCancellationRequested();

            // If it's not private, then we need to find possible references.
            if (visibility != SymbolVisibility.Private)
            {
                await AddNonSubmissionDependentProjectsAsync(symbol.ContainingAssembly, solution, sourceProject, dependentProjects, cancellationToken).ConfigureAwait(false);
            }

            // submission projects are special here. The fields generated inside the Script object
            // is private, but further submissions can bind to them.
            await AddSubmissionDependentProjectsAsync(solution, sourceProject, dependentProjects, cancellationToken).ConfigureAwait(false);

            return dependentProjects;
        }
Exemple #10
0
        public static bool Contains(this SymbolVisibilityGroup symbolVisibilityGroup, SymbolVisibility symbolVisibility)
        {
            return(symbolVisibility switch
            {
                SymbolVisibility.Public => (symbolVisibilityGroup & SymbolVisibilityGroup.Public) != 0,

                SymbolVisibility.Internal => (symbolVisibilityGroup & SymbolVisibilityGroup.Internal) != 0,

                SymbolVisibility.Private => (symbolVisibilityGroup & SymbolVisibilityGroup.Private) != 0,

                _ => throw new ArgumentOutOfRangeException(nameof(symbolVisibility), symbolVisibility, null),
            });
        public static bool Contains(this SymbolVisibilityGroup symbolVisibilityGroup, SymbolVisibility symbolVisibility)
        {
            switch (symbolVisibility)
            {
            case SymbolVisibility.Public:
                return((symbolVisibilityGroup & SymbolVisibilityGroup.Public) != 0);

            case SymbolVisibility.Internal:
                return((symbolVisibilityGroup & SymbolVisibilityGroup.Internal) != 0);

            case SymbolVisibility.Private:
                return((symbolVisibilityGroup & SymbolVisibilityGroup.Private) != 0);

            default:
                throw new ArgumentOutOfRangeException(nameof(symbolVisibility), symbolVisibility, null);
            }
        }
Exemple #12
0
        public static bool IsExternallyVisible(ISymbol symbol)
        {
            SymbolVisibility visibility = symbol.GetResultantVisibility();

            return(visibility == SymbolVisibility.Public || visibility == SymbolVisibility.Internal);
        }
Exemple #13
0
        /// <summary>
        /// Generate the intermediate <see cref="AtomSymbol"/> instances.
        /// </summary>
        /// <param name="container">structure representation</param>
        /// <param name="symbolRemap">use alternate symbols (used for Sgroup shortcuts)</param>
        /// <param name="visibility">defines whether an atom symbol is displayed</param>
        /// <param name="parameters">render model parameters</param>
        /// <returns>generated atom symbols (can contain <see langword="null"/>)</returns>
        private AtomSymbol[] GenerateAtomSymbols(IAtomContainer container,
                                                 Dictionary <IAtom, string> symbolRemap,
                                                 SymbolVisibility visibility,
                                                 RendererModel parameters,
                                                 ElementGroup annotations,
                                                 Color foreground,
                                                 double stroke,
                                                 StandardDonutGenerator donutGen)
        {
            var scale      = parameters.GetScale();
            var annDist    = parameters.GetAnnotationDistance() * (parameters.GetBondLength() / scale);
            var annScale   = (1 / scale) * parameters.GetAnnotationFontScale();
            var annColor   = parameters.GetAnnotationColor();
            var halfStroke = stroke / 2;

            var symbols = new AtomSymbol[container.Atoms.Count];
            var builder = container.Builder;

            // check if we should annotate attachment point numbers (maxAttach>1)
            // and queue them all up for processing
            var attachPoints = new List <IPseudoAtom>();
            int maxAttach    = 0;

            for (int i = 0; i < container.Atoms.Count; i++)
            {
                var atom = container.Atoms[i];

                if (IsHiddenFully(atom))
                {
                    continue;
                }

                if (atom is IPseudoAtom)
                {
                    var attachNum = ((IPseudoAtom)atom).AttachPointNum;
                    if (attachNum > 0)
                    {
                        attachPoints.Add((IPseudoAtom)atom);
                    }
                    if (attachNum > maxAttach)
                    {
                        maxAttach = attachNum;
                    }
                }

                var remapped     = symbolRemap.ContainsKey(atom);
                var bonds        = container.GetConnectedBonds(atom);
                var neighbors    = container.GetConnectedAtoms(atom);
                var visNeighbors = new List <IAtom>();

                // if a symbol is remapped we only want to consider
                // visible neighbors in the alignment calculation, otherwise
                // we include all neighbors
                foreach (var neighbor in neighbors)
                {
                    if (!remapped || !IsHidden(neighbor))
                    {
                        visNeighbors.Add(neighbor);
                    }
                }

                var auxVectors = new List <Vector2>(1);

                // only generate if the symbol is visible
                if (visibility.Visible(atom, bonds, parameters) || remapped)
                {
                    var hPosition = HydrogenPositionTools.Position(atom, visNeighbors);

                    if (atom.ImplicitHydrogenCount != null && atom.ImplicitHydrogenCount > 0)
                    {
                        auxVectors.Add(hPosition.Vector());
                    }

                    if (remapped)
                    {
                        symbols[i] = atomGenerator.GenerateAbbreviatedSymbol(symbolRemap[atom], hPosition);
                    }
                    else if (donutGen.IsChargeDelocalised(atom))
                    {
                        var charge = atom.FormalCharge;
                        atom.FormalCharge = 0;
                        // can't think of a better way to handle this without API
                        // change to symbol visibility
                        if (atom.AtomicNumber != 6)
                        {
                            symbols[i] = atomGenerator.GenerateSymbol(container, atom, hPosition, parameters);
                        }
                        atom.FormalCharge = charge;
                    }
                    else
                    {
                        symbols[i] = atomGenerator.GenerateSymbol(container, atom, hPosition, parameters);
                    }

                    if (symbols[i] != null)
                    {
                        // defines how the element is aligned on the atom point, when
                        // aligned to the left, the first character 'e.g. Cl' is used.
                        if (visNeighbors.Count < 4)
                        {
                            if (hPosition == HydrogenPosition.Left)
                            {
                                symbols[i] = symbols[i].AlignTo(AtomSymbol.SymbolAlignment.Right);
                            }
                            else
                            {
                                symbols[i] = symbols[i].AlignTo(AtomSymbol.SymbolAlignment.Left);
                            }
                        }

                        var p = atom.Point2D;

                        if (p == null)
                        {
                            throw new ArgumentException("Atom did not have 2D coordinates");
                        }

                        symbols[i] = symbols[i].Resize(1 / scale, 1 / -scale).Center(p.Value.X, p.Value.Y);
                    }
                }

                var label = GetAnnotationLabel(atom);

                if (label != null)
                {
                    // to ensure consistent draw distance we need to adjust the annotation distance
                    // depending on whether we are drawing next to an atom symbol or not.
                    double strokeAdjust = symbols[i] != null ? -halfStroke : 0;

                    var vector     = NewAtomAnnotationVector(atom, bonds, auxVectors);
                    var annOutline = GenerateAnnotation(atom.Point2D.Value, label, vector, annDist + strokeAdjust, annScale, font, emSize, symbols[i]);

                    // the AtomSymbol may migrate during bond generation and therefore the annotation
                    // needs to be tied to the symbol. If no symbol is available the annotation is
                    // fixed and we can add it to the annotation ElementGroup right away.
                    if (symbols[i] != null)
                    {
                        symbols[i] = symbols[i].AddAnnotation(annOutline);
                    }
                    else
                    {
                        annotations.Add(GeneralPath.ShapeOf(annOutline.GetOutline(), annColor));
                    }
                }
            }

            // label attachment points
            if (maxAttach > 1)
            {
                var    attachNumOutlines = new List <TextOutline>();
                double maxRadius         = 0;

                foreach (IPseudoAtom atom in attachPoints)
                {
                    int attachNum = atom.AttachPointNum;

                    // to ensure consistent draw distance we need to adjust the annotation distance
                    // depending on whether we are drawing next to an atom symbol or not.
                    var strokeAdjust = -halfStroke;

                    var vector = NewAttachPointAnnotationVector(
                        atom,
                        container.GetConnectedBonds(atom),
                        new List <Vector2>());

                    var outline = GenerateAnnotation(atom.Point2D.Value,
                                                     attachNum.ToString(),
                                                     vector,
                                                     1.75 * annDist + strokeAdjust,
                                                     annScale,
                                                     new Typeface(font.FontFamily, font.Style, WPF.FontWeights.Bold, font.Stretch),
                                                     emSize,
                                                     null);

                    attachNumOutlines.Add(outline);

                    var w = outline.GetBounds().Width;
                    var h = outline.GetBounds().Height;
                    var r = Math.Sqrt(w * w + h * h) / 2;
                    if (r > maxRadius)
                    {
                        maxRadius = r;
                    }
                }

                foreach (var outline in attachNumOutlines)
                {
                    var group  = new ElementGroup();
                    var radius = 2 * stroke + maxRadius;
                    var shape  = new EllipseGeometry(outline.GetCenter(), radius, radius);
                    var area1  = Geometry.Combine(shape, outline.GetOutline(), GeometryCombineMode.Exclude, Transform.Identity);
                    group.Add(GeneralPath.ShapeOf(area1, foreground));
                    annotations.Add(group);
                }
            }

            return(symbols);
        }
Exemple #14
0
 /// <summary>
 /// Display the atom symbol if is selected, otherwise use the provided visibility.
 /// </summary>
 /// <param name="visibility">visibility when not selected</param>
 /// <returns>visibility instance</returns>
 public static SymbolVisibility GetAll(SymbolVisibility visibility)
 {
     return(new SelectionVisibility(visibility, true));
 }
Exemple #15
0
 /// <summary>
 /// Display the atom symbol if is disconnected from any other selected atoms or bonds. The
 /// provided visibility is used when the atom is not selected.
 /// </summary>
 /// <param name="visibility">visibility when not selected</param>
 /// <returns>visibility instance</returns>
 public static SymbolVisibility Disconnected(SymbolVisibility visibility)
 {
     return(new SelectionVisibility(visibility, false));
 }
Exemple #16
0
 /// <summary>
 /// Internal constructor.
 /// </summary>
 /// <param name="delegate">default viability</param>
 /// <param name="showAll">all select atoms are displayed</param>
 private SelectionVisibility(SymbolVisibility @delegate, bool showAll)
 {
     this.delegate_ = @delegate;
     this.showAll   = showAll;
 }