com.android.tools.lint.detector.api
Class XmlContext

java.lang.Object
  extended by com.android.tools.lint.detector.api.Context
      extended by com.android.tools.lint.detector.api.XmlContext

@Beta
public class XmlContext
extends Context

A Context used when checking XML files.

NOTE: This is not a public or final API; if you rely on this be prepared to adjust your code for the next tools release.


Field Summary
 org.w3c.dom.Document document
          The XML document
 IDomParser parser
          The XML parser
 
Fields inherited from class com.android.tools.lint.detector.api.Context
file, mDriver
 
Constructor Summary
XmlContext(LintDriver driver, Project project, Project main, java.io.File file, com.android.resources.ResourceFolderType folderType)
          Construct a new XmlContext
 
Method Summary
 Location getLocation(org.w3c.dom.Node node)
          Returns the location for the given node, which may be an element or an attribute.
 Location getLocation(org.w3c.dom.Node textNode, int begin, int end)
          Creates a new location within an XML text node
 com.android.resources.ResourceFolderType getResourceFolderType()
          Returns the resource folder type of this XML file, if any.
protected  java.lang.String getSuppressCommentPrefix()
          Returns the comment marker used in Studio to suppress statements for language, if any
 boolean isSuppressed(org.w3c.dom.Node node, Issue issue)
           
 void report(Issue issue, Location location, java.lang.String message, java.lang.Object data)
          Reports an issue.
 void report(Issue issue, org.w3c.dom.Node scope, Location location, java.lang.String message, java.lang.Object data)
          Reports an issue applicable to a given DOM node.
 
Methods inherited from class com.android.tools.lint.detector.api.Context
containsCommentSuppress, getClient, getConfiguration, getContents, getDriver, getFolderVersion, getFolderVersion, getMainProject, getPhase, getProject, getProperty, getScope, getSdkInfo, isEnabled, isSuppressedWithComment, log, requestRepeat, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parser

public IDomParser parser
The XML parser


document

public org.w3c.dom.Document document
The XML document

Constructor Detail

XmlContext

public XmlContext(@NonNull
                  LintDriver driver,
                  @NonNull
                  Project project,
                  @Nullable
                  Project main,
                  @NonNull
                  java.io.File file,
                  @Nullable
                  com.android.resources.ResourceFolderType folderType)
Construct a new XmlContext

Parameters:
driver - the driver running through the checks
project - the project containing the file being checked
main - the main project if this project is a library project, or null if this is not a library project. The main project is the root project of all library projects, not necessarily the directly including project.
file - the file being checked
folderType - the ResourceFolderType of this file, if any
Method Detail

getLocation

@NonNull
public Location getLocation(@NonNull
                                    org.w3c.dom.Node node)
Returns the location for the given node, which may be an element or an attribute.

Parameters:
node - the node to look up the location for
Returns:
the location for the node

getLocation

@NonNull
public Location getLocation(@NonNull
                                    org.w3c.dom.Node textNode,
                                    int begin,
                                    int end)
Creates a new location within an XML text node

Parameters:
textNode - the text node
begin - the start offset within the text node (inclusive)
end - the end offset within the text node (exclusive)
Returns:
a new location

report

public void report(@NonNull
                   Issue issue,
                   @Nullable
                   org.w3c.dom.Node scope,
                   @Nullable
                   Location location,
                   @NonNull
                   java.lang.String message,
                   @Nullable
                   java.lang.Object data)
Reports an issue applicable to a given DOM node. The DOM node is used as the scope to check for suppress lint annotations.

Parameters:
issue - the issue to report
scope - the DOM node scope the error applies to. The lint infrastructure will check whether there are suppress directives on this node (or its enclosing nodes) and if so suppress the warning without involving the client.
location - the location of the issue, or null if not known
message - the message for this warning
data - any associated data, or null

report

public void report(@NonNull
                   Issue issue,
                   @Nullable
                   Location location,
                   @NonNull
                   java.lang.String message,
                   @Nullable
                   java.lang.Object data)
Description copied from class: Context
Reports an issue. Convenience wrapper around LintClient.report(com.android.tools.lint.detector.api.Context, com.android.tools.lint.detector.api.Issue, com.android.tools.lint.detector.api.Severity, com.android.tools.lint.detector.api.Location, java.lang.String, java.lang.Object)

Overrides:
report in class Context
Parameters:
issue - the issue to report
location - the location of the issue, or null if not known
message - the message for this warning
data - any associated data, or null

getResourceFolderType

@Nullable
public com.android.resources.ResourceFolderType getResourceFolderType()
Returns the resource folder type of this XML file, if any.

Returns:
the resource folder type or null

getSuppressCommentPrefix

@Nullable
protected java.lang.String getSuppressCommentPrefix()
Description copied from class: Context
Returns the comment marker used in Studio to suppress statements for language, if any

Overrides:
getSuppressCommentPrefix in class Context

isSuppressed

public boolean isSuppressed(@NonNull
                            org.w3c.dom.Node node,
                            @NonNull
                            Issue issue)