diff options
author | Tor Norbye <tnorbye@google.com> | 2012-04-05 14:35:56 -0700 |
---|---|---|
committer | android code review <noreply-gerritcodereview@google.com> | 2012-04-05 14:35:57 -0700 |
commit | 23ace30ff0d20f23524f527eb6cbd0a97c2bfdbd (patch) | |
tree | b62803fbd9ead6464f427c268cf8ffa6c9aaf6ee | |
parent | 08bafdfa22e2d20499d58118fdc0389c856b7028 (diff) | |
parent | e594c89f7d84578dcc0f8a96cb2192d3484dc0dc (diff) | |
download | sdk-23ace30ff0d20f23524f527eb6cbd0a97c2bfdbd.zip sdk-23ace30ff0d20f23524f527eb6cbd0a97c2bfdbd.tar.gz sdk-23ace30ff0d20f23524f527eb6cbd0a97c2bfdbd.tar.bz2 |
Merge "Issue 28264: Handle adding annotations from markers outside of class"
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/AddSuppressAnnotation.java | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/AddSuppressAnnotation.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/AddSuppressAnnotation.java index 6b945f8..1280bc7 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/AddSuppressAnnotation.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/AddSuppressAnnotation.java @@ -312,7 +312,21 @@ class AddSuppressAnnotation implements IMarkerResolution2 { boolean isClassDetector = issue != null && issue.getScope().contains(Scope.CLASS_FILE); NodeFinder nodeFinder = new NodeFinder(root, offset, length); - ASTNode coveringNode = nodeFinder.getCoveringNode(); + ASTNode coveringNode; + if (offset <= 0) { + // Error added on the first line of a Java class: typically from a class-based + // detector which lacks line information. Map this to the top level class + // in the file instead. + coveringNode = root; + if (root.types() != null && root.types().size() > 0) { + Object type = root.types().get(0); + if (type instanceof ASTNode) { + coveringNode = (ASTNode) type; + } + } + } else { + coveringNode = nodeFinder.getCoveringNode(); + } for (ASTNode body = coveringNode; body != null; body = body.getParent()) { if (body instanceof BodyDeclaration) { BodyDeclaration declaration = (BodyDeclaration) body; |