1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.tools.lint.checks;
18
19import com.android.tools.lint.detector.api.Detector;
20import com.android.tools.lint.detector.api.Issue;
21
22import java.util.List;
23
24@SuppressWarnings("javadoc")
25public class AnnotationDetectorTest extends AbstractCheckTest {
26    public void test() throws Exception {
27        assertEquals(
28            "src/test/pkg/WrongAnnotation.java:8: Error: The @SuppresLint annotation cannot be used on a local variable  with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" +
29            "    public static void foobar(View view, @SuppressLint(\"NewApi\") int foo) { // Invalid: class-file check\n" +
30            "                                         ~~~~~~~~~~~~~~~~~~~~~~~\n" +
31            "src/test/pkg/WrongAnnotation.java:9: Error: The @SuppresLint annotation cannot be used on a local variable  with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" +
32            "        @SuppressLint(\"NewApi\") // Invalid\n" +
33            "        ~~~~~~~~~~~~~~~~~~~~~~~\n" +
34            "src/test/pkg/WrongAnnotation.java:11: Error: The @SuppresLint annotation cannot be used on a local variable  with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" +
35            "        @SuppressLint({\"SdCardPath\", \"NewApi\"}) // Invalid: class-file based check on local variable\n" +
36            "        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
37            "src/test/pkg/WrongAnnotation.java:13: Error: The @SuppresLint annotation cannot be used on a local variable  with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" +
38            "        @android.annotation.SuppressLint({\"SdCardPath\", \"NewApi\"}) // Invalid (FQN)\n" +
39            "        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
40            "4 errors, 0 warnings\n" +
41            "",
42
43            lintProject(
44                "src/test/pkg/WrongAnnotation.java.txt=>src/test/pkg/WrongAnnotation.java"
45            ));
46    }
47
48    @Override
49    protected Detector getDetector() {
50        return new AnnotationDetector();
51    }
52
53    @Override
54    protected List<Issue> getIssues() {
55        List<Issue> issues = super.getIssues();
56
57        // Need these issues on to be found by the registry as well to look up scope
58        // in id references (these ids are referenced in the unit test java file below)
59        issues.add(ApiDetector.UNSUPPORTED);
60        issues.add(SdCardDetector.ISSUE);
61
62        return issues;
63    }
64}
65