aboutsummaryrefslogtreecommitdiffstats
path: root/lint
Commit message (Collapse)AuthorAgeFilesLines
...
* | Merge "New lint rule for invalid @+id references"Tor Norbye2011-12-1310-2/+532
|\ \
| * | New lint rule for invalid @+id referencesTor Norbye2011-12-1310-2/+532
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changeset adds a new layout rule which finds cases where you have RelativeLayout attributes pointing to id names that do not exist, such as layout_alignLeft="@+id/navbar" The +id/ syntax here creates the id on the fly, so aapt does not complain, but the new lint rule makes sure that at least one layout actually defines this id as its id. If no match is found, it looks for spelling mistakes and suggests other similar ids in the error message. This condition is flagged as an error. The detector also issues a related warning if it finds an id reference that is not defined in the same layout. This is sometimes okay (where you have deliberately referred to an element which will be included into this layout, or is in a layout including this one), but it's usually an accident. Change-Id: I7f3fa6f4cb5cef6dcd307256050fb9580887addd
* | | Fix unused resource detector for R.attr resourcesTor Norbye2011-12-135-1/+46
| |/ |/| | | | | | | | | | | | | When you use R.attr attributes from layouts as custom attributes, these need to be recorded as references such that the attrs are not considered unused. Change-Id: I15755cce084dbc71557066167b954ba3df395e55
* | Fix unused resource check to handle @string references in arraysTor Norbye2011-12-133-2/+23
|/ | | | | | This fixes 22850: lint incorrectly reports resources as unused. Change-Id: I4dc2e82319fcda8c59754911a67f871d5aa00fbc
* A few misc lint fixesTor Norbye2011-12-0919-81/+169
| | | | Change-Id: Idc81f7a2d033675a03209eeabda0216babc35ebe
* Add the Guava library to the toolsTor Norbye2011-12-0537-138/+144
| | | | | | | | | | | | This changeset adds the Guava library to ADT and lint. (It is also a prerequisite for the Lombok AST library which is added by a later CL.) This changeset also uses the library in a few simple ways: It replaces some custom I/O and collections code with calls into the equivalent Guava methods, and it also adds the @Beta annotation on the various "API" classes which are not yet stable. Change-Id: I2f50febfa075c32818404e888578a2e1e447d408
* Add Java Classfile supportTor Norbye2011-12-0521-12/+875
| | | | Change-Id: Ifcc1d88dabb07dc05b2e5c934743ad52f9b6dc1d
* Lint infrastructure improvementsTor Norbye2011-12-0562-606/+1546
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changeset fixes a bunch of issues in the infrastructure: (1) It cleans up the Context class quite a bit. It had some hardcoded XML stuff in it, which is now in a separate XmlContext class (and there will be a JavaContext class in the Java support CL). It also hides a bunch of public fields, cleans up some unused stuff, and introduces a couple of wrapper methods to make detector code cleaner; in particular, rather than calling context.client.report(context, ... you can now just call context.report(... and similarly there are wrappers for logging and checking for disabled issues. (2) The IParser interface is renamed to IDomParser since in the next CL there will also be an IJavaParser. Some other related cleanup. (3) There is now a "Location.Handle" interface. This allows detectors to create light-weight location holders, and later on call handle.resolve() to create a full-fledged Location. This is useful when detectors don't yet know whether they'll need a location for a node, but want to store it for later in case they do. As an example, the unused resource detector creates location handles for declaration and only resolves full locations for those that are found to be unused. Locations can now carry custom messages. For example, for a duplicate id error, the secondary location now contains a "original declaration here" message. And the CLI and HTML reports now include alternate locations in the output. Some other location cleanup too; using factory methods to make the code cleaner, some default implementations that can be shared, etc. (4) There's a new SDK info class intended to provide SDK information from a tool client (such as resource resolution). It currently just contains parent-view information, used for the ObsoleteLayoutParams detector and an upcoming CL for a ViewTypeDetector. (5) The Detector class now provides dummy implementations for the inner-interfaces, so we no longer need the adapter classes. This makes it easy to implement the XmlScanner or JavaScanner interfaces without needing to also stub out a bunch of methods. Change-Id: I4b3aaabe51febb25b000f9086703653bea6cf7c9
* Add flags to lint cli to turn off warnings, and turn on allTor Norbye2011-11-292-36/+118
| | | | | | | | | | | | Add gcc-style flags -w, -Wall and -Werror, and javac-style --nowarn (identical to -w) to turn off warnings (only check for errors), enable all warnings, and to turn all warnings into errors respectively. Also cleans up the print-usage code a little bit such that the format is nicer: the arguments all appear on the left and the explanations are all aligned on the right. Change-Id: I247f9e81ebe5322c7b19af2f043c7a82133c18a1
* Merge "Don't flag selector states with custom attributes as unreachable"Xavier Ducrohet2011-11-283-0/+25
|\
| * Don't flag selector states with custom attributes as unreachableTor Norbye2011-11-283-0/+25
| | | | | | | | | | | | Fix issue http://code.google.com/p/android/issues/detail?id=22339 Change-Id: Ic05b3623472b9642cddec35153348472448a277a
* | Special-case the drawable-nodpi folder in lint icon folder checksTor Norbye2011-11-282-8/+31
|/ | | | | | | | | | | The lint rule which makes sure that any icon provided in drawable-mdpi is also provided in drawable-hdpi (etc), needs to make a special case for the nodpi folder: icons defined there do not have to be defined in other density folders, and similarly icons provided in other density folders do not need to be provided in the nodpi folder. Change-Id: I799dd98a65b46f52ec28661f8376bd4367a8ce74 http://code.google.com/p/android/issues/detail?id=22337
* Fix string arrays incorrectly flagged as not localizedTor Norbye2011-11-285-0/+65
| | | | | | | | | | If you define the children of your <string-array> using @string resource references, then you don't need to redefine your <string-array> in all the other locales. This changeset fixes the lint translation check such that it only looks for translations for string arrays that have one or more elements that are not a string reference. Change-Id: I8daf0b36edad43635f47062b3fdf57b2617233ce
* Fix a few lint bugs reported by early access usersTor Norbye2011-11-2510-36/+82
| | | | Change-Id: I3f7d64737bdb1205dd147c9e071d56d33fb072c5
* Add security detector for oversharing content providersTor Norbye2011-11-235-10/+100
| | | | | | | | | | | Look for content providers which use a grant-uri-permission element and share everything ( / ). Also renames the ExportedServiceDetector to SecurityDetector since a single manifest scanner is used for both (and potentially more in the future.) Change-Id: I1e4ac0409c524e2655f8a389fa18162a94388b29
* Add overdraw detectorTor Norbye2011-11-2332-20/+967
| | | | | | | | This detector looks for potential overdraw scenarios where a root view specifies a background drawable, and the theme used for the corresponding activity also draws a background. Change-Id: I64f732740ec25f8af6333c2c38ac41da4c1f71b0
* Merge "Add lint support for fallback configurations"Tor Norbye2011-11-233-6/+50
|\
| * Add lint support for fallback configurationsTor Norbye2011-11-213-6/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changeset adds support for the command line lint tool to provide "fallback configurations". Lint already looks at any lint.xml files found in projects it scans, but if you are going to scan multiple projects you need to have a lint.xml in each project. This changeset adds a -config <file> option where you can point to a lint configuration file which will be used as a fallback for all projects, so if no specific severity is set for a particular issue in a given project lint.xml file, then it will fall back to the setting in the global lint.xml file and use that instead. This makes it project to have a master configuration used across lots of projects as part of a build step. Change-Id: I3a8d13d9ffaff04b22649b6464f97faf84d265d5
* | Merge "Add package support for Rules API and Detector API"Tor Norbye2011-11-234-39/+119
|\ \
| * | Add package support for Rules API and Detector APITor Norbye2011-11-234-39/+119
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | When writing custom view rules, and custom detectors, you may need access to the package name of the application (in order to produce the right namespace to look up custom attributes for). This changeset adds new methods to the two APIs such that clients can look up the application package. For lint, it also changes things such that the manifest file is always processed and information stashed in the Project object. This meant I could also remove the icon detector code to look up the manifest info directly. Change-Id: Id8eec96e2788f6d27481d7dcab0c544ea6e0a06d
* | Typography lint checkerTor Norbye2011-11-239-4/+641
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changeset adds a new typography detector. This looks at the strings defined by the application and makes various suggestions to make the text look better typographically, such as - suggesting directional single and double quotes instead of straight single or or double quotes - suggesting typographical apostrophes instead of straight ones - suggesting n-dashes instead of hyphens in number ranges - suggesting m-dashes instead of --'s - suggesting fractional characters instead of strings like 1/2 - suggesting the ellipsis character instead of "..." - suggesting the copyright symbol instead of (c) There is also an Eclipse quick fix for these issues. Change-Id: If3912f9d34841faf069174f291911f73e6b78c28
* | Add new detectors for layout parameters and deprecationsTor Norbye2011-11-2114-7/+839
|/ | | | | | | | | | | | | | | | | | | | | | This changeset adds two new detectors: (1) An "obsolete layout parameters" detector which finds cases where the layout parameters on a view do not match the current parent view. This usually happens when view XML is copied and pasted around, or layout hierarchies are changed, without the views themselves getting updated. The detector also tracks include tags and checks that tags are not only consistent within their own parent, but that root tag layout parameters and <merge> tag children are also consistent with their usages across <include>'s. There is also an Eclipse quickfix for this warning. (2) A deprecation detector. This currently only warns about AbsoluteLayout. Change-Id: I714e8a0d2a614ea4ee3fd5c7b60d012f18567169
* Merge "Add support for custom lint detectors"Tor Norbye2011-11-154-2/+107
|\
| * Add support for custom lint detectorsTor Norbye2011-11-154-2/+107
| | | | | | | | | | | | | | | | | | | | | | | | This changeset adds a mechanism where additional detectors can be added by the user, either via an environment variable (ANDROID_LINT_JARS) or by placing jar files in the ~/.android/lint/ directory. Each jar file is scanned for a manifest entry (Lint-Registry) which points to an implementation of an IssueRegistry, and the issues provided by that registry via getIssues() is added to the global list of issues to be checked. Change-Id: I0ac79a0d7dea50ae4258f70399b297afb761d4f8
* | Add two new layout detectorsTor Norbye2011-11-146-12/+182
|/ | | | | | | | | | | | | | | | | | | | This changeset adds two new layout_weight related detectors for LinearLayouts: (1) Nested weights. This looks for cases where you have a weight on a child of a LinearLayout that is defined within an outer view which also has a weight. This is very inefficient because of the way views need to get measured when weights ar used. (2) Baseline alignments. When you're using LinearLayouts as a way to proportionally distribute available space for children layouts (e.g. the children are not baseline views like buttons or text views) then it's more efficient to set baselineAligned=false on the LinearLayout. This also adds an Eclipse quickfix for this. Also makes a shared fix class for the many various lint fixes that just set an attribute. There will be more of these over time. Change-Id: Ia6082d2436a156f8d63d6930af98a2ed363550e6
* Tweak lint cli handlingTor Norbye2011-11-111-9/+49
| | | | | | | | | | | | First, after switching to a Category class the category print was printing an object hash instead of the category description. Second, wrap the --list output since it's often wider than the available line length. Also widen the wrap width from 70 to 78. Third, allow category arguments to the --list and --show commands. Change-Id: Ia71bc7b49ec5106623fa2d4a1083ed9f392bc733
* Minor lint tweaksTor Norbye2011-11-102-2/+6
| | | | | | | | | | | | | | | | | 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-102-6/+11
| | | | | | | | | | | | | 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-095-30/+160
| | | | | | | | | | | | | | | | | | | | 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
* Fix various lint bugsTor Norbye2011-11-098-24/+50
| | | | | | | | | | | | | | | | | | | | | This changeset fixes various lint bugs: 1) Handle XML files that contain a BOM (byte order marker); these files were throwing parsing errors before 2) Handle a bug in the position tracking in the command line XML parser where once it had computed the end range for an attribute it would use that as the end range of the surrounding element as well 3) Fix a bug in the Java source scanner where it would run into an exception processing package-info.java files. 4) Don't report unused resources on @+android:id resources 5) In the HTML summary, if the text overflows the available area, add scrollbars. Also tweak issue sorting some more. Change-Id: I9b88c1a936a5349559c4d7a5c87dcfa44e86d2f4
* Add gradual disclosure to the lint HTML reportTor Norbye2011-11-083-12/+91
| | | | | | | | | | | | | | When running lint on a large codebase the number of errors for any category can be daunting, forcing you to scroll a lot to see what the issues are. This changeset changes this such that for issues with more than 8 warnings, only the first 5 are shown inline, and then there is a "show more" button to disclose the rest. Also fix a limitation in the array size detector which meant that it didn't include a link to one of the files when detecting an array size inconsistency. Change-Id: I758879a0c6962f4663274e42a0c5a83ac1b8c8c6
* Add nodpi checkTor Norbye2011-11-087-52/+185
| | | | | | | | | | | 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-088-15/+333
| | | | | | | | | | | | | | | | | 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-0810-14/+339
| | | | | | | | | | | | | | | | | | 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-077-0/+852
| | | | | | | | | | | | | | | | | | | | 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-0754-1025/+2430
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-0256-399/+1089
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Add lint security check for exported servicesTor Norbye2011-11-027-0/+278
| | | | | | | | | This changeset adds a new lint check for exported services in the manifest. It checks that exported services define a permission (or inherit one from the application element) since omitting this can lead to open services not intended to be left unprotected. Change-Id: I1284f4c41ff3aabd790702978c39320648e033a2
* Turn on lint-on-save for all XML types, and move some codeTor Norbye2011-11-015-141/+100
| | | | | | | | | | | | 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
* Suppress unused resource ids by default and ignore donottranslateTor Norbye2011-10-316-2/+66
| | | | | | | | | | | | | | | (1) For the unused resource detector, separate out unused ids from other types of resources. Lots of projects have unused id's, and these are mostly harmless and often serve a useful documentation purpose in the layout. Therefore, unused id's get their own separate issue, and this issue is off by default. (2) There seems to be a convention in many Android projects that files named "donottranslate.xml" are ignored for translation purposes. The translation detector now ignores these files as well. Change-Id: Id3de99e8286b5a5c39b141af9c233f1515b493fb
* Fix Useless layout detector, and add HTML summaryTor Norbye2011-10-284-40/+138
| | | | | | | | | | First, fix the logic in the useless layout detector to properly consider the background attributes. Second, add a summary section at the top of the HTML report with hyperlinks to each issue section. Change-Id: I7e9e2d81babf977751fc3ca64e61fcc8434a0792
* Add Lint HTML reporting, and fix position information in parserTor Norbye2011-10-2828-174/+982
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-2626-208/+716
| | | | | | | | | | | | | | | | | | | | | 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-2575-167/+1046
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-2531-276/+579
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-2039-54/+1404
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-2087-0/+6334
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