This repository was archived by the owner on Aug 27, 2026. It is now read-only.
Repository navigation
Commit 69e1b80
authored
[java-source-utils] Add Java source code utilities (#623)
Context: https://github.com/javaparser/javaparser/tree/javaparser-parent-3.16.1
Context: #623
There are two parts of the current `.jar` binding toolchain which are
painful and could be improved:
1. Parameter names
2. Documentation extraction
Parameter names (1) are important because they become the names of
event members as part of ["event-ification"][0]. As such they are
semantically important, and the default behavior of "p0" makes for a
terrible user experience.
*If* the `.class` files in the `.jar` file are built with
`javac -parameters` (4273e5c), then the `.class` file will contain
parameter names and we're good. However, this may not be the case.
If the `.class` files are built with `javac -g`, then we'll try to
deduce parameter names from debug info, but that's also problematic.
What else can be used to provide parameter names?
It is not unusual for Java libraries to provide "source `.jar`" files,
e.g. Android provides `android-stubs-src.jar` files, and other
libraries may provide a `*-sources.jar` file. The contents of these
files are *Java source code*. These files are used by Android IDEs to
provide documentation for the Java library. They contain classes,
methods, parameter names, and associated Javadoc documentation.
What they are *not* guaranteed to do is *compile*. As such, we can't
compile them ourselves with `javac -parameters` and then process the
`.class` files, as they may refer to unresolvable types.
"Interestingly", we *already* have some tooling to deal with this:
`tools/param-name-importer` uses a custom Irony grammar to parse
the Android SDK `*-stubs-src.jar` files to grab parameter names.
However, this tooling is *too strict*; try to pass arbitrary Java
source code at it, and it quickly fails.
Which brings us to documentation (2): we have a [javadoc2mdoc][1] tool
which will parse Javadoc HTML documentation and convert it into
[**mdoc**(5)][2] documentation, which can be later turned into
[XML documentation comments][3] files by way of
[**mdoc export-msxdoc**(1)][4], but this tool is (1) painful to
maintain, because it processes Javadoc *HTML*, and
(2) *requires Javadoc HTML*.
Google hasn't updated their downloadable Javadoc `.zip` file since
API-24 (2016-October). API-30 is currently stable.
If we want newer docs, we either need to scrape the
developer.android.com/reference website to use with the existing
tooling, or... we need to be able to read the Javadoc comments within
the `*-stubs-src.jar` files provided with the Android SDK.
(Note: Android SDK docs are Apache 2; file format conversion is fine.)
We thus have two use-cases for which parsing Java source code would
be useful.
As luck would have it, there's a decent Apache 2-licensed Java project
which supports parsing Java source code: [JavaParser][5].
Add a new `tools/java-source-utils` program which will parse Java
source code to produce two artifacts: parameter names and
consolidated Javadoc documentation:
$ java -jar java-source-utils.jar --help
java-source-utils [-v] [<-a|--aar> AAR]* [<-j|--jar> JAR]* [<-s|--source> DIRS]*
[--bootclasspath CLASSPATH]
[<-P|--output-params> OUT.params.txt] [<-D|--output-javadoc> OUT.xml] FILES
Provide `--output-params OUT.params.txt`, and the specified file will
be created which follows the file format laid out in
[`JavaParameterNamesLoader.cs`][6]:
package java.lang
;---------------------------------------
class Object
wait(long timeout)
Provide `--output-javadoc api-javadocs.xml`, and the resulting file
will be a `class-parse`-like XML file which uses `//@jni-signature` as
the "key" and a child `1 parent 228ed69 commit 69e1b80
51 files changed
Lines changed: 2901 additions & 6 deletions
File tree
- .vscode
- build-tools
- Java.Interop.BootstrapTasks/Java.Interop.BootstrapTasks
- gradle
- gradle/wrapper
- tests/Xamarin.Android.Tools.Bytecode-Tests/java/com/xamarin
- tools/java-source-utils
- src
- main/java/com/microsoft/android
- ast
- util
- test
- java/com/microsoft/android
- resources/com
- microsoft/android
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| |||
251 | 253 | | |
252 | 254 | | |
253 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
254 | 260 | | |
255 | 261 | | |
256 | 262 | | |
| |||
294 | 300 | | |
295 | 301 | | |
296 | 302 | | |
| 303 | + | |
297 | 304 | | |
298 | 305 | | |
299 | 306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
147 | 151 | | |
148 | 152 | | |
149 | 153 | | |
| |||
Lines changed: 9 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
| 59 | + | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
107 | 111 | | |
108 | 112 | | |
109 | 113 | | |
| |||
121 | 125 | | |
122 | 126 | | |
123 | 127 | | |
124 | | - | |
| 128 | + | |
125 | 129 | | |
126 | 130 | | |
127 | 131 | | |
| 132 | + | |
128 | 133 | | |
129 | 134 | | |
130 | 135 | | |
| |||
Binary file not shown.
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments