Page 1 of 1

Generating .NET API list - a crude attempt

PostPosted: Thu Jun 09, 2011 7:51 pm
by ObtuseAngle
While I suspect that this will mostly be superseded by @help (particularly if we can access it is a standalone call from a text editor), I wanted to generate an API list for pop-up help (and possible autocompletion) in SciTE (my favourite editor).

Below is my rather crude first attempt (warning: generates a huge list).
Below the if true line are some sample alternatives for testing, if you don't want the whole list.

Any improvements (extracting further documentation from the assemblies, getting member argument names, etc) would be most welcome.

Obtusely yours, OA.

Code: Select all
"""
Get classes, methods/members, valueTypes in .NET framework

Significantly based on Andrew Hare's C# code in a thread on StackOverflow
Thread: http://stackoverflow.com/questions/2137444/exactly-how-large-is-the-net-3-5-framework-class-library
Andrew Hare: http://stackoverflow.com/users/34211/andrew-hare
"""

use System.Reflection
use System.Runtime.InteropServices
use System.Text.RegularExpressions

class Example

    def main
        assemblies = []
        for f in Directory.getFiles(RuntimeEnvironment.getRuntimeDirectory)
            if f.endsWith(".dll")
                assemblies.add(f)

        for name in assemblies
            # We need to catch BadImageFormatException
            # because not all DLLs in the runtime directory
            # are CLR assemblies.
            try
                filename = name.toString
                types = Assembly.loadFile(filename).getTypes

                for t in types
                    if t.isClass
                        if true
                        #~ if "FileExists" in t.toString
                        #~ if t.toString == "System.Net.WebClient"
                            ms = t.getMethods
                            invoke = false
                            for m in ms
                                s = m.toString
                                if " Invoke(" in s
                                    wordMatch = Regex.match(s, r"([\w+\.\[\]]+) Invoke(\([^\)]+\))")
                                    if wordMatch.success
                                        print '[t.toString][wordMatch.groups[2]] --> [wordMatch.groups[1]]'
                                        invoke = true
                            if not invoke
                                mms = t.getMembers
                                for mm in mms
                                    sm = mm.toString
                                    mwordMatch = Regex.match(sm, r"([\w+\.\[\]]+) (.+)")
                                    if mwordMatch.success
                                        print '[t.toString]() [mwordMatch.groups[2]] --> [mwordMatch.groups[1]]'
                    else if t.isValueType
                        pass
                        #~ print t.toString
            catch BadImageFormatException
                pass

Re: Generating .NET API list - a crude attempt

PostPosted: Fri Jun 10, 2011 12:36 am
by Charles
Cobra has command line features for this:
Code: Select all
cd Source
cobra -doc -files:files-to-compile.text

You can also try a library like:
cobra -doc-lib:Cobra.Lang
cobra -doc-lib:System.Web


-doc works on Cobra source code and -doc-lib works on any DLL. It's been awhile since I've tested them and last time I tried -doc-lib it had some problems with some libraries. I plan on fixing those problems as I intend the @help page generator to leverage that code rather than duplicate it. There's probably much room for improvement in the formatting and HTML output.

If you want to see what Cobra is doing, look at DocGenerator.cobra in the source. Note that it's working on Cobra compiler data structures.

If you want to see how Cobra reads DLLs, look at ScanClrType.cobra in BackEndClr in Source.

But there's nothing wrong with building your own solution if it works well for you.

Re: Generating .NET API list - a crude attempt

PostPosted: Fri Jun 10, 2011 12:06 pm
by RIGHT_THEN
Sorry Removing content wrote answer to wrong post
Good attempt thou.


Thanking_You
RIGHT_THEN

Re: Generating .NET API list - a crude attempt

PostPosted: Fri Jun 10, 2011 8:49 pm
by Charles
I fixed the major bugs in -doc-lib and it now runs successfully on the following:

Code: Select all
cobra -doc-lib:Cobra.Lang
cobra -doc-lib:System
cobra -doc-lib:System.Core
cobra -doc-lib:System.Web
cobra -doc-lib:mscorlib

It needs a lot of improvements (which are listed in DocGenerator.cobra), but at least it's usable now.

Re: Generating .NET API list - a crude attempt

PostPosted: Mon Jun 13, 2011 4:58 pm
by ObtuseAngle
Charles wrote:Cobra has command line features for this:
Code: Select all
cd Source
cobra -doc -files:files-to-compile.text

You can also try a library like:
cobra -doc-lib:Cobra.Lang
cobra -doc-lib:System.Web


-doc works on Cobra source code and -doc-lib works on any DLL.
[...]
If you want to see what Cobra is doing, look at DocGenerator.cobra in the source. Note that it's working on Cobra compiler data structures.

If you want to see how Cobra reads DLLs, look at ScanClrType.cobra in BackEndClr in Source.


Thanks!

I'll need to wrangle either the code or the output files to give me SciTE API format, but that's a lot further along than I would have been on my own.

Cheers, Obtuse.

Re: Generating .NET API list - a crude attempt

PostPosted: Tue Jun 14, 2011 11:01 am
by Charles
Is the SciTE API format simply something that you prefer, or is it something technical that allows for integration with SciTE?

Re: Generating .NET API list - a crude attempt

PostPosted: Tue Jun 14, 2011 4:46 pm
by ObtuseAngle
It's a simple text file of API information that allows SciTE to provide calltips for both autocompletion, e.g. (Python example)

Image

and for API parameter information, e.g.:

Image

The API parameter calltip above is the line in the .api file that gives both the above options, plus a few lines of configuration in my SciTEUser.properties file.
Basically it's just one API call per line in a text file.

Cheers, Obtuse.