• 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.client.api;
18 
19 import com.android.annotations.NonNull;
20 import com.android.annotations.Nullable;
21 import com.android.tools.lint.detector.api.Context;
22 import com.android.tools.lint.detector.api.Location;
23 import com.android.tools.lint.detector.api.XmlContext;
24 import com.google.common.annotations.Beta;
25 
26 import org.w3c.dom.Document;
27 import org.w3c.dom.Node;
28 
29 /**
30  * A wrapper for an XML parser. This allows tools integrating lint to map directly
31  * to builtin services, such as already-parsed data structures in XML editors.
32  * <p/>
33  * <b>NOTE: This is not a public or final API; if you rely on this be prepared
34  * to adjust your code for the next tools release.</b>
35  */
36 @Beta
37 public interface IDomParser {
38     /**
39      * Parse the file pointed to by the given context and return as a Document
40      *
41      * @param context the context pointing to the file to be parsed, typically
42      *            via {@link Context#getContents()} but the file handle (
43      *            {@link Context#file} can also be used to map to an existing
44      *            editor buffer in the surrounding tool, etc)
45      * @return the parsed DOM document, or null if parsing fails
46      */
47     @Nullable
parseXml(@onNull XmlContext context)48     Document parseXml(@NonNull XmlContext context);
49 
50     /**
51      * Returns a {@link Location} for the given DOM node
52      *
53      * @param context information about the file being parsed
54      * @param node the node to create a location for
55      * @return a location for the given node
56      */
57     @NonNull
getLocation(@onNull XmlContext context, @NonNull Node node)58     Location getLocation(@NonNull XmlContext context, @NonNull Node node);
59 
60     /**
61      * Creates a light-weight handle to a location for the given node. It can be
62      * turned into a full fledged location by
63      * {@link com.android.tools.lint.detector.api.Location.Handle#resolve()}.
64      *
65      * @param context the context providing the node
66      * @param node the node (element or attribute) to create a location handle
67      *            for
68      * @return a location handle
69      */
70     @NonNull
createLocationHandle(@onNull XmlContext context, @NonNull Node node)71     Location.Handle createLocationHandle(@NonNull XmlContext context, @NonNull Node node);
72 
73     /**
74      * Dispose any data structures held for the given context.
75      * @param context information about the file previously parsed
76      * @param document the document that was parsed and is now being disposed
77      */
dispose(@onNull XmlContext context, @NonNull Document document)78     void dispose(@NonNull XmlContext context, @NonNull Document document);
79 }
80