public class ToolUtil extends BasicToolUtil
Constructor and Description |
---|
ToolUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
addToProject(File f,
boolean test,
Conditions conditions)
Adds a file to a project.
|
static String |
decode(String ascii,
int start,
int end)
Converts an ASCII encoded string back to the original.
|
static String[] |
decodeArray(String ascii,
int start,
int end)
Converts an encoded string array back to the original.
|
static File |
decodeRelativeFile(String fn,
File relativeTo)
Gets a file from a platform-independent relative path representation.
|
static String |
encode(String from)
ASCII encodes a String, including tabs, newlines, and carriage returns.
|
static String |
encodeArray(String[] strings)
Encodes a String array.
|
static String |
encodeRelativeFile(File f,
File relativeTo)
Gets a platform-independent representation of a relative path.
|
static List<File> |
getClassFiles(File sourceFile,
ProjectState ps)
Gets the class files corresponding to a source file.
|
static String |
getCompilerEnvironment(File f)
Gets the compiler environment for a file.
|
static String |
getDetailMessage(Throwable t)
Gets the detail message for a throwable.
|
static String |
getJavaPackage(File f,
Charset charset)
Scans a Java source file to find the package.
|
static List<String> |
getLikelyHomeLocations()
Gets likely home directory locations for a tool installation.
|
static String |
getPackageRoot(File f,
Charset charset)
Gets the package root directory for a Java source file.
|
static File |
getRootFile(Class<?> klass)
Gets the root directory or jar file for a class.
|
static String |
getSensibleFilename(String filename,
File relativeTo)
Gets a non-empty sensible filename representation.
|
static String |
getSensibleFilename(String filename,
File relativeTo,
boolean emptyOK)
Gets a sensible filename representation.
|
static boolean |
isBundled(File dir)
Determines if a directory is part of a distribution bundle.
|
static boolean |
isModified(File f)
Determines if a file has been edited and not saved.
|
static boolean |
isTestFile(File f,
Conditions conditions)
Determines if a file is a test file.
|
static boolean |
mkdirs(File dir)
Creates directories.
|
static void |
recordToolAction(String name,
String lang)
Records a tool use.
|
static void |
setBundleDir(File bundleDirIn)
Sets the bundle directory.
|
static void |
setCompilerEnvironment(File f,
String lang,
String env)
Sets the compiler environment and language for a file.
|
getMenuShortcutKeyMaskEx, getSpacing
public static void addToProject(File f, boolean test, Conditions conditions)
f
- the file to be added.test
- true if the file is a test file, false otherwise.conditions
- the project associated with the active file for these
conditions is the one to which the file will be added.public static String decode(String ascii, int start, int end)
ascii
- string containing the encoded string.start
- first index of encoded string segment.end
- last index of encoded string segment, plus one.public static String[] decodeArray(String ascii, int start, int end)
ascii
- string containing the encoded string array.start
- first index of encoded string array.end
- last index of encoded string array, plus one.public static File decodeRelativeFile(String fn, File relativeTo)
fn
- the platform-independent relative path string.relativeTo
- relative directory or file in relative directory.fn
when applied to relativeTo
or the directory
containing relativeTo
.public static String encode(String from)
from
- the string to encode.public static String encodeArray(String[] strings)
strings
- the string array to encode.public static String encodeRelativeFile(File f, File relativeTo)
f
- the file the returned value will represent.relativeTo
- relative directory or file in relative directory.relativeTo
or the directory containing
relativeTo
to f
.public static List<File> getClassFiles(File sourceFile, ProjectState ps)
sourceFile
- file the source file of interest.ps
- the project associated with the source file.public static String getCompilerEnvironment(File f)
f
- the file.public static String getDetailMessage(Throwable t)
t
- the throwable of interest.public static String getJavaPackage(File f, Charset charset)
f
- the Java source file.charset
- the charset to use for scanning the file, or null to use
the system default.public static List<String> getLikelyHomeLocations()
public static String getPackageRoot(File f, Charset charset)
f
- the Java source file of interest.charset
- the charset to use for scanning the file, or null to use
the system default.public static File getRootFile(Class<?> klass)
klass
- the class of interest.public static String getSensibleFilename(String filename, File relativeTo)
filename
- the filename.relativeTo
- the relative directory.relativeTo
to the file
represented by filename
if it contains fewer file separators
than filename
and if relative
is true,
otherwise filename
is returned.public static String getSensibleFilename(String filename, File relativeTo, boolean emptyOK)
filename
- the filename.relativeTo
- the relative directory.emptyOK
- true if the result may be empty if the file is the
relative directory, false if . should be used instead.relativeTo
to the file
represented by filename
if it contains fewer file separators
than filename
and if relative
is true,
otherwise filename
is returned.public static boolean isModified(File f)
f
- the file of interest.public static boolean isTestFile(File f, Conditions conditions)
f
- the file of interest.conditions
- associated with the file.f
is a test file, false otherwise.public static boolean mkdirs(File dir)
dir
- the directory path to be created.public static void recordToolAction(String name, String lang)
name
- the tool name.lang
- the language name.public static void setCompilerEnvironment(File f, String lang, String env)
f
- the file.lang
- the language name.env
- the compiler environment name.public static void setBundleDir(File bundleDirIn)
bundleDirIn
- the bundle root directory. This may be null.public static boolean isBundled(File dir)
dir
- the directory to be tested.