From e594c89f7d84578dcc0f8a96cb2192d3484dc0dc Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Thu, 5 Apr 2012 14:12:43 -0700 Subject: Issue 28264: Handle adding annotations from markers outside of class This CL fixes 28264: Lint "The package.name is not registered in the manifest" fix doesn't do anything Change-Id: Icda6b02c77683b1ef0e5898b37958c75c38ebf29 --- .../eclipse/adt/internal/lint/AddSuppressAnnotation.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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; -- cgit v1.1