This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
213 lines (168 loc) · 8.56 KB
/
index.html
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<title>JavaParser - Home</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="stylesheets/normalize.css" media="screen">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/github-light.css" media="screen">
<link href="https://fonts.googleapis.com/css?family=Courgette" rel="stylesheet">
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
<!-- Place this tag in your head or just before your close body tag. -->
<script async defer src="https://buttons.github.io/buttons.js"></script>
</head>
<body>
<!--<div id="logo">
</div>-->
<section class="page-header" >
<h1 class="project-name title-font">JavaParser</h1>
<h2 class="project-tagline">Process Java code programmatically</h2>
</section>
<section class="navigation">
<ul>
<li class="selected"><a href="index.html">Home</a></li>
<li><a href="gettingstarted.html">Getting started</a>
<li><a href="about.html">About</a>
<li><a href="contributing.html">Contributing</a>
<li><a href="presentations.html">Presentations</a>
<li class="last"><a href="https://github.com/javaparser">on GitHub</a>
</ul>
</section>
<section class="main-content">
<p>
Our goal is to build a <b>simple</b> and <b>lightweight</b> set of tools
to generate, analyze, and process Java code.
</p>
<p>
All of this is offered under a business friendly <a href="#license">license</a>.
</p>
<p>
JavaParser is used in dozens of open-source and commercial projects.
Show your love adding one star more or spreading the word.
</p>
<center>
<!-- Place this tag where you want the button to render. -->
<a class="github-button" href="https://github.com/javaparser/javaparser" data-style="mega" data-count-href="/javaparser/javaparser/stargazers" data-count-api="/repos/javaparser/javaparser#stargazers_count" data-count-aria-label="# stargazers on GitHub" aria-label="Star javaparser/javaparser on GitHub">Star JavaParser</a>
<a href="https://twitter.com/share" class="twitter-share-button" data-size="large" data-text="I am using #javaparser a set of open-source tools to work with Java code" data-url="http://javaparser.org" data-show-count="false">Tweet</a><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
<script>window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
};
return t;
}(document, "script", "twitter-wjs"));</script>
</center>
<h2 class="area-title">What you can do with JavaParser</h2>
<p>JavaParser is a set of tools to:
<ul>
<li><a href="#parse">parse</a>
<li><a href="#analyze">analyze</a>
<li><a href="#transform">transform</a>
<li><a href="#generate">generate</a>
</ul>
Java code.
</p>
<div class="box">
<a href="https://leanpub.com/javaparservisited"><img src="images/javaparser-book.jpg" height="300px"/></a>
<h2>Want to learn JavaParser?</h2>
<p>
We <b>are writing</b> <a href="https://leanpub.com/javaparservisited">a book</a> on JavaParser and we need <a href="https://github.com/javaparser/javaparser-visited/issues/new">your feedback</a>!
</p>
<p>
Help us understanding what is not clear, what should we add, share examples and ideas with us.
You can also contact us <a href="https://gitter.im/javaparser/javaparserbook">on gitter</a> or on the <a href="https://github.com/javaparser/javaparser-visited/issues/new">book repository</a>.
</p>
<p>
It would be great if you could help us spread the word:
</p>
<a class="twitter-share-button"
href="https://twitter.com/intent/tweet?text=A+book+on+processing+Java+code%3F+Give+your+feedback+https%3A%2F%2Fgithub.com%2Fjavaparser%2Fjavaparser-visited+%23JavaParser"
data-size="large">
Tweet!</a></p>
</div>
<p>In the rest of the page we will look on different features of JavaParser. You may also be interested
in checking out some <a href="presentations.html">presentations</a> we gave about JavaParser.</p>
<a name="parse"></a>
<h3 class="subarea-title">Parsing Java code</h3>
<p>Using JavaParser you can get an Abstract Syntax Tree (AST) from Java code.
The AST is a structure representing your Java code in a way that it is easy to process:
</p>
<div class="highlight highlight-text-java"><pre class="prettyprint lang-java">
CompilationUnit compilationUnit = JavaParser.parse("class A { }");
Optional<ClassOrInterfaceDeclaration> classA = compilationUnit.getClassByName("A");
</pre></div>
<a name="analyze"></a>
<h3 class="subarea-title">Analyze Java code</h3>
<p>Suppose you want to look for fields which are public and not static.
This is pretty easy using JavaParser:</p>
<div class="highlight highlight-text-java"><pre class="prettyprint lang-java">
compilationUnit.findAll(FieldDeclaration.class).stream()
.filter(f -> f.isPublic() && !f.isStatic())
.forEach(f -> System.out.println("Check field at line " +
f.getRange().map(r -> r.begin.line).orElse(-1)));
</pre></div>
<a name="transform"></a>
<h3 class="subarea-title">Transform Java code</h3>
<p>Maybe you want to ensure all abstract classes have a name starting with <i>Abstract</i>:</p>
<div class="highlight highlight-text-java"><pre class="prettyprint lang-java">
compilationUnit.findAll(ClassOrInterfaceDeclaration.class).stream()
.filter(c -> !c.isInterface()
&& c.isAbstract()
&& !c.getNameAsString().startsWith("Abstract"))
.forEach(c -> {
String oldName = c.getNameAsString();
String newName = "Abstract" + oldName;
System.out.println("Renaming class " + oldName + " into " + newName);
c.setName(newName);
});
</pre></div>
<a name="generate"></a>
<h3 class="subarea-title">Generate Java code</h3>
<div class="highlight highlight-text-java"><pre class="prettyprint lang-java">
CompilationUnit compilationUnit = new CompilationUnit();
ClassOrInterfaceDeclaration myClass = compilationUnit
.addClass("MyClass")
.setPublic(true);
myClass.addField(int.class, "A_CONSTANT", PUBLIC, STATIC);
myClass.addField(String.class, "name", PRIVATE);
String code = myClass.toString();
</pre></div>
<h2 class="area-title">Components of JavaParser</h2>
JavaParser is both the name of the set of tools and of the main component: the parser.
In addition to JavaParser there is another component in the set of tools: <a href="https://github.com/javaparser/javasymbolsolver">JavaSymbolSolver</a>.
<p>The parser is extra lightweight (no dependencies at all!) and can give you super fast an AST for your Java code. Sometimes an AST is not enough because you want:</p>
<br>
<ul>
<li>Understand to which element a certain name refer: a field? A variable?
<li>You need to know the type of a complex expression
<li>You want to get a list of all the interfaces implemented (also indirectly) by a certain class
</ul>
JavaSymbolSolver does the extra work to answer this questions for you.
<h2>
<a id="license" class="anchor" href="#license" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>License</h2>
<p>JavaParser is available either under the terms of the LGPL License or the Apache License. You as the user are entitled to choose the terms under which adopt JavaParser.</p>
<p>For details about the LGPL License please refer to LICENSE.LGPL.</p>
<p>For details about the Apache License please refer to LICENSE.APACHE.</p>
<footer class="site-footer">
<span class=""><a href="https://github.com/javaparser">JavaParser</a> is maintained by Open-Source enthusiasts.</span>
</footer>
</section>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-89097232-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>