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

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

public class LintUtils
extends Object

Useful utility methods related to lint.


Constructor Summary
LintUtils()
           
 
Method Summary
static void copyFile(File src, File target)
          Copies a file
static Set<String> difference(Set<String> a, Set<String> b)
          Computes the set difference a - b
static boolean endsWith(String string, String suffix)
          Case insensitive ends with
static String formatList(List<String> strings, int maxItems)
          Format a list of strings, and cut of the list at maxItems if the number of items are greater.
static int getChildCount(Node node)
          Returns the number of children of the given node
static List<Element> getChildren(Node node)
          Returns the children elements of the given node
static Set<String> intersection(Set<String> a, Set<String> b)
          Computes the set intersection a intersect b
static boolean isFileBasedResourceType(com.android.resources.ResourceType type)
          Determine if the given type corresponds to a resource that has a unique file
static boolean isXmlFile(File file)
          Returns true if the given file represents an XML file
static byte[] readBytes(File src)
          Reads the file contents of the given file and returns it as a byte array.
static Set<String> union(Set<String> a, Set<String> b)
          Computes the set union a union b
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LintUtils

public LintUtils()
Method Detail

formatList

public static String formatList(List<String> strings,
                                int maxItems)
Format a list of strings, and cut of the list at maxItems if the number of items are greater.

Parameters:
strings - the list of strings to print out as a comma separated list
maxItems - the maximum number of items to print
Returns:
a comma separated list

difference

public static Set<String> difference(Set<String> a,
                                     Set<String> b)
Computes the set difference a - b

Parameters:
a - the set to subtract from
b - the set to subtract
Returns:
the elements that are in a but not in b

intersection

public static Set<String> intersection(Set<String> a,
                                       Set<String> b)
Computes the set intersection a intersect b

Parameters:
a - the first set to intersect
b - the second set to intersect
Returns:
the elements that are in a and in b

union

public static Set<String> union(Set<String> a,
                                Set<String> b)
Computes the set union a union b

Parameters:
a - the first set to add
b - the second set to add
Returns:
the elements that are in a or in b

isFileBasedResourceType

public static boolean isFileBasedResourceType(com.android.resources.ResourceType type)
Determine if the given type corresponds to a resource that has a unique file

Parameters:
type - the resource type to check
Returns:
true if the given type corresponds to a file-type resource

isXmlFile

public static boolean isXmlFile(File file)
Returns true if the given file represents an XML file

Parameters:
file - the file to be checked
Returns:
true if the given file is an xml file

endsWith

public static boolean endsWith(String string,
                               String suffix)
Case insensitive ends with

Parameters:
string - the string to be tested whether it ends with the given suffix
suffix - the suffix to check
Returns:
true if string ends with suffix, case-insensitively.

getChildren

public static List<Element> getChildren(Node node)
Returns the children elements of the given node

Parameters:
node - the parent node
Returns:
a list of element children, never null

getChildCount

public static int getChildCount(Node node)
Returns the number of children of the given node

Parameters:
node - the parent node
Returns:
the count of element children

copyFile

public static void copyFile(File src,
                            File target)
                     throws IOException
Copies a file

Parameters:
src - the file to copy
target - the filename to write the file into
Throws:
IOException - if an I/O problem occurs

readBytes

public static byte[] readBytes(File src)
                        throws IOException
Reads the file contents of the given file and returns it as a byte array.

Parameters:
src - the file to be read
Returns:
the contents of the file, or null
Throws:
IOException - if an I/O error occurs


Copyright © 2008-2012. All Rights Reserved.