示例#1
0
 public static SymbolModifiers GetRequiredModifiersOption(
     this AnalyzerOptions options,
     DiagnosticDescriptor rule,
     ISymbol symbol,
     Compilation compilation,
     SymbolModifiers defaultValue,
     CancellationToken cancellationToken)
 => options.GetRequiredModifiersOption(rule, symbol.Locations[0].SourceTree, compilation, defaultValue, cancellationToken);
 public static SymbolModifiers GetRequiredModifiersOption(
     this AnalyzerOptions options,
     DiagnosticDescriptor rule,
     SyntaxTree tree,
     Compilation compilation,
     SymbolModifiers defaultValue,
     CancellationToken cancellationToken)
 => options.GetFlagsEnumOptionValue(EditorConfigOptionNames.RequiredModifiers, rule, tree, compilation, defaultValue, cancellationToken);
示例#3
0
        public DebugMethod(DebugEnvironment envr, CDebugMethodSymbol method, DebugMethodScope scope)
        {
            this.debugEnv      = envr;
            this.methodSymbol  = method;
            this.DeclaringType = method.GetDeclaringType().CompilerType;
            SymbolModifiers modifier = this.methodSymbol.Modifiers;

            if ((modifier & SymbolModifiers.Abstract) != 0)
            {
                this.Flags |= MethodFlags.Abstract;
            }
            if ((modifier & SymbolModifiers.Final) != 0)
            {
                this.Flags |= MethodFlags.Final;
            }
            if ((modifier & SymbolModifiers.Private) != 0)
            {
                this.Flags |= MethodFlags.Private;
            }
            if ((modifier & SymbolModifiers.Public) != 0)
            {
                this.Flags |= MethodFlags.Public;
            }
            if ((modifier & SymbolModifiers.Static) != 0)
            {
                this.Flags |= MethodFlags.Static;
            }

            this.Scope = scope;
            if (this.methodSymbol != null)
            {
                IDebugFieldSymbol thisSymbol = this.methodSymbol.GetThis();
                if (thisSymbol != null)
                {
                    this.ThisParameter = new This(new DebugClassNode(this.debugEnv, thisSymbol.Type, thisSymbol.GetValue(null)));
                }
                ParameterList pList = new ParameterList();
                IEnumSymbol   param = methodSymbol.GetParameters();
                if (param != null)
                {
                    for (int i = 1; ; i++)
                    {
                        if (param.Current == null)
                        {
                            break;
                        }
                        ParameterField paramField = new DebugParameterField(this.debugEnv, param.Current, new Identifier(param.Current.Name), null, scope);
                        paramField.DeclaringType = scope;
                        pList[i] = new Parameter(paramField.Name, paramField.Type);
                        pList[i].ArgumentListIndex = i;
                        param.MoveNext();
                    }
                }
                this.Parameters = pList;
            }
        }
 public static SymbolModifiers GetRequiredModifiersOption(
     this AnalyzerOptions options,
     DiagnosticDescriptor rule,
     ISymbol symbol,
     Compilation compilation,
     SymbolModifiers defaultValue,
     CancellationToken cancellationToken)
 => TryGetSyntaxTreeForOption(symbol, out var tree)
     ? options.GetRequiredModifiersOption(rule, tree, compilation, defaultValue, cancellationToken)
     : defaultValue;
        /// <summary>
        /// Returns true if the given symbol has required symbol modifiers based on options:
        ///   1. If user has explicitly configured candidate <see cref="SymbolModifiers"/> in editor config options and
        ///      given symbol has all the required modifiers.
        ///   2. Otherwise, if user has not configured modifiers.
        /// </summary>
        public static bool MatchesConfiguredModifiers(
            this ISymbol symbol,
            AnalyzerOptions options,
            DiagnosticDescriptor rule,
            CancellationToken cancellationToken,
            SymbolModifiers defaultRequiredModifiers = SymbolModifiers.None)
        {
            var requiredModifiers = options.GetRequiredModifiersOption(rule, defaultRequiredModifiers, cancellationToken);

            return(symbol.GetSymbolModifiers().Contains(requiredModifiers));
        }
示例#6
0
 public static IEventSymbol OverrideEvent(
     this ISyntaxFactoryService codeFactory,
     IEventSymbol overriddenEvent,
     SymbolModifiers modifiers,
     INamedTypeSymbol newContainingType)
 {
     return(CodeGenerationSymbolFactory.CreateEventSymbol(
                overriddenEvent,
                attributes: null,
                accessibility: overriddenEvent.ComputeResultantAccessibility(newContainingType),
                modifiers: modifiers,
                explicitInterfaceSymbol: null,
                name: overriddenEvent.Name));
 }
示例#7
0
        public override MemberList GetMembersNamed(Identifier name)
        {
            MemberList      returnList = new MemberList();
            CDebugClassType classType  = this.GetDebugType as CDebugClassType;

            if (classType != null)
            {
                IEnumSymbol members = classType.GetMembers(name.Name, true, SymbolKind.Field | SymbolKind.Property, SymbolModifiers.All);
                if (members != null)
                {
                    while (members.Current != null)
                    {
                        if (members.Current.Name == name.Name)
                        {
                            Field           fieldMember = new DebugFieldNode(this.debugEnv, members.Current, name, this.Value, this, 0);
                            SymbolModifiers modifier    = members.Current.Modifiers;
                            if ((modifier & SymbolModifiers.Abstract) != 0)
                            {
                                fieldMember.Flags |= FieldFlags.None;
                            }
                            if ((modifier & SymbolModifiers.Final) != 0)
                            {
                                fieldMember.Flags |= FieldFlags.None;
                            }
                            if ((modifier & SymbolModifiers.Private) != 0)
                            {
                                fieldMember.Flags |= FieldFlags.Private;
                            }
                            if ((modifier & SymbolModifiers.Public) != 0)
                            {
                                fieldMember.Flags |= FieldFlags.Public;
                            }
                            if ((modifier & SymbolModifiers.Static) != 0)
                            {
                                fieldMember.Flags |= FieldFlags.Static;
                            }
                            returnList.Add(fieldMember);
                            break;
                        }
                        members.MoveNext();
                    }
                }
            }

            return(returnList);
        }
示例#8
0
        public static IMethodSymbol OverrideMethod(
            this ISyntaxFactoryService codeFactory,
            IMethodSymbol overriddenMethod,
            SymbolModifiers modifiers,
            INamedTypeSymbol newContainingType,
            Document newDocument,
            CancellationToken cancellationToken)
        {
            // Abstract: Throw not implemented
            if (overriddenMethod.IsAbstract)
            {
                return(CodeGenerationSymbolFactory.CreateMethodSymbol(
                           overriddenMethod,
                           accessibility: overriddenMethod.ComputeResultantAccessibility(newContainingType),
                           modifiers: modifiers,
                           statements: new[] { codeFactory.CreateThrowNotImplementStatement(newDocument.Project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken)) }));
            }
            else
            {
                // Otherwise, call the base method with the same parameters
                var typeParams = overriddenMethod.GetTypeArguments();
                var body       = codeFactory.CreateInvocationExpression(
                    codeFactory.CreateMemberAccessExpression(codeFactory.CreateBaseExpression(),
                                                             typeParams.IsDefaultOrEmpty
                        ? codeFactory.CreateIdentifierName(overriddenMethod.Name)
                        : codeFactory.CreateGenericName(overriddenMethod.Name, typeParams)),
                    codeFactory.CreateArguments(overriddenMethod.GetParameters()));

                return(CodeGenerationSymbolFactory.CreateMethodSymbol(
                           method: overriddenMethod,
                           accessibility: overriddenMethod.ComputeResultantAccessibility(newContainingType),
                           modifiers: modifiers,
                           statements: ((IMethodSymbol)overriddenMethod).ReturnsVoid
                        ? new SyntaxNode[] { codeFactory.CreateExpressionStatement(body) }
                        : new SyntaxNode[] { codeFactory.CreateReturnStatement(body) }));
            }
        }
 public static bool Contains(this SymbolModifiers modifiers, SymbolModifiers modifiersToCheck)
 => (modifiers & modifiersToCheck) == modifiersToCheck;
示例#10
0
        public static IPropertySymbol OverrideProperty(
            this ISyntaxFactoryService codeFactory,
            IPropertySymbol overriddenProperty,
            SymbolModifiers modifiers,
            INamedTypeSymbol containingType,
            Document document,
            CancellationToken cancellationToken)
        {
            var getAccessibility = overriddenProperty.GetMethod.ComputeResultantAccessibility(containingType);
            var setAccessibility = overriddenProperty.SetMethod.ComputeResultantAccessibility(containingType);

            SyntaxNode getBody = null;
            SyntaxNode setBody = null;

            // Implement an abstract property by throwing not implemented in accessors.
            if (overriddenProperty.IsAbstract)
            {
                getBody = codeFactory.CreateThrowNotImplementStatement(document.Project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken));
                setBody = getBody;
            }
            else if (overriddenProperty.IsIndexer() && document.Project.Language == LanguageNames.CSharp)
            {
                // Indexer: return or set base[]. Only in C#, since VB must refer to these by name.
                getBody = codeFactory.CreateReturnStatement(
                    codeFactory.CreateElementAccessExpression(
                        codeFactory.CreateBaseExpression(),
                        codeFactory.CreateArguments(overriddenProperty.Parameters)));

                setBody = codeFactory.CreateExpressionStatement(
                    codeFactory.CreateAssignExpression(
                        codeFactory.CreateElementAccessExpression(
                            codeFactory.CreateBaseExpression(),
                            codeFactory.CreateArguments(overriddenProperty.Parameters)),
                        codeFactory.CreateIdentifierName("value")));
            }
            else if (overriddenProperty.GetParameters().Any())
            {
                // Call accessors directly if C# overriding VB
                if (document.Project.Language == LanguageNames.CSharp &&
                    SymbolFinder.FindSourceDefinitionAsync(overriddenProperty, document.Project.Solution)
                    .WaitAndGetResult(CancellationToken.None).Language == LanguageNames.VisualBasic)
                {
                    var getName = overriddenProperty.GetMethod != null ? overriddenProperty.GetMethod.Name : null;
                    var setName = overriddenProperty.SetMethod != null ? overriddenProperty.SetMethod.Name : null;

                    getBody = getName == null
                        ? null
                        : codeFactory.CreateReturnStatement(
                        codeFactory.CreateInvocationExpression(
                            codeFactory.CreateMemberAccessExpression(
                                codeFactory.CreateBaseExpression(),
                                codeFactory.CreateIdentifierName(getName)),
                            codeFactory.CreateArguments(overriddenProperty.Parameters)));

                    setBody = setName == null
                        ? null
                        : codeFactory.CreateExpressionStatement(
                        codeFactory.CreateInvocationExpression(
                            codeFactory.CreateMemberAccessExpression(
                                codeFactory.CreateBaseExpression(),
                                codeFactory.CreateIdentifierName(setName)),
                            codeFactory.CreateArguments(overriddenProperty.SetMethod.GetParameters())));
                }
                else
                {
                    getBody = codeFactory.CreateReturnStatement(
                        codeFactory.CreateInvocationExpression(
                            codeFactory.CreateMemberAccessExpression(
                                codeFactory.CreateBaseExpression(),
                                codeFactory.CreateIdentifierName(overriddenProperty.Name)), codeFactory.CreateArguments(overriddenProperty.Parameters)));
                    setBody = codeFactory.CreateExpressionStatement(
                        codeFactory.CreateAssignExpression(
                            codeFactory.CreateInvocationExpression(
                                codeFactory.CreateMemberAccessExpression(
                                    codeFactory.CreateBaseExpression(),
                                    codeFactory.CreateIdentifierName(overriddenProperty.Name)), codeFactory.CreateArguments(overriddenProperty.Parameters)),
                            codeFactory.CreateIdentifierName("value")));
                }
            }
            else
            {
                // Regular property: return or set the base property
                getBody = codeFactory.CreateReturnStatement(
                    codeFactory.CreateMemberAccessExpression(
                        codeFactory.CreateBaseExpression(),
                        codeFactory.CreateIdentifierName(overriddenProperty.Name)));
                setBody = codeFactory.CreateExpressionStatement(
                    codeFactory.CreateAssignExpression(
                        codeFactory.CreateMemberAccessExpression(
                            codeFactory.CreateBaseExpression(),
                            codeFactory.CreateIdentifierName(overriddenProperty.Name)),
                        codeFactory.CreateIdentifierName("value")));
            }

            // Only generate a getter if the base getter is accessible.
            IMethodSymbol accessorGet = null;

            if (overriddenProperty.GetMethod != null && overriddenProperty.GetMethod.IsAccessibleWithin(containingType))
            {
                accessorGet = CodeGenerationSymbolFactory.CreateMethodSymbol(
                    overriddenProperty.GetMethod,
                    accessibility: getAccessibility,
                    statements: new[] { getBody },
                    modifiers: modifiers);
            }

            // Only generate a setter if the base setter is accessible.
            IMethodSymbol accessorSet = null;

            if (overriddenProperty.SetMethod != null &&
                overriddenProperty.SetMethod.IsAccessibleWithin(containingType) &&
                overriddenProperty.SetMethod.DeclaredAccessibility != Accessibility.Private)
            {
                accessorSet = CodeGenerationSymbolFactory.CreateMethodSymbol(
                    overriddenProperty.SetMethod,
                    accessibility: setAccessibility,
                    statements: new[] { setBody },
                    modifiers: modifiers);
            }

            return(CodeGenerationSymbolFactory.CreatePropertySymbol(
                       overriddenProperty,
                       accessibility: overriddenProperty.ComputeResultantAccessibility(containingType),
                       modifiers: modifiers,
                       name: overriddenProperty.Name,
                       isIndexer: overriddenProperty.IsIndexer(),
                       getMethod: accessorGet,
                       setMethod: accessorSet));
        }
示例#11
0
 public  IEnumSymbol GetMembers(string name, bool caseSensitive, SymbolKind kindFilter, SymbolModifiers modifierFilter) {
   IEnumSymbol pRetVal = null;
   uint fieldKindFiter = SymbolHelper.SymbolKindToFieldKind(kindFilter);
   uint fieldModFilter = SymbolHelper.SymbolModifiersToFieldModifiers((uint) modifierFilter);
   IEnumDebugFields enumFields = null;
   this.m_ContainerField.EnumFields((FIELD_KIND ) fieldKindFiter, (FIELD_MODIFIERS) fieldModFilter, name,
     caseSensitive == true ? NAME_MATCH.nmCaseSensitive : NAME_MATCH.nmCaseInsensitive, out enumFields);
   if (null != enumFields){
     pRetVal = new CEnumSymbols(enumFields, this.m_Context);
   }
   return pRetVal;
 }
示例#12
0
        public DebugFieldNode(DebugEnvironment envr, IDebugSymbol symbol, Identifier name, IDebugValue container, TypeNode declaringType, int id)
        {
            this.debugEnv      = envr;
            this.Symbol        = symbol;
            this.Container     = container;
            this.Name          = name;
            this.index         = id;
            this.DeclaringType = declaringType;
            switch (symbol.Type.Kind)
            {
            case TypeKind.Class:
                this.Type = new DebugClassNode(this.debugEnv, this.Symbol.Type, ((IDebugFieldSymbol )symbol).GetValue(Container));
                break;

            case TypeKind.Stream:
                this.Type = symbol.Type.CompilerType;
                break;

            case TypeKind.Tuple:
                StructTypes sType = ((IDebugStructuralType)this.Symbol.Type).StructuralType;
                switch (sType)
                {
                case StructTypes.Tuple:
                    FieldList   list    = new FieldList();
                    IEnumSymbol symbols = ((IDebugStructuralType)this.Symbol.Type).GetMembers(null, true, SymbolKind.Field, SymbolModifiers.All);
                    if (symbols != null)
                    {
                        while (symbols.Current != null)
                        {
                            Field           fieldMember = new DebugFieldNode(this.debugEnv, symbols.Current, new Identifier(symbols.Current.Name), ((IDebugFieldSymbol )symbol).GetValue(Container), null, 0);
                            SymbolModifiers modifier    = symbols.Current.Modifiers;
                            if ((modifier & SymbolModifiers.Abstract) != 0)
                            {
                                fieldMember.Flags |= FieldFlags.None;
                            }
                            if ((modifier & SymbolModifiers.Final) != 0)
                            {
                                fieldMember.Flags |= FieldFlags.None;
                            }
                            if ((modifier & SymbolModifiers.Private) != 0)
                            {
                                fieldMember.Flags |= FieldFlags.Private;
                            }
                            if ((modifier & SymbolModifiers.Public) != 0)
                            {
                                fieldMember.Flags |= FieldFlags.Public;
                            }
                            if ((modifier & SymbolModifiers.Static) != 0)
                            {
                                fieldMember.Flags |= FieldFlags.Static;
                            }
                            list.Add(fieldMember);
                            symbols.MoveNext();
                        }
                    }
                    Class dummy = new Class();
                    dummy.DeclaringModule = new Module();
                    this.Type             = TupleType.For(list, dummy);
                    break;

                case StructTypes.Union:
                    // HACK: Need a better way for identifying return types
                    this.Type = TypeUnion.For(SymbolHelper.GetTypeList(this.Symbol.Type.FullName, this.debugEnv.context), new Module());
                    break;

                case StructTypes.Intersection:
                    // TODO: Need to figure out Intersection Types, I think depends on figuring out return Type
                    //this.Type = TypeIntersection.For(typeList, new Module());
                    this.Type = new Class();
                    break;
                }

                /*FieldList list = new FieldList();
                 * IEnumSymbol symbols = ((IDebugStructuralType) this.Symbol.Type).GetMembers(null, true, SymbolKind.Field, SymbolModifiers.All);
                 * if (symbols != null){
                 * while(symbols.Current != null){
                 *  list.Add(new DebugFieldNode(this.debugEnv, symbols.Current, new Identifier(symbols.Current.Name), null, null, 0));
                 *  symbols.MoveNext();
                 * }
                 * }
                 * Class dummy = new Class();
                 * dummy.DeclaringModule = new Module();
                 * this.Type = TupleType.For(list, dummy);*/
                break;

            case TypeKind.Primitive:
                switch (this.Symbol.Type.TypeCode)
                {
                case TypeCode.Boolean:
                    this.Type = SystemTypes.Boolean;
                    break;

                case TypeCode.Char:
                    this.Type = SystemTypes.Char;
                    break;

                case TypeCode.Int16:
                    this.Type = SystemTypes.Int16;
                    break;

                case TypeCode.UInt16:
                    this.Type = SystemTypes.UInt32;
                    break;

                case TypeCode.Int32:
                    this.Type = SystemTypes.Int32;
                    break;

                case TypeCode.UInt32:
                    this.Type = SystemTypes.UInt32;
                    break;

                case TypeCode.Int64:
                    this.Type = SystemTypes.Int64;
                    break;

                case TypeCode.UInt64:
                    this.Type = SystemTypes.UInt64;
                    break;

                case TypeCode.Double:
                    this.Type = SystemTypes.Double;
                    break;

                case TypeCode.Single:
                    this.Type = SystemTypes.Single;
                    break;

                case TypeCode.SByte:
                    this.Type = SystemTypes.Int8;
                    break;

                case TypeCode.Byte:
                    this.Type = SystemTypes.UInt8;
                    break;

                case TypeCode.String:
                    this.Type = SystemTypes.String;
                    break;
                }
                break;

            case TypeKind.Enum:
                this.Type = new DebugEnumNode(this.debugEnv, this.Symbol.Type);
                break;
            }
        }