Value Analysis and Code Contracts

Around a year ago, for 4.0, I said I didn't like the changes to Value Analysis that required using JetBrains attributes for marking methods etc as not accepting nulls and so on.  I didn't like either of the options: polluting my code with attributes from a different (JetBrains) namespace, or linking deployed products to a 'development' DLL.

The previous option of being able to configure ReSharper with a list of methods that were known to be assertion methods, or were known to not accept nulls, or were known to accept format strings, seemed better to me.

This came back to me this week when I looked at Microsoft's Code Contracts.  Code Contracts looks like it could be a really useful project, but it's frustrating that there's no way I can configure ReSharper to know about any of the contracts.  So if I use it, I can't take advantage of ReSharpers analyses.  I just can't put attributes on Microsoft's methods.  And since those methods are static, I can't inherit them.  (I'm not going to try encapsulating the Code Contract methods within my own because Code Contracts does IL analysis and rewriting and I don't want to confuse that in any way.)

So please, for 4.5 can you give us back the functionality we had in 3.0, and let us configure what ReSharper uses for value analysis?  Please?

(Making 4.5 'aware' of Code Contracts isn't the right answer, I think.)

Thanks,

Geoff

7 comments

Hello,

On the Code Annotations page (Options / Code Inspection / Code Annotations)
you can copy entire source code for attributes and paste them into your code.
Then, you can change namespace to your own. Revisit the option page, enable
your namespace and make it default.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


IR> Around a year ago, for 4.0, /thread/273092?tstart=0 that required
IR> using JetBrains attributes for marking methods etc as not accepting
IR> nulls and so on. I didn't like either of the options: polluting my
IR> code with attributes from a different (JetBrains) namespace, or
IR> linking deployed products to a 'de
IR>
IR> velopment' DLL.
IR>
IR> The previous option of being able to configure ReSharper with a list
IR> of methods that were known to be assertion methods, or were known to
IR> not accept nulls, or were known to accept format strings, seemed
IR> better to me.
IR>
IR> This came back to me this week when I looked at Microsoft's
IR> http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx. Code
IR> Contracts looks like it could be a really useful project, but it's
IR> frustrating that there's no way I can configure ReSharper to know
IR> about any of the contracts. So if I use it, I
IR> can't take advantage of ReSharpers analyses. I just can't put
IR> attributes on Microsoft's methods. And since those methods are
IR> static, I can't inherit them. (I'm not going to try encapsulating
IR> the Code Contract methods within my own because Code Contracts does
IR> IL analysis and rewriting and I don't
IR> want to confuse that in any way.)
IR> So please, for 4.5 can you give us back the functionality we had in
IR> 3.0, and let us configure what ReSharper uses for value analysis?
IR> Please?
IR>
IR> (Making 4.5 'aware' of Code Contracts isn't the right answer, I
IR> think.)
IR>
IR> Thanks,
IR>
IR> Geoff
IR>
IR> ---
IR> Original message URL:
IR> http://www.jetbrains.net/devnet/message/5232946#5232946


0

Well, yes, I can do that, but it doesn't help.

I still have no way of annotating Microsoft's Code Contracts, whether with JetBrains attributes or 'mine'.  This is why I think annotation is the wrong approach - I don't always want to change the code to specify what a method does, even if it were always possible (which it isn't in this case).

Sometimes I just want to tell the tool 'This is how I want you to interpret calls to that method'.  And I could do that in 3.0, but not 4.0, 4.1 or 4.5EAP.

Geoff

0

Look into "C:\Program Files\JetBrains\ReSharper\v4.1\Bin\ExternalAnnotations"
You can create your own xml files for Code Contracts assemblies with annotations
you like.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


IR> Well, yes, I can do that, but it doesn't help.
IR>
IR> I still have no way of annotating Microsoft's Code Contracts,
IR> whether with JetBrains attributes or 'mine'. This is why I think
IR> annotation is the wrong approach - I don't always want to change the
IR> code to specify what a method does, even if it were always possible
IR> (which it isn't in this case).
IR>
IR> Sometimes I just want to tell the tool 'This is how I want you to
IR> interpret calls to that method'. And I could do that in 3.0, but
IR> not 4.0, 4.1 or 4.5EAP.
IR>
IR> Geoff
IR>
IR> ---
IR> Original message URL:
IR> http://www.jetbrains.net/devnet/message/5232952#5232952


0

orangy wrote:

Look into "C:\Program Files\JetBrains\ReSharper\v4.1\Bin\ExternalAnnotations"
You can create your own xml files for Code Contracts assemblies with annotations
you like.


Sincerely,
Ilya Ryzhenkov


JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


Ah, of course!  Thanks for that.  I'd forgotten about that option since it doesn't work with assemblies that are part of the current solution, but that doesn't apply in this case.

I've attached my first go at an XML file for Microsoft.Contracts.DLL if anyone wants to take it and improve it.

Now, next problem - the Code Contracts uses the paradigm:

    Contract.Requires (parameter != null);

for checking parameters and so on, but ReSharper's value analysis doesn't seem to pick up on that as a null check.  Should it (in which case I've done something wrong)?  Or will it in future be able to pick that up as a null check?

Many thanks,

    Geoff



Attachment(s):
Microsoft.Contracts.xml
0

Mark Requires as assertion method. Like, copy from Debug.Assert

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


IR>

orangy wrote:
IR>
IR> Look into "C:\Program
IR> Files\JetBrains\ReSharper\v4.1\Bin\ExternalAnnotations" You can
IR> create your own xml files for Code Contracts assemblies with
IR> annotations you like.
IR>
IR> Sincerely,
IR> Ilya Ryzhenkov
IR> JetBrains, Inc
IR> http://www.jetbrains.com
IR> "Develop with pleasure!"
IR>

IR>
IR> Ah, of course! Thanks for that. I'd forgotten about that option
IR> since it doesn't work with assemblies that are part of the current
IR> solution, but that doesn't apply in this case.
IR>
IR> I've attached my first go at an XML file for Microsoft.Contracts.DLL
IR> if anyone wants to take it and improve it.
IR>
IR> Now, next problem - the Code Contracts uses the paradigm:
IR>
IR> Contract.Requires (parameter != null);
IR>
IR> for checking parameters and so on, but ReSharper's value analysis
IR> doesn't seem to pick up on that as a null check. Should it (in
IR> which case I've done something wrong)? Or will it in future be able
IR> to pick that up as a null check?
IR>
IR> Many thanks,
IR>
IR> Geoff
IR>
IR> ---
IR> Original message URL:
IR> http://www.jetbrains.net/devnet/message/5232966#5232966


0

orangy wrote:

Mark Requires as assertion method. Like, copy from Debug.Assert


I (think I) did - in the file I attached I have the following:


  <member name="M:Microsoft.Contracts.Contract.Requires(System.Boolean)">
    <attribute ctor="M:JetBrains.Annotations.AssertionMethodAttribute.#ctor"/>
    <parameter name="condition">
      <attribute ctor="M:JetBrains.Annotations.AssertionConditionAttribute.#ctor(JetBrains.Annotations.AssertionConditionType)">
        <argument>0</argument>
      </attribute>
    </parameter>
  </member>
  <member name="M:Microsoft.Contracts.Contract.Requires(System.Boolean,System.String)">
    <attribute ctor="M:JetBrains.Annotations.AssertionMethodAttribute.#ctor"/>
    <parameter name="condition">
      <attribute ctor="M:JetBrains.Annotations.AssertionConditionAttribute.#ctor(JetBrains.Annotations.AssertionConditionType)">
        <argument>0</argument>
      </attribute>
    </parameter>
  </member>


That looks correct to me.  Should ReSharper 4.5EAP pick up on:

    Contract.Requires (parameter != null);

as checking 'parameter' for null?  Because at the minute it still underlines a subsequent 'parameter.MethodCall()' as a potential null reference problem.

Cheers,

Geoff


0

In the cold weather, the UGG boots are considered as the best shoes.More and more people like wearing the UGG boots such as the UGG Classic Metallic 5812]]>.With its development ,the UGG boots have lauched different kinds of boots into the fashion market,including the UGG Classic Short Boots]]> and the UGG Women's Highkoo]]>.However,in the fashion world,if you want to be more attractive and elegant,the beautiful shoes are not enough.You have to choose the best stylish handbag to match your shoes.Therefor,the designer replica handbags are very necessary.If you want to buy the best designer cheap handbags,i would like to introduce two famous brand handbags to you.I think there must be one handbag is your favorite.One is the famous brand Versace Handbags ,the other is the Ferragamo Handbags.Both of them are the famous brand in the world.Their quality are very good.

---
Original message URL: http://www.jetbrains.net/devnet/message/5254900#5254900

0

Please sign in to leave a comment.