• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 
17 package com.android.tools.lint.detector.api;
18 
19 import com.android.annotations.NonNull;
20 import com.android.resources.ResourceFolderType;
21 import com.google.common.annotations.Beta;
22 
23 import java.io.File;
24 
25 /**
26  * Specialized detector intended for XML resources. Detectors that apply to XML
27  * resources should extend this detector instead since it provides special
28  * iteration hooks that are more efficient.
29  * <p/>
30  * <b>NOTE: This is not a public or final API; if you rely on this be prepared
31  * to adjust your code for the next tools release.</b>
32  */
33 @Beta
34 public abstract class ResourceXmlDetector extends Detector implements Detector.XmlScanner {
35     @Override
appliesTo(@onNull Context context, @NonNull File file)36     public boolean appliesTo(@NonNull Context context, @NonNull File file) {
37         return LintUtils.isXmlFile(file);
38     }
39 
40     /**
41      * Returns whether this detector applies to the given folder type. This
42      * allows the detectors to be pruned from iteration, so for example when we
43      * are analyzing a string value file we don't need to look up detectors
44      * related to layout.
45      *
46      * @param folderType the folder type to be visited
47      * @return true if this detector can apply to resources in folders of the
48      *         given type
49      */
appliesTo(@onNull ResourceFolderType folderType)50     public boolean appliesTo(@NonNull ResourceFolderType folderType) {
51         return true;
52     }
53 
54     @Override
run(@onNull Context context)55     public void run(@NonNull Context context) {
56         // The infrastructure should never call this method on an xml detector since
57         // it will run the various visitors instead
58         assert false;
59     }
60 }
61