Skip to content

Commit

Permalink
Merge pull request ruby#2494 from ruby/javadoc
Browse files Browse the repository at this point in the history
Java documentation
  • Loading branch information
kddnewton authored Feb 24, 2024
2 parents 6dcceb4 + 62f7560 commit 71e83d4
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 32 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Documentation

concurrency:
group: "${{github.workflow}}-${{github.ref}}"
cancel-in-progress: true

on:
push:
branches:
- main
pull_request:

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2"
bundler-cache: true
- name: Install doxygen and dependencies
run: |
sudo apt-get update
sudo apt-get install doxygen graphviz
- name: Generate the templates
run: bundle exec rake templates
- name: Check ruby coverage
run: bundle exec rake rdoc:coverage
- name: Check C coverage
run: doxygen Doxyfile
- name: Check Java coverage
run: javadoc -Xdoclint:all,-missing -d ../doc/java -subpackages *
working-directory: java
3 changes: 3 additions & 0 deletions .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jobs:
run: bundle exec rake rdoc
- name: Build with Doxygen
run: doxygen Doxyfile
- name: Build with JavaDoc
run: javadoc -Xdoclint:all,-missing -d ../doc/java -subpackages *
working-directory: java
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
Expand Down
20 changes: 0 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -313,23 +313,3 @@ jobs:
run: |
scan-build bundle exec rake compile 2>&1 | tee /tmp/scan_build_output.log
grep -q 'scan-build: No bugs found.' /tmp/scan_build_output.log
documentation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2"
bundler-cache: true
- name: Install doxygen and dependencies
run: |
sudo apt-get update
sudo apt-get install doxygen graphviz
- name: Generate the templates
run: bundle exec rake templates
- name: Check ruby coverage
run: bundle exec rake rdoc:coverage
- name: Check C coverage
run: doxygen Doxyfile
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/_yardoc/
/coverage/
/doc/c/
/doc/java/
/doc/rb/
/pkg/
/spec/reports/
Expand Down
Binary file added doc/images/java.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions doc/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ h1 {
main {
display: grid;
grid-template-rows: 1fr 1fr;
grid-template-columns: 1fr 1fr;
height: 36vh;
margin: 2vh 30vw;
margin: 2vh 20vw;
}

@media only screen and (max-width: 1200px) {
main {
margin: 2vh 20vw;
margin: 2vh 10vw;
}
}

Expand All @@ -51,6 +52,10 @@ main {
vertical-align: middle;
}

.reference:first-child {
grid-column: span 2;
}

.reference > img {
height: 10vh;
width: 10vh;
Expand Down
10 changes: 7 additions & 3 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
<h1>Prism Ruby parser</h1>
</header>
<main>
<a class="reference" href="c/index.html">
<img src="images/c.svg" alt="C">
<h2>C reference</h2>
</a>
<a class="reference" href="rb/index.html">
<img src="images/ruby.svg" alt="Ruby">
<h2>Ruby reference</h2>
</a>
<a class="reference" href="c/index.html">
<img src="images/c.svg" alt="C">
<h2>C reference</h2>
<a class="reference" href="java/index.html">
<img src="images/java.png" alt="Java">
<h2>Java reference</h2>
</a>
</main>
<footer>
Expand Down
6 changes: 6 additions & 0 deletions templates/java/org/prism/AbstractNodeVisitor.java.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ public abstract class AbstractNodeVisitor<T> {
protected abstract T defaultVisit(Nodes.Node node);

<%- nodes.each do |node| -%>
/**
* Visit a <%= node.name %> node.
*
* @param node The node to visit.
* @return The result of visiting the node.
*/
public T visit<%= node.name -%>(Nodes.<%= node.name -%> node) {
return defaultVisit(node);
}
Expand Down
8 changes: 5 additions & 3 deletions templates/java/org/prism/Nodes.java.erb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public abstract class Nodes {
<%- flags.each do |group| -%>

/**
* <%= group.comment %>
* <%= Prism::JavaDoc.escape(group.comment) %>
*/
public static final class <%= group.name %> implements Comparable<<%= group.name %>> {
<%- group.values.each_with_index do |value, index| -%>
Expand Down Expand Up @@ -184,9 +184,11 @@ public abstract class Nodes {
<%- nodes.each do |node| -%>

/**
<%- node.each_comment_line do |line| -%>
* <pre>
<%- node.each_comment_java_line do |line| -%>
*<%= line %>
<%- end -%>
* </pre>
*/
public static final class <%= node.name -%> extends Node {
<%- if node.needs_serialized_length? -%>
Expand All @@ -196,7 +198,7 @@ public abstract class Nodes {
<%- if field.comment -%>
/**
* <pre>
<%- field.each_comment_line do |line| -%>
<%- field.each_comment_java_line do |line| -%>
*<%= line %>
<%- end -%>
* </pre>
Expand Down
49 changes: 45 additions & 4 deletions templates/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,39 @@ module Prism
JAVA_BACKEND = ENV["PRISM_JAVA_BACKEND"] || "truffleruby"
JAVA_STRING_TYPE = JAVA_BACKEND == "jruby" ? "org.jruby.RubySymbol" : "String"

# This module contains methods for escaping characters in JavaDoc comments.
module JavaDoc
ESCAPES = {
"'" => "&#39;",
"\"" => "&quot;",
"@" => "&#64;",
"&" => "&amp;",
"<" => "&lt;",
">" => "&gt;"
}.freeze

def self.escape(value)
value.gsub(/['&"<>@]/, ESCAPES)
end
end

# A comment attached to a field or node.
class Comment
attr_reader :value

def initialize(value)
@value = value
end

def each_line(&block)
value.each_line { |line| yield line.prepend(" ").rstrip }
end

def each_java_line(&block)
Comment.new(JavaDoc.escape(value)).each_line(&block)
end
end

# This represents a field on a node. It contains all of the necessary
# information to template out the code for that field.
class Field
Expand All @@ -21,8 +54,12 @@ def initialize(name:, comment: nil, **options)
@options = options
end

def each_comment_line
comment.each_line { |line| yield line.prepend(" ").rstrip } if comment
def each_comment_line(&block)
Comment.new(comment).each_line(&block) if comment
end

def each_comment_java_line(&block)
Comment.new(comment).each_java_line(&block) if comment
end

def semantic_field?
Expand Down Expand Up @@ -317,8 +354,12 @@ def initialize(config)
@comment = config.fetch("comment")
end

def each_comment_line
comment.each_line { |line| yield line.prepend(" ").rstrip }
def each_comment_line(&block)
Comment.new(comment).each_line(&block)
end

def each_comment_java_line(&block)
Comment.new(comment).each_java_line(&block)
end

def semantic_fields
Expand Down

0 comments on commit 71e83d4

Please sign in to comment.