home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
javagentor.tcl
< prev
next >
Wrap
Text File
|
1997-06-06
|
10KB
|
382 lines
#---------------------------------------------------------------------------
#
# Copyright (c) 1997 by Cayenne Software, Inc.
#
# This software is furnished under a license and may be used only in
# accordance with the terms of such license and with the inclusion of
# the above copyright notice. This software or any other copies thereof
# may not be provided or otherwise made available to any other person.
# No title to and ownership of the software is hereby transferred.
#
# The information in this software is subject to change without notice
# and should not be construed as a commitment by Cayenne Software, Inc.
#
#---------------------------------------------------------------------------
#
# File : javagentor.tcl
# Author :
# Original date : May 1997
# Description : Classes for code generation
#
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
# File: @(#)javafileha.tcl /main/hindenburg/5
#---------------------------------------------------------------------------
# Start user added include file section
# End user added include file section
require "filehandle.tcl"
Class JavaFileHandler : {FileHandler} {
constructor
method destructor
method getFileName
method getFileTypes
method getSpecialFiles
method setImpFrom
attribute javaType
}
constructor JavaFileHandler {class this} {
set this [FileHandler::constructor $class $this]
# Start constructor user section
$this javaType "java"
# End constructor user section
return $this
}
method JavaFileHandler::destructor {this} {
# Start destructor user section
# End destructor user section
$this FileHandler::destructor
}
method JavaFileHandler::getFileName {this class fileType} {
set unitName [$class getPropertyValue "source_file"]
if {$unitName == ""} {
set unitName [$class getName]
}
return "$unitName.$fileType"
}
method JavaFileHandler::getFileTypes {this} {
set list [List new]
$list append [$this javaType]
return $list
}
method JavaFileHandler::getSpecialFiles {this} {
return [List new]
}
method JavaFileHandler::setImpFrom {this fileName class} {
set unit [$class unit]
if {$unit == ""} {
return [fstorage::set_imp_from $fileName [$class getName]]
}
set names ""
[$unit containerSet] foreach container {
lappend names [$container name]
}
return [fstorage::set_imp_from $fileName $names]
}
# Do not delete this line -- regeneration end marker
#---------------------------------------------------------------------------
# File: @(#)javagenera.tcl /main/hindenburg/3
#---------------------------------------------------------------------------
# Start user added include file section
# End user added include file section
require "generator.tcl"
Class JavaGenerator : {Generator} {
constructor
method destructor
method generate
attribute fileHandler
}
constructor JavaGenerator {class this} {
set this [Generator::constructor $class $this]
# Start constructor user section
$this fileHandler [JavaFileHandler new]
# End constructor user section
return $this
}
method JavaGenerator::destructor {this} {
# Start destructor user section
# End destructor user section
$this Generator::destructor
}
method JavaGenerator::generate {this classList} {
set typeToClassDictionary [Dictionary new]
set javaModel [JavaModel new]
set regenerator [JavaRegenerator new]
set javaType [[$this fileHandler] javaType]
$classList foreach class {
$class generate $javaModel
set fileDesc [[$this fileHandler] openFile $class $javaType]
if {$fileDesc != ""} {
$regenerator regenerate $class $fileDesc
[$this fileHandler] closeFile $fileDesc
}
}
$javaModel generate $typeToClassDictionary
return $typeToClassDictionary
}
# Do not delete this line -- regeneration end marker
#---------------------------------------------------------------------------
# File: @(#)javaregene.tcl /main/hindenburg/5
#---------------------------------------------------------------------------
# Start user added include file section
# End user added include file section
require "regenerato.tcl"
Class JavaRegenerator : {Regenerator} {
constructor
method destructor
method addBodyToMethod
method findClass
method grabUserBody
method regenerate
method sanityCheck
}
constructor JavaRegenerator {class this} {
set this [Regenerator::constructor $class $this]
# Start constructor user section
# End constructor user section
return $this
}
method JavaRegenerator::destructor {this} {
# Start destructor user section
# End destructor user section
$this Regenerator::destructor
}
method JavaRegenerator::addBodyToMethod {this class name params body} {
if {[$class getName] == "$name"} {
set methodList [[$class container] constructorSet]
} else {
set methodList [[$class container] methodSet]
}
$methodList foreach javaMethod {
if {[$javaMethod name] == "$name"} {
set javaParams [[$javaMethod generateParameterList] contents]
if {"$javaParams" == "$params"} {
$javaMethod userBody $body
return "0"
}
}
}
return "-1"
}
method JavaRegenerator::findClass {this fileDesc} {
set classExpr {class[ ]+(.+)[ ]+extends[ ]+}
while {![eof $fileDesc]} {
set line [gets $fileDesc]
if [regexp $classExpr $line complete name] {
return $name
}
}
return ""
}
method JavaRegenerator::grabUserBody {this fileDesc} {
set result [TextSection new]
set line [gets $fileDesc]
while {![eof $fileDesc]} {
if {[string match *${JavaCookie::startUserSection} $line]} {
set result [TextSection new]
set line [gets $fileDesc]
while {![eof $fileDesc] &&
![string match *${JavaCookie::endUserSection} $line]} {
$result append "$line\n"
set line [gets $fileDesc]
}
return $result
}
if [string match "*//*${JavaCookie::endMarker}*" $line] {
return $result
}
$result append "$line\n"
set line [gets $fileDesc]
}
return $result
}
method JavaRegenerator::regenerate {this class fileDesc} {
if [$this sanityCheck $fileDesc] {
m4_error $E_OBSOLETESECT [$class getName]
return
}
set endRegeneration ${JavaCookie::regenerationEndSection}
set methodExpr {^[ ]*(public|private protected|private|protected)?[ ]*(static|abstract|final|native|synchronized)?[ ]*(static|abstract|final|native|synchronized)?([^=]+)[ ]+([^=]+)[ ]*(\(.*\))[ ]*(throws[ ]+.*)*([\{;])}
set staticExpr {^[ ]*static[ ]*\{}
set completeMatch ""
set access ""
set modifier1 ""
set modifier2 ""
set wtype ""
set method ""
set params ""
set throwsClause ""
set className [$this findClass $fileDesc]
while {![eof $fileDesc] && [$class getName] != $className} {
set className [$this findClass $fileDesc]
}
while {![eof $fileDesc]} {
set line [gets $fileDesc]
if [string match *$endRegeneration $line] {
break
}
if {[regexp $staticExpr $line completeMatch]} {
set body [$this grabUserBody $fileDesc]
if [$this addBodyToMethod $class static "" $body] {
if {[$body contents] != ""} {
set obsoleteBody(static) $body
set obsoleteLine(static) $line
set obsoleteName(static) static
}
}
} elseif {[regexp $methodExpr $line completeMatch access modifier1 modifier2 wtype method params throwsClause lineTerminator]} {
set body ""
if {[string match "*;" $lineTerminator] &&
([string match "abstract" $modifier1] ||
[string match "abstract" $modifier2] ||
[string match "native" $modifier1] ||
[string match "native" $modifier2])} {
# DO NOTHING -- abstract/native methods have no body
} else {
set body [$this grabUserBody $fileDesc]
if [$this addBodyToMethod $class $method $params $body] {
if {[$body contents] != ""} {
set obsoleteBody($method$params) $body
set obsoleteLine($method$params) $line
set obsoleteName($method$params) $method
}
}
}
}
}
if [info exists obsoleteBody] {
foreach signature [array names obsoleteBody] {
set name $obsoleteName($signature)
if {"$className" == "$name"} {
set methodList [[$class container] constructorSet]
} else {
set methodList [[$class container] methodSet]
}
$methodList foreach javaMethod {
if {[$javaMethod name] == "$name" &&
[$javaMethod userBody] == ""} {
set javaParams [$javaMethod generateParameterList]
m4_warning $W_OLDCODE $className $signature $name[$javaParams contents]
$javaMethod userBody $obsoleteBody($signature)
unset obsoleteBody($signature)
unset obsoleteLine($signature)
unset obsoleteName($signature)
break
}
}
if [info exists obsoleteBody($signature)] {
m4_warning $W_OBSOLETECODE $className $signature
set sect [[$class container] obsoleteCode]
if {$sect == ""} {
set sect [TextSection new]
[$class container] obsoleteCode $sect
}
$sect append "[string trimleft $obsoleteLine($signature)]\n"
$sect appendSect $obsoleteBody($signature)
$sect append "\}\n\n"
}
}
}
}
method JavaRegenerator::sanityCheck {this fileDesc} {
while {![eof $fileDesc]} {
set line [gets $fileDesc]
if {[string match *${JavaCookie::startObsoleteCodeSection} $line]} {
seek $fileDesc 0
return "1"
}
if {[string match *${JavaCookie::endObsoleteCodeSection} $line]} {
seek $fileDesc 0
return "1"
}
}
seek $fileDesc 0
return "0"
}
# Do not delete this line -- regeneration end marker