Ejemplo n.º 1
0
        private static void CheckForBooleanConstant(BinaryExpressionSyntax binaryExpression, ExpressionSyntax booleanContantExpression,
                                                    ErrorLocation errorLocation, SyntaxNodeAnalysisContext context, bool leftSide)
        {
            var expression = leftSide
                ? binaryExpression.Left
                : binaryExpression.Right;

            if (!EquivalenceChecker.AreEquivalent(expression.RemoveParentheses(), booleanContantExpression))
            {
                return;
            }

            Location location;

            switch (errorLocation)
            {
            case ErrorLocation.Normal:
                location = expression.GetLocation();
                break;

            case ErrorLocation.Extended:
                location = CalculateExtendedLocation(binaryExpression, leftSide);
                break;

            case ErrorLocation.Inverted:
                location = CalculateExtendedLocation(binaryExpression, !leftSide);
                break;

            default:
                location = null;
                break;
            }

            context.ReportDiagnostic(Diagnostic.Create(Rule, location));
        }
Ejemplo n.º 2
0
        protected void CheckForBooleanConstant(TBinaryExpression binaryExpression, IsBooleanLiteralKind isBooleanLiteralKind,
                                               ErrorLocation errorLocation, SyntaxNodeAnalysisContext context, bool isLeftSide)
        {
            var expression = isLeftSide
                ? RemoveParentheses(GetLeftNode(binaryExpression))
                : RemoveParentheses(GetRightNode(binaryExpression));

            if (!isBooleanLiteralKind(expression))
            {
                return;
            }

            context.ReportDiagnosticWhenActive(Diagnostic.Create(SupportedDiagnostics[0], GetLocation()));

            Location GetLocation()
            {
                switch (errorLocation)
                {
                case ErrorLocation.BoolLiteral:
                    return(expression.GetLocation());

                case ErrorLocation.BoolLiteralAndOperator:
                    return(CalculateExtendedLocation(binaryExpression, isLeftSide));

                case ErrorLocation.NonBoolLiteralExpression:
                    return(CalculateExtendedLocation(binaryExpression, !isLeftSide));

                default:
                    return(null);
                }
            }
        }
Ejemplo n.º 3
0
        public void LogError_WhenErrorHasNoExceptionAndLocation_LogsMessage()
        {
            var loggerFactory = TestLoggerFactory.Create();
            var logger        = loggerFactory.CreateLogger("Test");
            var errorCode     = ErrorCode.ExternalProcessError;

            const string stepName = "TestStep";

            var location = new ErrorLocation(
                stepName,
                new TextLocation("Text", new TextPosition(1, 1, 1), new TextPosition(2, 2, 2))
                );

            var expected =
                $"{errorCode.GetFormattedMessage("error")} (Step: {stepName} {location.TextLocation})";

            var error = new SingleError(location, errorCode, "error");

            logger.LogError(error);

            var logMessages = loggerFactory.Sink.LogEntries.ToList();

            Assert.Null(logMessages[0].Exception);

            Assert.Contains(
                logMessages,
                l => l.LogLevel == LogLevel.Error && l.Message !.Equals(expected)
                );
        }
Ejemplo n.º 4
0
        public void LogError_WhenErrorHasExceptionAndLocation_LogsMessage()
        {
            var loggerFactory = TestLoggerFactory.Create();
            var logger        = loggerFactory.CreateLogger("Test");

            const string stepName = "TestStep";

            var location = new ErrorLocation(
                stepName,
                new TextLocation("Text", new TextPosition(1, 1, 1), new TextPosition(2, 2, 2))
                );

            var expected = $"Test (Step: {stepName} {location.TextLocation})";

            var error = new SingleError(location, new Exception("Test"), ErrorCode.UnexpectedEnumValue);

            logger.LogError(error);

            var logMessages = loggerFactory.Sink.LogEntries.ToList();

            Assert.NotNull(logMessages[0].Exception);

            //Test (Step: TestStep Line: 1, Col: 1, Idx: 1 - Line: 2, Col: 2, Idx: 2 Text: Text)
            Assert.Contains(
                logMessages,
                l => l.LogLevel == LogLevel.Error && l.Message !.Equals(expected)
                );
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Try to Clone this context with additional set variables.
        /// </summary>
        public Result <TypeResolver, IError> TryCloneWithScopedStep(
            VariableName vn,
            TypeReference typeReference,
            TypeReference expectedScopedStepOutputType,
            IFreezableStep scopedStep,
            ErrorLocation errorLocation)
        {
            var newTypeResolver = Copy();

            var r1 = newTypeResolver.TryAddType(vn, typeReference);

            if (r1.IsFailure)
            {
                return(r1.ConvertFailure <TypeResolver>().MapError(x => x.WithLocation(errorLocation)));
            }

            var r2 = newTypeResolver.TryAddTypeHierarchy(expectedScopedStepOutputType, scopedStep);

            if (r2.IsFailure)
            {
                return(r2.ConvertFailure <TypeResolver>());
            }

            return(newTypeResolver);
        }
Ejemplo n.º 6
0
    //Tips表格信提取
    public TipsMotion TipsInfoGet(DataRow tips_row, string id, ref bool is_right)
    {
        _tipsMotion.TipsString = (string)tips_row[1].ToString();
        if (_tipsMotion.TipsString == "")
        {
            is_right = false;
            if (MotionPara.isEditor)
            {
                Debug.LogError(ErrorLocation.Locate("TIPS", "CONTENT", id) + ",Tips文本信息为空!");
            }
            return(_tipsMotion);
        }
        //处理文本播放时长
        _tipsMotion.StandardTime = GetPlayTime(_tipsMotion.TipsString);
        //TODO:语音播放时长要与播放速率匹配,调节起来与一般调速不一样,还需要再调节
        _tipsMotion.TipsTimeControl();
        //显示位置处理
        DisplayPos((string)tips_row[2].ToString(), id, ref is_right);
        //是否为标题判断
        _tipsMotion.IsTitle = BoolenJudge((string)tips_row[3].ToString(), id, "TITLE", ref is_right);
        //是否可移动判断
        _tipsMotion.IsMoveable = BoolenJudge((string)tips_row[4].ToString(), id, "MOVE", ref is_right);
        //是否同步运动判断,暂时取消,同步运动放到Motion选项中
        //_tipsMotion.IsSynchronized = BoolenJudge((string)tips_row[5].ToString(), id, "SYNCHRONIZE", ref is_right);

        return(_tipsMotion);
    }
Ejemplo n.º 7
0
 internal void Inject(ErrorLocation location)
 {
     if (this.locations.Contains(location))
     {
         throw this.error;
     }
 }
Ejemplo n.º 8
0
 public ValidationErrorBase(ITextRange range, string message, ErrorLocation location, ErrorSeverity severity) :
     base(range)
 {
     Message = message;
     Severity = severity;
     Location = location;
 }
Ejemplo n.º 9
0
        public void ToString_ReturnsMessageAndLocation()
        {
            var location = new ErrorLocation("test");
            var error    = new SingleError(location, ErrorCode.StepDoesNotExist, "test");

            Assert.Equal($"{error.Message} in {location.AsString()}", error.ToString());
        }
Ejemplo n.º 10
0
        public ExecutionFailureInfo(
            string type,
            string message,
            ExecutionFailureInfo cause,
            IEnumerable <ExecutionFailureInfo> suppressed,
            IEnumerable <string> stack,
            ErrorLocation errorLocation,
            ErrorCode errorCode,
            HostAddress remoteHost
            )
        {
            if (String.IsNullOrEmpty(type))
            {
                throw new ArgumentNullException("type", "The type cannot be null or empty.");
            }

            this.Type          = type;
            this.Message       = message;
            this.Cause         = cause;
            this.Suppressed    = suppressed ?? throw new ArgumentNullException("suppressed", "Suppressed cannot be null.");
            this.Stack         = stack ?? throw new ArgumentNullException("stack", "Stack cannot be null.");
            this.ErrorLocation = errorLocation;
            this.ErrorCode     = errorCode;
            this.RemoteHost    = remoteHost;
        }
Ejemplo n.º 11
0
 public ValidationErrorBase(ITextRange range, string message, ErrorLocation location, ErrorSeverity severity) :
     base(range)
 {
     Message  = message;
     Severity = severity;
     Location = location;
 }
Ejemplo n.º 12
0
 private void Init(ErrorLocation location, string message, ErrorType type, ErrorLevel level)
 {
     Location = location;
     Message  = message;
     Type     = type;
     Level    = level;
 }
Ejemplo n.º 13
0
 public ValidationErrorBase(ITextRange range, string message, ErrorLocation location, ErrorSeverity severity, int snapshotVersion) :
     base(range)
 {
     Message         = message;
     Severity        = severity;
     Location        = location;
     SnapshotVersion = snapshotVersion;
 }
Ejemplo n.º 14
0
 internal ErrorInjector(ErrorLocation errorAt, Exception error)
 {
     this.locations = new List <ErrorLocation>()
     {
         errorAt
     };
     this.error = error;
 }
Ejemplo n.º 15
0
 private static bool ReportError(IRuntimeCodeValidationErrorSink errorSink, ErrorLocation errorLocation, string errorMessage)
 {
     if (errorLocation == null)
     {
         return(RuntimeCompiledMethod.ReportError(errorSink, SourceLocation.Invalid, SourceLocation.Invalid, errorMessage));
     }
     else
     {
         return(RuntimeCompiledMethod.ReportError(errorSink, errorLocation.Start, errorLocation.End, errorMessage));
     }
 }
Ejemplo n.º 16
0
        private string LocationPath(ErrorLocation location)
        {
            switch (location)
            {
            case ErrorLocation.Source:
                return(this.SourceFile);

            case ErrorLocation.Transform:
                return(this.TransformFile);

            default:
                return(null);
            }
        }
Ejemplo n.º 17
0
    //PROGRAM表格信息提取
    public bool ProgramInfoGet(DataRow program_row, string id, DataTable group_table, IList <IMotion> _motionList,
                               IList <IList <IMotion> > _complexMotionList)
    {
        //提取Program ID
        string programID = ((string)program_row[2].ToString()).ToUpper();

        //检验ID是否正确
        if (MotionPara.programMotionID.Contains(programID))
        {
            if (programID == "TONGBANG")
            {
                //铜棒敲击
                return(CopperHit(program_row, id, group_table, _motionList, _complexMotionList));
            }
            else if (programID == "BAIFANG")
            {
                //物体摆放
                return(ObjPut(program_row, id, group_table, _motionList, _complexMotionList));
            }
            else if (programID == "NINGSONG")
            {
                //螺钉拧松拧紧
                return(NingSong(program_row, id, group_table, _motionList, _complexMotionList));
            }
            else if (programID == "NINGCHU")
            {
                //螺钉拧进拧出
                return(NingChu(program_row, id, group_table, _motionList, _complexMotionList));
            }
            else
            {
                //Program ID错误
                if (MotionPara.isEditor)
                {
                    Debug.LogError(ErrorLocation.Locate("PROGRAM", "PROGRAMID", id) + "," + programID +
                                   ":此ProgramID暂未定义,请联系相关程序猿,请确认!");
                }
                return(false);
            }
        }
        else
        {
            //Program ID错误
            if (MotionPara.isEditor)
            {
                Debug.LogError(ErrorLocation.Locate("PROGRAM", "PROGRAMID", id) + "," + programID + ":此ProgramID不存在,请确认!");
            }
            return(false);
        }
    }
Ejemplo n.º 18
0
        private static ITextRange GetLocationRange(IAstNode node, RToken token, ErrorLocation location)
        {
            ITextRange itemRange = node != null ? node : token as ITextRange;

            //switch (location)
            //{
            //    case ErrorLocation.BeforeToken:
            //        return new TextRange(Math.Max(0, itemRange.Start-1), 1);

            //    case ErrorLocation.AfterToken:
            //        return new TextRange(itemRange.End, 1);
            //}

            return itemRange;
        }
Ejemplo n.º 19
0
        private static ITextRange GetLocationRange(IAstNode node, RToken token, ErrorLocation location)
        {
            ITextRange itemRange = node != null ? node : token as ITextRange;

            //switch (location)
            //{
            //    case ErrorLocation.BeforeToken:
            //        return new TextRange(Math.Max(0, itemRange.Start-1), 1);

            //    case ErrorLocation.AfterToken:
            //        return new TextRange(itemRange.End, 1);
            //}

            return(itemRange);
        }
Ejemplo n.º 20
0
        public void ToDelimitedString_WithAllProperties_ReturnsCorrectlySequencedFields()
        {
            IType hl7Type = new ErrorLocation
            {
                SegmentId          = "1",
                SegmentSequence    = 2,
                FieldPosition      = 3,
                FieldRepetition    = 4,
                ComponentNumber    = 5,
                SubComponentNumber = 6
            };

            string expected = "1^2^3^4^5^6";
            string actual   = hl7Type.ToDelimitedString();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 21
0
        public void FromDelimitedString_WithAllProperties_ReturnsCorrectlyInitializedFields()
        {
            IType expected = new ErrorLocation
            {
                SegmentId          = "1",
                SegmentSequence    = 2,
                FieldPosition      = 3,
                FieldRepetition    = 4,
                ComponentNumber    = 5,
                SubComponentNumber = 6
            };

            IType actual = new ErrorLocation();

            actual.FromDelimitedString("1^2^3^4^5^6");

            expected.Should().BeEquivalentTo(actual);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// ログの出力
        /// </summary>
        /// <param name="value">エラー表現文字列</param>
        /// <param name="location">発生場所</param>
        public void ErrorOutput(String value, ErrorLocation location)
        {
            String errorlog = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss === ");

            errorlog += ErrorLocations[(int)location];
            errorlog += value + Environment.NewLine;
            if (!System.IO.File.Exists(path))
            {
                System.IO.File.Create(path).Close();
            }
            string[] lines = System.IO.File.ReadAllLines(path);
            if (lines.Length >= LogLineLength)
            {
                lines = lines.Skip(1).ToArray();
                System.IO.File.WriteAllLines(path, lines);
            }
            System.IO.File.AppendAllText(path, errorlog);
        }
Ejemplo n.º 23
0
        public void WithLocation_AddsLocationToErrors()
        {
            var errorBuilders = new[]
            {
                new ErrorBuilder(ErrorCode.DirectoryNotFound, "directory"),
                new ErrorBuilder(ErrorCode.MissingContext, "context")
            };

            var eb = new ErrorBuilderList(errorBuilders);

            var el = new ErrorLocation("test");

            var errors = eb.WithLocation(el).GetAllErrors();

            foreach (var err in errors)
            {
                Assert.Equal(el, err.Location);
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Logs a warning according to the line info
        /// </summary>
        /// <param name="message">The warning message</param>
        /// <param name="location">The file that caused the warning</param>
        /// <param name="lineInfo">The information of the line that caused the warning</param>
        internal void LogWarning(string message, ErrorLocation location, IJsonLineInfo lineInfo)
        {
            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (this.externalLogger != null)
            {
                if (lineInfo != null && lineInfo.HasLineInfo())
                {
                    this.externalLogger.LogWarning(message, this.LocationPath(location), lineInfo.LineNumber, lineInfo.LinePosition);
                }
                else
                {
                    this.externalLogger.LogWarning(message, this.LocationPath(location));
                }
            }
        }
Ejemplo n.º 25
0
 //标题和移动标志位判断
 private bool BoolenJudge(string bool_str, string id, string grid_type, ref bool is_right)
 {
     if (bool_str == "")
     {
         return(false);
     }
     else
     {
         bool_str = bool_str.ToUpper();
         if (bool_str == "TRUE")
         {
             return(true);
         }
         else if (bool_str == "FALSE")
         {
             return(false);
         }
         else
         {
             is_right = false;
             if (grid_type.ToUpper() == "TITLE")
             {
                 Debug.LogWarning(ErrorLocation.Locate("TIPS", "TITLE", id) + ", 标题填写错误,默认为非标题");
                 return(false);
             }
             else if (grid_type.ToUpper() == "MOVE")
             {
                 Debug.LogWarning(ErrorLocation.Locate("TIPS", "MOVE", id) + ", 移动选项填写错误,默认为非移动");
                 return(false);
             }
             else
             {
                 Debug.LogWarning(ErrorLocation.Locate("TIPS", "SYNCHRONIZE", id) + ", 同步运动选项填写错误,默认为同步");
                 return(true);
             }
         }
     }
 }
Ejemplo n.º 26
0
    //Excel表格信息提取总入口
    public bool ExcelAdd(DataRow excel_row, string id, DataTable group_table)
    {
        bool isRight = true;
        //Motion Type
        int motionInt = IntConversion(excel_row[3].ToString(), ref isRight);

        if (!isRight)
        {
            if (MotionPara.isEditor)
            {
                Debug.LogError(ErrorLocation.Locate("EXCEL", "MOTIONTYPE", id) + ",运动方式填写错误!");
            }
            return(false);
        }
        ExcelInfoManager excelMana = new ExcelInfoManager();

        if (motionInt == 1 || motionInt == 2 || motionInt == 3 || motionInt == 4 || motionInt == 5 || motionInt == 6)
        {          //运动符合要求
            BasicMotion excelMotion = excelMana.SimpleMotion(excel_row, id, group_table, ref isRight, motionInt);
            if (!isRight)
            {
                return(false);
            }
            _motionList.Add(excelMotion);
        }
        else
        {          //报错
            if (MotionPara.isEditor)
            {
                Debug.LogError(ErrorLocation.Locate("EXCEL", "MOTIONTYPE", id) + ",运动方式填写错误,暂时未包含该种运动方式!");
            }
            return(false);
        }
        simpleID.Add(simpleID.Count, id);
        return(true);
    }
Ejemplo n.º 27
0
        /// <inheritdoc/>
        public string ToDelimitedString()
        {
            CultureInfo culture = CultureInfo.CurrentCulture;

            return(string.Format(
                       culture,
                       StringHelper.StringFormatSequence(0, 13, Configuration.FieldSeparator),
                       Id,
                       ErrorCodeAndLocation,
                       ErrorLocation != null ? string.Join(Configuration.FieldRepeatSeparator, ErrorLocation.Select(x => x.ToDelimitedString())) : null,
                       Hl7ErrorCode?.ToDelimitedString(),
                       Severity,
                       ApplicationErrorCode?.ToDelimitedString(),
                       ApplicationErrorParameter != null ? string.Join(Configuration.FieldRepeatSeparator, ApplicationErrorParameter) : null,
                       DiagnosticInformation?.ToDelimitedString(),
                       UserMessage?.ToDelimitedString(),
                       InformPersonIndicator != null ? string.Join(Configuration.FieldRepeatSeparator, InformPersonIndicator.Select(x => x.ToDelimitedString())) : null,
                       OverrideType?.ToDelimitedString(),
                       OverrideReasonCode != null ? string.Join(Configuration.FieldRepeatSeparator, OverrideReasonCode.Select(x => x.ToDelimitedString())) : null,
                       HelpDeskContactPoint != null ? string.Join(Configuration.FieldRepeatSeparator, HelpDeskContactPoint.Select(x => x.ToDelimitedString())) : null
                       ).TrimEnd(Configuration.FieldSeparator.ToCharArray()));
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Error"/> class.
 /// </summary>
 /// <param name="source">The error location.</param>
 public Error(ISource source)
 {
     Location = new ErrorLocation(source);
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Error"/> class.
 /// </summary>
 /// <param name="location">The error location.</param>
 public Error(ErrorLocation location)
 {
     Location = location;
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Constructs validation warning for an element at a specified location.
 /// </summary>
 public ValidationWarning(ITextRange range, string message, ErrorLocation location) :
      base(range, message, location, ErrorSeverity.Warning)
 {
 }
Ejemplo n.º 31
0
 public ParseError(ParseErrorType errorType, ErrorLocation location, ITextRange range) :
     base(range) {
     this.ErrorType = errorType;
     this.Location = location;
 }
Ejemplo n.º 32
0
 public ValidationMessage(ITextRange range, string message, ErrorLocation location) :
     base(range, message, location, ErrorSeverity.Informational)
 {
 }
 public void Add(ITextRange range, string message, ErrorLocation location, int snapshotVersion)
 {
     Add(new ValidationError(range, message, location, snapshotVersion));
 }
Ejemplo n.º 34
0
 public ValidationError(ITextRange range, string message, ErrorLocation location, int snapshotVersion) :
     base(range, message, location, ErrorSeverity.Error, snapshotVersion)
 {
 }
Ejemplo n.º 35
0
 /// <summary>
 /// Constructs validation error for an element at a specified location.
 /// </summary>
 public ValidationError(IAstNode node, string message, ErrorLocation location) :
     base(node, message, location, ErrorSeverity.Error)
 {
 }
Ejemplo n.º 36
0
        private static void CheckForBooleanConstant(BinaryExpressionSyntax binaryExpression, bool leftSide,
            ExpressionSyntax booleanContantExpression, ErrorLocation errorLocation, SyntaxNodeAnalysisContext c)
        {
            var expression = leftSide
                ? binaryExpression.Left
                : binaryExpression.Right;

            if (EquivalenceChecker.AreEquivalent(expression, booleanContantExpression))
            {
                Location location = null;
                switch (errorLocation)
                {
                    case ErrorLocation.Normal:
                        location = expression.GetLocation();
                        break;
                    case ErrorLocation.Extended:
                        location = CalculateExtendedLocation(binaryExpression, leftSide);
                        break;
                    case ErrorLocation.Inverted:
                        location = CalculateExtendedLocation(binaryExpression, !leftSide);
                        break;
                }

                c.ReportDiagnostic(Diagnostic.Create(Rule, location));
            }
        }