Implementation hint?

Hi there,

obviously; I am not asking you guys to hand out the source code for
ReSharper ;)
What I am looking for is a 'simple' way to include a feature like your
'Optimize usings...' in our own free tool for generating code from XSD/WSDL
for contract-first Web services development
(http://www.thinktecture.com/WSCF/).

Any hint is greatly appreciated! Ideally based on a CodeDom
representation...
Thanks.

Cheers,
--
Christian Weyer
thinktecture
http://www.thinktecture.com
In-depth support and consulting for software architects and developers

*Smells like service spirit-Weblog
http://weblogs.asp.net/cweyer

*Independent Microsoft Regional Director
http://www.microsoft.com/rd



0
3 comments
Avatar
Permanently deleted user

Hi Christian,

I think that the simplest way to implement such a feature is the following.
First, resolve all
references in a source file and remember for each reference the declaration
to which the reference is resolved.
Second, virtually remove (e.g. by removing a node from the CodeDom tree or
other internal repr.)
a using directive, re-resolve references and check if all of them still resolve
to the same declarations.
If they do, the using directive is unnecesarry and can be omitted.
Repeat this routine for all using directives in the file, and you'll get
the result.

Of course, this is easy to say but not so easy to get worked. You'll need
a mechanism for resolving
references (identifiers) in your internal representation. Such a mechanism
seems to be a heavyweight
addition to a code-generation tool. So may be you won't want to implement
a full-fledged solution. I think
that you may benefit from the fact that actually you know what code your
tool generates. In particular, you know
what namespaces/types are referenced in the generated code, and you may add
only necessary usings
based on this information. Though this of course requires certain changes
to the generator itself, while
an independent 'Optimize usings' feature, once implemented, could be plugged
in with much less effort.

So the answer greatly depends on the architecture of your tool. Sorry if
it was quite useless... :)

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

Hi there,

obviously; I am not asking you guys to hand out the source code for
ReSharper ;)
What I am looking for is a 'simple' way to include a feature like your
'Optimize usings...' in our own free tool for generating code from
XSD/WSDL
for contract-first Web services development
(http://www.thinktecture.com/WSCF/).
Any hint is greatly appreciated! Ideally based on a CodeDom
representation...
Thanks.
Cheers,

*Smells like service spirit-Weblog
http://weblogs.asp.net/cweyer
*Independent Microsoft Regional Director
http://www.microsoft.com/rd




0
Avatar
Permanently deleted user

There are smarter policies, but they rely on the identifiers resolve process
implementation.

Hi Christian,

I think that the simplest way to implement such a feature is the
following.
First, resolve all
references in a source file and remember for each reference the
declaration
to which the reference is resolved.
Second, virtually remove (e.g. by removing a node from the CodeDom
tree or
other internal repr.)
a using directive, re-resolve references and check if all of them
still resolve
to the same declarations.
If they do, the using directive is unnecesarry and can be omitted.
Repeat this routine for all using directives in the file, and you'll
get
the result.
Of course, this is easy to say but not so easy to get worked. You'll
need
a mechanism for resolving
references (identifiers) in your internal representation. Such a
mechanism
seems to be a heavyweight
addition to a code-generation tool. So may be you won't want to
implement
a full-fledged solution. I think
that you may benefit from the fact that actually you know what code
your
tool generates. In particular, you know
what namespaces/types are referenced in the generated code, and you
may add
only necessary usings
based on this information. Though this of course requires certain
changes
to the generator itself, while
an independent 'Optimize usings' feature, once implemented, could be
plugged
in with much less effort.
So the answer greatly depends on the architecture of your tool. Sorry
if it was quite useless... :)

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

>> Hi there,
>>
>> obviously; I am not asking you guys to hand out the source code for
>> ReSharper ;)
>> What I am looking for is a 'simple' way to include a feature like
>> your
>> 'Optimize usings...' in our own free tool for generating code from
>> XSD/WSDL
>> for contract-first Web services development
>> (http://www.thinktecture.com/WSCF/).
>> Any hint is greatly appreciated! Ideally based on a CodeDom
>> representation...
>> Thanks.
>> Cheers,
>> *Smells like service spirit-Weblog
>> http://weblogs.asp.net/cweyer
>> *Independent Microsoft Regional Director
>> http://www.microsoft.com/rd



0
Avatar
Permanently deleted user

Dmitry,

thanks for your quick answer.
Hm, honestly I thought there may be much more generic and
"easy-to-implement" (R) solution ;). OK, too naive.
Now I have to rethink my goals.
Thanks.

Cheers,
--
Christian Weyer
thinktecture
http://www.thinktecture.com
In-depth support and consulting for software architects and developers

*Smells like service spirit-Weblog
http://weblogs.asp.net/cweyer

*Independent Microsoft Regional Director
http://www.microsoft.com/rd


"Dmitry Shaporenkov" <dsha@jetbrains.com> wrote in message
news:12644632446891785236339@news.intellij.net...

Hi Christian,

>

I think that the simplest way to implement such a feature is the
following. First, resolve all references in a source file and remember for
each reference the declaration to which the reference is resolved.
Second, virtually remove (e.g. by removing a node from the CodeDom tree or
other internal repr.)
a using directive, re-resolve references and check if all of them still
resolve to the same declarations. If they do, the using directive is
unnecesarry and can be omitted. Repeat this routine for all using
directives in the file, and you'll get the result.

>

Of course, this is easy to say but not so easy to get worked. You'll need
a mechanism for resolving
references (identifiers) in your internal representation. Such a mechanism
seems to be a heavyweight
addition to a code-generation tool. So may be you won't want to implement
a full-fledged solution. I think
that you may benefit from the fact that actually you know what code your
tool generates. In particular, you know
what namespaces/types are referenced in the generated code, and you may
add only necessary usings
based on this information. Though this of course requires certain changes
to the generator itself, while
an independent 'Optimize usings' feature, once implemented, could be
plugged in with much less effort.

>

So the answer greatly depends on the architecture of your tool. Sorry if
it was quite useless... :)

>

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

>
>> Hi there,
>>
>> obviously; I am not asking you guys to hand out the source code for
>> ReSharper ;)
>> What I am looking for is a 'simple' way to include a feature like your
>> 'Optimize usings...' in our own free tool for generating code from
>> XSD/WSDL
>> for contract-first Web services development
>> (http://www.thinktecture.com/WSCF/).
>> Any hint is greatly appreciated! Ideally based on a CodeDom
>> representation...
>> Thanks.
>> Cheers,
>>
>> *Smells like service spirit-Weblog
>> http://weblogs.asp.net/cweyer
>> *Independent Microsoft Regional Director
>> http://www.microsoft.com/rd
>
>



0

Please sign in to leave a comment.