-
Notifications
You must be signed in to change notification settings - Fork 219
/
ProgramHTMLOperatorDocGenerator.java
84 lines (71 loc) · 2.81 KB
/
ProgramHTMLOperatorDocGenerator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Copyright (C) 2001-2019 RapidMiner GmbH
*/
package com.rapidminer.doc;
import java.io.PrintWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.rapidminer.operator.Operator;
import com.rapidminer.tools.LogService;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.RootDoc;
/**
* Formats operator documentation in HTML style.
*
* @author Ingo Mierswa
*/
public class ProgramHTMLOperatorDocGenerator implements OperatorDocGenerator {
public void generateDoc(Operator op, RootDoc rootDoc, PrintWriter out) {
ClassDoc opDoc = rootDoc.classNamed(op.getClass().getName());
// name
out.println(op.getOperatorDescription().getName());
// Description
out.println(transformHTMLJavadocComment(opDoc.commentText(), op.getClass(), op.getOperatorDescription().getName()));
out.println("#####");
}
public String transformHTMLJavadocComment(String comment, final Class clazz, final String operatorName) {
try {
// Links
StringBuffer linksReplaced = new StringBuffer();
Pattern linkPattern = Pattern.compile("\\{@link (.*?)\\}");
Matcher linkMatcher = linkPattern.matcher(comment);
while (linkMatcher.find()) {
String classname = linkMatcher.group(1);
int period = classname.lastIndexOf(".");
if (period != -1)
classname = classname.substring(period + 1);
linkMatcher.appendReplacement(linksReplaced, "<i>" + classname + "</i>");
}
linkMatcher.appendTail(linksReplaced);
// RapidMiner Ref
StringBuffer refReplaced = new StringBuffer();
Pattern refPattern = Pattern.compile("\\{@rapidminer.ref (.*?)\\}");
Matcher refMatcher = refPattern.matcher(linksReplaced.toString());
while (refMatcher.find()) {
String refName = refMatcher.group(1);
int period = refName.lastIndexOf("|");
if (period != -1)
refName = refName.substring(period + 1);
refMatcher.appendReplacement(refReplaced, "<i>" + refName + "</i>");
}
refMatcher.appendTail(refReplaced);
// RapidMiner Math
StringBuffer mathReplaced = new StringBuffer();
Pattern mathPattern = Pattern.compile("\\{@rapidminer.math (.*?)\\}");
Matcher mathMatcher = mathPattern.matcher(refReplaced.toString());
while (mathMatcher.find()) {
String mathName = mathMatcher.group(1);
mathMatcher.appendReplacement(mathReplaced, "<i>" + mathName + "</i>");
}
mathMatcher.appendTail(mathReplaced);
return mathReplaced.toString();
} catch (Throwable e) {
LogService.getGlobal().log(operatorName + " (" + clazz.getName() + "): " + e, LogService.ERROR);
return "Cannot parse class comment: " + e;
}
}
/** Does nothing. */
public void beginGroup(String groupName, PrintWriter out) {}
/** Does nothing. */
public void endGroup(String groupName, PrintWriter out) {}
}