Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use regex to translate Doxygen commands #278

Merged
merged 5 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/main/java/org/bytedeco/javacpp/tools/DocTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2019 Samuel Audet, Hervé Guillemet
*
* Licensed either under the Apache License, Version 2.0, or (at your option)
* under the terms of the GNU General Public License as published by
* the Free Software Foundation (subject to the "Classpath" exception),
* either version 2, or any later version (collectively, the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.gnu.org/licenses/
* http://www.gnu.org/software/classpath/license.html
*
* or as provided in the LICENSE.txt file that accompanied this code.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.bytedeco.javacpp.tools;

import java.util.regex.Pattern;

/**
* Documentation tags, where we keep only the ones that could be compatible between Javadoc and Doxygen.
*
* @author Hervé Guillemet
*/
class DocTag {
static String[][] docTagsStr = {
{ "authors?\\b", "author" },
{ "deprecated\\b", "deprecated" },
{ "(?:exception|throws?)\\b", "throws" },
{ "param\\s*(\\[[a-z,\\s]+\\])\\s+(\\S+)", "param $2 $1 " },
{ "param\\b", "param" },
{ "(?:returns?|result)\\b", "return" },
{ "(?:see|sa)\\b", "see" },
{ "since\\b", "since" },
{ "version\\b", "version" }
/* "code", "docRoot", "inheritDoc", "link", "linkplain", "literal", "serial", "serialData", "serialField", "value" */
};
static DocTag[] docTags = new DocTag[docTagsStr.length];
static {
for (int i=0; i<docTagsStr.length; i++)
docTags[i] = new DocTag(docTagsStr[i][0], docTagsStr[i][1]);
}

Pattern pattern;
String replacement;
DocTag(String p, String r) {
pattern = Pattern.compile(p);
replacement = r;
}
}
28 changes: 11 additions & 17 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1426,10 +1426,6 @@ Declarator declarator(Context context, String defaultName, int infoNumber, boole
return dcl;
}

/** Documentation tags, where we keep only the ones that could be compatible between Javadoc and Doxygen. */
String[] docTags = {"author", "deprecated", "exception", "param", "return", "see", "since", "throws", "version",
/* "code", "docRoot", "inheritDoc", "link", "linkplain", "literal", "serial", "serialData", "serialField", "value" */};

/** Tries to adapt a Doxygen-style documentation comment to Javadoc-style. */
String commentDoc(String s, int startIndex) {
if (startIndex < 0 || startIndex > s.length()) {
Expand Down Expand Up @@ -1483,22 +1479,20 @@ String commentDoc(String s, int startIndex) {
}
sb.insert(index + 1, indent + "<p>");
} else if (c == '\\' || c == '@') {
String foundTag = null;
for (String tag : docTags) {
if (ss.startsWith(tag)) {
foundTag = tag;
boolean tagFound = false;
for (DocTag tag : DocTag.docTags) {
Matcher matcher = tag.pattern.matcher(ss);
if (matcher.lookingAt()) {
StringBuffer sbuf = new StringBuffer();
matcher.appendReplacement(sbuf, tag.replacement);
sb.replace(index + 1+ matcher.start(),
index + 1 + matcher.end(), sbuf.toString());
sb.setCharAt(index, '@');
tagFound = true;
break;
}
}
if (foundTag != null) {
sb.setCharAt(index, '@');
int n = index + foundTag.length() + 1;
if (sb.charAt(n) == 's' && !foundTag.endsWith("s")) {
sb.deleteCharAt(n);
} else if (!Character.isWhitespace(sb.charAt(n))) {
sb.insert(n, ' ');
}
} else {
if (!tagFound) {
// keep unmapped tags around as part of the comments
sb.setCharAt(index, '\\');
}
Expand Down