void Analyze (CompletionEngine engine,SemanticModel model, SyntaxNode node, ISymbol within, List<CompletionData> list, ParameterListSyntax parameterList, ISymbol symbol, HashSet<string> addedSymbols, CancellationToken cancellationToken)
		{
			var type = CheckParameterList (model, parameterList, symbol, cancellationToken);
			if (type == null)
				return;
			var startType = type;

			while (type.SpecialType != SpecialType.System_Object) {
				foreach (var member in type.GetMembers ()) {
					if (member.IsImplicitlyDeclared || member.IsStatic)
						continue;
					if (member.IsOrdinaryMethod () || member.Kind == SymbolKind.Field || member.Kind == SymbolKind.Property) {
						if (member.IsAccessibleWithin (within)) {
							var completionData = engine.Factory.CreateCastCompletionData(this, member, node, startType);
							if (addedSymbols.Contains (completionData.DisplayText))
								continue;
							addedSymbols.Add (completionData.DisplayText);
							list.Add (completionData);
						}
					}
				}

				type = type.BaseType;
			}
		}
Example #2
0
        public static glsl.ParameterListSyntax Translate(this cs.ParameterListSyntax node)
        {
            var parameters     = new glsl.ParameterListSyntax();
            var parameterNodes = node.Parameters.Translate();

            return(parameters.Update(node.OpenParenToken, parameterNodes, node.CloseParenToken));
        }
Example #3
0
        private string MakeParametersList(ParameterListSyntax syntax)
        {
            var args = syntax.Parameters;
            StringBuilder str = new StringBuilder();
            if (args.Count > 0)
            {
                var fstArg = args[0];
                if (fstArg.IsExtensionParameter())
                    this.AppendCompileIssue(syntax, IssueType.Error, IssueId.ExtensionMethodNotSupport);

                foreach (var arg in args)
                {
                    var info = _semanticModel.GetDeclaredSymbol(arg);
                    if (!info.Type.IsScriptSymbol())
                    {
                        this.AppendCompileIssue(syntax, IssueType.Error, IssueId.UseNonScript, info.Type);
                    }

                    if (arg.Default != null)
                    {
                        this.AppendCompileIssue(syntax, IssueType.Error, IssueId.DefaultParamNotSupport);
                    }

                    str.Append(_semanticModel.GetParameterSymbolName(arg)).Append(", ");
                }
                str.RemoveEnd(", ");
            }
            return str.ToString();
        }
 public static MethodDeclarationSyntax MethodDeclaration(
     SyntaxList<AttributeListSyntax> attributeLists,
     SyntaxTokenList modifiers,
     TypeSyntax returnType,
     ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier,
     SyntaxToken identifier,
     TypeParameterListSyntax typeParameterList,
     ParameterListSyntax parameterList,
     SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
     BlockSyntax body,
     SyntaxToken semicolonToken)
 {
     return SyntaxFactory.MethodDeclaration(
         attributeLists,
         modifiers,
         default(SyntaxToken),
         returnType,
         explicitInterfaceSpecifier,
         identifier,
         typeParameterList,
         parameterList,
         constraintClauses,
         body,
         default(ArrowExpressionClauseSyntax),
         semicolonToken);
 }
		void AppendParameter (StringBuilder sb, ParameterListSyntax parameters)
		{
			// Missing roslyn formatting option ?
			//			if (options.GetOption (CSharpFormattingOptions.Spacing ???))
			//	sb.Append (" ");
			sb.Append ("(");
			var hasParameters = parameters != null && parameters.Parameters.Count > 0;

			// Missing roslyn formatting option ?
			//if (hasParameters && options.GetOption (SpaceWithinMethodDeclarationParentheses))
			//	sb.Append (" ");

			bool first = true;
			if (hasParameters) {
				foreach (var param in parameters.Parameters) {
					if (!first) {
						//if (options.SpaceBeforeMethodDeclarationParameterComma)
						//	sb.Append (" ");
						sb.Append (",");
						//if (options.SpaceAfterMethodDeclarationParameterComma)
						sb.Append (" ");
					} else {
						first = false;
					}
					AppendEscaped (sb, param.ToString ());
				}
			}

			// Missing roslyn formatting option ?
			//if (hasParameters && options.SpaceWithinMethodDeclarationParentheses)
			//	sb.Append (" ");
			sb.Append (")");
		}
Example #6
0
        public SyntaxNode ParseClass(SyntaxNode node, string id, ParameterListSyntax args)
        {
            ClassDeclarationSyntax decl = (ClassDeclarationSyntax)node;

            var found_ctor = false;
            foreach (var member in decl.Members)
            {
                if (member is ConstructorDeclarationSyntax)
                {
                    ConstructorDeclarationSyntax ctor = (ConstructorDeclarationSyntax)member;
                    if (found_ctor)
                    {
                        //error
                        break;
                    }

                    found_ctor = true;
                    _plan.EntryPoint(ctor);
                }
                else if (member is MethodDeclarationSyntax)
                {
                    _plan.AddConsumer((MethodDeclarationSyntax)member);
                }
                else
                {
                    //error
                }
            }

            return _plan.Resolve();
        }
 private static ParameterListSyntax TransformParameterList(ParameterListSyntax list)
 {
     var resultingList = list.ReplaceNodes(
         WhereIsPointerParameter(list.Parameters),
         (n1, n2) => TransformParameterDefaultValue(n2.WithType(IntPtrTypeSyntax)));
     return resultingList;
 }
 public static SourceConstructorSymbol CreatePrimaryConstructorSymbol(
     SourceMemberContainerTypeSymbol containingType,
     ParameterListSyntax syntax,
     DiagnosticBag diagnostics)
 {
     return new SourceConstructorSymbol(containingType, syntax.GetLocation(), syntax, diagnostics);
 }
 private SourceConstructorSymbol(
     SourceMemberContainerTypeSymbol containingType,
     Location location,
     ParameterListSyntax syntax,
     DiagnosticBag diagnostics) :
     base(containingType, syntax.GetReference(), GetPrimaryConstructorBlockSyntaxReferenceOrNull(syntax), ImmutableArray.Create(location))
 {
     var declarationModifiers = (containingType.IsAbstract ? DeclarationModifiers.Protected : DeclarationModifiers.Public) | DeclarationModifiers.PrimaryCtor;
     this.flags = MakeFlags(MethodKind.Constructor, declarationModifiers, returnsVoid: true, isExtensionMethod: false);
     this.CheckModifiers(MethodKind.Constructor, location, diagnostics);
 }
        private async Task<Document> CollapseParameters(Document document, ParameterListSyntax parameterListNode, CancellationToken cancellationToken)
        {
            ParameterListSyntax updatedParameterList = SyntaxFactory.ParameterList(parameterListNode.OpenParenToken, 
                SyntaxFactory.SeparatedList(parameterListNode.Parameters.Select(p => p.WithoutLeadingTrivia().WithoutTrailingTrivia()).ToList()), 
                parameterListNode.CloseParenToken);

            SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken);
            var newRoot = root.ReplaceNode(parameterListNode, updatedParameterList);
            
            return await Formatter.FormatAsync(document.WithSyntaxRoot(newRoot), updatedParameterList.FullSpan);
        }
Example #11
0
        private static SyntaxReference GetPrimaryConstructorBlockSyntaxReferenceOrNull(ParameterListSyntax syntax)
        {
            foreach (var m in ((TypeDeclarationSyntax)syntax.Parent).Members)
            {
                if (m.Kind == SyntaxKind.PrimaryConstructorBody)
                {
                    return ((PrimaryConstructorBodySyntax)m).Body.GetReference();
                }
            }

            return null;
        }
Example #12
0
 /// <summary>
 /// Retourne les conditions sur les paramètres dans une listes d'expressions.
 /// </summary>
 /// <param name="expressions">Liste d'expressions.</param>
 /// <param name="paramètres">Les paramètres du constructeur.</param>
 /// <param name="modèleSémantique">Modèle sémantique.</param>
 /// <returns>La liste d'assignations.</returns>
 public static IEnumerable<IfStatementSyntax> TrouveConditionsParametres(SyntaxList<StatementSyntax> expressions, ParameterListSyntax paramètres, SemanticModel modèleSémantique) =>
     expressions
         .OfType<IfStatementSyntax>()
         .Where(e =>
             (e.Condition
                 ?.DescendantNodes()?.OfType<IdentifierNameSyntax>()
                 ?.Any(identifiant => modèleSémantique.GetSymbolInfo(identifiant).Symbol?.Kind == SymbolKind.Parameter)
             ?? false)
         && (e.Statement
                 ?.DescendantNodes()?.OfType<IdentifierNameSyntax>()
                 ?.All(identifiant => modèleSémantique.GetSymbolInfo(identifiant).Symbol?.Kind != SymbolKind.Field)
             ?? false));
 public static DelegateDeclarationSyntax DelegateDeclaration(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, SyntaxToken delegateKeyword, TypeSyntax returnType, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, ParameterListSyntax parameterList, SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses, SyntaxToken semicolonToken)
 {
     return DelegateDeclaration(
         attributeLists,
         modifiers, 
         delegateKeyword, 
         refKeyword: default(SyntaxToken), 
         returnType: returnType, 
         identifier: identifier, 
         typeParameterList: typeParameterList, 
         parameterList: parameterList, 
         constraintClauses: constraintClauses, 
         semicolonToken: semicolonToken);
 }
 public static DestructorDeclarationSyntax DestructorDeclaration(
     SyntaxList<AttributeListSyntax> attributeLists,
     SyntaxTokenList modifiers,
     SyntaxToken identifier,
     ParameterListSyntax parameterList,
     ArrowExpressionClauseSyntax expressionBody)
     => DestructorDeclaration(
         attributeLists,
         modifiers,
         SyntaxFactory.Token(SyntaxKind.TildeToken),
         identifier,
         parameterList,
         default(BlockSyntax),
         expressionBody,
         default(SyntaxToken));
 public static ConstructorDeclarationSyntax ConstructorDeclaration(
     SyntaxList<AttributeListSyntax> attributeLists,
     SyntaxTokenList modifiers,
     SyntaxToken identifier,
     ParameterListSyntax parameterList,
     ConstructorInitializerSyntax initializer,
     ArrowExpressionClauseSyntax expressionBody)
     => ConstructorDeclaration(
         attributeLists,
         modifiers,
         identifier,
         parameterList,
         initializer,
         default(BlockSyntax),
         expressionBody,
         default(SyntaxToken));
 public ConstructorDeclarationSyntax Update(
     SyntaxList<AttributeListSyntax> attributeLists,
     SyntaxTokenList modifiers, 
     SyntaxToken identifier,
     ParameterListSyntax parameterList, 
     ConstructorInitializerSyntax initializer, 
     BlockSyntax body, 
     SyntaxToken semicolonToken)
     => Update(
         attributeLists, 
         modifiers, 
         identifier, 
         parameterList, 
         initializer, 
         body, 
         default(ArrowExpressionClauseSyntax), 
         semicolonToken);
 public static DestructorDeclarationSyntax DestructorDeclaration(
     SyntaxList<AttributeListSyntax> attributeLists,
     SyntaxTokenList modifiers,
     SyntaxToken tildeToken,
     SyntaxToken identifier,
     ParameterListSyntax parameterList,
     BlockSyntax body,
     SyntaxToken semicolonToken)
     => DestructorDeclaration(
         attributeLists,
         modifiers,
         tildeToken,
         identifier,
         parameterList,
         body,
         default(ArrowExpressionClauseSyntax),
         semicolonToken);
        private async Task<Document> BreakParametersApart(Document document, ParameterListSyntax parameterListNode, CancellationToken cancellationToken)
        {
            if (parameterListNode.Parameters.Count < 2)
                return document;

            ParameterSyntax firstParameter = parameterListNode.Parameters.First();

            List<ParameterSyntax> updatedParameters = new List<ParameterSyntax>();
            updatedParameters.Add(firstParameter.WithoutLeadingTrivia().WithoutTrailingTrivia());

            foreach (ParameterSyntax parameter in parameterListNode.Parameters.Skip(1).ToList())
                updatedParameters.Add(parameter
                                        .WithoutTrailingTrivia()
                                        .WithLeadingTrivia(SyntaxFactory.EndOfLine("\r\n"), GetIndentTrivia(parameterListNode)));

            ParameterListSyntax updatedParameterList = SyntaxFactory.ParameterList(parameterListNode.OpenParenToken, 
                                                                                   SyntaxFactory.SeparatedList(updatedParameters), 
                                                                                   parameterListNode.CloseParenToken);

            SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken);
            var newRoot = root.ReplaceNode(parameterListNode, updatedParameterList);
            return document.WithSyntaxRoot(newRoot);
        }
 public ParameterListTranslation(ParameterListSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
 {
     Parameters = syntax.Parameters.Get<ParameterSyntax, ParameterTranslation>(this);
 }
 public AnonymousMethodExpressionSyntax Update(SyntaxToken asyncKeyword, SyntaxToken delegateKeyword, ParameterListSyntax parameterList, CSharpSyntaxNode body)
 => body is BlockSyntax block
Example #21
0
 public static MethodDeclarationSyntax Update(
     this MethodDeclarationSyntax syntax,
     SyntaxList<AttributeListSyntax> attributeLists,
     SyntaxTokenList modifiers,
     SyntaxToken refKeyword,
     TypeSyntax returnType,
     ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier,
     SyntaxToken identifier,
     TypeParameterListSyntax typeParameterList,
     ParameterListSyntax parameterList,
     SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
     BlockSyntax block,
     SyntaxToken semicolonToken)
 {
     return syntax.Update(
         attributeLists,
         modifiers,
         refKeyword,
         returnType,
         explicitInterfaceSpecifier,
         identifier,
         typeParameterList,
         parameterList,
         constraintClauses,
         block,
         default(ArrowExpressionClauseSyntax),
         semicolonToken);
 }
Example #22
0
 public static OperatorDeclarationSyntax Update(
     this OperatorDeclarationSyntax syntax,
     SyntaxList<AttributeListSyntax> attributeLists,
     SyntaxTokenList modifiers,
     TypeSyntax returnType,
     SyntaxToken operatorKeyword,
     SyntaxToken operatorToken,
     ParameterListSyntax parameterList,
     BlockSyntax block,
     SyntaxToken semicolonToken)
 {
     return syntax.Update(
         attributeLists,
         modifiers,
         returnType,
         operatorKeyword,
         operatorToken,
         parameterList,
         block,
         default(ArrowExpressionClauseSyntax),
         semicolonToken);
 }
 public ParenthesizedLambdaExpressionSyntax Update(SyntaxToken asyncKeyword, ParameterListSyntax parameterList, SyntaxToken arrowToken, CSharpSyntaxNode body)
 {
     return Update(asyncKeyword, parameterList, arrowToken, this.RefKeyword, body);
 }
            public override void VisitParameterList(ParameterListSyntax node)
            {
                var saveCurrentScope = currentScope;
                DeclarationScope parametersScope = null;

                switch (node.Parent.Kind)
                {
                    case SyntaxKind.ClassDeclaration:
                        if (((ClassDeclarationSyntax)node.Parent).ParameterList == node)
                        {
                            parametersScope = primaryConstructorParametersScopes[(ClassDeclarationSyntax)node.Parent];
                            currentScope = parametersScope;
                        }
                        break;
                    case SyntaxKind.StructDeclaration:
                        if (((StructDeclarationSyntax)node.Parent).ParameterList == node)
                        {
                            parametersScope = primaryConstructorParametersScopes[(StructDeclarationSyntax)node.Parent];
                            currentScope = parametersScope;
                        }
                        break;
                }

                base.VisitParameterList(node);

                if (parametersScope != null)
                {
                    Debug.Assert(currentScope == parametersScope);
                    Debug.Assert(currentScope.Parent == saveCurrentScope);
                    currentScope = saveCurrentScope;
                }
                else
                {
                    Debug.Assert(currentScope == saveCurrentScope);
                }
            }
Example #25
0
 public ParenthesizedLambdaExpressionSyntax Update(SyntaxToken asyncKeyword, ParameterListSyntax parameterList, SyntaxToken arrowToken, CSharpSyntaxNode body)
 {
     return(Update(asyncKeyword, parameterList, arrowToken, this.RefKeyword, body));
 }
        public static BaseMethodDeclarationSyntax WithParameterList(this BaseMethodDeclarationSyntax method, ParameterListSyntax pls)
        {
            switch (method.Kind())
            {
                case SyntaxKind.OperatorDeclaration:
                case SyntaxKind.ConversionOperatorDeclaration:
                    throw new NotImplementedException("Wasabi doesn't have operators");
                case SyntaxKind.MethodDeclaration:
                    return ((MethodDeclarationSyntax)method).WithParameterList(pls);
                case SyntaxKind.ConstructorDeclaration:
                    return ((ConstructorDeclarationSyntax)method).WithParameterList(pls);
                case SyntaxKind.DestructorDeclaration:
                    return ((DestructorDeclarationSyntax)method).WithParameterList(pls);
            }

            throw new NotImplementedException("WithParameterList " + method.Kind().ToString());
        }
		static ITypeSymbol CheckParameterList (SemanticModel model, ParameterListSyntax listSyntax, ISymbol parameter, CancellationToken cancellationToken)
		{
			var param = listSyntax?.Parameters.FirstOrDefault ();
			if (param == null)
				return null;
			var declared = model.GetDeclaredSymbol (param, cancellationToken);
			if (declared != parameter)
				return null;
			var assignmentExpr = listSyntax.Parent.Parent as AssignmentExpressionSyntax;
			if (assignmentExpr == null || !assignmentExpr.IsKind (SyntaxKind.AddAssignmentExpression))
				return null;
			var left = assignmentExpr.Left as MemberAccessExpressionSyntax;
			if (left == null)
				return null;
			var symbolInfo = model.GetSymbolInfo (left.Expression);
			if (symbolInfo.Symbol == null || symbolInfo.Symbol is ITypeSymbol)
				return null;
			return model.GetTypeInfo (left.Expression).Type;
		}
Example #28
0
 public MethodDeclarationSyntax Update(SyntaxList <AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax returnType, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, ParameterListSyntax parameterList, SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses, BlockSyntax body, ArrowExpressionClauseSyntax expressionBody, SyntaxToken semicolonToken)
 {
     return(Update(attributeLists, modifiers, this.RefKeyword, returnType, explicitInterfaceSpecifier, identifier, typeParameterList, parameterList, constraintClauses, body, expressionBody, semicolonToken));
 }
 private static ParameterListSyntax RemoveType(ParameterListSyntax parameterList)
 {
     return parameterList.WithParameters(SyntaxFactory.SeparatedList(parameterList.Parameters.Select(x => RemoveType(x)), parameterList.Parameters.GetSeparators()));
 }
 // Preserved as shipped public API for binary compatibility
 public LocalFunctionStatementSyntax Update(SyntaxTokenList modifiers, TypeSyntax returnType, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, ParameterListSyntax parameterList, SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses, BlockSyntax body, ArrowExpressionClauseSyntax expressionBody, SyntaxToken semicolonToken)
 {
     return(Update(attributeLists: default, modifiers, returnType, identifier, typeParameterList, parameterList, constraintClauses, body, expressionBody, semicolonToken));
Example #31
0
 internal static bool IsInParameterList(int position, ParameterListSyntax parameterList)
 => parameterList != null && IsBeforeToken(position, parameterList, parameterList.CloseParenToken);
        private static bool MatchArguments(ParameterListSyntax parameters, ArgumentListSyntax arguments)
        {
            if (arguments.Arguments.Count != parameters.Parameters.Count) return false;

            var paramNameList = parameters.Parameters.Select(p => p.Identifier.Text);
            var argNameList = arguments.Arguments
                .Where(a => a.Expression is IdentifierNameSyntax)
                .Select(a => (a.Expression as IdentifierNameSyntax).Identifier.Text);

            return paramNameList.SequenceEqual(argNameList);
        }
 public override VisualBasicSyntaxNode VisitParameterList(CSS.ParameterListSyntax node)
 {
     return(SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(node.Parameters.Select(p => (ParameterSyntax)p.Accept(this)))));
 }
 /// <summary>Creates a new ParenthesizedLambdaExpressionSyntax instance.</summary>
 public static ParenthesizedLambdaExpressionSyntax ParenthesizedLambdaExpression(SyntaxToken asyncKeyword, ParameterListSyntax parameterList, SyntaxToken arrowToken, CSharpSyntaxNode body)
 {
     return ParenthesizedLambdaExpression(asyncKeyword, parameterList, arrowToken, default(SyntaxToken), body);
 }
        private static void AnalyzeParametersList(SyntaxNodeAnalysisContext context, ParameterListSyntax parameterListSyntax)
        {
            if (parameterListSyntax == null ||
                parameterListSyntax.OpenParenToken.IsMissing ||
                parameterListSyntax.IsMissing ||
                !parameterListSyntax.Parameters.Any())
            {
                return;
            }

            var firstParameter = parameterListSyntax.Parameters[0];

            var firstParameterLineSpan = firstParameter.GetLineSpan();
            if (!firstParameterLineSpan.IsValid)
            {
                return;
            }

            var openParenLineSpan = parameterListSyntax.OpenParenToken.GetLineSpan();
            if (!openParenLineSpan.IsValid)
            {
                return;
            }

            if (openParenLineSpan.EndLinePosition.Line != firstParameterLineSpan.StartLinePosition.Line &&
                openParenLineSpan.EndLinePosition.Line != (firstParameterLineSpan.StartLinePosition.Line - 1))
            {
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, firstParameter.GetLocation()));
            }
        }
Example #36
0
 public ParenthesizedLambdaExpressionSyntax Update(SyntaxToken asyncKeyword, ParameterListSyntax parameterList, SyntaxToken arrowToken, CSharpSyntaxNode body)
 => body is BlockSyntax block
 public MethodDeclarationSyntax Update(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax returnType, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, ParameterListSyntax parameterList, SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses, BlockSyntax body, ArrowExpressionClauseSyntax expressionBody, SyntaxToken semicolonToken)
 {
     return Update(attributeLists, modifiers, this.RefKeyword, returnType, explicitInterfaceSpecifier, identifier, typeParameterList, parameterList, constraintClauses, body, expressionBody, semicolonToken);
 }
        private static void HandleParameterListSyntax(SyntaxNodeAnalysisContext context, ParameterListSyntax parameterList)
        {
            if (parameterList == null)
            {
                return;
            }

            SeparatedSyntaxList<ParameterSyntax> parameters = parameterList.Parameters;
            if (parameters.Count > 1)
            {
                Analyze(context, parameterList.OpenParenToken, parameters[0], parameters[1]);
            }
        }
Example #39
0
 public DelegateDeclarationSyntax Update(SyntaxList <AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, SyntaxToken delegateKeyword, TypeSyntax returnType, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, ParameterListSyntax parameterList, SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses, SyntaxToken semicolonToken)
 {
     return(Update(attributeLists, modifiers, delegateKeyword, this.RefKeyword, returnType, identifier, typeParameterList, parameterList, constraintClauses, semicolonToken));
 }