protected override bool TryInitializeState(
			Document document, SemanticModel model, SyntaxNode node, CancellationToken cancellationToken,
			out INamedTypeSymbol classType, out INamedTypeSymbol abstractClassType)
		{
			var baseClassNode = node as TypeSyntax;
			if (baseClassNode != null && baseClassNode.Parent is BaseTypeSyntax &&
				baseClassNode.Parent.IsParentKind(SyntaxKind.BaseList) &&
				((BaseTypeSyntax)baseClassNode.Parent).Type == baseClassNode)
			{
				if (baseClassNode.Parent.Parent.IsParentKind(SyntaxKind.ClassDeclaration))
				{
					abstractClassType = model.GetTypeInfo(baseClassNode, cancellationToken).Type as INamedTypeSymbol;
					cancellationToken.ThrowIfCancellationRequested();

					if (abstractClassType.IsAbstractClass())
					{
						var classDecl = baseClassNode.Parent.Parent.Parent as ClassDeclarationSyntax;
						classType = model.GetDeclaredSymbol(classDecl, cancellationToken) as INamedTypeSymbol;

						return classType != null && abstractClassType != null;
					}
				}
			}

			classType = null;
			abstractClassType = null;
			return false;
		}
示例#2
0
 public DiscoveryWalker(int start, int end, SemanticModel model)
 {
     _model = model;
     _start = start;
     _end = end;
     DefinedOutside = new Dictionary<string, string>();
 }
        /// <summary>
        /// This is jus a test to check the ability to preprocess the AST
        /// </summary>
        /// <param name="methodNode"></param>
        /// <param name="semanticModel"></param>
        /// <returns></returns>
        public static IMethodSymbol SimplifyASTForMethod(ref SyntaxNode methodNode, ref SemanticModel semanticModel)
        {
            var oldMethod = semanticModel.GetDeclaredSymbol(methodNode) as IMethodSymbol;

            var newMethodNode = MethodSimpifier.Test(methodNode);

            var annotation = new SyntaxAnnotation("Hi");

            newMethodNode = newMethodNode.WithAdditionalAnnotations(annotation);

            var root = methodNode.SyntaxTree.GetRoot();
            var newRoot = root.ReplaceNode(methodNode, newMethodNode);

            var oldCompilation = semanticModel.Compilation;

            var newCompilation = oldCompilation.ReplaceSyntaxTree(root.SyntaxTree, newRoot.SyntaxTree);
            var newSemanticModel = newCompilation.GetSemanticModel(newRoot.SyntaxTree);

            var recoveredMethodNode = newRoot.GetAnnotatedNodes(annotation).Single();

            var method = newSemanticModel.GetDeclaredSymbol(recoveredMethodNode) as IMethodSymbol;

            methodNode = recoveredMethodNode;
            semanticModel = newSemanticModel;

            return method;
        }
 public static SyntaxNode CreateUsing(SyntaxNode root, ObjectCreationExpressionSyntax objectCreation, SemanticModel semanticModel)
 {
     SyntaxNode newRoot;
     if (objectCreation.Parent.IsKind(SyntaxKind.SimpleAssignmentExpression))
     {
         var assignmentExpression = (AssignmentExpressionSyntax)objectCreation.Parent;
         var statement = assignmentExpression.Parent as ExpressionStatementSyntax;
         var identitySymbol = (ILocalSymbol)semanticModel.GetSymbolInfo(assignmentExpression.Left).Symbol;
         newRoot = UsedOutsideParentBlock(semanticModel, statement, identitySymbol)
             ? CreateRootAddingDisposeToEndOfMethod(root, statement, identitySymbol)
             : CreateRootWithUsing(root, statement, u => u.WithExpression(assignmentExpression));
     }
     else if (objectCreation.Parent.IsKind(SyntaxKind.EqualsValueClause) && objectCreation.Parent.Parent.IsKind(SyntaxKind.VariableDeclarator))
     {
         var variableDeclarator = (VariableDeclaratorSyntax)objectCreation.Parent.Parent;
         var variableDeclaration = (VariableDeclarationSyntax)variableDeclarator.Parent;
         var statement = (LocalDeclarationStatementSyntax)variableDeclaration.Parent;
         newRoot = CreateRootWithUsing(root, statement, u => u.WithDeclaration(variableDeclaration));
     }
     else
     {
         newRoot = CreateRootWithUsing(root, (ExpressionStatementSyntax)objectCreation.Parent, u => u.WithExpression(objectCreation));
     }
     return newRoot;
 }
 static bool CanBeNull(SemanticModel semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken)
 {
     var info = semanticModel.GetTypeInfo(expression, cancellationToken);
     if (info.ConvertedType.IsReferenceType || info.ConvertedType.IsNullableType())
         return true;
     return false;
 }
示例#6
0
        public static bool Applicable(SemanticModel semanticModel, ArgumentSyntax argument, IEnumerable<ParameterSyntax> parameters)
        {
            var symbolInfo = semanticModel.GetSymbolInfo(argument.Expression);
            var symbol = symbolInfo.Symbol;

            if (symbol == null)
            {
                return true;
            }

            if (symbol.Kind != SymbolKind.Field &&
                symbol.Kind != SymbolKind.Parameter &&
                symbol.Kind != SymbolKind.Local)
            {
                return false;
            }

            var field = symbol as IFieldSymbol;
            if (field != null)
            {
                return !field.IsReadOnly;
            }

            return true;
        }
示例#7
0
        private static ISymbol GetDeclaredSymbol(SemanticModel model, SyntaxNode node, bool getSymbol, CancellationToken cancellationToken)
        {
            if (!getSymbol)
            {
                return null;
            }

            var declaredSymbol = model.GetDeclaredSymbol(node, cancellationToken);

            // For namespace declarations, GetDeclaredSymbol returns a compilation scoped namespace symbol,
            // which includes declarations across the compilation, including those in referenced assemblies.
            // However, we are only interested in the namespace symbol scoped to the compilation's source assembly.
            var namespaceSymbol = declaredSymbol as INamespaceSymbol;
            if (namespaceSymbol != null && namespaceSymbol.ConstituentNamespaces.Length > 1)
            {
                var assemblyToScope = model.Compilation.Assembly;
                var assemblyScopedNamespaceSymbol = namespaceSymbol.ConstituentNamespaces.FirstOrDefault(ns => ns.ContainingAssembly == assemblyToScope);
                if (assemblyScopedNamespaceSymbol != null)
                {
                    Debug.Assert(assemblyScopedNamespaceSymbol.ConstituentNamespaces.Length == 1);
                    declaredSymbol = assemblyScopedNamespaceSymbol;
                }
            }

            return declaredSymbol;
        }
        private bool IsReportable(VariableDeclarationSyntax variableDeclaration, SemanticModel semanticModel)
        {
            bool result;
            TypeSyntax variableTypeName = variableDeclaration.Type;
            if (variableTypeName.IsVar)
            {
                // Implicitly-typed variables cannot have multiple declarators. Short circuit if it does.
                bool hasMultipleVariables = variableDeclaration.Variables.Skip(1).Any();
                if(hasMultipleVariables == false)
                {
                    // Special case: Ensure that 'var' isn't actually an alias to another type. (e.g. using var = System.String).
                    IAliasSymbol aliasInfo = semanticModel.GetAliasInfo(variableTypeName);
                    if (aliasInfo == null)
                    {
                        // Retrieve the type inferred for var.
                        ITypeSymbol type = semanticModel.GetTypeInfo(variableTypeName).ConvertedType;

                        // Special case: Ensure that 'var' isn't actually a type named 'var'.
                        if (type.Name.Equals("var", StringComparison.Ordinal) == false)
                        {
                            // Special case: Ensure that the type is not an anonymous type.
                            if (type.IsAnonymousType == false)
                            {
                                // Special case: Ensure that it's not a 'new' expression.
                                if (variableDeclaration.Variables.First().Initializer.Value.IsKind(SyntaxKind.ObjectCreationExpression))
                                {
                                    result = false;
                                }
                                else
                                {
                                    result = true;
                                }
                            }
                            else
                            {
                                result = false;
                            }
                        }
                        else
                        {
                            result = false;
                        }
                    }
                    else
                    {
                        result = false;
                    }
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            return result;
        }
		public MemberMetricsCalculator(SemanticModel semanticModel, Solution solution, IAsyncFactory<ISymbol, IMemberDocumentation> documentationFactory)
			: base(semanticModel)
		{
			_solution = solution;
			_documentationFactory = documentationFactory;
			_nameResolver = new MemberNameResolver(Model);
		}
        static bool IsDeclarationConstFriendly(LocalDeclarationStatementSyntax declaration, SemanticModel semanticModel)
        {
            // all variables could be const?
            foreach (var variable in declaration.Declaration.Variables)
            {
                if (variable.Initializer == null) return false;
                if (variable.Initializer.Value is InterpolatedStringExpressionSyntax) return false;

                // is constant
                var constantValue = semanticModel.GetConstantValue(variable.Initializer.Value);
                var valueIsConstant = constantValue.HasValue;
                if (!valueIsConstant) return false;

                // if reference type, value is null?
                var variableTypeName = declaration.Declaration.Type;
                var variableType = semanticModel.GetTypeInfo(variableTypeName).ConvertedType;
                if (variableType.IsReferenceType && variableType.SpecialType != SpecialType.System_String && constantValue.Value != null) return false;

                // nullable?
                if (variableType.OriginalDefinition?.SpecialType == SpecialType.System_Nullable_T) return false;

                // value can be converted to variable type?
                var conversion = semanticModel.ClassifyConversion(variable.Initializer.Value, variableType);
                if (!conversion.Exists || conversion.IsUserDefined) return false;
            }
            return true;
        }
        internal static bool HasFlagsAttribute(SyntaxNode node, SemanticModel semanticModel)
        {
            var symbol = semanticModel.GetDeclaredSymbol(node);

            return symbol != null && 
                symbol.GetAttributes().Any(attribute => attribute.AttributeClass.Is(KnownType.System_FlagsAttribute));
        }
 internal SyntaxNode CreateOrdinalMemberAccess(SyntaxGenerator syntaxFactoryService, SemanticModel model)
 {
     var stringComparisonType = WellKnownTypes.StringComparison(model.Compilation);
     return syntaxFactoryService.MemberAccessExpression(
         syntaxFactoryService.TypeExpression(stringComparisonType),
         syntaxFactoryService.IdentifierName(UseOrdinalStringComparisonAnalyzer.OrdinalText));
 }
        public static bool IsImmutable(this ITypeSymbol symbol, SemanticModel semanticModel)
        {
            Contract.Requires(symbol != null);
            Contract.Requires(semanticModel != null);

            return new PureMethodVerifier(semanticModel).IsImmutable(symbol);
        }
示例#14
0
 internal static SemanticMap From(SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken)
 {
     var map = new SemanticMap();
     var walker = new Walker(semanticModel, map, cancellationToken);
     walker.Visit(node);
     return map;
 }
 private static bool HasCheckForNullThatReturns(InvocationExpressionSyntax invocation, SemanticModel semanticModel, ISymbol symbol)
 {
     var method = invocation.FirstAncestorOfKind(SyntaxKind.MethodDeclaration) as MethodDeclarationSyntax;
     if (method != null && method.Body != null)
     {
         var ifs = method.Body.Statements.OfKind(SyntaxKind.IfStatement);
         foreach (IfStatementSyntax @if in ifs)
         {
             if ([email protected]?.IsKind(SyntaxKind.EqualsExpression) ?? true) continue;
             var equals = (BinaryExpressionSyntax)@if.Condition;
             if (equals.Left == null || equals.Right == null) continue;
             if (@if.GetLocation().SourceSpan.Start > invocation.GetLocation().SourceSpan.Start) return false;
             ISymbol identifierSymbol;
             if (equals.Right.IsKind(SyntaxKind.NullLiteralExpression) && equals.Left.IsKind(SyntaxKind.IdentifierName))
                 identifierSymbol = semanticModel.GetSymbolInfo(equals.Left).Symbol;
             else if (equals.Left.IsKind(SyntaxKind.NullLiteralExpression) && equals.Right.IsKind(SyntaxKind.IdentifierName))
                 identifierSymbol = semanticModel.GetSymbolInfo(equals.Right).Symbol;
             else continue;
             if (!symbol.Equals(identifierSymbol)) continue;
             if (@if.Statement == null) continue;
             if (@if.Statement.IsKind(SyntaxKind.Block))
             {
                 var ifBlock = (BlockSyntax)@if.Statement;
                 if (ifBlock.Statements.OfKind(SyntaxKind.ThrowStatement, SyntaxKind.ReturnStatement).Any()) return true;
             }
             else
             {
                 if (@if.Statement.IsAnyKind(SyntaxKind.ThrowStatement, SyntaxKind.ReturnStatement)) return true;
             }
         }
     }
     return false;
 }
        static IEnumerable<ParameterSyntax> ConvertParameters(SemanticModel model, SyntaxNode lambda, IEnumerable<ParameterSyntax> list)
        {
            ITypeSymbol type = null;
            int i = 0;
            foreach (var param in list)
            {
                if (param.Type != null)
                {
                    yield return param;
                }
                else
                {
                    if (type == null)
                    {
                        var typeInfo = model.GetTypeInfo(lambda);
                        type = typeInfo.ConvertedType ?? typeInfo.Type;
                        if (type == null || !type.IsDelegateType())
                            yield break;
                    }

                    yield return SyntaxFactory.Parameter(
                        param.AttributeLists,
                        param.Modifiers,
                        SyntaxFactory.ParseTypeName(type.GetDelegateInvokeMethod().Parameters[i].Type.ToMinimalDisplayString(model, lambda.SpanStart)),
                        param.Identifier,
                        null
                    );
                }
                i++;
            }
        }
 public Property(SemanticModel model, PropertyDeclarationSyntax syntax, AttributeSyntax attribute = null, AttributeSyntax classAttribute = null)
 {
     this.model = model;
     Syntax = syntax;
     propertyAttribute = attribute;
     ClassAttribute = classAttribute;
 }
 public StatMachineGeneratorFixer(Compilation compilation, SyntaxTree syntaxTree, SemanticModel semanticModel, string enclosingTypeName)
 {
     this.compilation = compilation;
     this.syntaxTree = syntaxTree;
     this.semanticModel = semanticModel;
     this.enclosingTypeName = enclosingTypeName;
 }
        private List<KeyValuePair<BinaryExpressionSyntax, BinaryExpressionSyntax>> FindReoccuringOperations(
            IEnumerable<BinaryExpressionSyntax> operations, SemanticModel semanticModel)
        {

            var originalList = operations.ToList();
            var copiedList = originalList.ToList();
            var duplicates = new List<KeyValuePair<BinaryExpressionSyntax, BinaryExpressionSyntax>>();
            var alreadyFound = new HashSet<BinaryExpressionSyntax>();

            foreach (var oItem in originalList)
            {
                foreach (var cItem in copiedList)
                {
                    if (alreadyFound.Contains(oItem) && alreadyFound.Contains(cItem)) continue;

                    if (IsEqualButNotTheSame(oItem, cItem, semanticModel))
                    {
                        alreadyFound.Add(oItem);
                        alreadyFound.Add(cItem);
                        duplicates.Add(new KeyValuePair<BinaryExpressionSyntax, BinaryExpressionSyntax>(oItem, cItem));
                        break;
                    }
                }
            }
            return duplicates;
        }
 protected static bool IsAcceptableOverload(IMethodSymbol methodSymbol, SemanticModel model)
 {
     var stringComparisonType = WellKnownTypes.StringComparison(model.Compilation);
     return methodSymbol.IsStatic
         ? IsAcceptableStaticOverload(methodSymbol, stringComparisonType)
         : IsAcceptableInstanceOverload(methodSymbol, stringComparisonType);
 }
        private static bool TryGetThreadStaticAttribute(SyntaxList<AttributeListSyntax> attributeLists, SemanticModel semanticModel, out AttributeSyntax threadStaticAttribute)
        {
            threadStaticAttribute = null;

            if (!attributeLists.Any())
            {
                return false;
            }

            foreach (var attributeList in attributeLists)
            {
                foreach (var attribute in attributeList.Attributes)
                {
                    var attributeType = semanticModel.GetTypeInfo(attribute).Type;

                    if (attributeType != null &&
                        attributeType.ToDisplayString() == ThreadStaticAttributeName)
                    {
                        threadStaticAttribute = attribute;
                        return true;
                    }
                }
            }

            return false;
        }
示例#22
0
 public Walker(SemanticModel semanticModel, SemanticMap map, CancellationToken cancellationToken) :
 base(SyntaxWalkerDepth.Token)
 {
     _semanticModel = semanticModel;
     _map = map;
     _cancellationToken = cancellationToken;
 }
        public static bool IsPure(this InvocationExpressionSyntax methodInvocation, SemanticModel semanticModel)
        {
            Contract.Requires(methodInvocation != null);
            Contract.Requires(semanticModel != null);

            return new PureMethodVerifier(semanticModel).IsPure(methodInvocation);
        }
		protected override Task<EvaluationResult> EvaluateImpl(SyntaxNode node, SemanticModel semanticModel, Solution solution)
		{
			//// TODO: For this to be correct, we need flow analysis to determine if a given method
			//// is actually invoked inside the current constructor. A method may be assigned to a
			//// delegate which can be called inside or outside the constructor. A method may also
			//// be called from within a lambda which is called inside or outside the constructor.
			//// Currently, FxCop does not produce a warning if a virtual method is called indirectly
			//// through a delegate or through a lambda.

			var constructor = (ConstructorDeclarationSyntax)node;
			var constructorSymbol = semanticModel.GetDeclaredSymbol(constructor);
			var containingType = constructorSymbol.ContainingType;

			if (
				constructor.Body.DescendantNodes()
				.Where(x => x.Kind() == SyntaxKind.InvocationExpression)
					.Any(x => CallVirtualMethod((InvocationExpressionSyntax)x, semanticModel, containingType)))
			{
				var result = new EvaluationResult
								 {
									 Snippet = node.ToFullString(),
									 LinesOfCodeAffected = GetLinesOfCode(node)
								 };
				return Task.FromResult(result);
			}

			return Task.FromResult<EvaluationResult>(null);
		}
        private static SyntaxNode ComputeReplacement(SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken)
        {
            var memberAccess = node.Parent as MemberAccessExpressionSyntax;
            if (memberAccess != null)
            {
                if (node == memberAccess.Name)
                {
                    node = memberAccess;
                }
            }

            var type = semanticModel.GetSymbolInfo(node, cancellationToken).Symbol as INamedTypeSymbol;

            PredefinedTypeSyntax typeSyntax;
            if (!PredefinedSpecialTypes.TryGetValue(type.SpecialType, out typeSyntax))
            {
                return node;
            }

            SyntaxNode newNode;
            if (node is CrefSyntax)
            {
                newNode = SyntaxFactory.TypeCref(typeSyntax);
            }
            else
            {
                newNode = typeSyntax;
            }

            return newNode.WithTriviaFrom(node).WithoutFormatting();
        }
示例#26
0
        public static async Task<ISymbol> FindApplicableAlias(this ITypeSymbol type, int position, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            try
            {
                if (semanticModel.IsSpeculativeSemanticModel)
                {
                    position = semanticModel.OriginalPositionForSpeculation;
                    semanticModel = semanticModel.ParentModel;
                }

                var root = await semanticModel.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);

                IEnumerable<UsingDirectiveSyntax> applicableUsings = GetApplicableUsings(position, root as CompilationUnitSyntax);
                foreach (var applicableUsing in applicableUsings)
                {
                    var alias = semanticModel.GetOriginalSemanticModel().GetDeclaredSymbol(applicableUsing, cancellationToken);
                    if (alias != null && alias.Target == type)
                    {
                        return alias;
                    }
                }

                return null;
            }
            catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
		static bool TryDetermineOverridableMembers(SemanticModel semanticModel, SyntaxToken startToken, Accessibility seenAccessibility, out ISet<ISymbol> overridableMembers, CancellationToken cancellationToken)
		{
			var result = new HashSet<ISymbol>();
			var containingType = semanticModel.GetEnclosingSymbol<INamedTypeSymbol>(startToken.SpanStart, cancellationToken);
			if (containingType != null && !containingType.IsScriptClass && !containingType.IsImplicitClass)
			{
				if (containingType.TypeKind == TypeKind.Class || containingType.TypeKind == TypeKind.Struct)
				{
					var baseTypes = containingType.GetBaseTypes().Reverse();
					foreach (var type in baseTypes)
					{
						cancellationToken.ThrowIfCancellationRequested();

						// Prefer overrides in derived classes
						RemoveOverriddenMembers(result, type, cancellationToken);

						// Retain overridable methods
						AddProtocolMembers(semanticModel, result, containingType, type, cancellationToken);
					}
					// Don't suggest already overridden members
					RemoveOverriddenMembers(result, containingType, cancellationToken);
				}
			}

			// Filter based on accessibility
			if (seenAccessibility != Accessibility.NotApplicable)
			{
				result.RemoveWhere(m => m.DeclaredAccessibility != seenAccessibility);
			}

			overridableMembers = result;
			return overridableMembers.Count > 0;
		}
        public static bool IsNullablePrimitiveType(this ITypeSymbol type, SemanticModel semanticModel)
        {
            Contract.Requires(type != null);
            Contract.Requires(semanticModel != null);

            return type.UnwrapFromNullableType(semanticModel)?.IsPrimitiveType() == true;
        }
            private void AnalyzeInvocationExpression(InvocationExpressionSyntax node, SemanticModel model, Action<Diagnostic> reportDiagnostic)
            {
                if (node.Expression.Kind() == SyntaxKind.SimpleMemberAccessExpression)
                {
                    var memberAccess = (MemberAccessExpressionSyntax)node.Expression;
                    if (memberAccess.Name != null && IsEqualsOrCompare(memberAccess.Name.Identifier.ValueText))
                    {
                        var methodSymbol = model.GetSymbolInfo(memberAccess.Name).Symbol as IMethodSymbol;
                        if (methodSymbol != null && methodSymbol.ContainingType.SpecialType == SpecialType.System_String)
                        {
                            Debug.Assert(IsEqualsOrCompare(methodSymbol.Name));

                            if (!IsAcceptableOverload(methodSymbol, model))
                            {
                                // wrong overload
                                reportDiagnostic(memberAccess.Name.GetLocation().CreateDiagnostic(Rule));
                            }
                            else
                            {
                                var lastArgument = node.ArgumentList.Arguments.Last();
                                var lastArgSymbol = model.GetSymbolInfo(lastArgument.Expression).Symbol;
                                if (lastArgSymbol != null && lastArgSymbol.ContainingType != null &&
                                    lastArgSymbol.ContainingType.Equals(StringComparisonType) &&
                                    !IsOrdinalOrOrdinalIgnoreCase(lastArgument, model))
                                {
                                    // right overload, wrong value
                                    reportDiagnostic(lastArgument.GetLocation().CreateDiagnostic(Rule));
                                }
                            }
                        }
                    }
                }
            }
		protected bool TryGetTypes(
			SyntaxNode expression,
			SemanticModel semanticModel,
			out INamedTypeSymbol source,
			out INamedTypeSymbol destination)
		{
			source = null;
			destination = null;

			var info = semanticModel.GetSymbolInfo(expression);
			var methodSymbol = info.Symbol as IMethodSymbol;
			if (methodSymbol == null)
			{
				return false;
			}

			var compilation = semanticModel.Compilation;
			var taskType = compilation.GetTypeByMetadataName("System.Threading.Tasks.Task");
			if (taskType == null)
			{
				return false;
			}

			var returnType = methodSymbol.ReturnType as INamedTypeSymbol;
			if (returnType == null)
			{
				return false;
			}

			source = taskType;
			destination = returnType;
			return true;
		}
示例#31
0
 public CatchStatementInterpreter(StatementInterpreterHandler statementInterpreterHandler,
                                  CatchClauseSyntax catchClauseSyntax,
                                  Microsoft.CodeAnalysis.SemanticModel semanticModel)
 {
     this.statementInterpreterHandler = statementInterpreterHandler;
     this.catchClauseSyntax           = catchClauseSyntax;
     this.semanticModel = semanticModel;
 }
示例#32
0
        public static GlslSyntaxTree Translate(this CSharpSyntaxTree tree)
        {
            var supportCode = File.ReadAllText("Shader.cs");

            supportCode += File.ReadAllText("Shader.Vectors.cs");
            supportCode += File.ReadAllText("Shader.Matrices.cs");
            var supportTree = CSharpSyntaxTree.ParseText(supportCode);
            var compilation = CSharpCompilation.Create("Shader").AddSyntaxTrees(tree, supportTree);

            model = compilation.GetSemanticModel(tree);
            return(new GlslSyntaxTree(tree.GetRoot().Translate()));
        }
示例#33
0
 public GetMembersVisitor(ISemanticModel semanticModel, SpecificationsElements specificationsElements,
                          MethodSymbol methodSymbol, string serverFxDALInterfacesNamespace,
                          ConcurrentDictionary <MethodDeclarationSyntax, ISemanticModel> semanticModelPerMethods,
                          ConcurrentDictionary <string, MethodDeclarationSyntax> methodPerMethodSymbols,
                          Dictionary <string, List <MethodDeclarationSyntax> > getMethods, List <MethodDeclarationSyntax> extensionMethods)
     : this(
         semanticModel, specificationsElements, serverFxDALInterfacesNamespace, semanticModelPerMethods,
         methodPerMethodSymbols, getMethods, extensionMethods,
         new Dictionary <string, PropertyDependence>(), new Dictionary <string, int>(), 0,
         new List <MethodSymbol>() { methodSymbol }, true)
 {
     _fromOriginalMethod = true;
 }
示例#34
0
        public MemberClassCouplingAnalyzer(Microsoft.CodeAnalysis.SemanticModel semanticModel) : base(semanticModel)
        {
            Dictionary <SymbolKind, Action <ISymbol> > symbolKinds = new Dictionary <SymbolKind, Action <ISymbol> >()
            {
                { SymbolKind.NamedType, new Action <ISymbol>((ISymbol x) => base.FilterTypeSymbol((ITypeSymbol)x)) },
                { SymbolKind.Parameter, new Action <ISymbol>((ISymbol x) => base.FilterTypeSymbol(((IParameterSymbol)x).Type)) },
                { SymbolKind.Method, new Action <ISymbol>((ISymbol x) => base.FilterTypeSymbol(((IMethodSymbol)x).ContainingType)) },
                { SymbolKind.Field, new Action <ISymbol>((ISymbol x) => base.FilterTypeSymbol(((IFieldSymbol)x).Type)) },
                { SymbolKind.Property, new Action <ISymbol>((ISymbol x) => base.FilterTypeSymbol(((IPropertySymbol)x).ContainingType)) },
                { SymbolKind.Event, new Action <ISymbol>((ISymbol x) => base.FilterTypeSymbol(((IEventSymbol)x).ContainingType)) },
                { SymbolKind.Local, new Action <ISymbol>((ISymbol x) => base.FilterTypeSymbol(((ILocalSymbol)x).Type)) },
                { SymbolKind.DynamicType, new Action <ISymbol>((ISymbol x) => base.FilterTypeSymbol(((IDynamicTypeSymbol)x).ContainingType)) }
            };

            this.symbolHandlers = symbolKinds;
        }
示例#35
0
 private GetMembersVisitor(ISemanticModel semanticModel, SpecificationsElements specificationsElements,
                           string serverFxDALInterfacesNamespace,
                           ConcurrentDictionary <MethodDeclarationSyntax, ISemanticModel> semanticModelPerMethods,
                           ConcurrentDictionary <string, MethodDeclarationSyntax> methodPerMethodSymbols,
                           Dictionary <string, List <MethodDeclarationSyntax> > getMethods, List <MethodDeclarationSyntax> extensionMethods,
                           Dictionary <string, PropertyDependence> variables, Dictionary <string, int> fromVariables,
                           int linqIndex, List <MethodSymbol> alreadyCalledMethods, bool definePropertyDependences, int failed = 0)
 {
     _semanticModel                  = semanticModel;
     _specificationsElements         = specificationsElements;
     _serverFxDALInterfacesNamespace = serverFxDALInterfacesNamespace;
     _semanticModelPerMethods        = semanticModelPerMethods;
     _methodPerMethodSymbols         = methodPerMethodSymbols;
     _getMethods                = getMethods;
     _extensionMethods          = extensionMethods;
     _variables                 = variables;
     _fromVariables             = fromVariables;
     _linqIndex                 = linqIndex;
     _alreadyCalledMethods      = alreadyCalledMethods;
     _properties                = new PropertyDependence();
     _definePropertyDependences = definePropertyDependences;
     _failed = failed;
 }
 public ForEachStatementInterpreter(StatementInterpreterHandler statementInterpreterHandler, ForEachStatementSyntax forEachStatementSyntax, Microsoft.CodeAnalysis.SemanticModel semanticModel)
 {
     this.statementInterpreterHandler = statementInterpreterHandler;
     this.forEachStatementSyntax      = forEachStatementSyntax;
     this.semanticModel = semanticModel;
 }
示例#37
0
 public LiteralStatementInterpreter(LiteralExpressionSyntax literalExpressionSyntax, Microsoft.CodeAnalysis.SemanticModel semanticModel)
 {
     this.literalExpressionSyntax = literalExpressionSyntax;
     this.semanticModel           = semanticModel;
 }
示例#38
0
 public LamdaStatementInterpreter(StatementInterpreterHandler statementInterpreterHandler, ParenthesizedLambdaExpressionSyntax parenthesizedLambdaExpressionSyntax, Microsoft.CodeAnalysis.SemanticModel semanticModel)
 {
     this.statementInterpreterHandler         = statementInterpreterHandler;
     this.parenthesizedLambdaExpressionSyntax = parenthesizedLambdaExpressionSyntax;
     this.semanticModel = semanticModel;
 }
 public ElementAccessStatementInterpreter(StatementInterpreterHandler statementInterpreterHandler, ElementAccessExpressionSyntax elementAccessExpressionSyntax, Microsoft.CodeAnalysis.SemanticModel semanticModel)
 {
     this.statementInterpreterHandler   = statementInterpreterHandler;
     this.elementAccessExpressionSyntax = elementAccessExpressionSyntax;
     this.semanticModel = semanticModel;
 }
示例#40
0
 public DefaultStatementInterpreter(Microsoft.CodeAnalysis.SemanticModel semanticModel, DefaultExpressionSyntax defaultExpressionSyntax)
 {
     this.semanticModel           = semanticModel;
     this.defaultExpressionSyntax = defaultExpressionSyntax;
 }
示例#41
0
 public SearchImportReplacementsVisitor(Microsoft.CodeAnalysis.SemanticModel model, Microsoft.CodeAnalysis.SymbolInfo info, CancellationToken cancellationToken)
 {
     this.cancellationToken = cancellationToken;
     this.model             = model;
     this.info = info;
 }
示例#42
0
 public TypeClassCouplingAnalyzer(Microsoft.CodeAnalysis.SemanticModel semanticModel) : base(semanticModel)
 {
 }
示例#43
0
 public InitializerStatementInterpreter(StatementInterpreterHandler statementInterpreterHandler, InitializerExpressionSyntax initializerExpressionSyntax, Microsoft.CodeAnalysis.SemanticModel semanticModel)
 {
     this.statementInterpreterHandler = statementInterpreterHandler;
     this.initializerExpressionSyntax = initializerExpressionSyntax;
     this.semanticModel = semanticModel;
 }
示例#44
0
 public AnonymousMethodStatementInterpreter(StatementInterpreterHandler statementInterpreterHandler, AnonymousMethodExpressionSyntax anonymousMethodExpressionSyntax, Microsoft.CodeAnalysis.SemanticModel semanticModel)
 {
     this.semanticModel = semanticModel;
     this.statementInterpreterHandler     = statementInterpreterHandler;
     this.anonymousMethodExpressionSyntax = anonymousMethodExpressionSyntax;
 }
示例#45
0
 /// <summary>
 /// Gets the current semantic model for this document if the model is already computed.
 /// </summary>
 public bool TryGetSemanticModel(out SemanticModel semanticModel)
 {
     semanticModel = null;
     return(this.model != null && this.model.TryGetTarget(out semanticModel));
 }
示例#46
0
 internal static DeclarationInfo GetDeclarationInfo(SemanticModel model, SyntaxNode node, bool getSymbol, CancellationToken cancellationToken)
 {
     return(GetDeclarationInfo(model, node, getSymbol, (IEnumerable <SyntaxNode>)null, cancellationToken));
 }
示例#47
0
 internal static DeclarationInfo GetDeclarationInfo(SemanticModel model, SyntaxNode node, bool getSymbol, CancellationToken cancellationToken, params SyntaxNode[] executableCodeBlocks)
 {
     return(GetDeclarationInfo(model, node, getSymbol, executableCodeBlocks.AsEnumerable(), cancellationToken));
 }
示例#48
0
 public BinaryStatementInterpreter(StatementInterpreterHandler statementInterpreterHandler, Microsoft.CodeAnalysis.SemanticModel semanticModel, BinaryExpressionSyntax binaryExpressionSyntax)
 {
     this.statementInterpreterHandler = statementInterpreterHandler;
     this.semanticModel          = semanticModel;
     this.binaryExpressionSyntax = binaryExpressionSyntax;
 }
 protected ClassCouplingAnalyzerBase(Microsoft.CodeAnalysis.SemanticModel semanticModel) : base(0)
 {
     this.semanticModel = semanticModel;
 }