private void frmMain_Load(object sender, EventArgs e)
 {
     try
     {
         //login
         UserApiClient _userApiClient = new UserApiClient(Core.Client);
         //user
         RoleApiClient apiClientRole = new RoleApiClient(Core.Client);
         _userController = new UserController(_userApiClient, apiClientRole);
         //
         timer1.Enabled          = true;
         timerCheckLogin.Enabled = true;
         MasterList.Innit(Core.User, Core.Path);
         if (Core.IsLogin)
         {
             lbUser.Text = Core.User;
         }
         else
         {
             lbUser.Text = "no login";
             if (!_userController.IsLogin())
             {
                 Login();
             }
         }
     }
     catch (Exception)
     {
     }
 }
Beispiel #2
0
        private void RefreshServers()
        {
            RefreshBtn.Enabled = false;
            var masterList = new MasterList("http://185.5.97.181:8000/master/public_servers");

            if (masterList.ListGot)
            {
                networkList = new NetworkList();
                if (networkList.InitSocket())
                {
                    Application.UseWaitCursor = true;
                    networkList.Start();
                    foreach (var server in masterList.Servers)
                    {
                        networkList.ServerData(server);
                    }
                    timerRefresh.Start();
                }
                else
                {
                    RefreshBtn.Enabled = true;
                }
            }
            else
            {
                RefreshBtn.Enabled = true;
            }
        }
Beispiel #3
0
        void MasterExecSave()
        {
            int i = -1;

            _dataService.UpdateLightZone(MasterCurrentObject, (updatedCount, error) =>
            {
                if (error != null)
                {
                    return;
                }                              // Report error here
                i = updatedCount;
            });

            MasterObjectButtonsVisibility = Visibility.Collapsed;
            MasterListCurtainVisibility   = Visibility.Collapsed;
            DetailListCurtainVisibility   = Visibility.Collapsed;
            ProxyListCurtainVisibility    = Visibility.Collapsed;


            if (MasterAddMode)
            {
                MasterList.Add(MasterCurrentObject);
                MasterSelectedItem = MasterCurrentObject;
            }
            //    if (MasterEditMode) //in EditMode MasterSelectedItem always not null
            //    {
            //        if (!partitionChanged)
            //        {
            //            MasterList[msix] = MasterCurrentObject;
            //            //MasterSelectedItem.RaiseIsLinkedChanged();
            //            MasterSelectedItem = MasterCurrentObject;
            //            //if (savedDsix != -1)
            //            //    DetailSelectedItem = DetailList[savedDsix];
            //        }
            //        else
            //        {
            //            MasterList.Remove(MasterSelectedItem);
            //            //DetailContentVisibility = Visibility.Hidden;
            //            partitionChanged = false;
            //        }
            //    }

            MasterAddMode  = false;
            MasterEditMode = false;
            MasterRemoveCmd.RaiseCanExecuteChanged();
            MasterAddCmd.RaiseCanExecuteChanged();

            //    //if (DetailSelectedItem != null)
            //    //{
            //    //    // при выполнении Save происходит замена .net объекта в MasterList
            //    //    // необходимо восстановить Visual State
            //    //    LightElement letmp = MasterSelectedItem;
            //    //    ControlChannel tmp = DetailSelectedItem;
            //    //    DetailSelectedItem = null;
            //    //    DetailSelectedItem = tmp;
            //    //    MasterSelectedItem = letmp;
            //    //}
            //}
            MessengerInstance.Send("", AppContext.UnBlockUIMsg);
        }
        private void UpdateMastets()
        {
            var selectedMaster = SelectedMaster?.Id;

            MasterList.Clear();
            if (_showAllMasters)
            {
                foreach (var master in _requestService.GetMasters(null))
                {
                    MasterList.Add(master);
                }
                SelectedMaster = MasterList.FirstOrDefault(m => m.Id == selectedMaster);
            }
            else
            {
                if (_selectedHouseId.HasValue)
                {
                    foreach (var master in _requestService.GetWorkersByHouseAndService(_selectedHouseId.Value, SelectedParentService.Id))
                    {
                        MasterList.Add(master);
                    }
                    SelectedMaster = MasterList.FirstOrDefault();
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Adds recurring appointments.
        /// </summary>
        /// <param name="item">The recurring appointment definition.</param>
        /// <param name="dateLimit">A date limit at which the recurring appointments end.</param>
        /// <remarks> The date limit may be dateTime.MaxValue which indicates no limit.</remarks>
        public void AddNewRecurringAppointments(IRecurringScheduleAppointment item, DateTime dateLimit)
        {
            string[] rulesArray = item.RecurrenceRule.Split(new char[] { RecurrenceSupport.RuleDelimiter });
            DateTime baseDate   = DateTime.Parse(rulesArray[0]);
            DateTime date       = rulesArray[1].Length > 0 ? DateTime.Parse(rulesArray[1]) : dateLimit;

            if (item.DateList == null)
            { //if null, then need to create it.
                CreateDateListFromItem(item);
                //conditionally set terminal date if present in rule.
                if (rulesArray[1].Length > 0)
                {
                    item.DateList.TerminalDate = date;
                }
            }
            item.DateList.IsValidRecurrence(date); //this populates DateList up through date
            bool needToSort = false;

            foreach (DateTime dt in item.DateList)
            {   //now go through and add appointments that match the datelist entries
                if (dt >= item.DateList.BaseDate && dt <= item.DateList.TerminalDate)
                {
                    AddAppointmentFromItem(item, dt);
                    needToSort = true;
                }
            }
            if (needToSort)
            {
                ResetBaseDate(item);
                MasterList.SortStartTime();
            }
        }
Beispiel #6
0
        private Activity DequeueActivity(bool firstRun)
        {
            // Load the available activities into the queue if the queue is empty
            // or on first run (repeat session situation)
            if (!ExecutionQueue.Any() || firstRun)
            {
                // Add activities based on the execution count which describes
                // the overall distribution or weight of different activities
                // being executed.
                List <Activity> activities = new List <Activity>();
                foreach (var item in MasterList.OrderBy(n => n.ExecutionOrder))
                {
                    activities.Add(item);
                }

                if (Randomize)
                {
                    // If randomize was set for this collection of activities, then shuffle them
                    activities.Shuffle();
                    TraceFactory.Logger.Debug("Activities were shuffled");
                }

                foreach (Activity activity in activities)
                {
                    // Then enqueue each activity onto the execution queue.
                    ExecutionQueue.Enqueue(activity);
                }
            }

            _currentActivityExecutionCount = 1;

            return(ExecutionQueue.Dequeue());
        }
Beispiel #7
0
 /// <summary>
 /// Add package info without change Dirty state of itself
 /// </summary>
 /// <param name="info"></param>
 public void AddInSilence(PackageInfo info)
 {
     if (!Exists(info))
     {
         MasterList.Add(info);
     }
 }
Beispiel #8
0
 public ProgramUI(IConsole consoleForAllReadsAndWrites)
 {
     _console              = consoleForAllReadsAndWrites;
     MasterList            = new MasterList();
     PastCustomerRepo      = new PastCustomerRepo();
     PotentialCustomerRepo = new PotentialCustomerRepo();
     PresentCustomerRepo   = new PresentCustomerRepo();
 }
Beispiel #9
0
        /// <summary>
        /// Initializes a new instance of the CsDocument class.
        /// </summary>
        /// <param name="sourceCode">
        /// The source code that this document represents.
        /// </param>
        /// <param name="parser">
        /// The parser that is creating this object.
        /// </param>
        internal CsDocument(SourceCode sourceCode, CsParser parser)
            : this(sourceCode, parser, null)
        {
            Param.AssertNotNull(sourceCode, "sourceCode");
            Param.AssertNotNull(parser, "parser");

            this.tokens = new MasterList <CsToken>();
        }
Beispiel #10
0
 /// <summary>
 /// Add package info and set Dirty state to True
 /// </summary>
 /// <param name="info"></param>
 public void Add(PackageInfo info)
 {
     if (!Exists(info))
     {
         MasterList.Add(info);
         IsDirty = true;
     }
 }
Beispiel #11
0
 public void Remove(PackageInfo info)
 {
     if (Exists(info))
     {
         MasterList.Remove(info);
         IsDirty = true;
     }
 }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (!isValidView)
            {
                MessageBox.Show("조회 후 처리해주세요.", "Error");
                return;
            }

            if (this.listDataTypes.SelectedIndex < 0)
            {
                MessageBox.Show("자료 종류를 선택하지 않았습니다.", "Error");
                return;
            }

            if (this.listDataTimes.SelectedIndex < 0)
            {
                MessageBox.Show("시간을 선택하지 않았습니다.", "Error");
                return;
            }

            // 자료 종류
            MasterList selectedMaster = (MasterList)this.listDataTypes.SelectedItem;
            string     dataTypeName   = selectedMaster.name;
            int        dataTypeId     = selectedMaster.id;

            // 자료 시간
            string dataTime = (string)this.listDataTimes.SelectedValue;

            // 자료일자
            DateTime d        = this.datePicker.Value;
            string   dataDate = d.ToString("yyyyMMdd");

            Console.WriteLine("자료종류: " + dataTypeId + ":" + dataTypeName);
            Console.WriteLine("자료일자: " + dataDate);
            Console.WriteLine("자료시간: " + dataTime);

            // 확인
            DialogResult result = MessageBox.Show("자료명: " + dataTypeName + "\n자료일자: " + dataDate + "\n자료시간: " + dataTime +
                                                  "\n\n삭제하시겠습니까? 삭제는 되돌릴 수 없습니다.", "주의", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result != DialogResult.Yes)
            {
                return;
            }

            // 삭제요청
            // 등록URL: data/<자료종류>/<자료일자>/<자료시간>
            string         resource_value = dataTypeId + "/" + dataDate + "/" + dataTime;
            HttpRestClient client         = new HttpRestClient(HttpRestClient.REST_METHOD_DELETE, "data/" + resource_value);

            if (!client.doWorkDialog())
            {
                client.showErrorDialog();
                return;
            }

            MessageBox.Show("삭제요청이 처리되었습니다.", "완료");
        }
Beispiel #13
0
 /// <summary>
 /// Initializes a new instance of the GenericType class.
 /// </summary>
 /// <param name="childTokens">
 /// The list of child tokens that form the generic token.
 /// </param>
 /// <param name="location">
 /// The location of the generic in the code.
 /// </param>
 /// <param name="parent">
 /// The parent of the token.
 /// </param>
 /// <param name="generated">
 /// True if the token is inside of a block of generated code.
 /// </param>
 internal GenericType(MasterList <CsToken> childTokens, CodeLocation location, Reference <ICodePart> parent, bool generated)
     : base(childTokens, location, parent, CsTokenClass.GenericType, generated)
 {
     Param.AssertNotNull(childTokens, "childTokens");
     Param.AssertGreaterThanOrEqualTo(childTokens.Count, 3, "childTokens");
     Param.AssertNotNull(location, "location");
     Param.AssertNotNull(parent, "parent");
     Param.Ignore(generated);
 }
 /// <summary>
 /// Initializes a new instance of the GenericType class.
 /// </summary>
 /// <param name="childTokens">
 /// The list of child tokens that form the generic token.
 /// </param>
 /// <param name="location">
 /// The location of the generic in the code.
 /// </param>
 /// <param name="parent">
 /// The parent of the token.
 /// </param>
 /// <param name="generated">
 /// True if the token is inside of a block of generated code.
 /// </param>
 internal GenericType(MasterList<CsToken> childTokens, CodeLocation location, Reference<ICodePart> parent, bool generated)
     : base(childTokens, location, parent, CsTokenClass.GenericType, generated)
 {
     Param.AssertNotNull(childTokens, "childTokens");
     Param.AssertGreaterThanOrEqualTo(childTokens.Count, 3, "childTokens");
     Param.AssertNotNull(location, "location");
     Param.AssertNotNull(parent, "parent");
     Param.Ignore(generated);
 }
Beispiel #15
0
        /// <summary>
        /// Initializes a new instance of the TypeToken class.
        /// </summary>
        /// <param name="childTokens">
        /// The list of child tokens that form the token.
        /// </param>
        /// <param name="location">
        /// The location of the token in the code.
        /// </param>
        /// <param name="parent">
        /// The parent of the token.
        /// </param>
        /// <param name="generated">
        /// True if the token is inside of a block of generated code.
        /// </param>
        internal TypeToken(MasterList <CsToken> childTokens, CodeLocation location, Reference <ICodePart> parent, bool generated)
            : base(CsTokenType.Other, CsTokenClass.Type, location, parent, generated)
        {
            Param.AssertNotNull(childTokens, "childTokens");
            Param.AssertNotNull(location, "location");
            Param.AssertNotNull(parent, "parent");
            Param.Ignore(generated);

            this.childTokens = childTokens;
        }
        /// <summary>
        /// Initializes a new instance of the ConstructorConstraint class.
        /// </summary>
        /// <param name="childTokens">
        /// The list of child tokens that form the token.
        /// </param>
        /// <param name="location">
        /// The location of the token in the code.
        /// </param>
        /// <param name="parent">
        /// The parent of the token.
        /// </param>
        /// <param name="generated">
        /// True if the token is inside of a block of generated code.
        /// </param>
        internal ConstructorConstraint(MasterList<CsToken> childTokens, CodeLocation location, Reference<ICodePart> parent, bool generated)
            : base(CsTokenType.Other, CsTokenClass.ConstructorConstraint, location, parent, generated)
        {
            Param.AssertNotNull(childTokens, "childTokens");
            Param.AssertNotNull(location, "location");
            Param.AssertNotNull(parent, "parent");
            Param.Ignore(generated);

            this.childTokens = childTokens;
        }
Beispiel #17
0
 void MasterExecRemove()
 {
     //_dataService.DeleteLightElement(MasterSelectedItem, (data, error) =>
     //    {
     //        if (error != null) { return; } // Report error here
     //        int updateCount = data;
     //    });
     MasterList.Remove(MasterSelectedItem);
     MasterSelectedItem = null;
 }
Beispiel #18
0
        public void RemoveBy(int fid)
        {
            var pi = SelectBy(fid);

            if (pi != null)
            {
                MasterList.Remove(pi);
                IsDirty = true;
            }
        }
Beispiel #19
0
        /// <summary>
        /// Initializes a new instance of the CsDocument class.
        /// </summary>
        /// <param name="sourceCode">
        /// The source code that this document represents.
        /// </param>
        /// <param name="parser">
        /// The parser that is creating this object.
        /// </param>
        /// <param name="tokens">
        /// The tokens in the document.
        /// </param>
        internal CsDocument(SourceCode sourceCode, CsParser parser, MasterList <CsToken> tokens)
            : base(sourceCode)
        {
            Param.AssertNotNull(sourceCode, "sourceCode");
            Param.AssertNotNull(parser, "parser");
            Param.Ignore(tokens);

            this.parser = parser;
            this.tokens = tokens;
        }
Beispiel #20
0
        public async Task <IActionResult> Create([Bind("MasterListId,Name,Active")] MasterList masterList)
        {
            if (ModelState.IsValid)
            {
                _context.Add(masterList);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(masterList));
        }
 private void CheckSpacing(MasterList<CsToken> tokens, bool v, object p)
 {
     for (Node<CsToken> tokenNode = tokens.First; tokenNode != null; tokenNode = tokenNode.Next)
     {
         if (tokenNode.Value.CsTokenClass == CsTokenClass.Whitespace &&
             tokenNode.Value.Text.Contains(" "))
         {
             this.Violate(tokenNode.Value);
         }
     }
 }
 private void CheckSpacing(MasterList<CsToken> tokens, bool v, object p)
 {
     for (Node<CsToken> tokenNode = tokens.First; tokenNode != null; tokenNode = tokenNode.Next)
     {
         if ((tokenNode.Next == null || tokenNode.Next.Value.CsTokenType == CsTokenType.EndOfLine) &&
             tokenNode.Value.CsTokenClass == CsTokenClass.Whitespace)
         {
             this.Violate(tokenNode.Value);
         }
     }
 }
Beispiel #23
0
 public string ReturnError()
 {
     if (MasterList.Contains(MasterWord))
     {
         return("Occurances of your keyword in the sentence:");
     }
     else
     {
         return("The sentence does not contain your keyword. Idiot.");
     }
 }
Beispiel #24
0
        public static void DamageCard(int sId, int value)
        {
            Card target = MasterList.Find(x => x.ServerId == sId);

            if (target == null)
            {
                throw new CardNotFoundException();
            }

            target.Damage(value);
        }
Beispiel #25
0
        private void CheckSpacing(MasterList <CsToken> tokens)
        {
            Param.AssertNotNull(tokens, "tokens");

            foreach (var token in tokens)
            {
                if (this.Cancel)
                {
                    break;
                }

                if (token.Generated)
                {
                    continue;
                }

                switch (token.CsTokenType)
                {
                case CsTokenType.WhiteSpace:
                    this.CheckWhitespace(token as Whitespace);
                    break;

                case CsTokenType.XmlHeader:
                    XmlHeader header = (XmlHeader)token;
                    foreach (var xmlChild in header.ChildTokens)
                    {
                        this.CheckTabsInComment(xmlChild);
                    }
                    break;

                case CsTokenType.SingleLineComment:
                case CsTokenType.MultiLineComment:
                    this.CheckTabsInComment(token);
                    break;
                }

                switch (token.CsTokenClass)
                {
                case CsTokenClass.ConstructorConstraint:
                    this.CheckSpacing(((ConstructorConstraint)token).ChildTokens);
                    break;

                case CsTokenClass.GenericType:
                    this.CheckGenericSpacing((GenericType)token);
                    this.CheckSpacing(((TypeToken)token).ChildTokens);
                    break;

                case CsTokenClass.Type:
                    this.CheckSpacing(((TypeToken)token).ChildTokens);
                    break;
                }
            }
        }
Beispiel #26
0
        //AttentionVM attentionVM;

        void MasterExecSave()
        {
            int  i           = -1;
            bool modeChanged = false;

            if (MasterCurrentObject.Mode != MasterCurrentObject.OldMode)
            {
                modeChanged = true;
            }
            _dataService.UpdateEventDevice(MasterCurrentObject, (updatedCount, error) =>
            {
                if (error != null)
                {
                    return;
                }                              // Report error here
                i = updatedCount;
            });

            MasterObjectButtonsVisibility = Visibility.Collapsed;
            MasterListCurtainVisibility   = Visibility.Collapsed;
            DetailListCurtainVisibility   = Visibility.Collapsed;


            if (MasterAddMode)
            {
                MasterSelectorSelectedItem = null;

                MasterList.Add(MasterCurrentObject);
                MasterSelectedItem   = MasterCurrentObject;
                MasterListVisibility = Visibility.Visible;
            }
            if (MasterEditMode) //in EditMode MasterSelectedItem always not null
            {
                MasterList[msix]   = MasterCurrentObject;
                MasterSelectedItem = MasterCurrentObject;
                if (!modeChanged)
                {
                    if (savedDsix != -1)
                    {
                        DetailSelectedItem = DetailList[savedDsix];
                    }
                }
            }

            MasterAddMode  = false;
            MasterEditMode = false;
            MasterCurrentObject.IsEditMode = false;
            MasterCurrentObject.IsAddMode  = false;
            MasterRemoveCmd.RaiseCanExecuteChanged();
            MasterAddCmd.RaiseCanExecuteChanged();

            MessengerInstance.Send("", AppContext.UnBlockUIMsg);
        }
Beispiel #27
0
 private void LoadData()
 {
     try
     {
         MasterList.LoadConfig(Core.User);
         AddRow();
     }
     catch (Exception ex)
     {
         MessageBox.Show($"Load data is error, {ex.ToString()}");
     }
 }
Beispiel #28
0
        protected override void Dispose(bool disposing)
        {
            Param.Ignore(disposing);
            base.Dispose(disposing);

            if (disposing)
            {
                this.contents   = null;
                this.tokens     = null;
                this.fileHeader = null;
                this.parser     = null;
            }
        }
Beispiel #29
0
 void SyncTrade(string tradeId)
 {
     syncTradeCount++;
     try {
         var trade = MasterList.FirstOrDefault(t => t.Id == tradeId);
         if (trade != null)
         {
             SyncTrade(trade);
         }
     } catch (Exception exc) { Log = exc; } finally {
         syncTradeCount--;
     }
 }
Beispiel #30
0
        public async Task <IActionResult> Edit(int id, [Bind("MasterListId,Name,Active")] MasterList masterList)
        {
            if (id != masterList.MasterListId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var currentActiveList = _context.MasterLists.FirstOrDefault(m => m.Active);
                    if (currentActiveList != null && masterList.Active)
                    {
                        currentActiveList.Active = false;
                        _context.Update(masterList);
                        await _context.SaveChangesAsync();
                    }
                }
                catch
                {
                    if (!MasterListExists(masterList.MasterListId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                try
                {
                    _context.Update(masterList);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MasterListExists(masterList.MasterListId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(masterList));
        }
        private void listDataTypes_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            isValidView = false;
            MasterList selectedMaster = (MasterList)this.listDataTypes.SelectedItem;

            if (selectedMaster != null && selectedMaster.timeList != null)
            {
                this.listDataTimes.DataSource    = new BindingSource(selectedMaster.timeList, null);
                this.listDataTimes.DisplayMember = "name";
                this.listDataTimes.ValueMember   = "id";

                this.listDataTimes.SelectedIndex = -1;
            }
        }
Beispiel #32
0
 public void RemovePunctuation(string[] stringArray)
 {
     foreach (string item in stringArray)
     {
         string[] newItem = item.Split(Punctuation);
         foreach (string foo in newItem)
         {
             if (foo != "." && foo != "," && foo != "(" && foo != ")" && foo != "!" && foo != "?" && foo != " " && foo != "")
             {
                 MasterList.Add(foo);
             }
         }
     }
 }
Beispiel #33
0
        public MasterListGroupInput Add(MasterListGroupInput inputModel)
        {
            MasterList entity = mapper.Map <MasterList>(inputModel);

            entity.Group        = ConstantConfig.MasterListMasterGroup;
            entity.CreatedBy    = GetCurrentUserLogin();
            entity.CreatedDate  = DateTime.Now;
            entity.ModifiedDate = DateTime.Now;
            entity.ModifiedBy   = GetCurrentUserLogin();
            entity.RecordStatus = ConstantConfig.RecordStatusConfig.Active;
            entity.UpdateToken  = Guid.NewGuid();
            masterListRepository.Add(entity);
            return(mapper.Map <MasterListGroupInput>(entity));
        }
Beispiel #34
0
        public MasterListGroupInput GetInputById(EntityId <int> idModel)
        {
            if (idModel == null)
            {
                return(null);
            }
            MasterList entity = masterListRepository.GetAll()
                                .Where(x => x.Group == ConstantConfig.MasterListMasterGroup && x.Id == idModel.Id).SingleOrDefault();

            if (entity == null)
            {
                return(null);
            }
            return(mapper.Map <MasterListGroupInput>(entity));
        }
        /// <summary>
        /// Initializes a new instance of the Attribute class.
        /// </summary>
        /// <param name="childTokens">
        /// The list of child tokens for the attribute.
        /// </param>
        /// <param name="location">
        /// The location of the attribute.
        /// </param>
        /// <param name="parent">
        /// The parent of the attribute.
        /// </param>
        /// <param name="attributeExpressions">
        /// The list of attribute expressions within this attribute.
        /// </param>
        /// <param name="generated">
        /// Indicates whether the attribute resides within a block of generated code.
        /// </param>
        internal Attribute(
            MasterList<CsToken> childTokens, CodeLocation location, Reference<ICodePart> parent, IEnumerable<AttributeExpression> attributeExpressions, bool generated)
            : base(CsTokenType.Attribute, CsTokenClass.Attribute, location, parent, generated)
        {
            Param.AssertNotNull(childTokens, "childTokens");
            Param.AssertGreaterThanOrEqualTo(childTokens.Count, 2, "childTokens");
            Param.AssertNotNull(location, "location");
            Param.AssertNotNull(parent, "parent");
            Param.AssertNotNull(attributeExpressions, "attributeExpressions");
            Param.Ignore(generated);

            this.childTokens = childTokens;

            this.attributeExpressions = new CodeUnitCollection<AttributeExpression>(this);
            this.attributeExpressions.AddRange(attributeExpressions);
        }
 private void CheckSpacing(MasterList<CsToken> tokens, bool v, object p)
 {
     for (Node<CsToken> tokenNode = tokens.First; tokenNode != null; tokenNode = tokenNode.Next)
     {
         if (tokenNode.Previous?.Value.CsTokenType == CsTokenType.EndOfLine &&
             tokenNode.Value.CsTokenClass == CsTokenClass.Whitespace)
         {
             var trimedSpace = tokenNode.Value.Text.TrimStart('\t');
             if (trimedSpace.Contains("\t") ||
                 trimedSpace.Length >= 4)
             {
                 this.Violate(tokenNode.Value);
             }
         }
     }
 }
Beispiel #37
0
 private void CheckCloseCurlyBracket(DocumentRoot root, MasterList<CsToken> tokens, Node<CsToken> tokenNode)
 {
     Node<CsToken> previous = tokenNode.Previous;
     if (((previous != null) && (previous.Value.CsTokenType != CsTokenType.WhiteSpace)) && (previous.Value.CsTokenType != CsTokenType.EndOfLine))
     {
         base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.ClosingCurlyBracketsMustBeSpacedCorrectly, new object[0]);
     }
     Node<CsToken> next = tokenNode.Next;
     if (next != null)
     {
         CsTokenType csTokenType = next.Value.CsTokenType;
         if ((((csTokenType != CsTokenType.WhiteSpace) && (csTokenType != CsTokenType.EndOfLine)) && ((csTokenType != CsTokenType.CloseParenthesis) && (csTokenType != CsTokenType.Semicolon))) && (csTokenType != CsTokenType.Comma))
         {
             base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.ClosingCurlyBracketsMustBeSpacedCorrectly, new object[0]);
         }
         if (csTokenType == CsTokenType.WhiteSpace)
         {
             foreach (CsToken token in tokens.ForwardIterator(tokenNode.Next.Next))
             {
                 CsTokenType type2 = token.CsTokenType;
                 switch (type2)
                 {
                     case CsTokenType.CloseParenthesis:
                     case CsTokenType.Semicolon:
                     case CsTokenType.Comma:
                     {
                         base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.ClosingCurlyBracketsMustBeSpacedCorrectly, new object[0]);
                         continue;
                     }
                 }
                 if (type2 != CsTokenType.WhiteSpace)
                 {
                     return;
                 }
             }
         }
     }
 }
Beispiel #38
0
 private void CheckSymbol(DocumentRoot root, MasterList<CsToken> tokens, Node<CsToken> tokenNode)
 {
     Node<CsToken> previous = tokenNode.Previous;
     if (((previous != null) && (previous.Value.CsTokenType != CsTokenType.WhiteSpace)) && (previous.Value.CsTokenType != CsTokenType.EndOfLine))
     {
         base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.SymbolsMustBeSpacedCorrectly, new object[] { tokenNode.Value.Text });
     }
     Node<CsToken> next = tokenNode.Next;
     if (((next != null) && (next.Value.CsTokenType != CsTokenType.WhiteSpace)) && (next.Value.CsTokenType != CsTokenType.EndOfLine))
     {
         if (previous != null)
         {
             foreach (CsToken token in tokens.ReverseIterator(previous))
             {
                 if (token.CsTokenType == CsTokenType.Operator)
                 {
                     return;
                 }
                 if (((token.CsTokenType != CsTokenType.WhiteSpace) && (token.CsTokenType != CsTokenType.EndOfLine)) && (((token.CsTokenType != CsTokenType.SingleLineComment) && (token.CsTokenType != CsTokenType.MultiLineComment)) && (token.CsTokenType != CsTokenType.PreprocessorDirective)))
                 {
                     break;
                 }
             }
         }
         base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.SymbolsMustBeSpacedCorrectly, new object[] { tokenNode.Value.Text });
     }
 }
Beispiel #39
0
 private void CheckKeywordWithoutSpace(DocumentRoot root, MasterList<CsToken> tokens, Node<CsToken> tokenNode)
 {
     Node<CsToken> next = tokenNode.Next;
     if ((next != null) && ((next.Value.CsTokenType == CsTokenType.WhiteSpace) || (next.Value.CsTokenType == CsTokenType.EndOfLine)))
     {
         foreach (CsToken token in tokens.ForwardIterator(next.Next))
         {
             if (token.CsTokenType == CsTokenType.OpenParenthesis)
             {
                 base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.KeywordsMustBeSpacedCorrectly, new object[] { tokenNode.Value.Text });
                 break;
             }
             if ((token.CsTokenType != CsTokenType.WhiteSpace) && (token.CsTokenType != CsTokenType.EndOfLine))
             {
                 break;
             }
         }
     }
 }
Beispiel #40
0
        private MasterList<CsToken> GetGenericArgumentList(Reference<ICodePart> genericTypeReference, bool unsafeCode, CsToken name, int startIndex, out int endIndex)
        {
            Param.AssertNotNull(genericTypeReference, "genericTypeReference");
            Param.Ignore(unsafeCode);
            Param.Ignore(name);
            Param.AssertGreaterThanOrEqualToZero(startIndex, "startIndex");

            endIndex = -1;
            MasterList<CsToken> genericArgumentListTokens = null;

            // Move past whitespace and comments.
            int index = startIndex;
            while (true)
            {
                Symbol next = this.symbols.Peek(index);
                if (next == null
                    || (next.SymbolType != SymbolType.WhiteSpace && next.SymbolType != SymbolType.EndOfLine && next.SymbolType != SymbolType.SingleLineComment
                        && next.SymbolType != SymbolType.MultiLineComment && next.SymbolType != SymbolType.PreprocessorDirective))
                {
                    break;
                }

                ++index;
            }

            // The next symbol should be an opening bracket, if this is a generic.
            Symbol symbol = this.symbols.Peek(index);
            if (symbol != null && symbol.SymbolType == SymbolType.LessThan)
            {
                // This might be a generic. Assume that it is and start creating tokens.
                genericArgumentListTokens = new MasterList<CsToken>();

                // Add the name if one was provided.
                if (name != null)
                {
                    genericArgumentListTokens.Add(name);
                }

                Node<CsToken> openingGenericBracketNode = null;

                // Add everything up to the opening bracket into the token list.
                for (int i = startIndex; i <= index; ++i)
                {
                    symbol = this.symbols.Peek(i);
                    Debug.Assert(symbol != null, "The next symbol should not be null");

                    if (symbol.SymbolType == SymbolType.LessThan)
                    {
                        if (openingGenericBracketNode != null)
                        {
                            // This is not a generic statement.
                            return null;
                        }

                        Bracket openingGenericBracket = new Bracket(
                            symbol.Text, CsTokenType.OpenGenericBracket, symbol.Location, genericTypeReference, this.symbols.Generated);
                        openingGenericBracketNode = genericArgumentListTokens.InsertLast(openingGenericBracket);
                    }
                    else
                    {
                        genericArgumentListTokens.Add(this.ConvertSymbol(symbol, TokenTypeFromSymbolType(symbol.SymbolType), genericTypeReference));
                    }
                }

                // Loop through the rest of the symbols.
                while (true)
                {
                    symbol = this.symbols.Peek(++index);
                    if (symbol == null)
                    {
                        // The code ran out before we found the end of the generic.
                        throw new SyntaxException(this.document.SourceCode, name.LineNumber);
                    }
                    else if (symbol.SymbolType == SymbolType.GreaterThan)
                    {
                        if (openingGenericBracketNode == null)
                        {
                            // This is not a generic statement.
                            return null;
                        }

                        // This is the end of the generic statement. Add the closing bracket to the token list.
                        Bracket closingGenericBracket = new Bracket(
                            symbol.Text, CsTokenType.CloseGenericBracket, symbol.Location, genericTypeReference, this.symbols.Generated);
                        Node<CsToken> closingGenericBracketNode = genericArgumentListTokens.InsertLast(closingGenericBracket);

                        ((Bracket)openingGenericBracketNode.Value).MatchingBracketNode = closingGenericBracketNode;
                        closingGenericBracket.MatchingBracketNode = openingGenericBracketNode;

                        endIndex = index;
                        break;
                    }
                    else if (symbol.SymbolType == SymbolType.Out || symbol.SymbolType == SymbolType.In)
                    {
                        // Get the in or out keyword.
                        genericArgumentListTokens.Add(
                            this.ConvertSymbol(symbol, symbol.SymbolType == SymbolType.In ? CsTokenType.In : CsTokenType.Out, genericTypeReference));
                    }
                    else if (symbol.SymbolType == SymbolType.Other)
                    {
                        int lastIndex = 0;
                        Reference<ICodePart> wordReference = new Reference<ICodePart>();
                        CsToken word = this.GetTypeTokenAux(wordReference, genericTypeReference, unsafeCode, true, false, index, out lastIndex);
                        if (word == null)
                        {
                            throw new SyntaxException(this.document.SourceCode, symbol.LineNumber);
                        }

                        // Advance the index to the end of the token.
                        index = lastIndex;

                        // Add the token.
                        genericArgumentListTokens.Add(word);
                    }
                    else if (symbol.SymbolType == SymbolType.WhiteSpace || symbol.SymbolType == SymbolType.EndOfLine || symbol.SymbolType == SymbolType.SingleLineComment
                             || symbol.SymbolType == SymbolType.MultiLineComment || symbol.SymbolType == SymbolType.PreprocessorDirective)
                    {
                        // Add these to the token list.
                        genericArgumentListTokens.Add(this.ConvertSymbol(symbol, TokenTypeFromSymbolType(symbol.SymbolType), genericTypeReference));
                    }
                    else if (symbol.SymbolType == SymbolType.Comma)
                    {
                        genericArgumentListTokens.Add(this.ConvertSymbol(symbol, CsTokenType.Comma, genericTypeReference));
                    }
                    else if (symbol.SymbolType == SymbolType.OpenSquareBracket)
                    {
                        // An attribute on the generic type.
                        genericArgumentListTokens.Add(this.GetAttribute(genericTypeReference, unsafeCode));
                    }
                    else
                    {
                        // Any other symbol signifies that this is not a generic statement.
                        genericArgumentListTokens = null;
                        break;
                    }
                }
            }

            return genericArgumentListTokens;
        }
        /// <summary>
        /// Checks a unary symbol for spacing.
        /// </summary>
        /// <param name="tokens">
        /// The master list of tokens.
        /// </param>
        /// <param name="tokenNode">
        /// The token to check.
        /// </param>
        private void CheckUnarySymbol(MasterList<CsToken> tokens, Node<CsToken> tokenNode)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tokenNode, "tokenNode");

            // These symbols should be preceded by whitespace but not followed by whitespace. They can
            // also be preceded by an open paren or an open square bracket.
            Node<CsToken> previousNode = tokenNode.Previous;
            if (previousNode != null)
            {
                CsTokenType previousNodeTokenType = previousNode.Value.CsTokenType;
                if (previousNodeTokenType != CsTokenType.WhiteSpace && previousNodeTokenType != CsTokenType.EndOfLine
                    && previousNodeTokenType != CsTokenType.OpenParenthesis && previousNodeTokenType != CsTokenType.OpenSquareBracket
                    && previousNodeTokenType != CsTokenType.CloseParenthesis)
                {
                    this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.SymbolsMustBeSpacedCorrectly, tokenNode.Value.Text);
                }

                // They should not be preceded by whitespace if the whitespace is preceded by a paranthesis.
                if (previousNodeTokenType == CsTokenType.WhiteSpace || previousNodeTokenType == CsTokenType.EndOfLine)
                {
                    foreach (CsToken item in tokens.ReverseIterator(previousNode))
                    {
                        if (item.CsTokenType == CsTokenType.OpenParenthesis || item.CsTokenType == CsTokenType.OpenSquareBracket)
                        {
                            this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.SymbolsMustBeSpacedCorrectly, tokenNode.Value.Text);
                        }
                        else if (item.CsTokenType == CsTokenType.WhiteSpace)
                        {
                            continue;
                        }

                        if (item.CsTokenType != CsTokenType.OpenParenthesis && item.CsTokenType != CsTokenType.OpenSquareBracket
                            && item.CsTokenType != CsTokenType.WhiteSpace)
                        {
                            break;
                        }
                    }
                }
            }

            Node<CsToken> nextNode = tokenNode.Next;
            if (nextNode != null)
            {
                CsTokenType tokenType = nextNode.Value.CsTokenType;
                if (tokenType == CsTokenType.WhiteSpace || tokenType == CsTokenType.EndOfLine || tokenType == CsTokenType.SingleLineComment
                    || tokenType == CsTokenType.MultiLineComment)
                {
                    this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.SymbolsMustBeSpacedCorrectly, tokenNode.Value.Text);
                }
            }
        }
Beispiel #42
0
 private void CheckOpenCurlyBracket(DocumentRoot root, MasterList<CsToken> tokens, Node<CsToken> tokenNode)
 {
     Node<CsToken> previous = tokenNode.Previous;
     if (previous != null)
     {
         CsTokenType csTokenType = previous.Value.CsTokenType;
         if (((csTokenType != CsTokenType.WhiteSpace) && (csTokenType != CsTokenType.EndOfLine)) && (csTokenType != CsTokenType.OpenParenthesis))
         {
             base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.OpeningCurlyBracketsMustBeSpacedCorrectly, new object[0]);
         }
         if (csTokenType == CsTokenType.WhiteSpace)
         {
             foreach (CsToken token in tokens.ReverseIterator(previous))
             {
                 CsTokenType type2 = token.CsTokenType;
                 if (type2 == CsTokenType.OpenParenthesis)
                 {
                     base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.OpeningCurlyBracketsMustBeSpacedCorrectly, new object[0]);
                 }
                 else if (type2 != CsTokenType.WhiteSpace)
                 {
                     break;
                 }
             }
         }
     }
     Node<CsToken> next = tokenNode.Next;
     if (((next != null) && (next.Value.CsTokenType != CsTokenType.WhiteSpace)) && (next.Value.CsTokenType != CsTokenType.EndOfLine))
     {
         base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.OpeningCurlyBracketsMustBeSpacedCorrectly, new object[0]);
     }
 }
        private void CheckCloseSquareBracket(MasterList<CsToken> tokens, Node<CsToken> tokenNode, Node<CsToken> parentTokenNode)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tokenNode, "tokenNode");
            Param.Ignore(parentTokenNode);

            // Close brackets should never be preceded by whitespace.
            Node<CsToken> previousNode = tokenNode.Previous;
            if (previousNode != null && (previousNode.Value.CsTokenType == CsTokenType.WhiteSpace || previousNode.Value.CsTokenType == CsTokenType.EndOfLine))
            {
                this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.ClosingSquareBracketsMustBeSpacedCorrectly);
            }

            // Close brackets should be followed either by whitespace, a bracket,
            // a paren, a semicolon, a comma, a period, or an increment or decrement symbol.
            Node<CsToken> nextNode = tokenNode.Next ?? parentTokenNode.Next;

            if (nextNode != null)
            {
                CsTokenType nextType = nextNode.Value.CsTokenType;
                if (nextType != CsTokenType.WhiteSpace && nextType != CsTokenType.EndOfLine && nextType != CsTokenType.CloseParenthesis
                    && nextType != CsTokenType.OpenParenthesis && // someDictionary["Test"]();
                    nextType != CsTokenType.CloseSquareBracket && // someIndexer[someArray[1]] = 2;
                    nextType != CsTokenType.OpenSquareBracket && // someArray[1][2] = 2;
                    nextType != CsTokenType.Semicolon && nextType != CsTokenType.Comma && nextType != CsTokenType.CloseGenericBracket && nextNode.Value.Text != "++"
                    && nextNode.Value.Text != "--" && nextNode.Value.Text != "?." && nextNode.Value.Text != "?" && !nextNode.Value.Text.StartsWith(".", StringComparison.Ordinal))
                {
                    this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.ClosingSquareBracketsMustBeSpacedCorrectly);
                }

                if (nextType == CsTokenType.WhiteSpace)
                {
                    // If this is followed by whitespace, make sure that the character just
                    // after the whitespace is not a paren, bracket, comma, or semicolon.
                    foreach (CsToken item in tokens.ForwardIterator(nextNode.Next))
                    {
                        CsTokenType itemType = item.CsTokenType;
                        if (itemType == CsTokenType.CloseParenthesis || itemType == CsTokenType.OpenParenthesis || itemType == CsTokenType.CloseSquareBracket
                            || itemType == CsTokenType.OpenSquareBracket || itemType == CsTokenType.Semicolon || itemType == CsTokenType.Comma)
                        {
                            this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.ClosingSquareBracketsMustBeSpacedCorrectly);
                        }
                        else if (itemType != CsTokenType.WhiteSpace)
                        {
                            break;
                        }
                    }
                }
            }
        }
        private void CheckOpenParen(MasterList<CsToken> tokens, Node<CsToken> tokenNode)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tokenNode, "tokenNode");

            bool firstOnLine = false;
            bool lastOnLine = false;

            // Open parenthesis should never be preceded by whitespace unless it is the
            // first thing on the line or it follows a keyword or it follows a symbol or a number.
            Node<CsToken> previousNode = tokenNode.Previous;
            if (previousNode != null)
            {
                if (previousNode.Value.CsTokenType == CsTokenType.WhiteSpace)
                {
                    foreach (CsToken item in tokens.ReverseIterator(previousNode))
                    {
                        CsTokenType itemType = item.CsTokenType;
                        if (itemType == CsTokenType.WhiteSpace)
                        {
                            continue;
                        }

                        if (itemType == CsTokenType.EndOfLine)
                        {
                            firstOnLine = true;
                            break;
                        }

                        if (itemType == CsTokenType.Case || itemType == CsTokenType.Catch || itemType == CsTokenType.CloseSquareBracket || itemType == CsTokenType.Comma
                            || itemType == CsTokenType.Equals || itemType == CsTokenType.Fixed || itemType == CsTokenType.For || itemType == CsTokenType.Foreach
                            || itemType == CsTokenType.From || ////itemType == CsTokenType.Goto ||
                            itemType == CsTokenType.Group || itemType == CsTokenType.If || itemType == CsTokenType.In || itemType == CsTokenType.Into
                            || itemType == CsTokenType.Join || itemType == CsTokenType.Let || itemType == CsTokenType.Lock || itemType == CsTokenType.MultiLineComment
                            || ////itemType == CsTokenType.New ||
                            itemType == CsTokenType.Number || itemType == CsTokenType.OperatorSymbol || itemType == CsTokenType.OpenCurlyBracket
                            || itemType == CsTokenType.OrderBy || itemType == CsTokenType.Return || itemType == CsTokenType.Select || itemType == CsTokenType.Semicolon
                            || ////itemType == CsTokenType.SingleLineComment ||
                            itemType == CsTokenType.Switch || itemType == CsTokenType.Throw || itemType == CsTokenType.Using || itemType == CsTokenType.Where
                            || itemType == CsTokenType.While || itemType == CsTokenType.WhileDo || itemType == CsTokenType.Yield || itemType == CsTokenType.LabelColon
                            || itemType == CsTokenType.Async || itemType == CsTokenType.By || itemType == CsTokenType.When)
                        {
                            break;
                        }

                        this.AddViolation(tokenNode.Value.FindParentElement(), previousNode.Value.Location, Rules.OpeningParenthesisMustBeSpacedCorrectly);
                    }
                }
            }

            // Open parens should never be followed by whitespace unless
            // it is the last thing on the line.
            Node<CsToken> next = tokenNode.Next;
            if (next != null && (next.Value.CsTokenType == CsTokenType.WhiteSpace || next.Value.CsTokenType == CsTokenType.EndOfLine))
            {
                // Look to see if there is any non whitespace character
                // on this line other than a comment.
                foreach (CsToken item in tokens.ForwardIterator(next))
                {
                    CsTokenType itemType = item.CsTokenType;
                    if (itemType == CsTokenType.EndOfLine)
                    {
                        lastOnLine = true;
                        break;
                    }
                    else if (itemType != CsTokenType.WhiteSpace && itemType != CsTokenType.SingleLineComment && itemType != CsTokenType.MultiLineComment)
                    {
                        this.AddViolation(tokenNode.Value.FindParentElement(), next.Value.Location, Rules.OpeningParenthesisMustBeSpacedCorrectly);
                        break;
                    }
                }
            }

            // Open parens cannot be the only thing on the line.
            if (firstOnLine && lastOnLine)
            {
                this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.OpeningParenthesisMustBeSpacedCorrectly);
            }
        }
Beispiel #45
0
        private void CheckCloseParen(DocumentRoot root, MasterList<CsToken> tokens, Node<CsToken> tokenNode)
        {
            Node<CsToken> previous = tokenNode.Previous;
            if ((previous != null) && ((previous.Value.CsTokenType == CsTokenType.WhiteSpace) || (previous.Value.CsTokenType == CsTokenType.EndOfLine)))
            {
                base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.ClosingParenthesisMustBeSpacedCorrectly, new object[0]);
            }
            Node<CsToken> next = tokenNode.Next;
            if (next == null)
            {
                return;
            }
            CsTokenType csTokenType = next.Value.CsTokenType;
            if (((csTokenType == CsTokenType.WhiteSpace
                    || csTokenType == CsTokenType.EndOfLine
                    || csTokenType == CsTokenType.CloseParenthesis
                    || csTokenType == CsTokenType.OpenParenthesis
                    || csTokenType == CsTokenType.CloseSquareBracket
                    || csTokenType == CsTokenType.OpenSquareBracket
                    || csTokenType == CsTokenType.CloseAttributeBracket
                    || csTokenType == CsTokenType.Semicolon
                    || csTokenType == CsTokenType.Comma
                    || csTokenType == CsTokenType.Other
                    || csTokenType == CsTokenType.Base
                    || csTokenType == CsTokenType.This
                    || csTokenType == CsTokenType.Null
                    || csTokenType == CsTokenType.New
                    || csTokenType == CsTokenType.Number
                    || csTokenType == CsTokenType.String
                    // Oleg Shuruev added
                    || csTokenType == CsTokenType.Typeof)
                || ((csTokenType == CsTokenType.Delegate)
                    || ((csTokenType == CsTokenType.OperatorSymbol)
                        && (((OperatorSymbol)next.Value).SymbolType == OperatorType.AddressOf))))
                || next.Value.Text.StartsWith(".", StringComparison.Ordinal))
            {
                goto Label_01C1;
            }
            bool flag = false;
            if (csTokenType == CsTokenType.OperatorSymbol)
            {
                OperatorSymbol symbol = next.Value as OperatorSymbol;
                if ((symbol.SymbolType == OperatorType.Negative) || (symbol.SymbolType == OperatorType.Positive))
                {
                    flag = true;
                }
            }
            if (flag)
            {
                goto Label_01C1;
            }
            bool flag2 = false;
            if (csTokenType == CsTokenType.LabelColon)
            {
                foreach (CsToken token in tokens.ReverseIterator(tokenNode.Previous))
                {
                    switch (token.CsTokenType)
                    {
                        case CsTokenType.EndOfLine:
                            goto Label_019E;

                        case CsTokenType.Case:
                            flag2 = true;
                            goto Label_019E;
                    }
                }
            }
            Label_019E:
            if (!flag2)
            {
                base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.ClosingParenthesisMustBeSpacedCorrectly, new object[0]);
            }
            Label_01C1:
            if (csTokenType == CsTokenType.WhiteSpace)
            {
                foreach (CsToken token2 in tokens.ForwardIterator(tokenNode.Next.Next))
                {
                    CsTokenType type3 = token2.CsTokenType;
                    switch (type3)
                    {
                        case CsTokenType.CloseParenthesis:
                        case CsTokenType.OpenParenthesis:
                        case CsTokenType.CloseSquareBracket:
                        case CsTokenType.OpenSquareBracket:
                        case CsTokenType.Semicolon:
                        case CsTokenType.Comma:
                        {
                            base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.ClosingParenthesisMustBeSpacedCorrectly, new object[0]);
                            continue;
                        }
                    }
                    if (type3 != CsTokenType.WhiteSpace)
                    {
                        return;
                    }
                }
            }
        }
        /// <summary>
        /// Checks to see if the passed in node is the first node on its line.
        /// </summary>
        /// <param name="tokens">
        /// The master list of tokens.
        /// </param>
        /// <param name="node">
        /// The node to check.
        /// </param>
        /// <returns>
        /// True if this node is the first on the line, otherwise false.
        /// </returns>
        private bool IsTokenFirstNonWhitespaceTokenOnLine(MasterList<CsToken> tokens, Node<CsToken> node)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(node, "node");

            Node<CsToken> previousNode = node.Previous;
            if (previousNode == null)
            {
                return true;
            }

            bool returnValue = true;
            foreach (CsToken item in tokens.ReverseIterator(previousNode))
            {
                if (item.LineNumber != node.Value.LineNumber)
                {
                    break;
                }

                if (item.CsTokenType != CsTokenType.WhiteSpace)
                {
                    returnValue = false;
                    break;
                }
            }

            return returnValue;
        }
        /// <summary>
        /// Checks a open bracket for spacing.
        /// </summary>
        /// <param name="tokens">
        /// The list of tokens being parsed.
        /// </param>
        /// <param name="tokenNode">
        /// The token to check.
        /// </param>
        private void CheckOpenCurlyBracket(MasterList<CsToken> tokens, Node<CsToken> tokenNode)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tokenNode, "tokenNode");

            // Open curly brackets should be preceded either by whitespace, or an open paren.
            Node<CsToken> previousNode = tokenNode.Previous;
            if (previousNode != null)
            {
                CsTokenType lastType = previousNode.Value.CsTokenType;
                if (lastType != CsTokenType.WhiteSpace && lastType != CsTokenType.EndOfLine && lastType != CsTokenType.OpenParenthesis)
                {
                    this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.OpeningCurlyBracketsMustBeSpacedCorrectly);
                }

                if (lastType == CsTokenType.WhiteSpace)
                {
                    // If this is preceded by whitespace, make sure that the character just
                    // before the whitespace is not an open paren.
                    foreach (CsToken item in tokens.ReverseIterator(previousNode))
                    {
                        CsTokenType itemType = item.CsTokenType;
                        if (itemType == CsTokenType.OpenParenthesis)
                        {
                            this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.OpeningCurlyBracketsMustBeSpacedCorrectly);
                        }
                        else if (itemType != CsTokenType.WhiteSpace)
                        {
                            break;
                        }
                    }
                }
            }

            // Open curly brackets should always be followed by whitespace.
            Node<CsToken> nextNode = tokenNode.Next;
            if (nextNode != null && nextNode.Value.CsTokenType != CsTokenType.WhiteSpace && nextNode.Value.CsTokenType != CsTokenType.EndOfLine)
            {
                this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.OpeningCurlyBracketsMustBeSpacedCorrectly);
            }
        }
        /// <summary>
        /// Checks a member access symbol for spacing.
        /// </summary>
        /// <param name="tokens">
        /// The list of tokens being parsed.
        /// </param>
        /// <param name="tokenNode">
        /// The token to check.
        /// </param>
        private void CheckMemberAccessSymbol(MasterList<CsToken> tokens, Node<CsToken> tokenNode)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tokenNode, "tokenNode");

            // Member access symbols should not have any whitespace on either side.
            Node<CsToken> previousNode = tokenNode.Previous;
            if (previousNode != null)
            {
                CsTokenType previousTokenType = previousNode.Value.CsTokenType;
                if (previousTokenType == CsTokenType.WhiteSpace || previousTokenType == CsTokenType.EndOfLine || previousTokenType == CsTokenType.SingleLineComment
                    || previousTokenType == CsTokenType.MultiLineComment)
                {
                    if (!this.IsTokenFirstNonWhitespaceTokenOnLine(tokens, tokenNode))
                    {
                        this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.MemberAccessSymbolsMustBeSpacedCorrectly);
                    }
                }
            }

            Node<CsToken> nextNode = tokenNode.Next;
            if (nextNode != null)
            {
                CsTokenType tokenType = nextNode.Value.CsTokenType;
                if (tokenType == CsTokenType.WhiteSpace || tokenType == CsTokenType.EndOfLine || tokenType == CsTokenType.SingleLineComment
                    || tokenType == CsTokenType.MultiLineComment)
                {
                    // Make sure the previous token is not the operator keyword.
                    if (previousNode != null)
                    {
                        foreach (CsToken item in tokens.ReverseIterator(previousNode))
                        {
                            CsTokenType itemType = item.CsTokenType;
                            if (itemType == CsTokenType.Operator)
                            {
                                return;
                            }
                            else if (itemType != CsTokenType.WhiteSpace && itemType != CsTokenType.EndOfLine && itemType != CsTokenType.SingleLineComment
                                     && itemType != CsTokenType.MultiLineComment)
                            {
                                break;
                            }
                        }
                    }

                    this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.MemberAccessSymbolsMustBeSpacedCorrectly);
                }
            }
        }
        /// <summary>
        /// Checks a keyword that should not be followed by a space.
        /// </summary>
        /// <param name="tokens">
        /// The list of tokens being parsed.
        /// </param>
        /// <param name="tokenNode">
        /// The token to check.
        /// </param>
        private void CheckKeywordWithoutSpace(MasterList<CsToken> tokens, Node<CsToken> tokenNode)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tokenNode, "tokenNode");

            // Keywords must not contain any space before the open parenthesis.
            Node<CsToken> temp = tokenNode.Next;
            if (temp != null && (temp.Value.CsTokenType == CsTokenType.WhiteSpace || temp.Value.CsTokenType == CsTokenType.EndOfLine))
            {
                // Make sure the next non-whitespace character is not an open parenthesis.
                foreach (CsToken nextNonWhitespaceToken in tokens.ForwardIterator(temp.Next))
                {
                    if (nextNonWhitespaceToken.CsTokenType == CsTokenType.OpenParenthesis)
                    {
                        this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.KeywordsMustBeSpacedCorrectly, tokenNode.Value.Text);

                        break;
                    }
                    else if (nextNonWhitespaceToken.CsTokenType != CsTokenType.WhiteSpace && nextNonWhitespaceToken.CsTokenType != CsTokenType.EndOfLine)
                    {
                        break;
                    }
                }
            }
        }
        private void CheckGenericSpacing(MasterList<CsToken> tokens, Node<CsToken> genericTokenNode)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(genericTokenNode, "genericTokenNode");

            GenericType generic = genericTokenNode.Value as GenericType;

            // Make sure it contains at least one token.
            if (generic.ChildTokens.Count > 0)
            {
                for (Node<CsToken> tokenNode = generic.ChildTokens.First; tokenNode != null; tokenNode = tokenNode.Next)
                {
                    if (this.Cancel)
                    {
                        break;
                    }

                    // Check whether this token is a generic and if so parse the tokens within
                    // the generic statement.
                    if (tokenNode.Value.CsTokenClass == CsTokenClass.GenericType)
                    {
                        this.CheckGenericSpacing(tokens, tokenNode);
                    }

                    if (!tokenNode.Value.Generated)
                    {
                        switch (tokenNode.Value.CsTokenType)
                        {
                            case CsTokenType.Comma:
                                this.CheckSemicolonAndComma(tokens, tokenNode);
                                break;

                            case CsTokenType.OpenParenthesis:
                                this.CheckOpenParen(generic.ChildTokens, tokenNode);
                                break;

                            case CsTokenType.CloseParenthesis:
                                this.CheckCloseParen(generic.ChildTokens, tokenNode);
                                break;

                            case CsTokenType.OpenSquareBracket:
                                this.CheckOpenSquareBracket(tokenNode);
                                break;

                            case CsTokenType.CloseSquareBracket:
                                this.CheckCloseSquareBracket(generic.ChildTokens, tokenNode, genericTokenNode);
                                break;

                            case CsTokenType.WhiteSpace:
                                this.CheckWhitespace(tokenNode);
                                break;

                            case CsTokenType.OpenGenericBracket:
                                this.CheckGenericTokenOpenBracket(tokenNode);
                                break;

                            case CsTokenType.CloseGenericBracket:
                                this.CheckGenericTokenCloseBracket(tokenNode, genericTokenNode);
                                break;

                            case CsTokenType.PreprocessorDirective:
                                this.CheckPreprocessorSpacing(tokenNode.Value);
                                break;

                            case CsTokenType.OperatorSymbol:
                                OperatorSymbol symbol = tokenNode.Value as OperatorSymbol;
                                if (symbol.SymbolType == OperatorType.MemberAccess || symbol.SymbolType == OperatorType.QualifiedAlias)
                                {
                                    this.CheckMemberAccessSymbol(generic.ChildTokens, tokenNode);
                                }
                                else
                                {
                                    goto default;
                                }

                                break;

                            case CsTokenType.Other:
                            case CsTokenType.EndOfLine:
                            case CsTokenType.In:
                            case CsTokenType.Out:

                                // Ignore these.
                                break;

                            default:

                                // There shouldn't be anything else within a generic type token.
                                Debug.Fail("Unexpected token type.");
                                break;
                        }
                    }
                }
            }
        }
Beispiel #51
0
 private void CheckMemberAccessSymbol(DocumentRoot root, MasterList<CsToken> tokens, Node<CsToken> tokenNode)
 {
     Node<CsToken> previous = tokenNode.Previous;
     if (previous == null)
     {
         switch (previous.Value.CsTokenType)
         {
             case CsTokenType.WhiteSpace:
             case CsTokenType.EndOfLine:
             case CsTokenType.SingleLineComment:
             case CsTokenType.MultiLineComment:
                 base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.MemberAccessSymbolsMustBeSpacedCorrectly, new object[0]);
                 break;
         }
     }
     Node<CsToken> next = tokenNode.Next;
     if (next == null)
     {
         switch (next.Value.CsTokenType)
         {
             case CsTokenType.WhiteSpace:
             case CsTokenType.EndOfLine:
             case CsTokenType.SingleLineComment:
             case CsTokenType.MultiLineComment:
                 if (previous != null)
                 {
                     foreach (CsToken token in tokens.ReverseIterator(previous))
                     {
                         CsTokenType csTokenType = token.CsTokenType;
                         if (csTokenType == CsTokenType.Operator)
                         {
                             return;
                         }
                         if (((csTokenType != CsTokenType.WhiteSpace) && (csTokenType != CsTokenType.EndOfLine)) && ((csTokenType != CsTokenType.SingleLineComment) && (csTokenType != CsTokenType.MultiLineComment)))
                         {
                             break;
                         }
                     }
                 }
                 base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.MemberAccessSymbolsMustBeSpacedCorrectly, new object[0]);
                 break;
         }
     }
 }
Beispiel #52
0
        private void CheckSpacing(DocumentRoot root, MasterList<CsToken> tokens, bool type)
        {
            if (tokens.Count > 0)
            {
                for (Node<CsToken> node = tokens.First; node != null; node = node.Next)
                {
                    OperatorSymbol symbol;
                    CsTokenClass class2;
                    if (base.Cancel)
                    {
                        return;
                    }
                    if (node.Value.Generated)
                    {
                        goto Label_049F;
                    }
                    switch (node.Value.CsTokenType)
                    {
                        case CsTokenType.OpenParenthesis:
                            this.CheckOpenParen(root, tokens, node);
                            goto Label_043E;

                        case CsTokenType.CloseParenthesis:
                            this.CheckCloseParen(root, tokens, node);
                            goto Label_043E;

                        case CsTokenType.OpenCurlyBracket:
                            this.CheckOpenCurlyBracket(root, tokens, node);
                            goto Label_043E;

                        case CsTokenType.CloseCurlyBracket:
                            this.CheckCloseCurlyBracket(root, tokens, node);
                            goto Label_043E;

                        case CsTokenType.OpenSquareBracket:
                            this.CheckOpenSquareBracket(root, node);
                            goto Label_043E;

                        case CsTokenType.CloseSquareBracket:
                            this.CheckCloseSquareBracket(root, tokens, node);
                            goto Label_043E;

                        case CsTokenType.OperatorSymbol:
                            symbol = node.Value as OperatorSymbol;
                            switch (symbol.Category)
                            {
                                case OperatorCategory.Relational:
                                case OperatorCategory.Logical:
                                case OperatorCategory.Assignment:
                                case OperatorCategory.Arithmetic:
                                case OperatorCategory.Shift:
                                case OperatorCategory.Conditional:
                                case OperatorCategory.Lambda:
                                    goto Label_03F7;

                                case OperatorCategory.IncrementDecrement:
                                    goto Label_0402;

                                case OperatorCategory.Unary:
                                    goto Label_040C;
                            }
                            goto Label_043E;

                        case CsTokenType.BaseColon:
                        case CsTokenType.WhereColon:
                            this.CheckSymbol(root, tokens, node);
                            goto Label_043E;

                        case CsTokenType.AttributeColon:
                        case CsTokenType.LabelColon:
                            this.CheckLabelColon(root, node);
                            goto Label_043E;

                        case CsTokenType.Comma:
                        case CsTokenType.Semicolon:
                            this.CheckSemicolonAndComma(root, node);
                            goto Label_043E;

                        case CsTokenType.NullableTypeSymbol:
                            this.CheckNullableTypeSymbol(root, node);
                            goto Label_043E;

                        case CsTokenType.Catch:
                        case CsTokenType.Fixed:
                        case CsTokenType.For:
                        case CsTokenType.Foreach:
                        case CsTokenType.From:
                        case CsTokenType.Group:
                        case CsTokenType.If:
                        case CsTokenType.In:
                        case CsTokenType.Into:
                        case CsTokenType.Join:
                        case CsTokenType.Let:
                        case CsTokenType.Lock:
                        case CsTokenType.OrderBy:
                        case CsTokenType.Return:
                        case CsTokenType.Select:
                        case CsTokenType.Stackalloc:
                        case CsTokenType.Switch:
                        case CsTokenType.Throw:
                        case CsTokenType.Using:
                        case CsTokenType.Where:
                        case CsTokenType.While:
                        case CsTokenType.WhileDo:
                        case CsTokenType.Yield:
                            this.CheckKeywordWithSpace(root, node);
                            goto Label_043E;

                        case CsTokenType.Checked:
                        case CsTokenType.DefaultValue:
                        case CsTokenType.Sizeof:
                        case CsTokenType.Typeof:
                        case CsTokenType.Unchecked:
                            this.CheckKeywordWithoutSpace(root, tokens, node);
                            goto Label_043E;

                        case CsTokenType.New:
                            this.CheckNewKeywordSpacing(root, tokens, node);
                            goto Label_043E;

                        case CsTokenType.Operator:
                            this.CheckOperatorKeyword(root, node);
                            goto Label_043E;

                        case CsTokenType.WhiteSpace:
                            this.CheckWhitespace(root, node);
                            goto Label_043E;

                        case CsTokenType.SingleLineComment:
                            this.CheckTabsInComment(root, node.Value);
                            this.CheckSingleLineComment(root, tokens, node);
                            goto Label_043E;

                        case CsTokenType.MultiLineComment:
                            this.CheckTabsInComment(root, node.Value);
                            goto Label_043E;

                        case CsTokenType.PreprocessorDirective:
                            this.CheckPreprocessorSpacing(root, node.Value as Preprocessor);
                            goto Label_043E;

                        case CsTokenType.Attribute:
                        {
                            Microsoft.StyleCop.CSharp.Attribute attribute = node.Value as Microsoft.StyleCop.CSharp.Attribute;
                            this.CheckSpacing(root, attribute.ChildTokens, false);
                            goto Label_043E;
                        }
                        case CsTokenType.OpenAttributeBracket:
                            this.CheckAttributeTokenOpenBracket(root, node);
                            goto Label_043E;

                        case CsTokenType.CloseAttributeBracket:
                            this.CheckAttributeTokenCloseBracket(root, node);
                            goto Label_043E;

                        case CsTokenType.XmlHeader:
                        {
                            XmlHeader header = (XmlHeader) node.Value;
                            this.CheckXmlHeaderComment(root, header);
                            for (Node<CsToken> node2 = header.ChildTokens.First; node2 != null; node2 = node2.Next)
                            {
                                this.CheckTabsInComment(root, node2.Value);
                            }
                            goto Label_043E;
                        }
                        default:
                            goto Label_043E;
                    }
                Label_03F7:
                    this.CheckSymbol(root, tokens, node);
                    goto Label_043E;
                Label_0402:
                    this.CheckIncrementDecrement(root, node);
                    goto Label_043E;
                Label_040C:
                    if (symbol.SymbolType == OperatorType.Negative)
                    {
                        this.CheckNegativeSign(root, node);
                    }
                    else if (symbol.SymbolType == OperatorType.Positive)
                    {
                        this.CheckPositiveSign(root, node);
                    }
                    else
                    {
                        this.CheckUnarySymbol(root, node);
                    }
                Label_043E:
                    class2 = node.Value.CsTokenClass;
                    if (class2 != CsTokenClass.GenericType)
                    {
                        if (class2 == CsTokenClass.Type)
                        {
                            goto Label_0487;
                        }
                        if (class2 == CsTokenClass.ConstructorConstraint)
                        {
                            this.CheckSpacing(root, ((ConstructorConstraint) node.Value).ChildTokens, false);
                        }
                        goto Label_049F;
                    }
                    this.CheckGenericSpacing(root, node.Value as GenericType);
                Label_0487:
                    this.CheckSpacing(root, ((TypeToken) node.Value).ChildTokens, true);
                Label_049F:;
                }
            }
        }
Beispiel #53
0
 private void CheckNewKeywordSpacing(DocumentRoot root, MasterList<CsToken> tokens, Node<CsToken> tokenNode)
 {
     Node<CsToken> next = tokenNode.Next;
     if (next != null)
     {
         if ((next.Value.CsTokenType == CsTokenType.WhiteSpace) || (next.Value.CsTokenType == CsTokenType.EndOfLine))
         {
             foreach (CsToken token in tokens.ForwardIterator(next.Next))
             {
                 if (token.CsTokenType == CsTokenType.OpenSquareBracket)
                 {
                     base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.CodeMustNotContainSpaceAfterNewKeywordInImplicitlyTypedArrayAllocation, new object[0]);
                     break;
                 }
                 if ((token.CsTokenType != CsTokenType.WhiteSpace) && (token.CsTokenType != CsTokenType.EndOfLine))
                 {
                     break;
                 }
             }
         }
         else if (next.Value.CsTokenType != CsTokenType.OpenSquareBracket)
         {
             base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.KeywordsMustBeSpacedCorrectly, new object[] { tokenNode.Value.Text });
         }
     }
 }
        /// <summary>
        /// Checks a close bracket for spacing.
        /// </summary>
        /// <param name="tokens">
        /// The list of tokens being parsed.
        /// </param>
        /// <param name="tokenNode">
        /// The token to check.
        /// </param>
        private void CheckCloseCurlyBracket(MasterList<CsToken> tokens, Node<CsToken> tokenNode)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tokenNode, "tokenNode");

            // Close curly brackets should always be preceded by whitespace.
            Node<CsToken> previousNode = tokenNode.Previous;
            if (previousNode != null && previousNode.Value.CsTokenType != CsTokenType.WhiteSpace && previousNode.Value.CsTokenType != CsTokenType.EndOfLine)
            {
                this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.ClosingCurlyBracketsMustBeSpacedCorrectly);
            }

            // Close curly brackets should be followed either by:
            // whitespace
            // a close paren
            // a dot,
            // a semicolon
            // open square bracket
            // or a comma.
            Node<CsToken> nextNode = tokenNode.Next;
            if (nextNode != null)
            {
                CsTokenType nextType = nextNode.Value.CsTokenType;
                if (nextType != CsTokenType.WhiteSpace && nextType != CsTokenType.EndOfLine && nextType != CsTokenType.CloseParenthesis && !IsTokenADot(nextNode.Value)
                    && nextType != CsTokenType.Semicolon && nextType != CsTokenType.OpenSquareBracket && nextType != CsTokenType.Comma)
                {
                    this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.ClosingCurlyBracketsMustBeSpacedCorrectly);
                }

                if (nextType == CsTokenType.WhiteSpace)
                {
                    // If this is followed by whitespace, make sure that the character just
                    // after the whitespace is not a close paren, semicolon, comma or dot.
                    foreach (CsToken item in tokens.ForwardIterator(tokenNode.Next.Next))
                    {
                        CsTokenType itemType = item.CsTokenType;
                        if (itemType == CsTokenType.CloseParenthesis || itemType == CsTokenType.Semicolon || itemType == CsTokenType.Comma || IsTokenADot(item))
                        {
                            this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.ClosingCurlyBracketsMustBeSpacedCorrectly);
                        }
                        else if (itemType != CsTokenType.WhiteSpace)
                        {
                            break;
                        }
                    }
                }
            }
        }
Beispiel #55
0
        private void CheckOpenParen(DocumentRoot root, MasterList<CsToken> tokens, Node<CsToken> tokenNode)
        {
            Node<CsToken> node2;
            bool flag = false;
            bool flag2 = false;
            Node<CsToken> previous = tokenNode.Previous;
            if ((previous != null) && (previous.Value.CsTokenType == CsTokenType.WhiteSpace))
            {
                foreach (CsToken token in tokens.ReverseIterator(previous))
                {
                    switch (token.CsTokenType)
                    {
                        case CsTokenType.WhiteSpace:
                        {
                            continue;
                        }
                        case CsTokenType.EndOfLine:
                            flag = true;
                            goto Label_017C;

                        case CsTokenType.Case:
                        case CsTokenType.Catch:
                        case CsTokenType.CloseSquareBracket:
                        case CsTokenType.Comma:
                        case CsTokenType.Equals:
                        case CsTokenType.Fixed:
                        case CsTokenType.For:
                        case CsTokenType.Foreach:
                        case CsTokenType.From:
                        case CsTokenType.Group:
                        case CsTokenType.If:
                        case CsTokenType.In:
                        case CsTokenType.Into:
                        case CsTokenType.Join:
                        case CsTokenType.Let:
                        case CsTokenType.Lock:
                        case CsTokenType.MultiLineComment:
                        case CsTokenType.Number:
                        case CsTokenType.OperatorSymbol:
                        case CsTokenType.OpenCurlyBracket:
                        case CsTokenType.OrderBy:
                        case CsTokenType.Return:
                        case CsTokenType.Select:
                        case CsTokenType.Semicolon:
                        case CsTokenType.Switch:
                        case CsTokenType.Throw:
                        case CsTokenType.Using:
                        case CsTokenType.Where:
                        case CsTokenType.While:
                        case CsTokenType.WhileDo:
                        case CsTokenType.Yield:
                            goto Label_017C;
                    }
                    base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.OpeningParenthesisMustBeSpacedCorrectly, new object[0]);
                }
            }
            Label_017C:
            node2 = tokenNode.Next;
            if ((node2 != null) && ((node2.Value.CsTokenType == CsTokenType.WhiteSpace) || (node2.Value.CsTokenType == CsTokenType.EndOfLine)))
            {
                foreach (CsToken token2 in tokens.ForwardIterator(node2))
                {
                    CsTokenType csTokenType = token2.CsTokenType;
                    if (csTokenType == CsTokenType.EndOfLine)
                    {
                        flag2 = true;
                        break;
                    }
                    if (((csTokenType != CsTokenType.WhiteSpace) && (csTokenType != CsTokenType.SingleLineComment)) && (csTokenType != CsTokenType.MultiLineComment))
                    {
                        base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.OpeningParenthesisMustBeSpacedCorrectly, new object[0]);
                        break;
                    }
                }
            }
            if (flag && flag2)
            {
                base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.OpeningParenthesisMustBeSpacedCorrectly, new object[0]);
            }
        }
        private void CheckCloseParen(MasterList<CsToken> tokens, Node<CsToken> tokenNode)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tokenNode, "tokenNode");

            // Close parens should never be preceded by whitespace.
            Node<CsToken> previousNode = tokenNode.Previous;
            if (previousNode != null)
            {
                if (previousNode.Value.CsTokenType == CsTokenType.WhiteSpace
                    || (previousNode.Value.CsTokenType == CsTokenType.EndOfLine && previousNode.Previous.Value.CsTokenType != CsTokenType.SingleLineComment))
                {
                    this.AddViolation(tokenNode.Value.FindParentElement(), previousNode.Value.Location, Rules.ClosingParenthesisMustBeSpacedCorrectly);
                }
            }

            // Find out what comes after the closing paren.
            Node<CsToken> nextNode = tokenNode.Next;

            if (nextNode != null)
            {
                CsTokenType nextType = nextNode.Value.CsTokenType;
                CsTokenType nextNextType = nextNode.Next == null ? CsTokenType.Other : nextNode.Next.Value.CsTokenType;

                if (tokenNode.Value.Parent is CastExpression)
                {
                    // There should not be any whitespace after the closing parenthesis in a cast expression.
                    if (nextType == CsTokenType.WhiteSpace)
                    {
                        this.AddViolation(tokenNode.Value.FindParentElement(), nextNode.Value.Location, Rules.ClosingParenthesisMustBeSpacedCorrectly);
                    }
                }
                else if (nextType == CsTokenType.LabelColon || nextNextType == CsTokenType.LabelColon)
                {
                    // If the next token is a colon, it's allowed to omit the whitespace only if we are in a switch\case statement.
                    bool followsCase = false;

                    foreach (CsToken item in tokens.ReverseIterator(tokenNode.Previous))
                    {
                        CsTokenType itemType = item.CsTokenType;
                        if (itemType == CsTokenType.EndOfLine)
                        {
                            break;
                        }
                        else if (itemType == CsTokenType.Case)
                        {
                            followsCase = true;
                            break;
                        }
                    }

                    if ((followsCase && nextType == CsTokenType.WhiteSpace) || (!followsCase && nextType != CsTokenType.WhiteSpace))
                    {
                        this.AddViolation(tokenNode.Value.FindParentElement(), nextNode.Value.Location, Rules.ClosingParenthesisMustBeSpacedCorrectly);
                    }
                }
                else if (nextType == CsTokenType.WhiteSpace)
                {
                    // Make sure that the character just after the whitespace is not a paren, bracket, a comma, or a semicolon.
                    foreach (CsToken item in tokens.ForwardIterator(tokenNode.Next.Next))
                    {
                        if (IsAllowedAfterClosingParenthesis(item))
                        {
                            this.AddViolation(tokenNode.Value.FindParentElement(), nextNode.Value.Location, Rules.ClosingParenthesisMustBeSpacedCorrectly);
                        }
                        else if (item.CsTokenType != CsTokenType.WhiteSpace)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    // For all other types, the parenthesis must be followed by whitespace, unless the next character is a paren, bracket, comma, or a semicolon.
                    if (nextNode.Value.CsTokenType != CsTokenType.EndOfLine && !IsAllowedAfterClosingParenthesis(nextNode.Value))
                    {
                        this.AddViolation(tokenNode.Value.FindParentElement(), nextNode.Value.Location, Rules.ClosingParenthesisMustBeSpacedCorrectly);
                    }
                }
            }
        }
Beispiel #57
0
 private void CheckSingleLineComment(DocumentRoot root, MasterList<CsToken> tokens, Node<CsToken> tokenNode)
 {
     if (tokenNode.Value.Text.Length > 2)
     {
         string text = tokenNode.Value.Text;
         if ((((text[2] != ' ') && (text[2] != '\t')) && ((text[2] != '/') && (text[2] != '\\'))) && (((text[1] != '\n') && (text[1] != '\r')) && (((text.Length < 4) || (text[2] != '-')) || (text[3] != '-'))))
         {
             base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.SingleLineCommentsMustBeginWithSingleSpace, new object[0]);
         }
         else if (((text.Length > 3) && ((text[3] == ' ') || (text[3] == '\t'))) && (text[2] != '\\'))
         {
             bool flag = true;
             int num = 0;
             foreach (CsToken token in tokens.ReverseIterator(tokenNode.Previous))
             {
                 if (token.CsTokenType == CsTokenType.EndOfLine)
                 {
                     if (++num != 2)
                     {
                         continue;
                     }
                     break;
                 }
                 if (token.CsTokenType == CsTokenType.SingleLineComment)
                 {
                     flag = false;
                     break;
                 }
                 if (token.CsTokenType != CsTokenType.WhiteSpace)
                 {
                     break;
                 }
             }
             if (flag)
             {
                 base.AddViolation(root, tokenNode.Value.LineNumber, Microsoft.StyleCop.CSharp.Rules.SingleLineCommentsMustBeginWithSingleSpace, new object[0]);
             }
         }
     }
 }
        private void CheckSpacing(MasterList<CsToken> tokens, bool type, Node<CsToken> parentTokenNode)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.Ignore(type);

            // Make sure it contains at least one token.
            if (tokens.Count > 0)
            {
                for (Node<CsToken> tokenNode = tokens.First; tokenNode != null; tokenNode = tokenNode.Next)
                {
                    if (this.Cancel)
                    {
                        break;
                    }

                    if (!tokenNode.Value.Generated)
                    {
                        switch (tokenNode.Value.CsTokenType)
                        {
                            case CsTokenType.Async:
                            case CsTokenType.By:
                            case CsTokenType.Catch:
                            case CsTokenType.Equals:
                            case CsTokenType.Fixed:
                            case CsTokenType.For:
                            case CsTokenType.Foreach:
                            case CsTokenType.From:
                            case CsTokenType.Group:
                            case CsTokenType.If:
                            case CsTokenType.In:
                            case CsTokenType.Into:
                            case CsTokenType.Join:
                            case CsTokenType.Let:
                            case CsTokenType.Lock:
                            case CsTokenType.On:
                            case CsTokenType.OrderBy:
                            case CsTokenType.Return:
                            case CsTokenType.Select:
                            case CsTokenType.Stackalloc:
                            case CsTokenType.Switch:
                            case CsTokenType.Throw:
                            case CsTokenType.Using:
                            case CsTokenType.Where:
                            case CsTokenType.While:
                            case CsTokenType.WhileDo:
                            case CsTokenType.Yield:

                                // These keywords must be followed by a space before the open parenthesis.
                                this.CheckKeywordWithSpace(tokenNode);
                                break;

                            case CsTokenType.New:
                                this.CheckNewKeywordSpacing(tokens, tokenNode);
                                break;

                            case CsTokenType.Checked:
                            case CsTokenType.Unchecked:
                            case CsTokenType.Sizeof:
                            case CsTokenType.Typeof:
                            case CsTokenType.DefaultValue:

                                // These keywords must not contain any space before the open parenthesis.
                                this.CheckKeywordWithoutSpace(tokens, tokenNode);
                                break;

                            case CsTokenType.Comma:
                            case CsTokenType.Semicolon:
                                this.CheckSemicolonAndComma(tokens, tokenNode);
                                break;

                            case CsTokenType.OpenParenthesis:
                                this.CheckOpenParen(tokens, tokenNode);
                                break;

                            case CsTokenType.CloseParenthesis:
                                this.CheckCloseParen(tokens, tokenNode);
                                break;

                            case CsTokenType.OpenSquareBracket:
                                this.CheckOpenSquareBracket(tokenNode);
                                break;

                            case CsTokenType.CloseSquareBracket:
                                this.CheckCloseSquareBracket(tokens, tokenNode, parentTokenNode);
                                break;

                            case CsTokenType.OpenCurlyBracket:
                                this.CheckOpenCurlyBracket(tokens, tokenNode);
                                break;

                            case CsTokenType.CloseCurlyBracket:
                                this.CheckCloseCurlyBracket(tokens, tokenNode);
                                break;

                            case CsTokenType.OpenAttributeBracket:
                                this.CheckAttributeTokenOpenBracket(tokenNode);
                                break;

                            case CsTokenType.CloseAttributeBracket:
                                this.CheckAttributeTokenCloseBracket(tokens, tokenNode);
                                break;

                            case CsTokenType.BaseColon:
                            case CsTokenType.WhereColon:
                                this.CheckSymbol(tokens, tokenNode);
                                break;

                            case CsTokenType.AttributeColon:
                            case CsTokenType.LabelColon:
                                this.CheckLabelColon(tokenNode);
                                break;

                            case CsTokenType.WhiteSpace:
                                this.CheckWhitespace(tokenNode);
                                break;

                            case CsTokenType.XmlHeader:
                                XmlHeader header = (XmlHeader)tokenNode.Value;
                                this.CheckXmlHeaderComment(header);

                                // Look for tabs in the xml header string. Look at 
                                // each sub-token in the header individually to get the
                                // line numbers correct.
                                for (Node<CsToken> xmlHeaderToken = header.ChildTokens.First; xmlHeaderToken != null; xmlHeaderToken = xmlHeaderToken.Next)
                                {
                                    this.CheckTabsInComment(xmlHeaderToken.Value);
                                }

                                break;

                            case CsTokenType.Attribute:
                                Attribute attribute = tokenNode.Value as StyleCop.CSharp.Attribute;
                                this.CheckSpacing(attribute.ChildTokens, false, tokenNode);
                                break;

                            case CsTokenType.PreprocessorDirective:
                                this.CheckPreprocessorSpacing(tokenNode.Value as Preprocessor);
                                break;

                            case CsTokenType.SingleLineComment:

                                // Look for tabs in the comment string.
                                this.CheckTabsInComment(tokenNode.Value);

                                // Check spacing in the comment.
                                this.CheckSingleLineComment(tokens, tokenNode);
                                break;

                            case CsTokenType.MultiLineComment:

                                // Look for tabs in the comment string.
                                this.CheckTabsInComment(tokenNode.Value);
                                break;

                            case CsTokenType.NullableTypeSymbol:
                                this.CheckNullableTypeSymbol(tokenNode);
                                break;

                            case CsTokenType.Operator:
                                this.CheckOperatorKeyword(tokenNode);
                                break;

                            case CsTokenType.OperatorSymbol:
                                OperatorSymbol operatorSymbol = tokenNode.Value as OperatorSymbol;
                                switch (operatorSymbol.Category)
                                {
                                    case OperatorCategory.Reference:
                                        switch (operatorSymbol.SymbolType)
                                        {
                                            case OperatorType.QualifiedAlias:
                                            case OperatorType.Pointer:
                                            case OperatorType.MemberAccess:
                                                this.CheckMemberAccessSymbol(tokens, tokenNode);
                                                break;

                                            case OperatorType.AddressOf:
                                            case OperatorType.Dereference:
                                                this.CheckUnsafeAccessSymbols(tokenNode, type, parentTokenNode);
                                                break;

                                            default:
                                                Debug.Fail("Unexpected operator category.");
                                                break;
                                        }

                                        break;

                                    case OperatorCategory.Arithmetic:
                                    case OperatorCategory.Assignment:
                                    case OperatorCategory.Conditional:
                                    case OperatorCategory.Logical:
                                    case OperatorCategory.Relational:
                                    case OperatorCategory.Shift:
                                    case OperatorCategory.Lambda:

                                        // Symbols should have whitespace on both sides except null conditional '?.'
                                        this.CheckSymbol(tokens, tokenNode);
                                        break;

                                    case OperatorCategory.IncrementDecrement:
                                        this.CheckIncrementDecrement(tokenNode);
                                        break;

                                    case OperatorCategory.Unary:
                                        if (operatorSymbol.SymbolType == OperatorType.Negative)
                                        {
                                            this.CheckPositiveOrNegativeSign(tokenNode, false);
                                        }
                                        else if (operatorSymbol.SymbolType == OperatorType.Positive)
                                        {
                                            this.CheckPositiveOrNegativeSign(tokenNode, true);
                                        }
                                        else
                                        {
                                            this.CheckUnarySymbol(tokens, tokenNode);
                                        }

                                        break;
                                }

                                break;
                        }

                        switch (tokenNode.Value.CsTokenClass)
                        {
                            case CsTokenClass.ConstructorConstraint:
                                this.CheckSpacing(((ConstructorConstraint)tokenNode.Value).ChildTokens, false, tokenNode);
                                break;

                            case CsTokenClass.GenericType:
                                this.CheckGenericSpacing(tokens, tokenNode);
                                goto case CsTokenClass.Type;

                            case CsTokenClass.Type:
                                this.CheckSpacing(((TypeToken)tokenNode.Value).ChildTokens, true, tokenNode);
                                break;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Checks the spacing around a 'new' keyword.
        /// </summary>
        /// <param name="tokens">
        /// The token list.
        /// </param>
        /// <param name="tokenNode">
        /// The token node to check.
        /// </param>
        private void CheckNewKeywordSpacing(MasterList<CsToken> tokens, Node<CsToken> tokenNode)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tokenNode, "tokenNode");

            // The keywords must be followed by a space, unless the next token is an opening square bracket, in which case
            // there should be no space.
            Node<CsToken> temp = tokenNode.Next;
            if (temp != null)
            {
                if (temp.Value.CsTokenType == CsTokenType.WhiteSpace || temp.Value.CsTokenType == CsTokenType.EndOfLine)
                {
                    // The keyword is followed by whitespace. Make sure the next non-whitespace character is not an opening bracket.
                    foreach (CsToken nextNonWhitespaceToken in tokens.ForwardIterator(temp.Next))
                    {
                        if (nextNonWhitespaceToken.CsTokenType == CsTokenType.OpenSquareBracket)
                        {
                            this.AddViolation(
                                tokenNode.Value.FindParentElement(),
                                tokenNode.Value.Location,
                                Rules.CodeMustNotContainSpaceAfterNewKeywordInImplicitlyTypedArrayAllocation);
                            break;
                        }
                        else if (nextNonWhitespaceToken.CsTokenType != CsTokenType.WhiteSpace && nextNonWhitespaceToken.CsTokenType != CsTokenType.EndOfLine)
                        {
                            break;
                        }
                    }
                }
                else if (temp.Value.CsTokenType != CsTokenType.OpenSquareBracket)
                {
                    // The keyword is not followed by whitespace.
                    this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.KeywordsMustBeSpacedCorrectly, tokenNode.Value.Text);
                }
            }
        }
        /// <summary>
        /// Checks a symbol for spacing.
        /// </summary>
        /// <param name="tokens">
        /// The list of tokens being parsed.
        /// </param>
        /// <param name="tokenNode">
        /// The token to check.
        /// </param>
        private void CheckSymbol(MasterList<CsToken> tokens, Node<CsToken> tokenNode)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tokenNode, "tokenNode");

            OperatorSymbol operatorSymbol = tokenNode.Value as OperatorSymbol;
            if (operatorSymbol != null && operatorSymbol.SymbolType == OperatorType.NullConditional)
            {
                // Symbols should not have whitespace on both sides for operator '?.'.
                Node<CsToken> previousNode = tokenNode.Previous;
                if (previousNode != null && previousNode.Value.CsTokenType == CsTokenType.WhiteSpace && previousNode.Value.CsTokenType != CsTokenType.EndOfLine)
                {
                    this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.SymbolsMustBeSpacedCorrectly, tokenNode.Value.Text);
                }

                Node<CsToken> nextNode = tokenNode.Next;
                if (nextNode != null && nextNode.Value.CsTokenType == CsTokenType.WhiteSpace && nextNode.Value.CsTokenType != CsTokenType.EndOfLine)
                {
                    this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.SymbolsMustBeSpacedCorrectly, tokenNode.Value.Text);
                }

                if (operatorSymbol.Text.Length > 2 || operatorSymbol.Text.Contains("\r") || operatorSymbol.Text.Contains("\n") || operatorSymbol.Text.Contains(" "))
                {
                    this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.DoNotSplitNullConditionalOperators, tokenNode.Value.Text);
                }
            }
            else
            {
                // Symbols should have whitespace on both sides.
                Node<CsToken> previousNode = tokenNode.Previous;
                if (previousNode != null && previousNode.Value.CsTokenType != CsTokenType.WhiteSpace && previousNode.Value.CsTokenType != CsTokenType.EndOfLine)
                {
                    this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.Location, Rules.SymbolsMustBeSpacedCorrectly, tokenNode.Value.Text);
                }

                Node<CsToken> nextNode = tokenNode.Next;
                if (nextNode != null && nextNode.Value.CsTokenType != CsTokenType.WhiteSpace && nextNode.Value.CsTokenType != CsTokenType.EndOfLine)
                {
                    // Make sure the previous token is not operator.
                    if (previousNode != null)
                    {
                        foreach (CsToken item in tokens.ReverseIterator(previousNode))
                        {
                            if (item.CsTokenType == CsTokenType.Operator)
                            {
                                return;
                            }
                            else if (item.CsTokenType != CsTokenType.WhiteSpace && item.CsTokenType != CsTokenType.EndOfLine
                                     && item.CsTokenType != CsTokenType.SingleLineComment && item.CsTokenType != CsTokenType.MultiLineComment
                                     && item.CsTokenType != CsTokenType.PreprocessorDirective)
                            {
                                break;
                            }
                        }
                    }

                    this.AddViolation(tokenNode.Value.FindParentElement(), tokenNode.Value.LineNumber, Rules.SymbolsMustBeSpacedCorrectly, tokenNode.Value.Text);
                }
            }
        }