Пример #1
0
        public static PXCodeType?GetCodeTypeFromGenericName(this ITypeSymbol genericName)
        {
            if (!genericName.IsValidForColoring())
            {
                return(null);
            }

            if (genericName.IsStatic)
            {
                if (TypeNames.PXUpdateBqlTypes.Contains(genericName.Name))
                {
                    return(PXCodeType.BqlCommand);
                }
                else if (genericName.IsFBQLJoin())
                {
                    return(PXCodeType.BqlOperator);
                }
            }

            IEnumerable <ITypeSymbol> typeHierarchy = genericName.GetBaseTypes()
                                                      .ConcatStructList(genericName.AllInterfaces);
            PXCodeType?resolvedColoredCodeType = null;

            foreach (ITypeSymbol typeOrInterface in typeHierarchy)
            {
                if (TypeNames.TypeNamesToCodeTypesForGenericName.TryGetValue(typeOrInterface.Name, out PXCodeType coloredCodeType))
                {
                    resolvedColoredCodeType = coloredCodeType;
                    break;
                }
            }

            return(resolvedColoredCodeType);
        }
Пример #2
0
        public static PXCodeType?GetColoringTypeFromIdentifier(this ITypeSymbol identifierType, bool skipValidation = false,
                                                               bool checkItself = false)
        {
            if (!skipValidation && !identifierType.IsValidForColoring())
            {
                return(null);
            }

            IEnumerable <ITypeSymbol> typeHierarchy = checkItself
                                ? identifierType.GetBaseTypesAndThis()
                                : identifierType.GetBaseTypes();

            typeHierarchy = typeHierarchy.ConcatStructList(identifierType.AllInterfaces);
            PXCodeType?resolvedColoredCodeType = null;

            foreach (ITypeSymbol typeOrInterface in typeHierarchy)
            {
                if (TypeNames.TypeNamesToCodeTypesForIdentifier.TryGetValue(typeOrInterface.Name, out PXCodeType coloredCodeType))
                {
                    resolvedColoredCodeType = coloredCodeType;
                    break;
                }
            }

            return(resolvedColoredCodeType);
        }
Пример #3
0
            public async override void VisitGenericName(GenericNameSyntax genericNode)
            {
                if (_cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                SemanticModel semanticModel = await _document.SemanticModelAsync(_cancellationToken);

                ITypeSymbol typeSymbol = semanticModel.GetSymbolInfo(genericNode).Symbol as ITypeSymbol;

                if (typeSymbol == null)
                {
                    if (!_cancellationToken.IsCancellationRequested)
                    {
                        base.VisitGenericName(genericNode);
                    }

                    return;
                }

                if (_cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                if (genericNode.IsUnboundGenericName)
                {
                    typeSymbol = typeSymbol.OriginalDefinition;
                }

                PXCodeType?         coloredCodeType    = typeSymbol.GetCodeTypeFromGenericName();
                IClassificationType classificationType = coloredCodeType.HasValue
                    ? _tagger.Provider[coloredCodeType.Value]
                    : null;

                if (classificationType == null)
                {
                    if (!_cancellationToken.IsCancellationRequested)
                    {
                        base.VisitGenericName(genericNode);
                    }

                    UpdateCodeEditorIfNecessary();
                    return;
                }

                if (coloredCodeType.Value == PXCodeType.BqlCommand)
                {
                    ColorAndOutlineBqlCommandBeginning(genericNode, classificationType);
                }
                else
                {
                    ColorAndOutlineBqlPartsAndPXActions(genericNode, typeSymbol, classificationType, coloredCodeType.Value);
                }

                UpdateCodeEditorIfNecessary();
            }
Пример #4
0
            /// <summary>
            /// Count parameters in type symbol retrieved for <see cref="Microsoft.CodeAnalysis.CSharp.Syntax.IdentifierNameSyntax"/> syntax node.
            /// Return <c>false</c> if the diagnostic should be stopped
            /// </summary>
            /// <param name="typeSymbol">The type symbol.</param>
            /// <param name="cancellationToken">(Optional) The cancellation token.</param>
            /// <returns/>
            public bool CountParametersInTypeSymbolForIdentifierNode(ITypeSymbol typeSymbol, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (!IsCountingValid || typeSymbol == null)
                {
                    return(false);
                }

                PXCodeType?codeType = typeSymbol.GetCodeTypeFromIdentifier();

                return(CountParametersInTypeSymbolBasedOnCodeType(typeSymbol, codeType, cancellationToken));
            }
            private void ColorIdentifierTypeSymbol(ITypeSymbol typeSymbol, TextSpan span, bool isTypeParameter)
            {
                PXCodeType?coloredCodeType = typeSymbol.GetColoringTypeFromIdentifier(skipValidation: isTypeParameter,
                                                                                      checkItself: isTypeParameter);
                IClassificationType classificationType = coloredCodeType.HasValue
                                        ? _tagger.Provider[coloredCodeType.Value]
                                        : null;

                if (classificationType == null ||
                    (coloredCodeType.Value == PXCodeType.PXGraph && !_tagger.Provider.Package.PXGraphColoringEnabled) ||
                    (coloredCodeType.Value == PXCodeType.PXAction && !_tagger.Provider.Package.PXActionColoringEnabled))
                {
                    return;
                }

                AddClassificationTag(span, classificationType);
            }
Пример #6
0
            /// <summary>
            /// Count parameters in type symbol. Return <c>false</c> if the diagnostic should be stopped
            /// </summary>
            /// <param name="typeSymbol">The type symbol.</param>
            /// <param name="cancellationToken">(Optional) The cancellation token.</param>
            /// <returns/>
            public bool CountParametersInTypeSymbol(ITypeSymbol typeSymbol, CancellationToken cancellationToken = default)
            {
                if (!IsCountingValid || typeSymbol == null || IsCancelled(cancellationToken))
                {
                    return(false);
                }

                PXCodeType?codeType = typeSymbol.GetCodeTypeFromGenericName();

                switch (codeType)
                {
                case PXCodeType.BqlCommand:
                    _currentParameterWeight = DefaultWeight;
                    IsCountingValid         = !typeSymbol.IsCustomBqlCommand(_pxContext);                     //diagnostic for types inherited from standard views disabled. TODO: make analysis for them
                    return(IsCountingValid);

                case PXCodeType.BqlOperator when typeSymbol.InheritsFrom(_pxContext.BQL.CustomPredicate):                          //Custom predicate
                {
                    IsCountingValid = ProcessCustomPredicate(typeSymbol);
                    return(IsCountingValid);
                }

                case PXCodeType.BqlOperator:
                    _currentParameterWeight = DefaultWeight;
                    return(IsCountingValid);

                case PXCodeType.BqlParameter:
                    if (!UpdateParametersCount(typeSymbol) && !cancellationToken.IsCancellationRequested)
                    {
                        UpdateParametersCount(typeSymbol.OriginalDefinition);
                    }

                    return(true);
                }

                return(true);
            }
Пример #7
0
            private bool CountParametersInTypeSymbolBasedOnCodeType(ITypeSymbol typeSymbol, PXCodeType?codeType, CancellationToken cancellationToken)
            {
                switch (codeType)
                {
                case PXCodeType.BqlCommand:
                    _currentParameterWeight = DefaultWeight;
                    IsCountingValid         = !typeSymbol.IsCustomBqlCommand(_pxContext);                     //diagnostic for types inherited from standard views disabled. TODO: make analysis for them
                    return(IsCountingValid);

                case PXCodeType.BqlOperator when typeSymbol.InheritsFrom(_pxContext.BQL.CustomPredicate):                          //Custom predicate
                {
                    IsCountingValid = ProcessCustomPredicate(typeSymbol);
                    return(IsCountingValid);
                }

                case PXCodeType.BqlOperator:
                    _currentParameterWeight = DefaultWeight;
                    return(IsCountingValid);

                case PXCodeType.BqlParameter:

                    if (!cancellationToken.IsCancellationRequested)
                    {
                        UpdateParametersCount(typeSymbol);
                    }

                    return(true);

                default:
                    return(true);
                }
            }