############################################################################### # # Package: NaturalDocs::Parser::JavaDoc # ############################################################################### # # A package for translating JavaDoc topics into Natural Docs. # # Supported tags: # # - @param # - @author # - @deprecated # - @code, @literal (doesn't change font) # - @exception, @throws (doesn't link to class) # - @link, @linkplain (doesn't change font) # - @return, @returns # - @see # - @since # - @value (shown as link instead of replacement) # - @version # # Stripped tags: # # - @inheritDoc # - @serial, @serialField, @serialData # - All other block level tags. # # Unsupported tags: # # These will appear literally in the output because I cannot handle them easily. # # - @docRoot # - Any other tags not mentioned # # Supported HTML: # # - p # - b, i, u # - pre # - a href # - ol, ul, li (ol gets converted to ul) # - gt, lt, amp, quot, nbsp entities # # Stripped HTML: # # - code # - HTML comments # # Unsupported HTML: # # These will appear literally in the output because I cannot handle them easily. # # - Any tags with additional properties other than a href. (ex.
)
# - Any other tags not mentioned
#
# Reference:
#
# http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javadoc.html
#
###############################################################################
# This file is part of Natural Docs, which is Copyright (C) 2003-2008 Greg Valure
# Natural Docs is licensed under the GPL
use strict;
use integer;
package NaturalDocs::Parser::JavaDoc;
#
# hash: blockTags
# An existence hash of the all-lowercase JavaDoc block tags, not including the @.
#
my %blockTags = ( 'param' => 1, 'author' => 1, 'deprecated' => 1, 'exception' => 1, 'return' => 1, 'see' => 1,
'serial' => 1, 'serialfield' => 1, 'serialdata' => 1, 'since' => 1, 'throws' => 1, 'version' => 1,
'returns' => 1 );
#
# hash: inlineTags
# An existence hash of the all-lowercase JavaDoc inline tags, not including the @.
#
my %inlineTags = ( 'inheritdoc' => 1, 'docroot' => 1, 'code' => 1, 'literal' => 1, 'link' => 1, 'linkplain' => 1, 'value' => 1 );
##
# Examines the comment and returns whether it is *definitely* JavaDoc content, i.e. is owned by this package.
#
# Parameters:
#
# commentLines - An arrayref of the comment lines. Must have been run through ' . $self->FormatText($unformattedText, 1) . ' ' . $self->FormatText($unformattedText, 1) . ' ' . $returns . ' ' . $since . ' ' . $version . ' ' . $deprecation . ' ' . $authors . ' ' . $seeAlso . ' /gi; }
else
{ $text =~ s/<p>//gi; };
$text =~ s/<a href="mailto:(.*?)".*?>(.*?)<\/a>/$self->MakeEMailLink($1, $2)/gie;
$text =~ s/<a href="(.*?)".*?>(.*?)<\/a>/$self->MakeURLLink($1, $2)/gie;
$text =~ s/ / /gi;
$text =~ s/&/&/gi;
$text =~ s/>/>/gi;
$text =~ s/</</gi;
$text =~ s/"/"/gi;
# JavaDoc
$text =~ s/\{\@inheritdoc\}//gi;
$text =~ s/\{\@(?:linkplain|link|value) ([^\}]*)\}/$self->ConvertLink($1)/gie;
return $text;
};
sub ConvertAmpChars #(text)
{
my ($self, $text) = @_;
$text =~ s/&/&/g;
$text =~ s/</g;
$text =~ s/>/>/g;
$text =~ s/"/"/g;
return $text;
};
sub ConvertLink #(text)
{
my ($self, $text) = @_;
$text =~ /^ *([a-z0-9\_\.\:\#]+(?:\([^\)]*\))?) *(.*)$/i;
my ($target, $label) = ($1, $2);
# Convert the anchor to part of the link, but remove it altogether if it's the beginning of the link.
$target =~ s/^\#//;
$target =~ s/\#/\./;
$label =~ s/ +$//;
if (!length $label)
{ return ''; }
else
{ return ''; };
};
sub MakeURLLink #(target, text)
{
my ($self, $target, $text) = @_;
return '' . $unformattedText . '
';
$sharedCodeIndent = undef;
};
$inCode = 0;
$unformattedText = undef;
}
elsif (length($token))
{
if (!$inCode)
{
$token =~ s/^ +//;
if ($unformattedText)
{ $unformattedText .= ' '; };
}
else
{
$token =~ /^( *)/;
my $indent = length($1);
if (!defined $sharedCodeIndent || $indent < $sharedCodeIndent)
{ $sharedCodeIndent = $indent; };
};
$unformattedText .= $token;
};
};
if ($inCode && $unformattedText)
{ $unformattedText .= "\n"; };
$i++;
};
if ($unformattedText)
{
if ($inCode)
{
$unformattedText =~ s/^ {$sharedCodeIndent}//mg;
$unformattedText =~ s/\n{3,}/\n\n/g;
$unformattedText =~ s/\n+$//;
$output .= '' . $unformattedText . '
';
}
else
{ $output .= '' . $params . '
'; };
if ($returns)
{ $output .= '' . $throws . '
'; };
if ($since)
{ $output .= '$1<\/ul>/gi;
$text =~ s/<ol.*?>(.*?)<\/ol>/
$1<\/ul>/gi;
$text =~ s/<li.*?>(.*?)<\/li>/