Class FileUtils
java.lang.Object
io.github.syst3ms.skriptparser.util.FileUtils
Utility functions for file parsing
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intgetIndentationLevel(String line, boolean countAllSpaces) Counts the number of indents (a single tab or 4 spaces) at the beginning of a line, or alternatively just counts the amount of spaces at the beginning of a line (with a tab counting as 4 regular spaces).static FilegetJarFile(Class<?> cla) Retrieves the JAR file containing the given Class.static voidloadClasses(File jarFile, String rootPackage, String... subPackages) Loads all classes of selected packages of the provided JAR file.static voidloadClasses(Path directory, String rootPackage, String... subPackages) Loads all classes of selected packages of the skript-parser JAR.readAllLines(Path filePath) Parses a file and returns a list containing all of its lines.static String
-
Field Details
-
LEADING_WHITESPACE_PATTERN
-
MULTILINE_SYNTAX_TOKEN
- See Also:
-
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
readAllLines
Parses a file and returns a list containing all of its lines.This parser offers the possibility to stretch out code across multiple lines by simply adding a single backslash before a line break to indicate to the parser that it should be considered as a single line. For example :
set {large_list::*} to "one long string", \ "a second long string", \ "yet another long string" \ "an even longer string which would make reading very awkward otherwise", \ "nearing the end of the list" and \ "the end of the list"This text will be interpreted as a single long line with all the strings back to back. The actual indentation before each additional line doesn't matter, all that matters is that it stays consistent.- Parameters:
filePath- the file to parse- Returns:
- the lines of the file
- Throws:
IOException- if the file can't be read
-
getIndentationLevel
Counts the number of indents (a single tab or 4 spaces) at the beginning of a line, or alternatively just counts the amount of spaces at the beginning of a line (with a tab counting as 4 regular spaces).- Parameters:
line- the linecountAllSpaces- if true, the method will count each space separately rather than in groups of 4- Returns:
- the indentation level
-
removeExtension
-
loadClasses
public static void loadClasses(File jarFile, String rootPackage, String... subPackages) throws IOException Loads all classes of selected packages of the provided JAR file.- Parameters:
jarFile- the JAR filerootPackage- a root packagesubPackages- a list of all subpackages of the root package, in which classes will be loaded- Throws:
IOException- if an I/O error has occurred
-
loadClasses
public static void loadClasses(Path directory, String rootPackage, String... subPackages) throws IOException Loads all classes of selected packages of the skript-parser JAR.- Parameters:
directory- the directory in which the root package is containedrootPackage- a root packagesubPackages- a list of all subpackages of the root package, in which classes will be leadied- Throws:
IOException- if an I/O error has occurred
-
getJarFile
Retrieves the JAR file containing the given Class. Passing down the current class is recommended.- Parameters:
cla- the class- Returns:
- the JAR file containing the class
- Throws:
URISyntaxException
-