public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { SourcePoint? startPoint = null; SourcePoint? endPoint = null; foreach (var token in from token in csElement.ElementTokens where token.LineNumber == violation.Line && token.CsTokenType != CsTokenType.WhiteSpace select token) { if (token.CsTokenType == CsTokenType.Namespace) { startPoint = endPoint = new SourcePoint(token.Location.StartPoint.LineNumber, token.Location.StartPoint.IndexOnLine + 1); } else if (token.CsTokenType == CsTokenType.OpenCurlyBracket || token.CsTokenType == CsTokenType.EndOfLine) { if (startPoint != null) { var sourceRange = new SourceRange(startPoint.Value, endPoint.Value); yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, sourceRange); } yield break; } else if (startPoint != null) { endPoint = new SourcePoint(token.Location.EndPoint.LineNumber, token.Location.EndPoint.IndexOnLine + 2); } } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { bool specialPredecessorFound = true; bool whitespaceFound = false; foreach (var token in this.getTokens(csElement).Flatten().Where(x => x.LineNumber == violation.Line)) { if (!specialPredecessorFound && whitespaceFound && this.reportIssueFor(token, violation)) { whitespaceFound = false; yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(token.Location.StartPoint.LineNumber, token.Location.StartPoint.IndexOnLine + 1, token.Location.EndPoint.LineNumber, token.Location.EndPoint.IndexOnLine + 2)); } else if (this.specialPredecessors.Contains(token.CsTokenType)) { specialPredecessorFound = true; whitespaceFound = false; } else if (token.CsTokenType == CsTokenType.WhiteSpace) { whitespaceFound = true; } else { specialPredecessorFound = false; whitespaceFound = false; } } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { foreach (var method in from x in enumerate(new ElementTypeFilter(LanguageElementType.Method)) let method = (DX.Method)x.ToLanguageElement() where method.RecoveredRange.Start.Line == violation.Line && method.IsStatic && method.IsConstructor && method.FirstChild == null select method) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, method.NameRange); } foreach (var statement in from x in enumerate(new ElementTypeFilter(deleteWhenEmpty)) let statement = x.ToLanguageElement() where statement.RecoveredRange.Start.Line == violation.Line && (statement.ElementType == LanguageElementType.Try || statement.FirstChild == null) select statement) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, statement.GetKeywordRange()); } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { var preprocessorToken = (from token in csElement.ElementTokens where token.LineNumber == violation.Line && token.CsTokenType == CsTokenType.PreprocessorDirective select token).FirstOrDefault(); if (preprocessorToken != null) { int underlineLength = 1; while (preprocessorToken.Text[underlineLength] == ' ' || preprocessorToken.Text[underlineLength] == '\t') { underlineLength++; } while (underlineLength < preprocessorToken.Text.Length && preprocessorToken.Text[underlineLength] != ' ' && preprocessorToken.Text[underlineLength] != '\t') { underlineLength++; } var startPoint = preprocessorToken.Location.StartPoint; var sourceRange = new SourceRange(startPoint.LineNumber, startPoint.IndexOnLine + 1, startPoint.LineNumber, startPoint.IndexOnLine + 1 + underlineLength); yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, sourceRange); } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { bool predecessorFound = true; CodeLocation issueLocation = null; foreach (var token in this.getTokens(csElement).Flatten().Where(x => x.LineNumber == violation.Line)) { if (!predecessorFound && !requiredFollowers.Contains(token.CsTokenType) && issueLocation != null) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(issueLocation.StartPoint.LineNumber, issueLocation.StartPoint.IndexOnLine + 1, issueLocation.EndPoint.LineNumber, issueLocation.EndPoint.IndexOnLine + 2)); predecessorFound = false; issueLocation = null; } else if (reportIssueFor(token, violation)) { issueLocation = token.Location; } else if (requiredPredecessors.Contains(token.CsTokenType)) { predecessorFound = true; } else { predecessorFound = false; issueLocation = null; } } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { CsToken potentialViolation = null; bool whitespaceFound = false; foreach (var token in this.getTokens(csElement).Flatten().Where(x => x.LineNumber == violation.Line)) { if (potentialViolation != null && token.CsTokenType == CsTokenType.WhiteSpace) { whitespaceFound = true; } else if (potentialViolation != null && whitespaceFound && isBannedFollower(token)) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(potentialViolation.Location.StartPoint.LineNumber, potentialViolation.Location.StartPoint.IndexOnLine + 1, potentialViolation.Location.EndPoint.LineNumber, potentialViolation.Location.EndPoint.IndexOnLine + 2)); whitespaceFound = false; potentialViolation = null; } else if (this.reportIssueFor(token, violation)) { potentialViolation = token; whitespaceFound = false; } else { whitespaceFound = false; potentialViolation = null; } } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { foreach (BinaryOperatorExpression operation in from x in enumerate(new ElementTypeFilter(LanguageElementType.BinaryOperatorExpression)) let binaryOperation = (BinaryOperatorExpression)x.ToLanguageElement() where binaryOperation.RecoveredRange.Start.Line == violation.Line && (binaryOperation.LeftSide.ElementType == LanguageElementType.BinaryOperatorExpression || binaryOperation.RightSide.ElementType == LanguageElementType.BinaryOperatorExpression) select binaryOperation) { var parentType = operators[operation.Name]; var leftChildType = operation.LeftSide.ElementType == LanguageElementType.BinaryOperatorExpression ? operators[operation.LeftSide.Name] : parentType; var rightChildType = operation.RightSide.ElementType == LanguageElementType.BinaryOperatorExpression ? operators[operation.RightSide.Name] : parentType; var isLeftModulo = operation.LeftSide.ElementType == LanguageElementType.BinaryOperatorExpression ? operation.LeftSide.Name == "%" : operation.Name == "%"; var isRightModulo = operation.RightSide.ElementType == LanguageElementType.BinaryOperatorExpression ? operation.RightSide.Name == "%" : operation.Name == "%"; if (rightChildType > parentType) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, operation.RightSide.RecoveredRange); } else if (leftChildType > parentType || (leftChildType == rightChildType && isLeftModulo != isRightModulo)) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, operation.LeftSide.RecoveredRange); } } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { CodePoint startPoint = null; CodePoint endPoint = null; foreach (var token in from token in csElement.ElementTokens where token.LineNumber >= violation.Line select token) { if (token.CsTokenType == CsTokenType.UsingDirective || token.CsTokenType == CsTokenType.Using) { startPoint = token.Location.StartPoint; continue; } if (token.CsTokenType == CsTokenType.Semicolon) { endPoint = token.Location.EndPoint; } if (startPoint != null && endPoint != null) { var sourceRange = new SourceRange(startPoint.LineNumber, startPoint.IndexOnLine + 1, endPoint.LineNumber, endPoint.IndexOnLine + 2); yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, sourceRange); } } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { int prefixLength = "The call to ".Length; var memberName = violation.Message.Substring(prefixLength, violation.Message.IndexOf(" must") - prefixLength); var thisFound = false; foreach (var token in from token in csElement.ElementTokens where token.LineNumber == violation.Line && token.CsTokenType != CsTokenType.WhiteSpace select token) { if (token.CsTokenType == CsTokenType.This || (thisFound && token.Text == ".")) { thisFound = true; } else { if (token.Text == memberName && !thisFound) { var sourceRange = new SourceRange(token.Location.StartPoint.LineNumber, token.Location.StartPoint.IndexOnLine + 1, token.Location.EndPoint.LineNumber, token.Location.EndPoint.IndexOnLine + 2); yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, sourceRange); } thisFound = false; } } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { CodePoint startPoint = null; CodePoint endPoint = null; bool emptyLine = true; foreach (var token in csElement.ElementTokens.Flatten().Where(x => x.LineNumber == violation.Line)) { if (startPoint == null) { startPoint = token.Location.StartPoint; endPoint = token.Location.EndPoint; emptyLine = token.CsTokenType == CsTokenType.WhiteSpace || token.CsTokenType == CsTokenType.EndOfLine; } if (token.CsTokenType != CsTokenType.WhiteSpace && token.CsTokenType != CsTokenType.EndOfLine) { if (emptyLine) { startPoint = token.Location.StartPoint; emptyLine = false; } endPoint = token.Location.EndPoint; } else if (token.CsTokenType == CsTokenType.EndOfLine) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(startPoint.LineNumber, startPoint.IndexOnLine + 1, endPoint.LineNumber, endPoint.IndexOnLine + 2)); } } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { CsToken startToken = null; foreach (var token in from token in csElement.ElementTokens where violation.Line == token.Location.StartPoint.LineNumber && (token.CsTokenType == CsTokenType.OpenCurlyBracket || token.CsTokenType == CsTokenType.CloseCurlyBracket) select token) { if (token.CsTokenType == CsTokenType.OpenCurlyBracket) { startToken = token; continue; } if (token.CsTokenType == CsTokenType.CloseCurlyBracket) { var sourceRange = new SourceRange(startToken.Location.StartPoint.LineNumber, startToken.Location.StartPoint.IndexOnLine + 1, token.Location.EndPoint.LineNumber, token.Location.EndPoint.IndexOnLine + 2); yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, sourceRange); } } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { foreach (var operation in from x in enumerate(new ElementTypeFilter(LanguageElementType.LogicalOperation)) let logicalOperation = (LogicalOperation)x.ToLanguageElement() where logicalOperation.RecoveredRange.Start.Line == violation.Line && (logicalOperation.LeftSide.ElementType == LanguageElementType.LogicalOperation || logicalOperation.RightSide.ElementType == LanguageElementType.LogicalOperation) select logicalOperation) { var parentType = operators[operation.Name]; var leftChildType = operation.LeftSide.ElementType == LanguageElementType.LogicalOperation ? operators[operation.LeftSide.Name] : parentType; var rightChildType = operation.RightSide.ElementType == LanguageElementType.LogicalOperation ? operators[operation.RightSide.Name] : parentType; if (rightChildType > parentType) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, operation.RightSide.RecoveredRange); } else if (leftChildType > parentType) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, operation.LeftSide.RecoveredRange); } } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { return this.issueLocators.SelectMany(locator => locator.GetCodeIssues(sourceCode, enumerate, violation, csElement)); }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { return Enumerable.Empty<StyleCopCodeIssue>(); }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { return (from token in csElement.ElementTokens where token.LineNumber == violation.Line && this.tokenTypes.Contains(token.CsTokenType) let location = token.Location select new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(location.StartPoint.LineNumber, location.StartPoint.IndexOnLine + 1, location.EndPoint.LineNumber, location.EndPoint.IndexOnLine + 2))).Take(1); }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { var startPoint = csElement.ElementTokens.First().Location.StartPoint; var endPoint = csElement.ElementTokens.Last().Location.EndPoint; var sourceRange = new SourceRange(startPoint.LineNumber, startPoint.IndexOnLine + 1, endPoint.LineNumber, endPoint.IndexOnLine + 2); yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, sourceRange); }
public IDictionary<string, List<Violation>> GetViolations(IProjectElement project, ISourceCode sourceCode) { var styleCopProject = new CodeProject( project.FullName.GetHashCode(), this.GetProjectFolder(project), this.configuration); this.violations.Clear(); this.environment.AddSourceCode(styleCopProject, sourceCode.FilePath, sourceCode); this.styleCopConsole.Start(new List<CodeProject> { styleCopProject }); return new Dictionary<string, List<Violation>>(this.violations); }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { return from x in enumerate(new ElementTypeFilter(LanguageElementType.Statement)) let statement = (DX.Statement)x.ToLanguageElement() where statement.StartLine == violation.Line && statement.DetailNodeCount == 0 select new StyleCopCodeIssue(CodeIssueType.CodeSmell, statement.Range); }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { var token = this.getTokens(csElement).Flatten().LastOrDefault(x => x.LineNumber == violation.Line && this.reportIssueFor(x, violation)); if (token != null) { var issueLocation = token.Location; yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(issueLocation.StartPoint.LineNumber, issueLocation.StartPoint.IndexOnLine + 1, issueLocation.EndPoint.LineNumber, issueLocation.EndPoint.IndexOnLine + 2)); } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> crEnumerable, Violation violation, CsElement csElement) { return from token in csElement.ElementTokens where token.Text.StartsWith("///") && !token.Text.StartsWith("////") let startPoint = token.Location.StartPoint let endPoint = token.Location.EndPoint let sourceRange = new SourceRange(startPoint.LineNumber, startPoint.IndexOnLine + 1, endPoint.LineNumber, endPoint.IndexOnLine + 2) select new StyleCopCodeIssue(CodeIssueType.CodeSmell, sourceRange); }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { bool inTypeOfOrSizeOfOrDefault = false; bool openParenFound = false; bool typeFound = false; CsToken potentialViolation = null; foreach (var token in this.getTokens(csElement).Where(x => x.LineNumber == violation.Line)) { if (token.CsTokenType == CsTokenType.Typeof || token.CsTokenType == CsTokenType.Sizeof || token.CsTokenType == CsTokenType.DefaultValue) { inTypeOfOrSizeOfOrDefault = true; } else if (inTypeOfOrSizeOfOrDefault && token.CsTokenType == CsTokenType.CloseParenthesis) { inTypeOfOrSizeOfOrDefault = false; } else if (!inTypeOfOrSizeOfOrDefault && token.CsTokenType == CsTokenType.OpenParenthesis) { openParenFound = true; } else if (!inTypeOfOrSizeOfOrDefault && openParenFound && potentialViolation == null && token.CsTokenType == CsTokenType.WhiteSpace) { } else if (!inTypeOfOrSizeOfOrDefault && openParenFound && potentialViolation == null && token is TypeToken) { typeFound = true; } else if (!inTypeOfOrSizeOfOrDefault && openParenFound && typeFound && potentialViolation == null && token.CsTokenType == CsTokenType.CloseParenthesis) { potentialViolation = token; } else if (!inTypeOfOrSizeOfOrDefault && potentialViolation != null && token.CsTokenType == CsTokenType.WhiteSpace) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(potentialViolation.Location.StartPoint.LineNumber, potentialViolation.Location.StartPoint.IndexOnLine + 1, potentialViolation.Location.EndPoint.LineNumber, potentialViolation.Location.EndPoint.IndexOnLine + 2)); openParenFound = false; typeFound = false; potentialViolation = null; } else { openParenFound = false; typeFound = false; potentialViolation = null; } } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { foreach (var token in csElement.Header.ChildTokens.Where(childToken => childToken.CsTokenType == CsTokenType.XmlHeaderLine && ((childToken.Text.Length > 3 && childToken.Text[3] != ' ') || (childToken.Text.Length > 4 && childToken.Text[4] == ' ')))) { var location = token.Location; yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(location.StartPoint.LineNumber, location.StartPoint.IndexOnLine + 1, location.EndPoint.LineNumber, location.EndPoint.IndexOnLine + 2)); } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { var token = csElement.Header.ChildTokens.Last(); if (token == null) { return Enumerable.Empty<StyleCopCodeIssue>(); } var location = token.Location; return new[] { new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(location.StartPoint.LineNumber, location.StartPoint.IndexOnLine + 1, location.EndPoint.LineNumber, location.EndPoint.IndexOnLine + 2)) }; }
public void AddViolationIssue(CheckCodeIssuesEventArgs ea, ISourceCode sourceCode, Violation violation) { var message = string.Format("{0}: {1}", violation.Rule.CheckId, violation.Message); var csElement = violation.Element as CsElement; if (csElement == null) { ea.AddSmell(new SourceRange(violation.Line, 1, violation.Line, sourceCode.LengthOfLine(violation.Line) + 1), message, violation, 10); return; } foreach (var styleCopCodeIssue in this.issueLocator.GetCodeIssues(sourceCode, filter => ea.GetEnumerable(ea.Scope, filter), violation, csElement)) { ea.AddIssue(styleCopCodeIssue.IssueType, styleCopCodeIssue.Range, message, violation); } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { foreach (var element in from x in enumerate(new ElementTypeFilter(orderableElements)) where x.FirstNameRange.Start.Line == violation.Line select x) { var nameRange = element.FirstNameRange; var sourceRange = new SourceRange(nameRange.Start.Line, nameRange.Start.Offset, nameRange.End.Line, nameRange.End.Offset); yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, sourceRange); } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { foreach (IElement element in from x in enumerate(new ElementTypeFilter(LanguageElementType.Attribute)) where x.FirstNameRange.Start.Line == violation.Line select x) { if (element.Name.Contains("SuppressMessage")) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, element.FirstNameRange); } } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { var locations = from token in csElement.ElementTokens where token.LineNumber == violation.Line && this.tokenTypes.Contains(token.CsTokenType) select token.Location; var firstToken = locations.FirstOrDefault(); var lastToken = locations.LastOrDefault(); if (firstToken != null && lastToken != null) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(firstToken.StartPoint.LineNumber, firstToken.StartPoint.IndexOnLine + 1, lastToken.EndPoint.LineNumber, lastToken.EndPoint.IndexOnLine + 2)); } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { foreach (var element in from x in enumerate(new ElementTypeFilter(LanguageElementType.MethodCall)) where x.FirstNameRange.Start.Line == violation.Line && x.Name == this.methodName select x) { MethodCall methodCall = (MethodCall)element.ToLanguageElement(); if (this.qualifyParameters(methodCall)) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, methodCall.Range); } } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { foreach (var method in from x in enumerate(new ElementTypeFilter(LanguageElementType.AnonymousMethodExpression)) let method = (DX.AnonymousMethodExpression)x.ToLanguageElement() where method.RecoveredRange.Start.Line == violation.Line && method.ParameterCount == 0 && !method.ParamOpenRange.IsEmpty && !method.ParamCloseRange.IsEmpty select method) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(method.RecoveredRange.Start.Line, method.RecoveredRange.Start.Offset, method.ParamCloseRange.End.Line, method.ParamCloseRange.End.Offset)); } }
public IEnumerable<StyleCopCodeIssue> GetCodeIssues( ISourceCode sourceCode, Func<ElementTypeFilter, IEnumerable<IElement>> enumerate, Violation violation, CsElement csElement) { foreach (ParentingStatement statement in enumerate(new ElementTypeFilter(new[] { LanguageElementType.If, LanguageElementType.While, LanguageElementType.Lock, LanguageElementType.For, LanguageElementType.ForEach, LanguageElementType.Do, LanguageElementType.UsingStatement })) .Select(element => element.ToLanguageElement())) { if (!statement.HasDelimitedBlock && statement.NodeCount == 1 && statement.BlockCodeRange.Start.Line == violation.Line && violation.Message.Contains(statement.GetKeyword())) { yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, statement.BlockCodeRange); } } }
// Expression = OpChainExpression private IParsingProduct ParseExpression(ISourceCode src) { return(ParseOperatorChainExp(src)); }
/// <summary> /// Tries to parse the expression specified by the given parsing source with <see cref="DefaultParsingOptions"/> as <see cref="ParsingOptions"/>. /// If successful, returns not <c>null</c> expression node. /// If compilation is failed sets the error and returns <c>null</c>. /// </summary> /// <param name="source">The source of extension.</param> /// <param name="src">The parsing source.</param> /// <returns>The not <c>null</c> expression node if successful; otherwise <c>null</c>.</returns> public static IParsingProduct TryParse(this IExpressionParser source, ISourceCode src) { return(source.TryParse(src, DefaultParsingOptions)); }
/// <inheritdoc /> public ParsedValue TryParse(ISourceCode src, string valueTypeId) { throw new NotImplementedException(); }
/// <inheritdoc /> public IExecutableExpressionNode Compile(ISourceCode source) { return((IExecutableExpressionNode)_parser.TryParse(source)); }
public Report(IReportOptions options, IEnviornmentVariables enviornmentVariables, ISourceCode sourceCode, ICoverage coverage) { _reportOptions = new Lazy <IReportOptions>(() => options); EnviornmentVariables = enviornmentVariables; SourceCode = sourceCode; Coverage = coverage; _reporter = new Lazy <string>(() => $"{Env}{Network}{CombinedCoverage}"); }
/// <inheritdoc /> public ParsedValue TryParse(ISourceCode src) { throw new NotImplementedException(); }
/// <inheritdoc /> IParsingProduct IGrammarProductsFactory.ParseValue(ISourceCode src) { return(ParseUnsignedNumber(src)); }
public static IParsingProduct TryAggregateParse(this IReadOnlyCollection <IExpressionParser> parsers, ISourceCode src, ParsingOptions options = DefaultParsingOptions) { using var ctx = src.GetFurtherContext(); var nodes = new IParsingProduct[parsers.Count]; var idx = 0; foreach (var parser in parsers) { var res = parser.TryParse(ctx, options); if (res == null) { return(null); } nodes[idx] = res; idx++; } ctx.Accept(); return(ctx.CreateExpressionForAcceptedFragment(FXB.ExpressionTypes.Concatenation, nodes)); }
public Yaml(ISourceCode sourceCode) { SourceCode = sourceCode; _fileName = new Lazy <string>(LoadFileName); }
// Value = ? value parsed by the IGrammarProductsFactory ? private IParsingProduct ParseValue(ISourceCode src) { return(_grammarProductsFactory.ParseValue(src)); }
public EmptyNode(ISourceCode src) : this(src.GetFurtherContext()) { }
public ScriptPackage(string id, string name, ISourceCode sourceCode) { Id = id; Name = name; SourceCode = sourceCode; }
public static IParsingProduct TryAggregateParse(this IEnumerable <IExpressionParser> source, ISourceCode src, ParsingOptions options = DefaultParsingOptions) { if (source is IReadOnlyCollection <IExpressionParser> collection) { return(TryAggregateParse(collection, src, options)); } List <IParsingProduct> nodes = null; using var ctx = src.GetFurtherContext(); foreach (var parser in source) { var res = parser.TryParse(src, options); if (res == null) { return(null); } nodes ??= new List <IParsingProduct>(); nodes.Add(res); } ctx.Accept(); return(ctx.CreateExpressionForAcceptedFragment(FXB.ExpressionTypes.Concatenation, nodes)); }