Skip to content

Commit d2aa658

Browse files
authored
Merge pull request #39 from tnorbye/update-docs
Update lint documentation snapshot
2 parents 6b10430 + b106798 commit d2aa658

20 files changed

+6040
-4412
lines changed

docs/README.md.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
* [Lint Features](features.md.html)
1616
* [Recent Changes](changes.md.html)
1717
* Documents for users of lint, in the `usage` folder:
18+
- [Complete Book](user-guide.md.html), containing all of the below
19+
documents as chapters, suitable for offline reading
20+
- [Performance Tuning Tips](usage/performance-tuning.md.html)
1821
- [How to suppress incidents](usage/suppressing.md.html)
1922
- [How to use baselines](usage/baselines.md.html)
2023
- [How to use `lint.xml` files](usage/lintxml.md.html)
2124
- [Environment variables and properties](usage/variables.md.html)
2225
* Documents for authors of additional lint checks, in the
2326
`api-guide` folder:
24-
- [Complete Book](book.md.html), containing all of the below
27+
- [Complete Book](api-guide.md.html), containing all of the below
2528
documents as chapters, suitable for offline reading
2629
- [Basics](api-guide/basics.md.html)
2730
- [A Sample Lint Check](api-guide/example.md.html)

docs/api-guide.html

Lines changed: 4519 additions & 0 deletions
Large diffs are not rendered by default.

docs/api-guide.md.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<meta charset="utf-8" lang="kotlin">
2+
3+
**Android Lint API Guide**
4+
5+
This chapter inlines all the API documentation into a single
6+
long book, suitable for printing or reading on a tablet.
7+
8+
(insert api-guide/terminology.md.html here)
9+
(insert api-guide/basics.md.html here)
10+
(insert api-guide/example.md.html here)
11+
(insert api-guide/publishing.md.html here)
12+
(insert api-guide/unit-testing.md.html here)
13+
(insert api-guide/quickfixes.md.html here)
14+
(insert api-guide/partial-analysis.md.html here)
15+
(insert api-guide/faq.md.html here)
16+
17+
# Appendix: Recent Changes
18+
(insert api-guide/changes.md.html here)
19+
(insert usage/variables.md.html here)
20+
21+
<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>

docs/api-guide/basics.md.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,13 @@
10611061
it, unless you want to look at individual details like specific
10621062
whitespace between AST nodes, which is represented in PSI but not UAST.
10631063

1064+
!!! Tip
1065+
You can find additional documentation from JetBrains for both
1066+
[PSI](https://plugins.jetbrains.com/docs/intellij/psi.html) and
1067+
[UAST](https://plugins.jetbrains.com/docs/intellij/uast.html).
1068+
Just note that their documentation is aimed at IDE plugin developers
1069+
rather than lint developers.
1070+
10641071
## Testing
10651072

10661073
Writing unit tests for the lint check is important, and this is covered

docs/api-guide/changes.md.html

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
This chapter lists recent changes to lint that affect lint check
44
authors: new features, API and behavior changes, and so on. For
5-
information about user visible changes to lint, see
6-
[](../usage/changes.md.html).
5+
information about user visible changes to lint, see the User
6+
Guide.
77

88
**7.0**
99

@@ -12,10 +12,10 @@
1212
* Partial analysis. Lint's architecture has changed to support better
1313
scalability across large projects, where module results can be
1414
cached, etc. See the api-guide's dedicated chapter for more details.
15-
To opt in before it's turned on by default to test this on your full
16-
Gradle projects rather than just the detector tests, add
15+
It is enabled by default starting in AGP 7.0.0-alpha13, but you can
16+
disable it by adding
1717

18-
`android.experimental.useLintPartialAnalysis=true`
18+
`android.enableParallelLint=false`
1919

2020
to your `gradle.properties` file. If you want to debug your lint check
2121
you may want to also set
@@ -72,4 +72,27 @@
7272

7373
* API documentation is now available.
7474

75+
* Certain Kotlin PSI elements have new implementations known as
76+
_ultra light classes_. Ultra light classes improve performance
77+
by answering PSI queries "directly from source" rather than
78+
delegating to the Kotlin compiler backend. You may see ultra
79+
light classes when accessing the `UElement.javaPsi` property of a
80+
Kotlin UAST element. They can also appear when resolving references.
81+
For example, resolving a Kotlin field reference to its declaration
82+
may result in an instance of `KtUltraLightFieldForSourceDeclaration`.
83+
As a reminder, Kotlin light classes represent the "Java view" of an
84+
underlying Kotlin PSI element. To access the underlying Kotlin PSI
85+
element you should use `UElement.sourcePsi` (preferred)
86+
or otherwise the extension property `PsiElement.unwrapped` (declared
87+
in `org.jetbrains.kotlin.asJava`).
88+
89+
* There is a new bug where calling `getNameIdentifier()` on Kotlin
90+
fields may return `null`
91+
([KT-45629](https://youtrack.jetbrains.com/issue/KT-45629)).
92+
As a workaround you can use `JavaContext.findNameElement()` instead.
93+
94+
* Kotlin references to Java methods now trigger both the
95+
`visitMethodCall()` callback _and_ the `visitReference()` callback.
96+
Previously only `visitMethodCall()` was triggered.
97+
7598
<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>

docs/api-guide/example.md.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers
7272
buildscript {
7373
ext {
74-
kotlinVersion = '1.4.31'
74+
kotlinVersion = '1.4.32'
7575

7676
// Current lint target: Studio 4.2 / AGP 7
7777
//gradlePluginVersion = '4.2.0-beta06'

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
* 4% were updated to report incidents with data for later filtering
113113
* 1% were updated to perform map recording and later reduce filtering
114114

115-
## Does my Detector Need Work?
115+
## Does My Detector Need Work?
116116

117117
At this point you're probably wondering whether your checks are in the
118118
89% category where you don't need to do anything, or in the remaining
@@ -494,7 +494,7 @@
494494
you cannot just create incidents and filter or customize them later.
495495

496496
The most complicated example of this is lint's built-in
497-
UnusedResourceDetector, which locates unused resources. This “requires”
497+
[UnusedResourceDetector](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-master-dev:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/UnusedResourceDetector.java), which locates unused resources. This “requires”
498498
global analysis, since we want to include all resources in the entire
499499
project. We also cannot just store lists of “resources declared” and
500500
"resources referenced“ since we really want to treat this as a graph.

docs/api-guide/publishing.md.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,34 @@
111111
clean builds. There are some bugs in the Android Gradle Plugin issue
112112
tracker for this.
113113

114+
### Unpublishing
115+
116+
If you end up “deleting” a lint check, perhaps because the original
117+
conditions for the lint check are not true, don't just stop
118+
distributing lint checks with your library. Instead, you'll want to
119+
update your `IssueRegistry` to override the `deletedIssues` property to
120+
return your deleted issue id or ids:
121+
122+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123+
/**
124+
* The issue id's from any issues that have been deleted from this
125+
* registry. This is here such that when an issue no longer applies
126+
* and is no longer registered, any existing mentions of the issue
127+
* id in baselines, lint.xml files etc are gracefully handled.
128+
*/
129+
open val deletedIssues: List<String> = emptyList()
130+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131+
132+
The reason you'll want to do this is listed right there in the doc: If
133+
you don't do this, and if users have for example listed your issue id
134+
in their `build.gradle` file or in `lint.xml` to say change the
135+
severity, then lint will report an error that it's an unknown id. This
136+
is done to catch issue id typos. And if the user has a baseline file
137+
listing incidents from your check, then if your issue id is not
138+
registered as deleted, lint will think this is an issue that has been
139+
"fixed“ since it's no longer reported, and lint will issue an
140+
informational message that the baseline contains issues no longer
141+
reported (which is done such that users can update their baseline
142+
files, to ensure that the fixed issues aren't reintroduced again.)
143+
114144
<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>

docs/api-guide/terminology.md.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@
8282
apply (such as “Android”, or “Server”, and so on). This means that an
8383
Android-specific check won't trigger warnings on non-Android code.
8484

85+
Scanner
86+
: A `Scanner` is a particular interface a detector can implement to
87+
indicate that it supports a specific set of callbacks. For example,
88+
the `XmlScanner` interface is where the methods for visiting XML
89+
elements and attributes are defined, and the `ClassScanner` is where
90+
the ASM bytecode handling methods are defined, and so on.
91+
8592
Scope
8693
: `Scope` is an enum which lists various types of files that a detector
8794
may want to analyze.

docs/api-guide/unit-testing.md.html

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,23 +236,23 @@
236236

237237
## Library Dependencies and Stubs
238238

239-
Let's say you're writing a lint check for something like the
240-
AndroidX library's `RecyclerView` widget.
239+
Let's say you're writing a lint check for something like the Android
240+
Jetpack library's `RecyclerView` widget.
241241

242242
In this case, it's highly likely that your unit test will reference
243243
`RecyclerView`. But how does lint know what `RecyclerView` is? If it
244244
doesn't, type resolve won't work, and as a result the detector won't.
245245

246-
You could make your test ”depend“ on the recyclerview. This is
246+
You could make your test ”depend“ on the `RecyclerView`. This is
247247
possible, using the `LibraryReferenceTestFile`, but is not recommended.
248248

249249
Instead, the recommended approach is to just use ”stubs“; create
250250
skeleton classes which represent only the **signatures** of the
251-
library, and in particular, only the subset that your lint check
252-
cares about.
251+
library, and in particular, only the subset that your lint check cares
252+
about.
253253

254-
For example, for lint's own recycler view test, the unit test
255-
declares a field holding the recycler view stub:
254+
For example, for lint's own `RecyclerView` test, the unit test declares
255+
a field holding the recycler view stub:
256256

257257
```
258258
private val recyclerViewStub = java(
@@ -349,4 +349,16 @@
349349
project it will only provide the binaries, not the sources, for
350350
upstream modules.)
351351

352+
## My Detector Isn't Invoked From a Test!
353+
354+
One common question we hear is
355+
356+
> My Detector works fine when I run it in the IDE or from Gradle, but
357+
> from my unit test, my detector is never called! Why?
358+
359+
This is almost always because the test sources are referring to some
360+
library or dependency which isn't on the class path. See the ”Library
361+
Dependencies and Stubs“ section above, as well as the [frequently asked
362+
questions](faq.md.html).
363+
352364
<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>

0 commit comments

Comments
 (0)