示例#1
0
		void HandleVisitorPropertyDeclarationVisited (PropertyDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckProperty (node, data))
					return;
			}
		}
示例#2
0
		void HandleVisitorVariableDeclarationStatementVisited (VariableDeclarationStatement node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckVariableDeclaration (node, data))
					return;
			}
		}
示例#3
0
		void HandleVisitorFixedFieldDeclarationVisited (FixedFieldDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckField (node, data))
					return;
			}
		}
示例#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);
        }
示例#5
0
 void HandleVisitorDelegateDeclarationVisited(DelegateDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckDelegate(node, data))
         {
             return;
         }
     }
 }
示例#6
0
 void HandleVisitorCustomEventDeclarationVisited(CustomEventDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckEvent(node, data))
         {
             return;
         }
     }
 }
示例#7
0
 void HandleVisitorEnumMemberDeclarationVisited(EnumMemberDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckEnumMember(node, data))
         {
             return;
         }
     }
 }
示例#8
0
 void HandleVisitorNamespaceDeclarationVisited(NamespaceDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckNamespace(node, data))
         {
             return;
         }
     }
 }
示例#9
0
 void HandleVisitorPropertyDeclarationVisited(PropertyDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckProperty(node, data))
         {
             return;
         }
     }
 }
示例#10
0
 void HandleVisitorMethodDeclarationVisited(MethodDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckMethod(node, data))
         {
             return;
         }
     }
 }
示例#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);
					}
				);
			}
		}
示例#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)
				)
			);
		}
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
         }
                   );
     }
 }
示例#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);
        }
示例#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)
                    )
                );
        }
示例#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);
        }
示例#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);
        }
示例#24
0
		void HandleVisitorDelegateDeclarationVisited (DelegateDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckDelegate (node, data))
					return;
			}
		}
示例#25
0
		void HandleVisitorNamespaceDeclarationVisited (NamespaceDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckNamespace (node, data))
					return;
			}
		}
示例#26
0
		void HandleVisitorTypeParameterDeclarationVisited (TypeParameterDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckTypeParameter (node, data))
					return;
			}
		}
示例#27
0
		void HandleVisitorEnumMemberDeclarationVisited (EnumMemberDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckEnumMember (node, data))
					return;
			}
		}
示例#28
0
		void HandleVisitorCustomEventDeclarationVisited (CustomEventDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckEvent (node, data))
					return;
			}
		}
示例#29
0
 void HandleVisitorTypeParameterDeclarationVisited(TypeParameterDeclaration node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckTypeParameter(node, data))
         {
             return;
         }
     }
 }
示例#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;
		}
示例#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;
		}
示例#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)
                     );
        }
示例#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;
		}
示例#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;
		}
示例#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;
		}
示例#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;
		}
示例#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;
		}
示例#39
0
		void HandleVisitorMethodDeclarationVisited (MethodDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckMethod (node, data))
					return;
			}
		}
示例#40
0
 void HandleVisitorVariableDeclarationStatementVisited(VariableDeclarationStatement node, InspectionData data)
 {
     foreach (var rule in policy.Rules)
     {
         if (rule.CheckVariableDeclaration(node, data))
         {
             return;
         }
     }
 }