|
|
Java and Delphi code generationPyNSource can convert your python source into java files (just the class declarations of course, not the meat of the code) and thus you can import the resulting java files into a more sophisticated UML modelling tool that understands java. There you can auto-layout your UML and you can print out.or take screen shots of the resulting diagrams. You can even write a batch file to automate the java code generation. Thus when you fire up you Java based UML modelling tool and do an import, you only import the changes to your diagram and you don't lose the custom way you have laid out your diagrams. PyNSource can also generate Delphi (object pascal) code. ExampleHere we will convert a single python file into a number of java files. Java likes to have one class per file, whereas python doesn't mind if you have multiple classes in one file. 1. Input: python codeAssuming the following python code class ParseMeTest:
def __init__(self):
self.a = 10 # class attribute
self.b = Blah() # class attribute COMPOSITE
self.a.c = 20 # skip
self.__class__.d = 30 # static class attribute
self.e.append(10) # class attribute (list/vector)
self.f.append(Blah()) # class attribute (list/vector) COMPOSITE
def IsInBattle(self):
if not self.tileinfo:
return 0
return self.tileinfo.battletriggered def DoA(self):
pass
class ParseMeTest2(ParseMeTest):
def DoB(self):
self._secretinfo = 2
lives in a file called fred.py on my desktop in a folder called c:\stuff, it can be turned into java code with the following command: 2. Run the conversionCMD> \python22\python.exe \wherever\pynsource.py -j c:\stuff c:\stuff\fred.py
3. Output: java source filesThe resulting files will be: ParseMeTest.java ParseMeTest2.java Blah.java also dict.java list.java unittest.java variant.java object.java The latter files (dict, list, unittest, variant and object) are always generated as a matter of course, just in case you need to compile your java code and your generated java code refers to these classes. For example, if your python code has a class inheriting from class object, then the above object.java file will satisfy the java compiler wanting to find that class.
4. Output: java source files - contents of which are...Java code generated (one class per file): // Generated by PyNSource http://www.atug.com/andypatterns/pynsource.htm public class ParseMeTest {
public variant a;
public Blah b = new Blah();
public static variant d;
public variant e;
public Blah f = new Blah();
public void __init__() {
}
public void IsInBattle() {
}
public void DoA() {
}
}// Generated by PyNSource http://www.atug.com/andypatterns/pynsource.htm public class ParseMeTest2 extends ParseMeTest {
public variant _secretinfo;
public void DoB() {
}
}// Generated by PyNSource http://www.atug.com/andypatterns/pynsource.htm
public class Blah {
public void __init__() {
}
}
public class variant {
}
etc.
Importing the generated java code into a UML toolJust import the resulting .java files into something like Enterprise Architect (commercial) or ESS-Model (free). Enterprise Architect
Enterprise Architect importing java files (see above, which was once Python code) note in the above diagram the phrase 'Blah b = new Blah()' is not strictly UML and this seems to be a fault with the version of Enterprise Architect. Please email me with any free UML tools that I can list here for people to use. LATEST TIP for big images in Enterprise Architect.Export the entire UML image as EMF format, then open in Windows XP 'picture and fax viewer' (usually the default viewer for most documents. This will create a reasonable sized huge image which you can zoom into. Additional step: If you want a small size, zoomable pdf, and have Adobe Acrobat installed, print to Adobe pdfWriter from within the Windows XP 'picture and fax viewer', selecting "Full page fax print' within the print wizard.
and you will end up with a pdf file of the entire, huge image, which you can zoom cleanly (vector graphics, no chunkiness) and pan over at your lesiure. Or put it in a web page and let all your developers have easy access to it. ESS-ModelerESS-Model is free and very fast. It has a pretty good layout algorithm too, plus an overview window fo large scale navigation of your models. It can also export as XMI.
So the idea with a tool like this is to convert your python source into java files and import them into this UML tool so that it can auto-layout the UML and you can print out.or take screen shots of the resulting diagrams. Of course you can instead use the supplied free tool pynsourceGui.py which does the same thing, though the layout algorithm is not as nice and there is no overview window.
Jbuilder - Analysing Jbuilder Projects
Imagine you want to process a bunch of python code and emit java source code, then run
jbuilder X Enterprise and use the UML reverse engineering features to visualise your python code. The Borland project file will also live in .../Tests/PythonToJavaTest01/ with a name
PythonToJavaTest01.jpx pynsource -j src pythoninput01\*.py Jbuilder X EnterpriseBorland's Jbuilder enterprise has a UML reverse engineering feature, though it doesn't combine multiple classes onto the one diagram (though it does show refrences to other classes on the one diagram). You can use it free for 30 days or purrchase it.
PyNSource - batch file usage examplesYou can automate the java code generation by putting often used the
invocations of pynsource into a batch file, for each of my commonly used
projects. e.g. the above example creates java files out of all the python code found in the
directories referred to by MAPEDITOR and places the resulting java source code
into the single folder "C:/CC/Devel/UML diagrams/Feb2004_pynSource_1_1/MapEditor/src".
Delphi code generationYou can generate Delphi pascal files using the -d option instead of the -j (for java) option. Importing into the fantastic tool Modelmaker works well: |