The Code Menu
Android Studio 2: The New UI
Course 2 ยท Chapter 9 ยท Inspect, Analyze and Refactor
The IDE can check your code without running it (inspections and lint), tidy it in bulk (Code Cleanup) and restructure it safely (refactoring). Older guides send you to an Analyze menu for the first group. On Rabbit 2 that menu is gone, and the commands live in the Code menu. This chapter shows where everything went.
Where the Analyze Menu Went
The main menu (Chapter 1) has: File, Edit, View, Navigate, Code, Refactor, Build, Run, Tools, VCS (or Git), Window, Help. There is no Analyze. The Code menu now contains (checked on the install):
| Code menu entry | What it is for |
|---|---|
| Inspect Code | (docs) Manually runs the configured lint and other IDE inspections; results appear in the Inspection Results window. |
| Inspect for Play Policy Insights | Checks the project against Google Play policy (general knowledge from the name; not checked). |
| Code Cleanup | (docs, from JetBrains' IntelliJ documentation, which Android Studio is built on) Applies quick-fixes in bulk to a chosen scope without asking about each problem. |
| Analyze Code > | A submenu of further analysis tools (I did not open it). |
| Analyze Stack Trace or Thread Dump | Paste a crash's stack trace and get clickable links into your source (general knowledge). |
Android Studio's lint page names the path as Code > Inspect Code; an older Android page still says Analyze > Inspect Code (docs). Same command, older location. The Code menu also holds the editing commands you use daily (reformat, optimise imports and so on, general knowledge).
Lint and the Problems Window
Lint is Android's static checker: it finds likely bugs, missing translations, accessibility and performance problems. Inspect Code runs it together with the IDE's own inspections. Issues also appear as you type (underlines in the editor) and in the Problems tool window, Alt+6 (checked on the install). Use Inspect Code when you want the whole project checked at once rather than the open file.
(general knowledge: the Gradle task name is standard, but I have not run it on this install; on Windows use gradlew lint.)
The Refactor Menu
Refactoring has its own top-level menu now. (general knowledge, the menu's contents were not captured) The ones to learn first: Rename (changes every use of a name, Shift+F6), Extract (turn selected code into a function, variable or constant) and Safe Delete (delete only if nothing uses it). They check the whole project, which is why they beat find-and-replace.
Try It Yourself
Open the Code menu and write down every entry. Check there is no Analyze menu. Open the Analyze Code submenu and list what it contains.
๐ View solutionAdd an unused variable and a hard-coded string to a Kotlin file, then run Code > Inspect Code on the whole project. Find your two problems in the results and say how the results are grouped.
๐ View solutionRename a function with Refactor > Rename and check that every call changed. Then copy a stack trace (invent one if needed) and try Analyze Stack Trace or Thread Dump. Report what each did.
๐ View solutionChecked in the docs (one web search, summaries only): Code > Inspect Code and the Inspection Results window; the older Analyze > Inspect Code path; Code Cleanup as described for IntelliJ and Rider (not Android Studio's own page).
Not verified: the Analyze Code submenu; what Play Policy Insights and Analyze Stack Trace actually do; the Refactor menu's contents and shortcuts; the
gradlew lint command; the exercises (not run by me).
A screenshot of the Analyze Code submenu and the Refactor menu would verify this chapter.Sources: Improve your code with lint checks (developer.android.com), Run inspections (jetbrains.com).