示例#1
0
        internal SourceAttributeData(
            SyntaxReference applicationNode,
            NamedTypeSymbol attributeClass,
            MethodSymbol attributeConstructor,
            ImmutableArray<TypedConstant> constructorArguments,
            ImmutableArray<int> constructorArgumentsSourceIndices,
            ImmutableArray<KeyValuePair<string, TypedConstant>> namedArguments,
            bool hasErrors,
            bool isConditionallyOmitted)
        {
            Debug.Assert(!isConditionallyOmitted || (object)attributeClass != null && attributeClass.IsConditional);
            Debug.Assert(!constructorArguments.IsDefault);
            Debug.Assert(!namedArguments.IsDefault);
            Debug.Assert(constructorArgumentsSourceIndices.IsDefault ||
                constructorArgumentsSourceIndices.Any() && constructorArgumentsSourceIndices.Length == constructorArguments.Length);

            _attributeClass = attributeClass;
            _attributeConstructor = attributeConstructor;
            _constructorArguments = constructorArguments;
            _constructorArgumentsSourceIndices = constructorArgumentsSourceIndices;
            _namedArguments = namedArguments;
            _isConditionallyOmitted = isConditionallyOmitted;
            _hasErrors = hasErrors;
            _applicationNode = applicationNode;
        }
示例#2
0
 internal SourceAttributeData(SyntaxReference applicationNode, NamedTypeSymbol attributeClass, MethodSymbol attributeConstructor, bool hasErrors)
     : this(
     applicationNode,
     attributeClass,
     attributeConstructor,
     constructorArguments: ImmutableArray<TypedConstant>.Empty,
     constructorArgumentsSourceIndices: default(ImmutableArray<int>),
     namedArguments: ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty,
     hasErrors: hasErrors,
     isConditionallyOmitted: false)
 {
 }
 internal RetargetingAttributeData(
     SyntaxReference applicationNode,
     NamedTypeSymbol attributeClass,
     MethodSymbol attributeConstructor,
     ImmutableArray<TypedConstant> constructorArguments,
     ImmutableArray<int> constructorArgumentsSourceIndices,
     ImmutableArray<KeyValuePair<string, TypedConstant>> namedArguments,
     bool hasErrors,
     bool isConditionallyOmitted)
     : base(applicationNode, attributeClass, attributeConstructor, constructorArguments, constructorArgumentsSourceIndices, namedArguments, hasErrors, isConditionallyOmitted)
 {
 }
        internal static async Task <SyntaxNode> GetTopmostSyntaxNodeForDeclarationAsync(SyntaxReference declaration, ISymbol declaredSymbol, SemanticModelProvider semanticModelProvider, CancellationToken cancellationToken)
        {
            var declSyntax = await declaration.GetSyntaxAsync(cancellationToken).ConfigureAwait(false);

            if (declSyntax.Language == LanguageNames.VisualBasic)
            {
                SemanticModel model = semanticModelProvider.GetSemanticModel(declSyntax);
                while (declSyntax.Parent != null && Equals(model.GetDeclaredSymbol(declSyntax.Parent, cancellationToken), declaredSymbol))
                {
                    declSyntax = declSyntax.Parent;
                }
            }

            return(declSyntax);
        }
		static List<InsertionPoint> GetInsertionPoints (IReadonlyTextDocument data, ITypeSymbol type, List<InsertionPoint> result, TextSpan sourceSpan, SyntaxReference declaringType)
		{
			var openBraceToken = declaringType.GetSyntax ().ChildTokens ().FirstOrDefault (t => t.IsKind (SyntaxKind.OpenBraceToken));
			if (!openBraceToken.IsMissing) {
				var domLocation = data.OffsetToLocation (openBraceToken.SpanStart);
				result.Add (GetInsertionPosition (data, domLocation.Line, domLocation.Column));
				//			result.Add (GetInsertionPosition (data, realStartLocation.Line, realStartLocation.Column));
				result [0].LineBefore = NewLineInsertion.None;
			}
			foreach (var member in type.GetMembers ()) {
				if (member.IsImplicitlyDeclared || !member.IsDefinedInSource ())
					continue;
				//var domLocation = member.BodyRegion.End;
				foreach (var loc in member.DeclaringSyntaxReferences) {
					if (loc.SyntaxTree.FilePath != declaringType.SyntaxTree.FilePath || !declaringType.Span.Contains (sourceSpan))
						continue;
					var domLocation = data.OffsetToLocation (loc.Span.End);

					if (domLocation.Line <= 0) {
						var lineSegment = data.GetLineByOffset (loc.Span.Start);
						if (lineSegment == null)
							continue;
						domLocation = new DocumentLocation (lineSegment.LineNumber, lineSegment.Length + 1);
					}
					result.Add (GetInsertionPosition (data, domLocation.Line, domLocation.Column));
					break;
				}
			}

			result [result.Count - 1].LineAfter = NewLineInsertion.None;
			CheckStartPoint (data, result [0], result.Count == 1);
			if (result.Count > 1) {
				result.RemoveAt (result.Count - 1); 
				NewLineInsertion insertLine;
				var typeSyntaxReference = type.DeclaringSyntaxReferences.FirstOrDefault (r => r.Span.Contains (sourceSpan));

				var lineBefore = data.GetLineByOffset (typeSyntaxReference.Span.End).PreviousLine;
				if (lineBefore != null && lineBefore.Length == lineBefore.GetIndentation (data).Length) {
					insertLine = NewLineInsertion.None;
				} else {
					insertLine = NewLineInsertion.Eol;
				}
				// search for line start
				var line = data.GetLineByOffset (typeSyntaxReference.Span.End);
				int col = typeSyntaxReference.Span.End - line.Offset;
				if (line != null) {
					var lineOffset = line.Offset;
					col = Math.Min (line.Length, col);
					while (lineOffset + col - 2 >= 0 && col > 1 && char.IsWhiteSpace (data.GetCharAt (lineOffset + col - 2)))
						col--;
				}
				result.Add (new InsertionPoint (new DocumentLocation (line.LineNumber, col), insertLine, NewLineInsertion.Eol));
				CheckEndPoint (data, result [result.Count - 1], result.Count == 1);
			}

//			foreach (var region in parsedDocument.UserRegions.Where (r => type.BodyRegion.IsInside (r.Region.Begin))) {
//				result.Add (new InsertionPoint (new DocumentLocation (region.Region.BeginLine + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
//				result.Add (new InsertionPoint (new DocumentLocation (region.Region.EndLine, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
//				result.Add (new InsertionPoint (new DocumentLocation (region.Region.EndLine + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
//			}
			result.Sort ((left, right) => left.Location.CompareTo (right.Location));
			//foreach (var res in result)
			//	Console.WriteLine (res);
			return result;
		}
示例#6
0
文件: CSEX.cs 项目: knat/SData
 internal static TextSpan GetTextSpan(SyntaxReference sr)
 {
     if (sr != null)
     {
         return GetTextSpan(sr.GetSyntax().GetLocation());
     }
     return default(TextSpan);
 }