Skip to content

Commit 8e14c94

Browse files
committed
Fix some typos and grammar
1 parent 560a5de commit 8e14c94

File tree

5 files changed

+60
-57
lines changed

5 files changed

+60
-57
lines changed

docs/README.md.html

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- [A Sample Lint Check](api-guide/example.md.html)
3737
- [Analyzing data flow](api-guide/dataflow-analyzer.md.html)
3838
- [Publishing a Lint check](api-guide/publishing.md.html)
39+
- [AST Analysis](api-guide/ast-analysis.md.html)
3940
- [Unit Testing](api-guide/unit-testing.md.html)
4041
- [Test Modes](api-guide/test-modes.md.html)
4142
- [Annotations](api-guide/annotations.md.html)

docs/api-guide.html

+27-28
Original file line numberDiff line numberDiff line change
@@ -2276,7 +2276,7 @@
22762276

22772277
Anyway, you can see there is quite a bit of detail here — tracking
22782278
things like the keywords, the variables, references to for example the
2279-
package — and higher level concepts like a class and a field which I've
2279+
package — and higher level concepts like a class and a field, which I've
22802280
marked with a thicker border.
22812281

22822282
</p><p>
@@ -2298,7 +2298,7 @@
22982298

22992299
<p></p><p>
23002300

2301-
This is for a program which is completely equivalent to the Java one.
2301+
This program is equivalent to the Java one.
23022302
But notice that it has a completely different shape! They reference
23032303
different element classes, <code>PsiClass</code> versus <code>KtClass</code>, and on and on
23042304
all the way down.
@@ -2313,7 +2313,7 @@
23132313
<p>
23142314

23152315

2316-
We can construct a new AST which represents the same concepts:
2316+
We can construct a new AST that represents the same concepts:
23172317

23182318
</p><p>
23192319

@@ -2337,7 +2337,7 @@
23372337
<p></p><p>
23382338

23392339
As you can see, the ASTs are not always identical. For Strings, in
2340-
Kotlin, we often end up with an extra parent <code>UiInjectionHost</code>. But for
2340+
Kotlin, we often end up with an extra parent <code>UInjectionHost</code>. But for
23412341
our purposes, you can see that the ASTs are mostly the same, so if you
23422342
handle the Kotlin scenario, you'll handle the Java ones too.
23432343

@@ -2348,7 +2348,7 @@
23482348

23492349
Note that “Unified” in the name here is a bit misleading. From the name
23502350
you may assume that this is some sort of superset of the ASTs across
2351-
languages — and AST that can represent everything needed by all
2351+
languages — an AST that can represent everything needed by all
23522352
languages. But that's not the case! Instead, a better way to think of it
23532353
is as the <strong class="asterisk">Java view</strong> of the AST.
23542354

@@ -2362,9 +2362,8 @@
23622362
<span class="line"></span>)</code></pre><p>
23632363

23642364
This is a Kotlin data class with two properties. So you might expect
2365-
that UAST would have a way to represent these concepts — properties,
2366-
and java classes. This should be a <code>UDataClass</code> with two <code>UProperty</code>
2367-
children, right?
2365+
that UAST would have a way to represent these concepts. This should
2366+
be a <code>UDataClass</code> with two <code>UProperty</code> children, right?
23682367

23692368
</p><p>
23702369

@@ -2442,7 +2441,7 @@
24422441
<p>
24432442

24442443

2445-
Every node in UAST is a subclass of a UElement. There's a parent
2444+
Every node in UAST is a subclass of a <code>UElement</code>. There's a parent
24462445
pointer, which is handy for navigating around in the AST.
24472446

24482447
</p><p>
@@ -2454,7 +2453,7 @@
24542453

24552454
</p><p>
24562455

2457-
Or in the debugger, anytime you have a UElement, you can call
2456+
Or in the debugger, anytime you have a <code>UElement</code>, you can call
24582457
<code>UElement.asRecursiveLogString</code> on it, evaluate and see what you find.
24592458

24602459
</p><p>
@@ -2488,7 +2487,7 @@
24882487

24892488

24902489
You generally shouldn't visit a source file on your own. Lint has a
2491-
special <code>UElementHandler</code> for that which is used to ensure that we don't
2490+
special <code>UElementHandler</code> for that, which is used to ensure we don't
24922491
repeat visiting a source file thousands of times, one per detector.
24932492

24942493
</p><p>
@@ -2538,7 +2537,7 @@
25382537

25392538
We have our UAST tree in the top right corner. And here's the Java PSI
25402539
AST behind the scenes. We can access the underlying PSI node for a
2541-
UElement by accessing the sourcePsi element. So when you do need to dip
2540+
<code>UElement</code> by accessing the <code>sourcePsi</code> property. So when you do need to dip
25422541
into something language specific, that's trivial to do.
25432542

25442543
</p><p>
@@ -2547,18 +2546,18 @@
25472546

25482547
</p><p>
25492548

2550-
Each of the UElement nodes point back into the PSI AST - whether a Java
2549+
Most <code>UElement</code> nodes point back to the PSI AST - whether a Java
25512550
AST or a Kotlin AST. Here's the same AST, but with the <strong class="asterisk">type</strong> of the
2552-
<code>sourcePsi</code> attribute for each node added.
2551+
<code>sourcePsi</code> property for each node added.
25532552

25542553
</p><p>
25552554

25562555
</p><center><a href="api-guide/images/uast-sourcepsi-type.png" target="_blank"><img class="markdeep" src="api-guide/images/uast-sourcepsi-type.png"></a></center>
25572556

25582557
<p></p><p>
25592558

2560-
You can see that the class generated to represent the top level
2561-
functions here doesn't have a non-null <code>sourcePsi</code>, because in the
2559+
You can see that the facade class generated to contain the top level
2560+
functions has a null <code>sourcePsi</code>, because in the
25622561
Kotlin PSI, there is no real <code>KtClass</code> for a facade class. And for the
25632562
three members, the private field and the getter and the setter, they all
25642563
correspond to the exact same, single <code>KtProperty</code> instance, the single
@@ -2596,8 +2595,8 @@
25962595

25972596
</p><p>
25982597

2599-
There <em class="asterisk">are</em> lint checks which are language specific — for example, if
2600-
you write a lint check which forbids the use of companion objects — in
2598+
There <em class="asterisk">are</em> lint checks that are language specific — for example, if
2599+
you write a lint check that forbids the use of companion objects — in
26012600
that case, there's no big advantage to using UAST over PSI; it's only
26022601
ever going to run on Kotlin code. (Note however that lint's APIs and
26032602
convenience callbacks are all targeting UAST, so it's easier to write
@@ -2622,10 +2621,10 @@
26222621
</p><p>
26232622

26242623
For example, let's say you need to determine if a <code>UClass</code> is a Kotlin
2625-
“companion object. You could cheat and look at the class name to see if
2626-
it's ”Companion“. But that's not quite right; in Kotlin you can
2624+
“companion object. You could cheat and look at the class name to see if
2625+
it's “Companion”. But that's not quite right; in Kotlin you can
26272626
specify a custom companion object name, and of course users are free
2628-
to create classes named ”Companion“ that aren't companion objects:
2627+
to create classes named “Companion” that aren't companion objects:
26292628

26302629
</p><pre class="listing tilde"><code><span class="line"></span><span class="hljs-keyword">class</span> <span class="hljs-title class_">Test</span> {
26312630
<span class="line"></span> <span class="hljs-keyword">companion</span> <span class="hljs-keyword">object</span> MyName { <span class="hljs-comment">// Companion object not named "Companion"!</span>
@@ -2635,8 +2634,8 @@
26352634
<span class="line"></span> }
26362635
<span class="line"></span>}</code></pre><p>
26372636

2638-
The right way to do this, is using Kotlin PSI, via the
2639-
<code>UElement.sourcePsi</code> attribute:
2637+
The right way to do this is using Kotlin PSI, via the
2638+
<code>UElement.sourcePsi</code> property:
26402639

26412640
</p><pre class="listing tilde"><code><span class="line"></span><span class="hljs-comment">// Skip companion objects</span>
26422641
<span class="line"></span><span class="hljs-keyword">val</span> source = node.sourcePsi
@@ -2645,7 +2644,7 @@
26452644
<span class="line"></span>}</code></pre><p>
26462645

26472646
(To figure out how to write the above code, use a debugger on a test
2648-
case and look at the <code>UClass.sourcePsi</code> attribute; you'll discover that
2647+
case and look at the <code>UClass.sourcePsi</code> property; you'll discover that
26492648
it's some subclass of <code>KtObjectDeclaration</code>; look up its most general
26502649
super interface or class, and then use code completion to discover
26512650
available APIs, such as <code>isCompanion()</code>.)
@@ -2665,7 +2664,7 @@
26652664
Lint doesn't actually give you access to everything you need if you want
26662665
to try to look up types in Kotlin PSI; you need something called the
26672666
“binding context”, which is not exposed anywhere! And this omission is
2668-
deliberate, because that was an implementation detail of the old
2667+
deliberate, because this is an implementation detail of the old
26692668
compiler. The future is K2; a complete rewrite of the compiler front
26702669
end, which is no longer using the old binding context. And as part of
26712670
the tooling support for K2, there's a new API called the “Kotlin
@@ -2719,7 +2718,7 @@
27192718

27202719
Before the Kotlin lint analysis API, lint didn't have a way to reason
27212720
about the <code>Nothing</code> type. UAST only returns Java types, which maps to
2722-
void. So instead, lint had an ugly hack which just hardcoded well known
2721+
void. So instead, lint had an ugly hack that just hardcoded well known
27232722
names of methods that don't return:
27242723

27252724
</p><pre class="listing tilde"><code><span class="line"></span><span class="hljs-keyword">if</span> (nextStatement <span class="hljs-keyword">is</span> UCallExpression) {
@@ -2764,7 +2763,7 @@
27642763

27652764
</p><p>
27662765

2767-
Similarly on a <code>KtDeclaration</code> (such as a named function or property) I
2766+
Similarly, on a <code>KtDeclaration</code> (such as a named function or property) I
27682767
can call <code>getSymbol()</code> to get the symbol for that method or property, to
27692768
for example look up parameter information. And on a <code>KtExpression</code> (such
27702769
as an if statement) I can call <code>getKtType()</code> to get the Kotlin type.
@@ -2779,7 +2778,7 @@
27792778
</p><p>
27802779

27812780
In the new implementation of <code>callNeverReturns</code>, we resolve the call,
2782-
look up the corresponding function which of course is a <code>KtSymbol</code>
2781+
look up the corresponding function, which of course is a <code>KtSymbol</code>
27832782
itself, and from that we get the return type, and then we can just check
27842783
if it's the <code>Nothing</code> type.
27852784

docs/api-guide/ast-analysis.md.html

+27-28
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
Anyway, you can see there is quite a bit of detail here -- tracking
4444
things like the keywords, the variables, references to for example the
45-
package -- and higher level concepts like a class and a field which I've
45+
package -- and higher level concepts like a class and a field, which I've
4646
marked with a thicker border.
4747

4848
Here's the corresponding Kotlin program:
@@ -60,7 +60,7 @@
6060

6161
![](images/kotlin-psi.png)
6262

63-
This is for a program which is completely equivalent to the Java one.
63+
This program is equivalent to the Java one.
6464
But notice that it has a completely different shape! They reference
6565
different element classes, `PsiClass` versus `KtClass`, and on and on
6666
all the way down.
@@ -70,7 +70,7 @@
7070

7171
## UAST
7272

73-
We can construct a new AST which represents the same concepts:
73+
We can construct a new AST that represents the same concepts:
7474

7575
![](images/uast-java.png)
7676

@@ -84,15 +84,15 @@
8484
![](images/uast-kotlin.png)
8585

8686
As you can see, the ASTs are not always identical. For Strings, in
87-
Kotlin, we often end up with an extra parent `UiInjectionHost`. But for
87+
Kotlin, we often end up with an extra parent `UInjectionHost`. But for
8888
our purposes, you can see that the ASTs are mostly the same, so if you
8989
handle the Kotlin scenario, you'll handle the Java ones too.
9090

9191
## UAST: The Java View
9292

9393
Note that “Unified” in the name here is a bit misleading. From the name
9494
you may assume that this is some sort of superset of the ASTs across
95-
languages -- and AST that can represent everything needed by all
95+
languages -- an AST that can represent everything needed by all
9696
languages. But that's not the case! Instead, a better way to think of it
9797
is as the **Java view** of the AST.
9898

@@ -106,9 +106,8 @@
106106
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107107

108108
This is a Kotlin data class with two properties. So you might expect
109-
that UAST would have a way to represent these concepts -- properties,
110-
and java classes. This should be a `UDataClass` with two `UProperty`
111-
children, right?
109+
that UAST would have a way to represent these concepts. This should
110+
be a `UDataClass` with two `UProperty` children, right?
112111

113112
But Java doesn't support properties. If you try to access a `Person`
114113
instance from Java, you'll notice that it exposes a number of public
@@ -166,15 +165,15 @@
166165

167166
## UElement
168167

169-
Every node in UAST is a subclass of a UElement. There's a parent
168+
Every node in UAST is a subclass of a `UElement`. There's a parent
170169
pointer, which is handy for navigating around in the AST.
171170

172171
The real skill you need for writing lint checks is understanding the
173172
AST, and then doing pattern matching on it. And a simple trick for this
174173
is to create the Kotlin or Java code you want, in a unit test, and then
175174
in your detector, recursively print out the UAST as a tree.
176175

177-
Or in the debugger, anytime you have a UElement, you can call
176+
Or in the debugger, anytime you have a `UElement`, you can call
178177
`UElement.asRecursiveLogString` on it, evaluate and see what you find.
179178

180179
For example, for the following Kotlin code:
@@ -209,7 +208,7 @@
209208
## Visiting
210209

211210
You generally shouldn't visit a source file on your own. Lint has a
212-
special `UElementHandler` for that which is used to ensure that we don't
211+
special `UElementHandler` for that, which is used to ensure we don't
213212
repeat visiting a source file thousands of times, one per detector.
214213

215214
But when you're doing local analysis, you sometimes need to visit a
@@ -246,19 +245,19 @@
246245

247246
We have our UAST tree in the top right corner. And here's the Java PSI
248247
AST behind the scenes. We can access the underlying PSI node for a
249-
UElement by accessing the sourcePsi element. So when you do need to dip
248+
`UElement` by accessing the `sourcePsi` property. So when you do need to dip
250249
into something language specific, that's trivial to do.
251250

252251
Note that in some cases, these references are null.
253252

254-
Each of the UElement nodes point back into the PSI AST - whether a Java
253+
Most `UElement` nodes point back to the PSI AST - whether a Java
255254
AST or a Kotlin AST. Here's the same AST, but with the **type** of the
256-
`sourcePsi` attribute for each node added.
255+
`sourcePsi` property for each node added.
257256

258257
![](images/uast-sourcepsi-type.png)
259258

260-
You can see that the class generated to represent the top level
261-
functions here doesn't have a non-null `sourcePsi`, because in the
259+
You can see that the facade class generated to contain the top level
260+
functions has a null `sourcePsi`, because in the
262261
Kotlin PSI, there is no real `KtClass` for a facade class. And for the
263262
three members, the private field and the getter and the setter, they all
264263
correspond to the exact same, single `KtProperty` instance, the single
@@ -288,8 +287,8 @@
288287
across the languages. Declarations. Function calls. Super classes.
289288
Assignments. If expressions. Return statements. And on and on.
290289

291-
There *are* lint checks which are language specific -- for example, if
292-
you write a lint check which forbids the use of companion objects -- in
290+
There *are* lint checks that are language specific -- for example, if
291+
you write a lint check that forbids the use of companion objects -- in
293292
that case, there's no big advantage to using UAST over PSI; it's only
294293
ever going to run on Kotlin code. (Note however that lint's APIs and
295294
convenience callbacks are all targeting UAST, so it's easier to write
@@ -308,10 +307,10 @@
308307
language specific, and where the language details aren't exposed in UAST.
309308

310309
For example, let's say you need to determine if a `UClass` is a Kotlin
311-
"companion object. You could cheat and look at the class name to see if
312-
it's ”Companion“. But that's not quite right; in Kotlin you can
310+
companion object. You could cheat and look at the class name to see if
311+
it's “Companion”. But that's not quite right; in Kotlin you can
313312
specify a custom companion object name, and of course users are free
314-
to create classes named ”Companion“ that aren't companion objects:
313+
to create classes named “Companion” that aren't companion objects:
315314

316315
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin
317316
class Test {
@@ -323,8 +322,8 @@
323322
}
324323
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
325324

326-
The right way to do this, is using Kotlin PSI, via the
327-
`UElement.sourcePsi` attribute:
325+
The right way to do this is using Kotlin PSI, via the
326+
`UElement.sourcePsi` property:
328327

329328
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin
330329
// Skip companion objects
@@ -335,7 +334,7 @@
335334
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
336335

337336
(To figure out how to write the above code, use a debugger on a test
338-
case and look at the `UClass.sourcePsi` attribute; you'll discover that
337+
case and look at the `UClass.sourcePsi` property; you'll discover that
339338
it's some subclass of `KtObjectDeclaration`; look up its most general
340339
super interface or class, and then use code completion to discover
341340
available APIs, such as `isCompanion()`.)
@@ -350,7 +349,7 @@
350349
Lint doesn't actually give you access to everything you need if you want
351350
to try to look up types in Kotlin PSI; you need something called the
352351
"binding context”, which is not exposed anywhere! And this omission is
353-
deliberate, because that was an implementation detail of the old
352+
deliberate, because this is an implementation detail of the old
354353
compiler. The future is K2; a complete rewrite of the compiler front
355354
end, which is no longer using the old binding context. And as part of
356355
the tooling support for K2, there's a new API called the “Kotlin
@@ -398,7 +397,7 @@
398397

399398
Before the Kotlin lint analysis API, lint didn't have a way to reason
400399
about the `Nothing` type. UAST only returns Java types, which maps to
401-
void. So instead, lint had an ugly hack which just hardcoded well known
400+
void. So instead, lint had an ugly hack that just hardcoded well known
402401
names of methods that don't return:
403402

404403
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin
@@ -441,7 +440,7 @@
441440
Here, we have a `KtCallExpression`, and inside the `analyze` block we
442441
can call `resolveCall()` on it to reach the called method's symbol.
443442

444-
Similarly on a `KtDeclaration` (such as a named function or property) I
443+
Similarly, on a `KtDeclaration` (such as a named function or property) I
445444
can call `getSymbol()` to get the symbol for that method or property, to
446445
for example look up parameter information. And on a `KtExpression` (such
447446
as an if statement) I can call `getKtType()` to get the Kotlin type.
@@ -452,7 +451,7 @@
452451
so on.
453452

454453
In the new implementation of `callNeverReturns`, we resolve the call,
455-
look up the corresponding function which of course is a `KtSymbol`
454+
look up the corresponding function, which of course is a `KtSymbol`
456455
itself, and from that we get the return type, and then we can just check
457456
if it's the `Nothing` type.
458457

0 commit comments

Comments
 (0)