From: Byron S. <bsa...@us...> - 2005-05-19 03:42:13
|
bsaltysiak 05/05/18 20:42:06 Added: flash project.xml plugin.properties project.properties LICENSE.txt plugin.jelly flash/src/plugin-resources/as2api api_model.rb api_loader.rb style.css xmlwriter.rb documenter.rb html_output.rb doc_comment.rb flash/xdocs changes.xml properties.xml goals.xml flash/src/plugin-resources/as2api/parse lexer.rb parser.rb as_io.rb Log: initial checkin: accomplishes "docs" goal and report Revision Changes Path 1.1 maven-plugins/flash/project.xml Index: project.xml =================================================================== <?xml version="1.0" encoding="ISO-8859-1"?> <project> <extend>${basedir}/../plugin-project.xml</extend> <!--pomVersion is in parent --> <id>maven-flash-plugin</id> <name>Maven flash plugin</name> <!-- groupId is in parent --> <currentVersion>0.1</currentVersion> <!-- organization is in parent --> <inceptionYear>2005</inceptionYear> <!-- package, logo are in parent. no gumpRepositoryId --> <description><![CDATA[ <p> A plugin to maven that will make certain project tasks involving Flash easier. Currently, the plugin uses as2api-0.2 to produce a JavaDoc-like api documentation. A report of this documentation is also included so that it can be easily added to any project using Flash w/ ActionScript2. </p> <p> Future new capabilities of the plugin may include compilation and/or unit testing. </p> <p> An extension of existing functionality could be to support swappable documentation tools. </p> <p> <b>Note:</b><br/> Due to the lack of the ability to generate the docs in a location other than the as2api folder and my current lack of Ruby knowledge to change the underlying code only one project should generate docs on the same machine at the same time. </p> ]]> </description> <shortDescription>A Flash plugin for Maven.</shortDescription> !-- issue tracking url, siteAddress are in parent --> <siteDirectory>/home/groups/m/ma/maven-plugins/htdocs/flash/</siteDirectory> <repository> <connection>scm:cvs:pserver:an...@cv...:/cvsroot/maven-plugins/:maven-plugins/flash</connection> <url>http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/maven-plugins/maven-plugins/flash/</url> </repository> <versions> </versions> <branches> </branches> <!-- mailingLists are in parent --> <developers> <developer> <name>Byron Saltysiak</name> <id>bsaltysiak</id> <email>byr...@gm...</email> </developer> </developers> <dependencies> </dependencies> <build/> </project> 1.1 maven-plugins/flash/plugin.properties Index: plugin.properties =================================================================== maven.flash.src.dir=${basedir}/src/flash maven.flash.docs.output.dir=${basedir}/target/flashdocs maven.flash.swfs= maven.flash.mx.classpath=/home/bsalty/work/Classes maven.flash.mx.classes=true maven.flash.classpath= 1.1 maven-plugins/flash/project.properties Index: project.properties =================================================================== # ------------------------------------------------------------------- # P R O J E C T P R O P E R T I E S # ------------------------------------------------------------------- maven.xdoc.date=left maven.xdoc.version=${pom.currentVersion} maven.license.licenseFile=${basedir}/../LICENSE.txt maven.ui.banner.background=white maven.ui.body.background=white maven.ui.body.foreground=black maven.repo.remote=http://www.ibiblio.org/maven 1.1 maven-plugins/flash/LICENSE.txt Index: LICENSE.txt =================================================================== GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the program's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. <signature of Ty Coon>, 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. 1.1 maven-plugins/flash/plugin.jelly Index: plugin.jelly =================================================================== <?xml version="1.0" encoding="ISO-8859-1"?> <!-- /* * Copyright 2004 Byron Saltysiak * * Protected by the GNU General Public License. * * */ --> <project xmlns:j="jelly:core" xmlns:license="license" xmlns:util="jelly:util" xmlns:ant="jelly:ant" xmlns:doc="doc" xmlns:artifact="artifact" xmlns:caller="caller"> <!-- ==================================================== --> <!-- REPORT GOALS --> <!-- ==================================================== --> <goal name="maven-flash-docs-plugin:register" prereqs="xdoc:init"> <doc:registerReport name="Flash AS2Doc" pluginName="maven-flash-docs-plugin" link="flashdocs/frameset" target="_blank" description="AS2Doc for Flash" /> </goal> <goal name="maven-flash-docs-plugin:deregister"> <doc:deregisterReport name="Flash AS2Doc"/> </goal> <goal name="maven-flash-docs-plugin:report"> <attainGoal name="flash:docs"/> <ant:echo>copying ${maven.flash.docs.output.dir} to ${maven.gen.docs}</ant:echo> <ant:copy todir="${basedir}/target/docs/flashdocs"> <fileset dir="${maven.flash.docs.output.dir}"/> </ant:copy> <!-- <ant:copy todir="${maven.gen.docs}/flashdocs"> <fileset dir="${maven.flash.docs.output.dir}"/> </ant:copy> --> </goal> <!-- ==================================================== --> <!-- COMPILE GOALS --> <!-- ==================================================== --> <goal name="flash:init"> <ant:exec executable="mtasc" failifexecutionfails="true" output="/dev/null"/> </goal> <goal name="flash:compile"> <ant:exec executable="/usr/local/bin/mtasc" failonerror="true" dir="./src"> <arg value="-pack"/> <arg value="${maven.flash.src.dir}"/> <arg value="-cp"/> <arg value="/usr/local/bin/std"/> <arg value="-cp"/> <arg value="/home/bsalty/work/Classes"/> <arg value="-mx"/> <arg value="-v"/> <j:if test="${maven.flash.mx.classes}"> </j:if> <arg value="-swf"/> <arg value="sample_chat.swf"/> </ant:exec> </goal> <!-- ==================================================== --> <!-- DOC GOALS --> <!-- ==================================================== --> <goal name="flash:docs"> <ant:exec executable="ruby" failonerror="true" dir="${plugin.resources}/as2api"> <arg value="${plugin.resources}/as2api/documenter.rb"/> <arg value="${maven.flash.src.dir}"/> <!-- <arg value="${maven.flash.docs.output.dir}"/> --> </ant:exec> <ant:move todir="${maven.flash.docs.output.dir}"> <fileset dir="${plugin.resources}/as2api/apidocs"/> </ant:move> <ant:copy file="${plugin.resources}/as2api/style.css" tofile="${maven.flash.docs.output.dir}/style.css" /> </goal> </project> 1.1 maven-plugins/flash/src/plugin-resources/as2api/api_model.rb Index: api_model.rb =================================================================== # These classes represent the data-model upon which as2api operates. The # class names are all prefixed with 'AS' becase many would otherwise clash # with Ruby's inbuild classes with the same name. # TODO: The interfaces to these classes still, in places, make direct use of # types provided by ActionScript::Parse (i.e. methods expecting or # returning subclasses of ASToken). These classes should be refactored # to insulate the documentation-generating subsystem from those details # Superclass for ASClass and ASInterface, one instance of an ASType subclass # is created per compilation unit successfully parsed class ASType # give this ASType the given name (an array of IdentifierToken values # found by the parser) def initialize(name) @package_name = name[0, name.length-1].join(".") @name = name.last.body @source_utf8 = false @methods = [] @constructor = nil @extends = nil @comment = nil @type_resolver = nil @import_manager = nil @input_filename = nil end attr_accessor :package, :extends, :comment, :source_utf8, :type_resolver, :import_manager, :input_filename, :intrinsic, :constructor def add_method(method) @methods << method end def each_method @methods.each do |meth| yield meth end end def methods @methods.dup end def methods? !@methods.empty? end def constructor? !@constructor.nil? end # The type's name, excluding its package-prefix def unqualified_name @name end # ascends the hierarchy of resolved supertypes of this type, passing # each ASType to the given block. Stops when a type does not extend # anything, or when the class it extends wasn't resolved. def each_ancestor parent = @extends while !parent.nil? && parent.resolved? yield parent.resolved_type parent = parent.resolved_type.extends end end # The whole type name, including package-prefix def qualified_name if @package_name == "" @name else "#{@package_name}.#{@name}" end end # The package-prefix on this type's name def package_name @package_name end # This exists mostly as a hack to handle types that are declaired without # a package-prefix 'class SomeClass {', but shich are located in the # directory structure such that a package is implied (and indeed used by # Flash when the fileis found). # # When a type has no package-prefix, and this method is called on it with # an argument "com/foobar", we will 're-package' the type to subsequently # become 'com.foobar.SomeClass' def sourcepath_location(path) path = "" if path == "." if @package_name == "" and path != "" @package_name = path.gsub("/", ".") else if @package_name != path.gsub("/", ".") $stderr.puts("package #{@package_name.inspect} doesn't match location #{path.inspect}") end end end # compare two types based on their qualified names def <=>(other) qualified_name <=> other.qualified_name cmp = qualified_name.downcase <=> other.qualified_name.downcase return cmp unless cmp==0 qualified_name <=> other.qualified_name end def document? true end end class ASVoidType < ASType def initialize @name = "Void" @package_name = "" end def document? false end end AS_VOID = ASVoidType.new # Classes are types that (just for the perposes of API docs) have fields, and # implement interfaces class ASClass < ASType def initialize(name) @dynamic = false @interfaces = [] @fields = [] super(name) end attr_accessor :dynamic def implements_interfaces? !@interfaces.empty? end def add_interface(name) @interfaces << name end def each_interface @interfaces.each do |name| yield name end end def add_field(field) @fields << field end def fields? !@fields.empty? end def each_field @fields.each do |field| yield field end end def fields @fields.dup end def get_field_called(name) each_field do |field| return field if field.name == name end nil end end # ASInterface doesn't add anything to the superclass, it just affirms that # the API only supported by ASClass will not be available here class ASInterface < ASType def initialize(name) super(name) end def implements_interfaces? false end def fields? false end end # A member in some type class ASMember def initialize(access, name) @access = access @name = name @comment = nil end attr_accessor :access, :name, :comment # compares two members based on their names def <=>(other) cmp = name.downcase <=> other.name.downcase return cmp unless cmp==0 name <=> other.name end end # A method member, which may appear in an ASClass or ASInterface class ASMethod < ASMember def initialize(access, name) super(access, name) @return_type = nil @args = [] end attr_accessor :return_type def add_arg(arg) @args << arg end def arguments @args end def agument(index) @args[index] end end # A field member, which may appear in an ASClass, but not an ASInterface class ASField < ASMember end class ASExplicitField < ASField def initialize(access, name) super(access, name) @field_type = nil end attr_accessor :field_type def readwrite?; true; end def read?; true; end def write?; true; end end # A field implied by the presence of "get" or "set" methods with this name class ASImplicitField < ASField def initialize(name) super(nil, name) @getter_method = nil @setter_method = nil end attr_accessor :getter_method, :setter_method def readwrite? !(@getter_method.nil? || @setter_method.nil?) end def read? !@getter_method.nil? end def write? !@setter_method.nil? end def access (@getter_method || @setter_method).access end def comment (@getter_method || @setter_method).comment end def field_type if read? return @getter_method.return_type else unless @setter_method.arguments.empty? arg = @setter_method.arguments[0] return arg.arg_type end end return nil end end # A formal function parameter, a list of which appear in an ASMethod class ASArg def initialize(name) @name = name @arg_type = nil end attr_accessor :name, :arg_type end # A simple aggregation of ASType objects class ASPackage def initialize(name) @name = name @types = [] end attr_accessor :name def add_type(type) @types << type end def each_type @types.each do |type| yield type end end def classes result = [] each_type do |type| result << type if type.instance_of?(ASClass) end result end def interfaces result = [] each_type do |type| result << type if type.instance_of?(ASInterface) end result end def <=>(other) cmp = name.downcase <=> other.name.downcase return cmp unless cmp==0 name <=> other.name end end 1.1 maven-plugins/flash/src/plugin-resources/as2api/api_loader.rb Index: api_loader.rb =================================================================== require 'parse/lexer' require 'parse/parser' require 'api_model' # We used to just define the class again to add this attribute, but I want # to be compatable with Ruby1.6, which doesn' allow 'class ModName::ClassName' ActionScript::Parse::ASToken.module_eval("attr_accessor :last_comment") # Hacked subclass of SkipASLexer that remembers multiline comment tokens as # they're bing skipped over, and then pokes them into the next real token # that comes by class DocASLexer < ActionScript::Parse::SkipASLexer def initialize(io) super(io) @last_comment= nil end attr_accessor :last_comment protected def skip?(tok) if tok.instance_of?(ActionScript::Parse::MultiLineCommentToken) && tok.body =~ /^\*/ @last_comment = tok end result = super(tok) unless result if @last_comment tok.last_comment = @last_comment @last_comment = nil end end result end end # Take the comment tokens stuffed into 'real' tokens by DocASLexer, and # pass these to our DocASHandler instance for parts of the grammar where # they might contain API docs class DocASParser < ActionScript::Parse::ASParser def parse_class_or_intrinsic_definition snarf_comment super() end def parse_interface_definition snarf_comment super() end def parse_class_member snarf_comment super() end def parse_interface_function snarf_comment super() end private def snarf_comment @handler.doc_comment @lex.peek_next.last_comment end end # Builds a model of the API being processed as ActionScript::Parse::Parser # recognises pieces of the ActionScript grammar class DocASHandler < ActionScript::Parse::ASHandler def compilation_unit_start @type_resolver = LocalTypeResolver.new @import_manager = ImportManager.new @defined_type = nil end attr_accessor :defined_type def doc_comment(comment) @doc_comment = comment end def import(name) @import_manager.add_import(name) end def start_class(dynamic, name, super_name, interfaces) @defined_type = ASClass.new(name) if @doc_comment @defined_type.comment = @doc_comment end @defined_type.dynamic = dynamic if super_name @defined_type.extends = @type_resolver.resolve(super_name) end if interfaces interfaces.each do |interface| @defined_type.add_interface(@type_resolver.resolve(interface)) end end @defined_type.type_resolver = @type_resolver @defined_type.import_manager = @import_manager end def start_intrinsic_class(dynamic, name, super_name, interfaces) start_class(dynamic, name, super_name, interfaces) @defined_type.intrinsic = true end def start_interface(name, super_name) @defined_type = ASInterface.new(name) if @doc_comment @defined_type.comment = @doc_comment end if super_name @defined_type.extends = @type_resolver.resolve(super_name) end @defined_type.type_resolver = @type_resolver @defined_type.import_manager = @import_manager end def access_modifier(modifier) @last_modifier = modifier end def show_modifier visibility = @last_modifier.visibility if visibility.instance_of?(ActionScript::Parse::PublicToken) print "public " elsif visibility.instance_of?(ActionScript::Parse::PrivateToken) print "private " end if @last_modifier.is_static print "static " end end def start_member_field(name, type) field = ASExplicitField.new(@last_modifier, name.body) unless type.nil? field.field_type = @type_resolver.resolve(type) end @defined_type.add_field(field) end def interface_function(name, sig) member_function(name, sig) end def intrinsic_member_function(name, sig) member_function(name, sig) end def member_function(name, sig) if sig.implicit_property_modifier.nil? real_member_function(name, sig) else implicit_property_function(name, sig) end end private def create_method(name, sig) method = ASMethod.new(@last_modifier, name.body) if sig.return_type method.return_type = @type_resolver.resolve(sig.return_type) end sig.arguments.each do |arg| argument = ASArg.new(arg.name.body) if arg.type argument.arg_type = @type_resolver.resolve(arg.type) end method.add_arg(argument) end if @doc_comment method.comment = @doc_comment end method end def real_member_function(name, sig) method = create_method(name, sig) if name.body == @defined_type.unqualified_name @defined_type.constructor = method else @defined_type.add_method(method) end end def implicit_property_function(name, sig) field = @defined_type.get_field_called(name.body) if field.nil? field = ASImplicitField.new(name.body) @defined_type.add_field(field) end func = create_method(name, sig) if sig.implicit_property_modifier == "get" field.getter_method = func elsif sig.implicit_property_modifier == "set" field.setter_method = func else raise "unknown property-modifier #{sig.implicit_property_modifier.inspect}" end end end # The following classes could maybe be split into a different unit from those # above # Records the classes and packages imported into a compilation unit class ImportManager # FIXME: 'Manager' code smell! rename ImportList, or something clearer def initialize @types = [] @packages = [] end def add_import(name) if name.last.instance_of?(ActionScript::Parse::StarToken) name.pop add_package_import(name) else add_type_import(name) end end def add_type_import(name) @types << name end def each_type @types.each do |type_name| yield type_name end end def add_package_import(name) @packages << name end def each_package @packages.each do |package_name| yield package_name end end end # A proxy for some type referred to by a particular name within a compilation # unit. After we've parsed all compilation units, we'll be able to resolve # what real type this proxy stands for (i.e. becase we'll have found the # types pulled into the compilation unit by 'import com.example.*') class TypeProxy # TODO: this should be in api_model.rb def initialize(name) @name = name @resolved_type = nil end attr_accessor :name, :resolved_type def resolved? !@resolved_type.nil? end def local_name # TODO: come up with smarter representations for resolved vs. unresolved # types @name.join(".") end def qualified? @name.size > 1 end end # Resolves type names to instances of TypeProxy for a particular compilation # unit (the same name could refer to different types in different compilation # units). class LocalTypeResolver # TODO: This class actually implements a namespace, so maybe should be # renamed as such. Also, in as much as the TypeProxy objects this # class supplies *aren't* resolved yet, this class is completely # mis-named. def initialize @named_types = {} end def resolve(name) type = @named_types[name.join(".")] if type.nil? type = TypeProxy.new(name) @named_types[name.join(".")] = type end type end def each @named_types.each_value do |type| yield type end end end # Collects types that are produced by parsing compilation units, building the # package list as types from different packages are added. # # #resolve_types can be used to resolve inter-type references after all the # ActionScript has been parsed, resolving the real types that the collected # TypeProxy objects are standing in for. class GlobalTypeAggregator # TODO: this structure sucks; responsibility for type resolution should be # entirely seperate from aggregation, not shoe-horned into this class def initialize @types = [] @packages = {} end def add_type(type) @types << type package_name = type.package_name package = @packages[package_name] if package.nil? package = ASPackage.new(package_name) @packages[package_name] = package end package.add_type(type) end def each_type @types.each do |type| yield type end end def types @types.dup end def each_package @packages.each_value do |package| yield package end end def packages @packages.values end def resolve_types # Eeek!... qname_map = {} qname_map[AS_VOID.qualified_name] = AS_VOID @types.each do |type| qname_map[type.qualified_name] = type end @types.each do |type| local_namespace = qname_map.dup local_namespace[type.unqualified_name] = type import_types_into_namespace(type, local_namespace) import_packages_into_namespace(type, local_namespace) resolver = type.type_resolver resolver.each do |type_proxy| real_type = local_namespace[type_proxy.name.join(".")] if real_type type_proxy.resolved_type = real_type else $stderr.puts "#{type.input_filename}:#{type_proxy.name.first.lineno}: Found no definition of type known locally as #{type_proxy.name.join('.').inspect}" end end end end private def collect_package_types(package_name) # TODO: dump this and use ASPackage instead, now it's available @types.each do |type| if type.package_name == package_name yield type end end end def import_types_into_namespace(type, local_namespace) importer = type.import_manager importer.each_type do |type_name| import_type = local_namespace[type_name.join(".")] if import_type local_namespace[type_name.last.body] = import_type else $stderr.puts "#{type.input_filename}:#{type_name.first.lineno}: Couldn't resolve import of #{type_name.join(".").inspect}" end end end def import_packages_into_namespace(type, local_namespace) importer = type.import_manager importer.each_package do |package_name| collect_package_types(package_name.join(".")) do |package_type| if local_namespace.has_key?(package_type.unqualified_name) $stderr.puts "#{package_type.unqualified_name} already refers to #{local_namespace[package_type.unqualified_name].qualified_name}" end local_namespace[package_type.unqualified_name] = package_type end end end end 1.1 maven-plugins/flash/src/plugin-resources/as2api/style.css Index: style.css =================================================================== h2 { background-color: #ccccff; } .method_details, .field_details { border-bottom: 2px solid gray; padding-bottom: .5em; } .main_nav { background-color: #EEEEFF; padding: 4px; } .main_nav > * { font-family: sans-serif; font-weight: bolder; padding: 4px; } .nav_current { background-color: #00008B; color: #FFFFFF; } table.summary_list { border-collapse: collapse; width: 100%; margin-bottom: 1em; } table.summary_list th { background-color: #CCCCFF; font-size: larger; } table.summary_list td, table.summary_list th { border: 2px solid grey; padding: .2em; } /* .unresolved_type { background-color: red; color: white; } */ .footer { text-align: center; font-size: smaller; } /* .read_write_only { } */ 1.1 maven-plugins/flash/src/plugin-resources/as2api/xmlwriter.rb Index: xmlwriter.rb =================================================================== class XMLWriter def initialize(io) @io = io end def doctype(name, syspub, public_id, system_id) @io.puts("<!DOCTYPE #{name} #{syspub} \"#{public_id}\" \"#{system_id}\">") end def element(text, attrs=nil) start_tag(text, attrs) yield end_tag(text) end def simple_element(text, body, attrs=nil) start_tag(text, attrs) pcdata(body) end_tag(text) end def start_tag(text, attrs=nil) chk_name(text) @io.print('<') @io.print(text) unless attrs.nil? attrs.each do |key, val| @io.print(' ') @io.print(key) @io.print('="') @io.print(val.gsub(/"/, """)) @io.print('"') end end @io.print('>') end def empty_tag(text, attrs=nil) chk_name(text) @io.print('<') @io.print(text) unless attrs.nil? attrs.each do |key, val| @io.print(' ') @io.print(key) @io.print('="') @io.print(val.gsub(/"/, """)) @io.print('"') end end @io.print('/>') end def end_tag(text) chk_name(text) @io.print('</') @io.print(text) @io.print('>') end def pcdata(text) @io.print(text.gsub(/&/, '&').gsub(/</, '<').gsub(/>/, '>')) end def cdata(text) raise "CDATA text must not contain ']]>'" if text =~ /\]\]>/ @io.print("<![CDATA[") @io.print(text) @io.print("]]>") end def comment(text) raise "comment must not contain '--'" if text =~ /--/ @io.print("<!--") @io.print(text) @io.print("-->") end def pi(text) raise "processing instruction must not contain '?>'" if text =~ /\?>/ @io.print("<?") @io.print(text) @io.print("?>") end private def chk_name(name) raise "bad character '#{$&}' in tag name #{name}" if name =~ /[<>& "']/ end end 1.1 maven-plugins/flash/src/plugin-resources/as2api/documenter.rb Index: documenter.rb =================================================================== require 'parse/lexer' # TODO: remove this requirement require 'parse/as_io' require 'api_loader' def simple_parse(input) as_io = ASIO.new(input) lex = DocASLexer.new(ActionScript::Parse::ASLexer.new(as_io)) parse = DocASParser.new(lex) handler = DocASHandler.new parse.handler = handler parse.parse_compilation_unit handler.defined_type end BOM = "\357\273\277" # Look for a byte-order-marker in the first 3 bytes of io. # Eats the BOM and returns true on finding one; rewinds the stream to its # start and returns false if none is found. def detect_bom?(io) return true if io.read(3) == BOM io.seek(0) false end def parse_options end # lists the .as files in 'path', and it's subdirectories def each_source(path) require 'find' path = path.sub(/\/+$/, "") Find.find(path) do |f| base = File.basename(f) # Ignore anything named 'CVS', or starting with a dot Find.prune if base =~ /^\./ || base == "CVS" if base =~ /\.as$/ yield f[path.length+1, f.length] end end end # Support for other kinds of output would be useful in the future. # When the need arises, maybe the interface to 'output' subsystems will need # more formalisation than just 'document_types()' require 'html_output' type_agregator = GlobalTypeAggregator.new path = ARGV[0] #outDir = ARGV[1] outDir = "apidocs" each_source(path) do |name| File.open(File.join(path, name)) do |io| begin is_utf8 = detect_bom?(io) print "Parsing #{path}:#{name.inspect}" type = simple_parse(io) type.input_filename = name type.sourcepath_location(File.dirname(name)) puts " -> #{type.qualified_name}" type.source_utf8 = is_utf8 type_agregator.add_type(type) rescue =>e $stderr.puts "#{name}: #{e.message}\n#{e.backtrace.join("\n")}" end end end type_agregator.resolve_types document_types(outDir, type_agregator) 1.1 maven-plugins/flash/src/plugin-resources/as2api/html_output.rb Index: html_output.rb =================================================================== require 'xmlwriter' require 'doc_comment' def link_type_proxy(out, type_proxy, qualified=false) if type_proxy.resolved? && type_proxy.resolved_type.document? link_type(out, type_proxy.resolved_type, qualified) else if type_proxy.resolved? out.pcdata(type_proxy.local_name) else out.simple_element("span", type_proxy.local_name, {"class"=>"unresolved_type"}) end end end def link_for_type(type) base_path(type.qualified_name.gsub(/\./, "/")+".html") end def link_type(out, type, qualified=false) href = link_for_type(type) if qualified out.simple_element("a", type.qualified_name, {"href"=>href}) else out.simple_element("a", type.unqualified_name, {"href"=>href, "title"=>type.qualified_name}) end end def method_synopsis(out, method) out.element("code", {"class", "method_synopsis"}) do if method.access.is_static out.pcdata("static ") end unless method.access.visibility.nil? out.pcdata("#{method.access.visibility.body} ") end out.pcdata("function ") out.element("strong", {"class"=>"method_name"}) do out.pcdata(method.name) end out.pcdata("(") method.arguments.each_with_index do |arg, index| out.pcdata(", ") if index > 0 out.pcdata(arg.name) if arg.arg_type out.pcdata(":") link_type_proxy(out, arg.arg_type) end end out.pcdata(")") if method.return_type out.pcdata(":") link_type_proxy(out, method.return_type) end end end def field_synopsis(out, field) out.element("code", {"class", "field_synopsis"}) do if field.instance_of?(ASImplicitField) implicit_field_synopsis(out, field) else explicit_field_synopsis(out, field) end end end def explicit_field_synopsis(out, field) if field.access.is_static out.pcdata("static ") end unless field.access.visibility.nil? out.pcdata("#{field.access.visibility.body} ") end out.element("strong", {"class"=>"field_name"}) do out.pcdata(field.name) end if field.field_type out.pcdata(":") link_type_proxy(out, field.field_type) end end def implicit_field_synopsis(out, field) if field.access.is_static out.pcdata("static ") end unless field.access.visibility.nil? out.pcdata("#{field.access.visibility.body} ") end out.element("strong", {"class"=>"field_name"}) do out.pcdata(field.name) end field_type = field.field_type unless field_type.nil? out.pcdata(":") link_type_proxy(out, field_type) end unless field.readwrite? out.pcdata(" ") out.element("em", {"class"=>"read_write_only"}) do if field.read? out.pcdata("[Read Only]") else out.pcdata("[Write Only]") end end end end def class_navigation(out) out.element("div", {"class", "main_nav"}) do out.simple_element("a", "Overview", {"href"=>base_path("overview-summary.html")}) out.simple_element("a", "Package", {"href"=>"package-summary.html"}) out.simple_element("span", "Class", {"class"=>"nav_current"}) end end def document_method(out, method, alt_row=false) css_class = "method_details" css_class << " alt_row" if alt_row out.element("div", {"class"=>css_class}) do out.empty_tag("a", {"name"=>"method_#{method.name}"}) out.simple_element("h3", method.name) method_synopsis(out, method) if method.comment out.element("blockquote") do docs = DocComment.new docs.parse(method.comment.body) out.pcdata(docs.description) out.element("dl", {"class"=>"method_additional_info"}) do # TODO: assumes that params named in docs match formal arguments # should really filter out those that don't match before this # test if docs.parameters? out.simple_element("dt", "Parameters") out.element("dd") do out.element("table", {"class"=>"arguments"}) do method.arguments.each do |arg| desc = docs.param(arg.name) if desc out.element("tr") do out.element("td") do out.simple_element("code", arg.name) end out.simple_element("td", desc) end end end end end end if docs.exceptions? out.simple_element("dt", "throws") out.element("dd") do out.element("table", {"class"=>"exceptions"}) do docs.each_exception do |type, desc| out.element("tr") do out.element("td") do out.simple_element("code", type) end out.simple_element("td", desc) end end end end end # TODO: see-also end end end end end def document_field(out, field) out.empty_tag("a", {"name"=>"field_#{field.name}"}) out.simple_element("h3", field.name) out.element("div", {"class"=>"field_details"}) do field_synopsis(out, field) if field.comment out.element("blockquote") do docs = DocComment.new docs.parse(field.comment.body) out.pcdata(docs.description) out.element("dl", {"class"=>"field_additional_info"}) do # TODO: see-also end end end end end $base_path = "" $path = "" def base_path(file) "#{$base_path}#{file}" end def in_subdir(path) save_path = $path save_base_path = $base_path.dup path = path.split(File::SEPARATOR) if path.first == "" path.shift $path = "/" end path.each do |part| if $path == "" $path = part else $base_path << ".."+File::SEPARATOR $path = File.join($path, part) end unless FileTest.exist?($path) Dir.mkdir($path) end end yield $path = save_path $base_path = save_base_path end def write_file(name) File.open(File.join($path, name), "w") do |io| yield io end end def html_file(name, title, encoding=nil) write_file("#{name}.html") do |io| out = XMLWriter.new(io) encoding = "iso-8859-1" if encoding.nil? out.pi("xml version=\"1.0\" encoding=\"#{encoding}\"") out.element("html") do out.element("head") do out.simple_element("title", title) out.empty_tag("link", {"rel"=>"stylesheet", "type"=>"text/css", "href"=>base_path("style.css")}) yield out end end end end def html_body(name, title, encoding=nil) html_file(name, title, encoding) do |out| out.element("body") do yield out footer(out) end end end def footer(out) out.element("div", {"class"=>"footer"}) do out.simple_element("a", "as2api", {"href"=>"http://www.badgers-in-foil.co.uk/projects/as2api/", "title"=>"ActionScript 2 API Documentation Generator"}) end end def type_hierachy(out, type) out.element("pre", {"class"=>"type_hierachy"}) do count = 0 unless type.extends.nil? count = type_hierachy_recursive(out, type.extends) end if count > 0 out.pcdata(" " * count) out.pcdata("+--") end out.simple_element("strong", type.qualified_name) end end def type_hierachy_recursive(out, type_proxy) count = 0 if type_proxy.resolved? type = type_proxy.resolved_type unless type.extends.nil? count = type_hierachy_recursive(out, type.extends) end else out.pcdata("????\n") count = 1 end if count > 0 out.pcdata(" " * count) out.pcdata("+--") end link_type_proxy(out, type_proxy, true) out.pcdata("\n") return count + 1 end def field_index_list(out, type) out.element("div", {"class"=>"field_index"}) do out.simple_element("h2", "Field Index") list_fields(out, type) out.element("dl") do type.each_ancestor do |type| if type.fields? out.element("dt") do out.pcdata("Inherited from ") link_type(out, type) end out.element("dd") do list_fields(out, type, link_for_type(type)) end end end end end end def list_fields(out, type, href_prefix="") fields = type.fields.sort fields.each_with_index do |field, index| out.pcdata(", ") if index > 0 out.element("code") do out.element("a", {"href"=>"#{href_prefix}#field_#{field.name}"}) do out.pcdata(field.name) end end end end def field_detail_list(out, type) out.element("div", {"class"=>"field_detail_list"}) do out.simple_element("h2", "Field Detail") type.each_field do |field| document_field(out, field) end end end def method_index_list(out, type) out.element("div", {"class"=>"method_index"}) do out.simple_element("h2", "Method Index") if type.constructor? out.element("p") do out.element("code") do out.pcdata("new ") out.element("a", {"href"=>"#method_#{type.constructor.name}"}) ... [truncated message content] |