code-analysis

Visual Studio: Code analyzer to determine what exceptions a method can throw?

白昼怎懂夜的黑 提交于 2019-12-05 18:18:23
One nice thing about Java, which was also a curse, is that you always knew what exceptions a method could throw. Is there a static code analysis tool that can determine what exceptions a method can throw? It would be great to be able to type /// and have the xml documentation declaration section fill in the <exceptions> block automatically If you use Resharper, you can use this plugin: http://code.google.com/p/agentjohnsonplugin/ 来源: https://stackoverflow.com/questions/4359465/visual-studio-code-analyzer-to-determine-what-exceptions-a-method-can-throw

Collection properties should be read only - Loophole?

戏子无情 提交于 2019-12-05 15:55:58
In the process of adhering to code analysis errors, I'm changing my properties to have private setters. Then I started trying to understand why a bit more. From some research, MS says this : A writable collection property allows a user to replace the collection with a completely different collection. And the answer, here , states: Adding a public setter on a List<T> object is dangerous. But the reason why it's dangerous is not listed. And that's the part where I'm curious. If we have this collection: public List<Foo> Foos { get; set; } Why make the setter private? Apparently we don't want

Add a parameter to a method with a Roslyn CodeFixProvider

狂风中的少年 提交于 2019-12-05 14:16:56
I'm writing a Roslyn Code Analyzer that I want to identify if an async method does not take a CancellationToken and then suggest a code fix that adds it: //Before Code Fix: public async Task Example(){} //After Code Fix public async Task Example(CancellationToken token){} I've wired up the DiagnosticAnalyzer to correctly report a Diagnostic by inspecting the methodDeclaration.ParameterList.Parameters , but I can't find the Roslyn API for adding a Paramater to the ParameterList inside a CodeFixProvider . This is what I've got so far: private async Task<Document>

How to parse C++ source in Python?

余生颓废 提交于 2019-12-05 14:11:15
问题 We want to parse our huge C++ source tree to gain enough info to feed to another tool to make diagrams of class and object relations, discern the overall organization of things etc. My best try so far is a Python script that scans all .cpp and .h files, runs regex searches to try to detect class declarations, methods, etc. We don't need a full-blown analyzer to capture every detail, or some heavy UML diagram generator - there's a lot of detail we'd like to ignore and we're inventing new types

C# CA2104 - Automated Code Analysis dislikes static readonly mutable types

混江龙づ霸主 提交于 2019-12-05 12:55:57
I've got a code like this: public abstract class Base { // is going to be used in deriving classes // let's assume foo is threadsafe protected static readonly Foo StaticFoo = new Foo(); } Visual Studio 2008's Code Analysis pops up this message: CA2104 : Microsoft.Security : Remove the read-only designation from 'Base.StaticFoo' or change the field to one that is an immutable reference type. If the reference type 'Foo' is, in fact, immutable, exclude this message. Is my design instrinsically flawed, or can i add a [SuppressMessage] in the source? The problem is that it gives the wrong

Class dependency graph with doxygen

瘦欲@ 提交于 2019-12-05 10:36:43
I want to generate a class dependency graph for a large project in C++. I'm trying to do it with doxygen . Here is the sample code: class Used { public: void bar(); }; class Base { }; class Derived : public Base { public: void foo(Used*); // Dependency on class Used }; Here is the collaboration diagram generated by doxygen: Nice, but Derived depends on Used through the method foo , and I want to see this on the diagram, like this: Unfortunately, doxygen generates such dependency only if Used is aggregated with Derived (used as a class member). Is there a way to show other kinds of dependencies

Perl Challenge - Directory Iterator

老子叫甜甜 提交于 2019-12-05 10:22:44
You sometimes hear it said about Perl that there might be 6 different ways to approach the same problem. Good Perl developers usually have well-reasoned insights for making choices between the various possible methods of implementation. So an example Perl problem: A simple script which recursively iterates through a directory structure, looking for files which were modified recently (after a certain date, which would be variable). Save the results to a file. The question, for Perl developers: What is your best way to accomplish this? This sounds like a job for File::Find::Rule : #!/usr/bin

Using an AdHocWorkspace results in “The language 'C#' is not supported.”

杀马特。学长 韩版系。学妹 提交于 2019-12-05 10:04:23
Using the RC2 of Microsoft.CodeAnalysis.CSharp.Workspaces in VS2015, this code throws an exception: var tree = CSharpSyntaxTree.ParseText(...); var workspace = new AdhocWorkspace(); var newRoot = Simplifier.Expand(tree.GetRoot(), compilation.GetSemanticModel(tree, false), workspace, n => true, true, CancellationToken.None); The exception message is "The language 'C#' is not supported." What am I missing to make this work? You need to add a reference to the C# Workspaces NuGet package . This will copy the C# DLLs to your output, and let Roslyn's MEF scanner see the language services. 来源: https:

How to change Application Not Responding (ANR) Timeout in AOSP [closed]

十年热恋 提交于 2019-12-05 09:55:15
Closed . This question needs details or clarity . It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post . Closed 6 years ago . How do I change the Application Not Responding (ANR) timeout in the AOSP source code? The default timeout is 5 seconds, but where is that set and how do I change it? The ANR Timeout is defined in File InputDispatcher.cpp (frameworks\base\libs\ui) . Copying and pasting that piece of code below. // Default input dispatching timeout if there is no focused application or paused window // from which to

Code Analysis CA1060 Fix

流过昼夜 提交于 2019-12-05 08:13:25
I have the following code in my application: [DllImport("user32.dll")] private static extern int GetWindowLong(IntPtr hwnd, int index); [DllImport("user32.dll")] private static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle); [DllImport("user32.dll")] private static extern bool SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, int x, int y, int width, int height, uint flags); [DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam); I am getting the following warning from Code Analysis (FxCop): CA1060 : Microsoft