aboutsummaryrefslogtreecommitdiffstats
path: root/lint/libs/lint_api/src/com
Commit message (Collapse)AuthorAgeFilesLines
...
* Minor lint tweaksTor Norbye2011-11-101-2/+3
| | | | | | | | | | | | | | | | | First, replace tabs with spaces in the quoted error lines in the command line output, since otherwise the column marker (^) which is space based may not line up with the part of the line it is supposed to point to. Second, make the code which looks up the project corresponding to a selection able to find a project when you click on something *in* a project, such as a Java file within a Java project. Third, don't print "skipping file because it contains parser errors" in the CLI output; there's no need to since the parser themselves report parsing errors now. Change-Id: I57fd8a783c422a287cf9529caa1f858d7cff52d1
* Fix path-to-file conversion methodTor Norbye2011-11-101-0/+4
| | | | | | | | | | | | | Looking up the File object for an IFile did not work when projects were located outside of the workspace (e.g. "import existing project" without "copy into workspace"). This made the Run Lint action not work on these types of projects. Also fix a related problem where the HTML reporter should produce absolute paths when creating image links, and don't inline 9-patch images. Change-Id: I3eb8879cf394a17330f54c6e77032e033459de5b
* Fix bugs in unused resource detectorTor Norbye2011-11-091-0/+17
| | | | | | | | | | | | | | | | | | | | First, look at the text node children of <style> tags to pick up references to resources, such as @dimen/foo or ?attr/bar. Second, look at the XML files for declarations of resources; these provide the actual location of the unused resource (which is stored in a map for the error reporter), as well as makes the lint work on source trees that do not have a built gen/ folder. Third, make the detector use the project-provided source paths rather than being hardcoded to src/ and gen/. Fourth, ignore R.style unused warnings since these can be false positives and will require some more analysis. Move some constants from checks into the LintConstants class. Change-Id: Iee062fd7f6452d90716004ef0beb1f869fb57df4
* Add nodpi checkTor Norbye2011-11-081-0/+26
| | | | | | | | | | | Adds a new icon check which makes sure that any icons which appear in a -nodpi folder do not also appear in a density folder such as -mdpi. This changeset also pulls the "missing density folder" out as a separate issue from the "missing icon" issue where it warns about icons that are present in some but not all density folders. Change-Id: I0198613487100e2a9421b69eb55de690d8a814fd
* Add duplicate icon detectorTor Norbye2011-11-081-0/+33
| | | | | | | | | | | | | | | | | This changeset adds a detector which finds two types of icon duplication: - Unrelated drawable resources which have the exact same bitmap. This could mean that the wrong icon was checked in, or that you could potentially consolidate to using a single resource. - Resources which have the same bitmap for multiple different configurations, such as the same icon in both -mdpi and in -hdpi. Unlike the various dip size checking methods, this also works for nine patch files. Change-Id: Ibe2d0900cecb66c2589400f24c2af9a76ad8dabe
* Add lint check for accidental omission of android: prefixTor Norbye2011-11-082-0/+43
| | | | | | | | | | | | | | | | | | This changeset adds a new detector which finds cases where you are attempting to reference a view attribute in a layout on one of the android views, but you forgot to add the android: prefix. For example, you might attempt to set the "orientation" attribute on a LinearLayout, which aapt will not complain about since it will interpret it as a custom attribute on the target view. There is also an Eclipse quickfix for this suggestion (as well as a quickfix for the ScrollViewChildDetector). This changeset also modifies the HTML report to bundle up associated image resources in a local resource directory, and fixes a bug in the category sort. Change-Id: I984d1d575c0f9ec36fc450abf68ba75328cebf80
* New lint icon detectorTor Norbye2011-11-071-0/+14
| | | | | | | | | | | | | | | | | | | | This changeset adds a new image detector which looks for various issues related to icons: (1) Are there bitmap icons in the densityless res/drawable/ folder? (2) Do the icons appear in all the density folders (except, optionally, ldpi) (3) Are the launcher/notification/etc icons of the expected size? (For example a launcher icon should be 48x48 in mdpi). This issue is disabled by default. (4) Do the various bitmaps roughly have the same density-adjusted sizes across all the densities for the same configuration parameters? This will catch cases where assets are placed in the wrong place. (5) It warns about using .gif files since that format is supported but discouraged. Change-Id: Ibe0f97cba7cada5ac0deee244310a38dbc721873
* Lint Architecture Changes: Configurations, Categories, etc.Tor Norbye2011-11-0718-500/+1528
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changeset makes various architectural changes to lint: (1) Add configurations, which are basically user preferences for lint in a given project, such as providing a custom severity for an issue, or disabling a specific warning in a specific file. In Eclipse, there is a project configuration (stored in lint.xml in each project), as well as a global configuration (stored using Eclipse preference data). Project configurations inherit from the global configuration. The options dialog now shows up both as a project property page (showing the issue state for the project configuration), as well as a normal preference page (showing the global or "fallback" configuraiton). I also changed the Options UI for issues from a Table to a TreeViewer to add in category nodes, and changed the checkbox UI to have a custom severity toggle instead. The lint quickfixes also now have 3 suppression options: * Ignore in this file * Ignore in this project * Disable check (2) Change detectors to be registered by class and instantiated for each lint run rather than having a fixed list of detectors get reused over and over. Turns out that since some detectors store state, this prevented lints from running concurrently since the two runs could stomp each other's state. To do this effectively I've also switched from a DetectorRegistry to an IssueRegistry, which contains the global list of available issues and each issue can point to the class detecting the issue (and these are created on the fly based on parameters like scope.) (3) Explicit Categories. Categories used to just be a string property on issues; now it's an explicit class with both a name and an explanation, with parents to allow nesting (such that for example the Usability category has an Icons sub category), and finally the category class provides sorting. Categories also show up in the HTML Report now as separate sections. (4) Other API changes: * I changed the package containing APIs for lint clients to an explicit "client" package * Moved the LintConstants class up from lint-checks to lint-api and added a LintUtils class which contains many generic methods that were spread around in specific detectors. * The detectors are now talking to a wrapper client rather than directly to lint clients, such that the wrapper client can filter out results on disabled checks etc, which means that tools can assume they always get correct reports and don't have to worry about improperly written detectors. * I renamed ToolContext to LintClient. * I got rid of the "isEnabled" state, which was a bit redundant with the severity since severity has a Severity.IGNORE value. * I added a LintListener interface, which notifies about progress (and the CLI tool will print "."'s for each processed file unless suppressed with -q). * A new dispose method on the parser interface to for example allow IDEs to lock/unlock read models on underlying data. (5) I added a toolbar action for running Lint on the currently selected project. I also added an --xml export option intended for use with CI plugins. Change-Id: Icadd9b2d14d075234d97b31398806111af747b7b
* Lint infrastructure fixesTor Norbye2011-11-029-194/+663
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changeset makes a number of infrastructure fixes to lint. It also has some user visible aspects: (1) The "run lint on export" option, which aborts Export APK if fatal errors are found, now only checks for fatal issues, which should be significantly faster (since it skips expensive detectors like the unused resource detector). (2) The command line lint tool lets you specify not just issue ids, but categories to enable or disable as well. In addition to the --enable and --disable flags to add or remove checks, there is also a --check flag which runs the exact specified checks. Thus you can for example run "lint --check Security" to run the security related lint checks. When using --show to display the available id's, they are organized and described under category labels. I also cleaned up the categories a bit; "Layout" isn't a category anymore, and instead the layoutopt options are placed in other categories like "Performance" or "Usability". (3) From the command line you can now also specify multiple projects or even search a directory for projects contained recursively within it. This required a bunch of infrastructure changes to handle partitioning up the arguments into related projects (since checks have before-project and after-project hooks that need to run properly). (4) On the infrastructure side the "scope" concept was changed to become a scope set, and a detector can declare that an issue requires analysis of any of {manifest, resource file, java source file, resource folder, ...} etc. When lint runs it determines which detectors are applicable (for example, for a single-file lint run it will ignore detectors which require a wider scope). And when applicable, a detector will be called for all the various scopes it requires. Therefore, the unused resource detector, which used to have to manually scan the manifest file on its own, now automatically gets called as part of the manifest file parse, the resource file parses, and the java file scan. Single-file linting is still only supported for XML files. Change-Id: I49a5e2b27f8f6da22904085089aa0c4d2eee67f6
* Turn on lint-on-save for all XML types, and move some codeTor Norbye2011-11-012-137/+59
| | | | | | | | | | | | Turn on lint-on-save for all XML editor types since there are per-file rules for other file types than layouts now (such as manifest files and drawable files). Move some methods up from ResourceXmlDetector such that XML detectors that aren't resource detectors (such as manifest detectors) can access them. Also move some constants around. Change-Id: Iba8972142ffd8c8da43249f9d302f69ce7fe7add
* Add Lint HTML reporting, and fix position information in parserTor Norbye2011-10-281-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changeset adds a HTML report option for the lint command line driver, and cleans up the code a bit. It also fixes the feature where the line containing the error is shown along with each error, and turns it on by default. This was previously turned off because the position information for XML nodes was fairly inaccurate (no column information, and the element offset was the end of the opening tag rather than the beginning). With the HTML report, where not just the error line but the window of code around the error is shown, having accurate offset information even in the CLI driver was important. Therefore, this changeset also rewrites the PositionXmlParser. The old approach used XML transformers; now we instead use a SAX parser to incrementally build up the DOM, and marking node offsets as we go along. SAX still only gives element-end offsets, line+column instead of offsets, and no information for individual attributes, so the builder also scans the source in order to build up accurate information. Results are now accumulated during the error reporting phase, then sorted in priority, category and finally file+line number order before being shown as HTML or text. Finally, the code to escape code to attribute values was missing that < is an invalid attribute character, so this CL fixes that issue as well. Also fix some incorrect copyrights. Change-Id: I652a1545b92865a88ecb4e6526616ba4cd75b512
* Two new lint warnings: array-size check, and manifest orderTor Norbye2011-10-266-173/+250
| | | | | | | | | | | | | | | | | | | | | This changeset adds two warnings: (1) A new lint warning which checks the sizes (number of items) in arrays of the same name across the various resource files and warns if the number of items differ. (2) A new "manifest order" detector which looks for element ordering problems in manifest files, such as placing <uses-sdk> after the <application> element. It also cleans up the way XML detectors were handled such that a detector can be an XML detector without being a resource detector (such as the manifest detector for example). Finally it also moves classpath initialization into the tool context where it belongs. Change-Id: I02fee56bfdbe1064874acf70f18db79897d8a908
* Lint: Unused resource detector, and framework improvementsTor Norbye2011-10-257-59/+306
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changeset contains a number of changes to the lint support: (1) Preparation to support Java (.java source and .class binary checks). The lint-api and lint-checks libraries do not yet contain any APIs for visiting Java ASTs or visiting bytecodes, but there is preliminary support such as interfaces Java and Class detectors can implement, and they are provided with the source paths and output paths. (2) Various other framework API changes such as making ToolContext an abstract class (to easy future API additions), moving file reading to the tool context, making the Xml/Java/Class detectors marker interfaces instead of abstract classes such that a detector can have more than one behavior. And the error reporter now passes a data field along with each issue containing data intended for use by tools to for example make a quickfix able to identify target data without having to parse the error message or infer it from the error range. (3) A new "unused resource" detector which identifies unused resources (strings, ids, layouts, etc) in a project. The default lint-checks implementation performs only simple string analysis, but in the Eclipse plugin this is replaced by a specialized detector which uses the Eclipse Java model to do more accurate AST-based analysis. This is a technique lint should support anyway (the ability of a tool to provide optimized versions of the builtin checks) but longer term once we get actual Java AST support into the API this might move. Various misc smaller fixes I ran into along the way and changes to the test infrastructure. Change-Id: Ic5aab0180b53de70f1fd36540c854abb8210e751
* Lint improvementsTor Norbye2011-10-257-41/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | First, in the translation detector, split out the report into two separate issues: - Failing to provide a translation for a string defined by the default locale (Error) - Unused translations (strings found in languages but no longer in the default locale) (Warning) Also add region handling such that a region can define just a subset of the available strings and fall back to the overall language for strings it does not define. Second, the Quickfix in Eclipse for the px to dp conversion now shows a dedicated dialog which has a combobox for the available densities rather than asking the user to type in the density number in a text field. Third, the CLI driver (the "lint" command line tool) has a bunch of new flags for controlling the report format as well as for dumping out information about available issues: Usage: lint [flags] <project directories> Flags: --suppress <id-list>: Suppress a list of issue id's. --enable <id-list>: Only check the specific list of issues --fullpath : Use full paths in the error output --lines : Include the lines with errors in the output --list: List the available issue id's and exit. --show: List available issues along with full explanations --show <ids>: Show full explanations for the given list of issue id's Id lists should be comma separated with no spaces. Here's an example of what an issue explanation looks like: % lint --show DuplicateIds DuplicateIds ------------ Summary: Checks for duplicate ids within a single layout or within an include hierarchy Priority: 7 / 10 Severity: Warning Category: Layout It's okay for two independent layouts to use the same ids. However, within a single layout (including the case where two separate layouts are fused together with an include tag) the ids should be unique such that theActivity#findViewById() method can work predictably. --- The layout editor now runs lint on every edit operation instead of on every save. And finally the scope has been moved from Detectors to Issues such that when looking at issue markers we can clear those associated with the scope the analysis is run under. We also run the detectors when any of the associated issues is eligible. Change-Id: I3f068de4edeb3ed166eeb7ab7f2cff84d7ae5cbd
* More lint checks: translation, i18n, proguard, gridlayout, "px"Tor Norbye2011-10-204-9/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changeset adds more lint checks: (1) Translation. It looks at all the string values in the application, and if there are discrepancies (where a translatable string is not defined in all provided languages and regions) then these are listed. (2) Internationalization. It looks for text: and contentDescription: attributes and ensures that these refer to @string resources, not hardcoded string values. This lint warning also has an associated quickfix when shown in Eclipse which invokes the Extract String refactoring wizard on the right selection context. (3) Proguard. It looks for the old (broken) patterns we had in older proguard.cfg files (-keepclasseswithmembernames instead of -keepclasseswithmembers which implies shrinking.) (4) GridLayout. It looks at the layout constraints provided on views in a GridLayout and ensures that they fall within the overall dimensions of the grid. (5) "px" usage. It looks for dimensions using "px" as a unit and recommends switching to dp instead. This lint warning also has a quickfix in Eclipse which pops up a dialog asking for the screen density and then converts the px value to the right dp value and changes the unit. (6) TextFields. It looks at EditTexts and makes sure they either set inputType, hint or inputMethod. There's a quickfix in Eclipse for setting the inputType, which adds the property and automatically invokes content assist for showing the possible values. This changeset also adds some quick fixes for a few existing lint warnings: (7) Accessibility: Insert a content description attribute, front the editor and select the placeholder value. (8) Useless leaf layout: Remove the leaf layout (9) Useless middle layout: Invoke the Remove Container visual refactoring 10) Inefficient Linear Layout Weights: Change the attribute to 0dp Plus unit tests. Change-Id: Iebd7b23224a898bd1851abd578460019aee44df5
* Static analyzerTor Norbye2011-10-2015-0/+1735
This changeset adds a static analyzer, "lint", which looks for various potential bugs in Android projects. It has 3 parts: (1) A library which performs the actual static checks. This library is standalone: it does not depend on Eclipse. (Technically the library has two halves: an API half, for use by third party developers to write additional detectors, and an actual implementation of a bunch of built-in checks.) (2) A command line driver, "lint", which runs the static checks and emits any warnings to standard out. This can be thought of as a replacement for the layoutopt tool. (3) Eclipse integration. Lint errors are added to the Problems view as well as shown as editor annotations. There's an options panel for controlling which detectors are enabled. There's also a quickfix for disabling errors directly within the editor and a marker resolution for disabling them via the Problems view. The static checks are run on an XML file right after it has been saved. (This is optional via a toggle on the same preference page as the detector list.) The static checks are also run when you export an APK, and if any fatal errors are found the export is abandoned. (This is also optional via an option). Finally you can run a full lint through the Android Tools menu, and there's also an action to clear all the lint markers there. There's also a new indicator on the layout editor which shows whether there are lint errors on the associated file, and when clicked brings up a dialog listing the specific errors. This changeset also includes a number of checks: * An accessibility detector which warns about images missing contentDescriptions * A drawable selector detector which warns about state lists where not all states are reachable (e.g. it is not the case that only the last item in the list omits a state qualifier) * A detector finding duplicate ids, not just in the current layout but across included layouts (transitively) as well * All the layoutopt ones ported to Java + DOM * Unit tests for the above. The focus here is on getting the infrastructure in place, and it currently focuses on XML resource files and analyzing them efficiently. See the comment in XmlVisitor for details on that. Change-Id: Ic5f5f37d92bfb96ff901b959aaac24db33552ff7