void HandleVisitorPropertyDeclarationVisited (PropertyDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckProperty (node, data))
					return;
			}
		}
		void HandleVisitorVariableDeclarationStatementVisited (VariableDeclarationStatement node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckVariableDeclaration (node, data))
					return;
			}
		}
		void HandleVisitorFixedFieldDeclarationVisited (FixedFieldDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckField (node, data))
					return;
			}
		}
Beispiel #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);
        }
 void HandleVisitorDelegateDeclarationVisited(DelegateDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckDelegate(node, data))
         {
             return;
         }
     }
 }
 void HandleVisitorCustomEventDeclarationVisited(CustomEventDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckEvent(node, data))
         {
             return;
         }
     }
 }
 void HandleVisitorEnumMemberDeclarationVisited(EnumMemberDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckEnumMember(node, data))
         {
             return;
         }
     }
 }
 void HandleVisitorNamespaceDeclarationVisited(NamespaceDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckNamespace(node, data))
         {
             return;
         }
     }
 }
 void HandleVisitorPropertyDeclarationVisited(PropertyDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckProperty(node, data))
         {
             return;
         }
     }
 }
 void HandleVisitorMethodDeclarationVisited(MethodDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckMethod(node, data))
         {
             return;
         }
     }
 }
 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);
					}
				);
			}
		}
		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)
				)
			);
		}
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
         }
                   );
     }
 }
Beispiel #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);
        }
Beispiel #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)
                    )
                );
        }
Beispiel #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);
        }
Beispiel #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);
        }
		void HandleVisitorDelegateDeclarationVisited (DelegateDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckDelegate (node, data))
					return;
			}
		}
		void HandleVisitorNamespaceDeclarationVisited (NamespaceDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckNamespace (node, data))
					return;
			}
		}
		void HandleVisitorTypeParameterDeclarationVisited (TypeParameterDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckTypeParameter (node, data))
					return;
			}
		}
		void HandleVisitorEnumMemberDeclarationVisited (EnumMemberDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckEnumMember (node, data))
					return;
			}
		}
		void HandleVisitorCustomEventDeclarationVisited (CustomEventDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckEvent (node, data))
					return;
			}
		}
 void HandleVisitorTypeParameterDeclarationVisited(TypeParameterDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckTypeParameter(node, data))
         {
             return;
         }
     }
 }
Beispiel #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;
		}
Beispiel #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;
		}
Beispiel #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)
                     );
        }
Beispiel #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;
		}
Beispiel #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;
		}
Beispiel #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;
		}
Beispiel #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;
		}
Beispiel #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;
		}
		void HandleVisitorMethodDeclarationVisited (MethodDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckMethod (node, data))
					return;
			}
		}
 void HandleVisitorVariableDeclarationStatementVisited(VariableDeclarationStatement node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckVariableDeclaration(node, data))
         {
             return;
         }
     }
 }