Example #1
0
		void HandleVisitorPropertyDeclarationVisited (PropertyDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckProperty (node, data))
					return;
			}
		}
Example #2
0
		void HandleVisitorVariableDeclarationStatementVisited (VariableDeclarationStatement node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckVariableDeclaration (node, data))
					return;
			}
		}
Example #3
0
		void HandleVisitorFixedFieldDeclarationVisited (FixedFieldDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckField (node, data))
					return;
			}
		}
Example #4
0
        public bool CheckType(ICS.TypeDeclaration node, InspectionData data)
        {
            if (MatchKind != 0)
            {
                switch (MatchKind)
                {
                case DeclarationKinds.Class:
                    if (node.ClassType != ICSharpCode.NRefactory.CSharp.ClassType.Class)
                    {
                        return(false);
                    }
                    break;

                case DeclarationKinds.Enum:
                    if (node.ClassType != ICSharpCode.NRefactory.CSharp.ClassType.Enum)
                    {
                        return(false);
                    }
                    break;

                case DeclarationKinds.Struct:
                    if (node.ClassType != ICSharpCode.NRefactory.CSharp.ClassType.Struct)
                    {
                        return(false);
                    }
                    break;

                case DeclarationKinds.Interface:
                    if (node.ClassType != ICSharpCode.NRefactory.CSharp.ClassType.Interface)
                    {
                        return(false);
                    }
                    break;

//				case DeclarationKinds.Delegate:
//					if (node.ClassType != ICSharpCode.NRefactory.CSharp.ClassType.Delegate)
//						return false;
//					break;
                default:
                    return(false);
                }
            }

            if (!CheckAttributedNode(node, ICS.Modifiers.Internal))
            {
                return(false);
            }

            string name = node.Name;

            if (IsValid(name))
            {
                return(true);
            }

            data.Add(GetFixableResult(node.NameToken.StartLocation, null, name));
            return(true);
        }
Example #5
0
 void HandleVisitorDelegateDeclarationVisited(DelegateDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckDelegate(node, data))
         {
             return;
         }
     }
 }
Example #6
0
 void HandleVisitorCustomEventDeclarationVisited(CustomEventDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckEvent(node, data))
         {
             return;
         }
     }
 }
Example #7
0
 void HandleVisitorEnumMemberDeclarationVisited(EnumMemberDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckEnumMember(node, data))
         {
             return;
         }
     }
 }
Example #8
0
 void HandleVisitorNamespaceDeclarationVisited(NamespaceDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckNamespace(node, data))
         {
             return;
         }
     }
 }
Example #9
0
 void HandleVisitorPropertyDeclarationVisited(PropertyDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckProperty(node, data))
         {
             return;
         }
     }
 }
Example #10
0
 void HandleVisitorMethodDeclarationVisited(MethodDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckMethod(node, data))
         {
             return;
         }
     }
 }
Example #11
0
 void HandleVisitorFixedFieldDeclarationVisited(FixedFieldDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckField(node, data))
         {
             return;
         }
     }
 }
		void HandleVisitiorVariableDeclarationStatementVisited (VariableDeclarationStatement node, InspectionData data)
		{
			if (node.Type is PrimitiveType)
				return;
			if (node.Type is SimpleType && ((SimpleType)node.Type).Identifier == "var") 
				return;
			var severity = base.node.GetSeverity ();
			if (severity == MonoDevelop.SourceEditor.QuickTaskSeverity.None)
				return;
			//only checks for cases where the type would be obvious - assignment of new, cast, etc.
			//also check the type actually matches else the user might want to assign different subclasses later
			foreach (var v in node.Variables) {
				if (v.Initializer.IsNull)
					return;
				
				var arrCreate = v.Initializer as ArrayCreateExpression;
				if (arrCreate != null) {
					var n = node.Type as ComposedType;
					//FIXME: check the specifier compatibility
					if (n != null && n.ArraySpecifiers.Any () && n.BaseType.IsMatch (arrCreate.Type))
						continue;
					return;
				}
				var objCreate = v.Initializer as ObjectCreateExpression;
				if (objCreate != null) {
					if (objCreate.Type.IsMatch (node.Type))
						continue;
					return;
				}
				var asCast = v.Initializer as AsExpression;
				if (asCast != null) {
					if (asCast.Type.IsMatch (node.Type))
						continue;
					return;
				}
				var cast = v.Initializer as CastExpression;
				if (cast != null) {
					if (cast.Type.IsMatch (node.Type))
						continue;
					return;
				}
				return;
			}
			
			data.Add (new Result (
					new DomRegion (node.Type.StartLocation.Line, node.Type.StartLocation.Column, node.Type.EndLocation.Line, node.Type.EndLocation.Column),
					GettextCatalog.GetString ("Use implicitly typed local variable decaration"),
					severity,
					ResultCertainty.High, 
					ResultImportance.Medium,
					severity != MonoDevelop.SourceEditor.QuickTaskSeverity.Suggestion)
				);
		}
		void HandleVisitorUsingDeclarationVisited (UsingDeclaration node, InspectionData data)
		{
			if (!data.Graph.UsedUsings.Contains (node.Namespace)) {
				AddResult (data,
					new DomRegion (node.StartLocation.Line, node.StartLocation.Column, node.EndLocation.Line, node.EndLocation.Column),
					GettextCatalog.GetString ("Remove unused usings"),
					delegate {
						RefactoringOptions options = new RefactoringOptions () { Document = data.Document, Dom = data.Document.Dom};
						new RemoveUnusedImportsRefactoring ().Run (options);
					}
				);
			}
		}
Example #14
0
		protected void AddResult (InspectionData data, DomRegion region, string menuText, Action fix)
		{
			var severity = node.GetSeverity ();
			if (severity == MonoDevelop.SourceEditor.QuickTaskSeverity.None)
				return;
			data.Add (
				new GenericResults (
					region,
					node.Title,
					severity, 
					ResultCertainty.High, 
					ResultImportance.Low,
					new GenericFix (menuText, fix)
				)
			);
		}
Example #15
0
        public bool CheckDelegate(ICS.DelegateDeclaration node, InspectionData data)
        {
            if ((MatchKind != 0 && (MatchKind & DeclarationKinds.Delegate) == 0) || !CheckAttributedNode(node, ICS.Modifiers.Internal))
            {
                return(false);
            }

            string name = node.Name;

            if (IsValid(name))
            {
                return(true);
            }

            data.Add(GetFixableResult(node.NameToken.StartLocation, null, name));
            return(true);
        }
Example #16
0
        public bool CheckEvent(ICS.CustomEventDeclaration node, InspectionData data)
        {
            if ((MatchKind != 0 && (MatchKind & DeclarationKinds.Event) == 0) || !CheckAttributedNode(node, ICS.Modifiers.Private))
            {
                return(false);
            }

            var name = node.Name;

            if (IsValid(name))
            {
                return(true);
            }

            data.Add(GetFixableResult(node.NameToken.StartLocation, null, name));
            return(true);
        }
Example #17
0
        public bool CheckEnumMember(ICS.EnumMemberDeclaration node, InspectionData data)
        {
            if ((MatchKind != 0 && (MatchKind & DeclarationKinds.EnumMember) == 0))
            {
                return(false);
            }

            string name = node.Name;

            if (IsValid(name))
            {
                return(true);
            }

            data.Add(GetFixableResult(node.NameToken.StartLocation, null, name));
            return(true);
        }
Example #18
0
        public bool CheckNamespace(ICS.NamespaceDeclaration node, InspectionData data)
        {
            if ((MatchKind != 0 && (MatchKind & DeclarationKinds.Namespace) == 0))
            {
                return(false);
            }

            string name = node.Name;

            if (IsValid(name))
            {
                return(true);
            }

            data.Add(GetFixableResult(node.Identifiers.First().StartLocation, null, name));
            return(true);
        }
Example #19
0
 void HandleVisitorUsingDeclarationVisited(UsingDeclaration node, InspectionData data)
 {
     if (!data.Graph.UsedUsings.Contains(node.Namespace))
     {
         AddResult(data,
                   new DomRegion(node.StartLocation.Line, node.StartLocation.Column, node.EndLocation.Line, node.EndLocation.Column),
                   GettextCatalog.GetString("Remove unused usings"),
                   delegate {
             RefactoringOptions options = new RefactoringOptions()
             {
                 Document = data.Document, Dom = data.Document.Dom
             };
             new RemoveUnusedImportsRefactoring().Run(options);
         }
                   );
     }
 }
Example #20
0
        public bool CheckEvent(ICS.EventDeclaration node, InspectionData data)
        {
            if ((MatchKind != 0 && (MatchKind & DeclarationKinds.Event) == 0) || !CheckAttributedNode(node, ICS.Modifiers.Private))
            {
                return(false);
            }

            foreach (var v in node.Variables)
            {
                string name = v.Name;
                if (IsValid(name))
                {
                    continue;
                }
                data.Add(GetFixableResult(v.NameToken.StartLocation, null, name));
            }

            return(true);
        }
Example #21
0
        protected void AddResult(InspectionData data, DomRegion region, string menuText, Action fix)
        {
            var severity = node.GetSeverity();

            if (severity == MonoDevelop.SourceEditor.QuickTaskSeverity.None)
            {
                return;
            }
            data.Add(
                new GenericResults(
                    region,
                    node.Title,
                    severity,
                    ResultCertainty.High,
                    ResultImportance.Low,
                    new GenericFix(menuText, fix)
                    )
                );
        }
Example #22
0
        public static IEnumerable <Result> Check(Document input)
        {
            var unit = input != null ? input.ParsedDocument.LanguageAST as ICSharpCode.NRefactory.CSharp.CompilationUnit : null;

            if (unit == null)
            {
                return(Enumerable.Empty <Result> ());
            }

            var cg = new CallGraph();

            cg.Inspect(input, input.GetResolver(), unit);
            var data = new InspectionData()
            {
                Graph = cg, Document = input
            };

            unit.AcceptVisitor(visitor, data);
            return(data.Results);
        }
Example #23
0
        public bool CheckVariableDeclaration(ICS.VariableDeclarationStatement node, InspectionData data)
        {
            if ((MatchKind != 0 && (MatchKind & DeclarationKinds.LocalVariable) == 0) || !CheckModifiers(node.Modifiers, ICS.Modifiers.Private))
            {
                return(false);
            }
            var member = data.Document.CompilationUnit.GetMemberAt(node.StartLocation.Line, node.StartLocation.Column);

            foreach (var var in node.Variables)
            {
                string name = var.Name;
                if (IsValid(name))
                {
                    continue;
                }
                var v = new LocalVariable(member, name, DomReturnType.Void,
                                          new DomRegion(node.StartLocation.Line, node.StartLocation.Column,
                                                        node.EndLocation.Line, node.EndLocation.Column));
                data.Add(GetFixableResult(var.NameToken.StartLocation, v, name));
            }

            return(true);
        }
Example #24
0
		void HandleVisitorDelegateDeclarationVisited (DelegateDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckDelegate (node, data))
					return;
			}
		}
Example #25
0
		void HandleVisitorNamespaceDeclarationVisited (NamespaceDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckNamespace (node, data))
					return;
			}
		}
Example #26
0
		void HandleVisitorTypeParameterDeclarationVisited (TypeParameterDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckTypeParameter (node, data))
					return;
			}
		}
Example #27
0
		void HandleVisitorEnumMemberDeclarationVisited (EnumMemberDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckEnumMember (node, data))
					return;
			}
		}
Example #28
0
		void HandleVisitorCustomEventDeclarationVisited (CustomEventDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckEvent (node, data))
					return;
			}
		}
Example #29
0
 void HandleVisitorTypeParameterDeclarationVisited(TypeParameterDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckTypeParameter(node, data))
         {
             return;
         }
     }
 }
Example #30
0
		public bool CheckEnumMember (ICS.EnumMemberDeclaration node, InspectionData data)
		{
			if ((MatchKind != 0 && (MatchKind & DeclarationKinds.EnumMember) == 0))
				return false;
			
			string name = node.Name;
			if (IsValid (name))
				return true;
			
			data.Add (GetFixableResult (node.NameToken.StartLocation, null, name));
			return true;
		}
Example #31
0
		public bool CheckDelegate (ICS.DelegateDeclaration node, InspectionData data)
		{
			if ((MatchKind != 0 && (MatchKind & DeclarationKinds.Delegate) == 0) || !CheckAttributedNode (node, ICS.Modifiers.Internal))
				return false;
			
			string name = node.Name;
			if (IsValid (name))
				return true;
			
			data.Add (GetFixableResult (node.NameToken.StartLocation, null, name));
			return true;
		}
Example #32
0
		public bool CheckType (ICS.TypeDeclaration node, InspectionData data)
		{
			if (MatchKind != 0) {
				switch (MatchKind) {
				case DeclarationKinds.Class:
					if (node.ClassType != ICSharpCode.NRefactory.TypeSystem.ClassType.Class)
						return false;
					break;
				case DeclarationKinds.Enum:
					if (node.ClassType != ICSharpCode.NRefactory.TypeSystem.ClassType.Enum)
						return false;
					break;
				case DeclarationKinds.Struct:
					if (node.ClassType != ICSharpCode.NRefactory.TypeSystem.ClassType.Struct)
						return false;
					break;
				case DeclarationKinds.Interface:
					if (node.ClassType != ICSharpCode.NRefactory.TypeSystem.ClassType.Interface)
						return false;
					break;
				case DeclarationKinds.Delegate:
					if (node.ClassType != ICSharpCode.NRefactory.TypeSystem.ClassType.Delegate)
						return false;
					break;
				default:
					return false;
				}
			}
			
			if (!CheckAttributedNode (node, ICS.Modifiers.Internal))
				return false;
			
			string name = node.Name;
			if (IsValid (name))
				return true;
			
			data.Add (GetFixableResult (node.NameToken.StartLocation, null, name));
			return true;
		}
        void HandleVisitiorVariableDeclarationStatementVisited(VariableDeclarationStatement node, InspectionData data)
        {
            if (node.Type is PrimitiveType)
            {
                return;
            }
            if (node.Type is SimpleType && ((SimpleType)node.Type).Identifier == "var")
            {
                return;
            }
            var severity = base.node.GetSeverity();

            if (severity == MonoDevelop.SourceEditor.QuickTaskSeverity.None)
            {
                return;
            }
            //only checks for cases where the type would be obvious - assignment of new, cast, etc.
            //also check the type actually matches else the user might want to assign different subclasses later
            foreach (var v in node.Variables)
            {
                if (v.Initializer.IsNull)
                {
                    return;
                }

                var arrCreate = v.Initializer as ArrayCreateExpression;
                if (arrCreate != null)
                {
                    var n = node.Type as ComposedType;
                    //FIXME: check the specifier compatibility
                    if (n != null && n.ArraySpecifiers.Any() && n.BaseType.IsMatch(arrCreate.Type))
                    {
                        continue;
                    }
                    return;
                }
                var objCreate = v.Initializer as ObjectCreateExpression;
                if (objCreate != null)
                {
                    if (objCreate.Type.IsMatch(node.Type))
                    {
                        continue;
                    }
                    return;
                }
                var asCast = v.Initializer as AsExpression;
                if (asCast != null)
                {
                    if (asCast.Type.IsMatch(node.Type))
                    {
                        continue;
                    }
                    return;
                }
                var cast = v.Initializer as CastExpression;
                if (cast != null)
                {
                    if (cast.Type.IsMatch(node.Type))
                    {
                        continue;
                    }
                    return;
                }
                return;
            }

            data.Add(new Result(
                         new DomRegion(node.Type.StartLocation.Line, node.Type.StartLocation.Column, node.Type.EndLocation.Line, node.Type.EndLocation.Column),
                         GettextCatalog.GetString("Use implicitly typed local variable decaration"),
                         severity,
                         ResultCertainty.High,
                         ResultImportance.Medium,
                         severity != MonoDevelop.SourceEditor.QuickTaskSeverity.Suggestion)
                     );
        }
Example #34
0
		public bool CheckEvent (ICS.EventDeclaration node, InspectionData data)
		{
			if ((MatchKind != 0 && (MatchKind & DeclarationKinds.Event) == 0) || !CheckAttributedNode (node, ICS.Modifiers.Private))
				return false;
			
			foreach (var v in node.Variables) {
				string name = v.Name;
				if (IsValid (name))
					continue;
				data.Add (GetFixableResult (v.NameToken.StartLocation, null, name));
			}
			
			return true;
		}
Example #35
0
		public bool CheckVariableDeclaration (ICS.VariableDeclarationStatement node, InspectionData data)
		{
			if ((MatchKind != 0 && (MatchKind & DeclarationKinds.LocalVariable) == 0) || !CheckModifiers (node.Modifiers, ICS.Modifiers.Private))
				return false;
			var member = data.Document.CompilationUnit.GetMemberAt (node.StartLocation.Line, node.StartLocation.Column);
			foreach (var var in node.Variables) {
				string name = var.Name;
				if (IsValid (name))
					continue;
				var v = new LocalVariable (member, name, DomReturnType.Void,
					new DomRegion (node.StartLocation.Line, node.StartLocation.Column,
					node.EndLocation.Line, node.EndLocation.Column));
				data.Add (GetFixableResult (var.NameToken.StartLocation, v, name));
			}
			
			return true;
		}
Example #36
0
		public bool CheckNamespace (ICS.NamespaceDeclaration node, InspectionData data)
		{
			if ((MatchKind != 0 && (MatchKind & DeclarationKinds.Namespace) == 0))
				return false;
			
			string name = node.Name;
			if (IsValid (name))
				return true;
			
			data.Add (GetFixableResult (node.Identifiers.First ().StartLocation, null, name));
			return true;
		}
Example #37
0
		public bool CheckEvent (ICS.CustomEventDeclaration node, InspectionData data)
		{
			if ((MatchKind != 0 && (MatchKind & DeclarationKinds.Event) == 0) || !CheckAttributedNode (node, ICS.Modifiers.Private))
				return false;
			
			var name = node.Name;
			if (IsValid (name))
				return true;
			
			data.Add (GetFixableResult (node.NameToken.StartLocation, null, name));
			return true;
		}
Example #38
0
		public static IEnumerable<Result> Check (Document input)
		{
			var unit = input != null ? input.ParsedDocument.LanguageAST as ICSharpCode.NRefactory.CSharp.CompilationUnit : null;
			if (unit == null)
				return Enumerable.Empty<Result> ();
				
			var cg = new CallGraph ();
			cg.Inspect (input, input.GetResolver (), unit);
			var data = new InspectionData () { Graph = cg, Document = input };
			unit.AcceptVisitor (visitor, data);
			return data.Results;
		}
Example #39
0
		void HandleVisitorMethodDeclarationVisited (MethodDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckMethod (node, data))
					return;
			}
		}
Example #40
0
 void HandleVisitorVariableDeclarationStatementVisited(VariableDeclarationStatement node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckVariableDeclaration(node, data))
         {
             return;
         }
     }
 }