--- a/JavaDecompiler.st Sat Mar 22 14:19:50 1997 +0000
+++ b/JavaDecompiler.st Sat Mar 22 14:21:04 1997 +0000
@@ -314,6 +314,208 @@
^ DecoderTable
! !
+!JavaDecompiler class methodsFor:'class definition generation'!
+
+definitionOf:aJavaClass on:s
+ |pckgName needCR fields staticFields superClass
+ interfaces|
+
+ pckgName := aJavaClass package.
+
+ s nextPutAll:'package ' , (pckgName copy replaceAll:$/ by:$.).
+ s nextPutAll:';'; cr; cr.
+
+ needCR := false.
+ aJavaClass isPublic ifTrue:[
+ s nextPutAll:'public '.
+ needCR := true.
+ ].
+ aJavaClass isAbstract ifTrue:[
+ s nextPutAll:'abstract '.
+ needCR := true.
+ ].
+ aJavaClass isFinal ifTrue:[
+ s nextPutAll:'final '.
+ needCR := true.
+ ].
+
+ needCR ifTrue:[
+ s cr
+ ].
+ aJavaClass isInterface ifTrue:[
+ s nextPutAll:'interface '.
+ ] ifFalse:[
+ s nextPutAll:'class '.
+ ].
+ s nextPutAll:aJavaClass name; space.
+ superClass := aJavaClass superclass.
+
+ superClass ~~ (Java at:'java.lang.Object') ifTrue:[
+ s nextPutAll:'extends '.
+ (superClass package ~= 'java/lang'
+ and:[superClass package ~= pckgName]) ifTrue:[
+ s nextPutAll:(superClass displayString); space
+ ] ifFalse:[
+ s nextPutAll:(superClass name); space
+ ]
+ ].
+
+ (interfaces := aJavaClass interfaces) size > 0 ifTrue:[
+ s nextPutAll:'implements '.
+ interfaces keysAndValuesDo:[:nr :if |
+ nr ~~ 1 ifTrue:[
+ s nextPutAll:', '.
+ ].
+ (if package ~= 'java/lang'
+ and:[if package ~= pckgName]) ifTrue:[
+ s nextPutAll:(if displayString)
+ ] ifFalse:[
+ s nextPutAll:(if name)
+ ]
+ ].
+ s space.
+ ].
+
+ s nextPutAll:'{'; cr.
+
+ needCR := false.
+ staticFields := aJavaClass staticFields.
+ staticFields size > 0 ifTrue:[
+ needCR := true.
+
+ staticFields do:[:aField |
+ |type v|
+
+ s nextPutAll:' '.
+ aField isPublic ifTrue:[
+ s nextPutAll:'public '.
+ ] ifFalse:[
+ s nextPutAll:'private '.
+ ].
+ s nextPutAll:'static '.
+ aField isFinal ifTrue:[
+ s nextPutAll:'final '.
+ ].
+
+ ((type := aField type) startsWith:pckgName) ifTrue:[
+ type := type copyFrom:(pckgName size + 1 + 1).
+ ] ifFalse:[
+ (type startsWith:'java.lang.') ifTrue:[
+ type := type copyFrom:(11).
+ ]
+ ].
+ type := type copy replaceAll:$/ with:$..
+ s nextPutAll:type; space;
+ nextPutAll:aField name.
+
+ (v := aField constantValue) notNil ifTrue:[
+ s nextPutAll:' = '; nextPutAll:v displayString.
+ ].
+
+ s nextPutAll:';'; cr.
+ needCR := true.
+ ].
+ ].
+
+
+ fields := aJavaClass fields.
+ fields size > 0 ifTrue:[
+ needCR ifTrue:[
+ s cr
+ ].
+ needCR := true.
+
+ fields do:[:aField |
+ |type|
+
+ s nextPutAll:' '.
+ aField isPublic ifTrue:[
+ s nextPutAll:'public '.
+ ] ifFalse:[
+ s nextPutAll:'private '.
+ ].
+ aField isFinal ifTrue:[
+ s nextPutAll:'final '.
+ ].
+
+ ((type := aField type) startsWith:pckgName) ifTrue:[
+ type := type copyFrom:(pckgName size + 1 + 1).
+ ].
+ type := type copy replaceAll:$/ with:$..
+ s nextPutAll:type; space;
+ nextPutAll:aField name; nextPutAll:';'; cr.
+ ].
+ ].
+
+ aJavaClass methodDictionary size > 0 ifTrue:[
+ needCR ifTrue:[
+ s cr
+ ].
+ needCR := true.
+
+ aJavaClass methodDictionary do:[:aMethod |
+ |type|
+
+ s nextPutAll:' '.
+ aMethod isPublic ifTrue:[
+ s nextPutAll:'public '.
+ ] ifFalse:[
+ aMethod isProtected ifTrue:[
+ s nextPutAll:'protected '.
+ ] ifFalse:[
+ s nextPutAll:'private '.
+ ]
+ ].
+ aMethod isFinal ifTrue:[
+ s nextPutAll:'final '.
+ ].
+ aMethod isStatic ifTrue:[
+ s nextPutAll:'static '.
+ ].
+ aMethod isNative ifTrue:[
+ s nextPutAll:'native '.
+ ].
+ aMethod isSynchronized ifTrue:[
+ s nextPutAll:'synchronized '.
+ ].
+
+ aMethod name = '<init>' ifTrue:[
+ s nextPutAll:aJavaClass name; nextPutAll:'()'.
+ ] ifFalse:[
+ s nextPutAll:(aMethod signatureName)
+ ].
+ s space.
+
+ aMethod exceptionTable size > 0 ifTrue:[
+ s nextPutAll:'throws '.
+
+ aMethod exceptionTable keysAndValuesDo:[:index :aClassRef |
+ |nm|
+
+ nm := aClassRef fullName.
+ (nm startsWith:pckgName) ifTrue:[
+ nm := nm copyFrom:pckgName size + 2
+ ] ifFalse:[
+ (nm startsWith:'java/lang') ifTrue:[
+ nm := nm copyFrom:'java/lang' size + 2.
+ ].
+ ].
+ index ~~ 1 ifTrue:[
+ s nextPutAll:', '
+ ].
+ s nextPutAll:((nm copyFrom:1) replaceAll:$/ with:$.)
+ ]
+ ].
+
+ s nextPutAll:';'; cr.
+ ].
+ ].
+
+ s nextPutAll:'}'; cr.
+
+ "Created: 22.3.1997 / 14:29:37 / cg"
+! !
+
!JavaDecompiler class methodsFor:'decompiling'!
decompile:aJavaMethod
@@ -624,6 +826,6 @@
!JavaDecompiler class methodsFor:'documentation'!
version
- ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaDecompiler.st,v 1.23 1997/03/20 14:38:40 cg Exp $'
+ ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaDecompiler.st,v 1.24 1997/03/22 14:21:04 cg Exp $'
! !
JavaDecompiler initialize!