mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
Fix indents in ImportStatement
This commit is contained in:
@@ -31,97 +31,97 @@ import java.util.regex.Matcher;
|
||||
*/
|
||||
public class ImportStatement {
|
||||
|
||||
private static final String importKw = "import";
|
||||
private static final String staticKw = "static";
|
||||
private static final String importKw = "import";
|
||||
private static final String staticKw = "static";
|
||||
|
||||
private boolean isClass;
|
||||
private boolean isStarred;
|
||||
private boolean isStatic;
|
||||
private boolean isClass;
|
||||
private boolean isStarred;
|
||||
private boolean isStatic;
|
||||
|
||||
/**
|
||||
* Full class name of the import with all packages
|
||||
* Ends with star for starred imports
|
||||
*/
|
||||
private String className;
|
||||
/**
|
||||
* Full class name of the import with all packages
|
||||
* Ends with star for starred imports
|
||||
*/
|
||||
private String className;
|
||||
|
||||
/**
|
||||
* Name of the package e.g. everything before last dot
|
||||
*/
|
||||
private String packageName;
|
||||
/**
|
||||
* Name of the package e.g. everything before last dot
|
||||
*/
|
||||
private String packageName;
|
||||
|
||||
private ImportStatement() { }
|
||||
private ImportStatement() { }
|
||||
|
||||
public static ImportStatement wholePackage(String pckg) {
|
||||
ImportStatement is = new ImportStatement();
|
||||
is.packageName = pckg;
|
||||
is.className = "*";
|
||||
is.isStarred = true;
|
||||
return is;
|
||||
}
|
||||
public static ImportStatement wholePackage(String pckg) {
|
||||
ImportStatement is = new ImportStatement();
|
||||
is.packageName = pckg;
|
||||
is.className = "*";
|
||||
is.isStarred = true;
|
||||
return is;
|
||||
}
|
||||
|
||||
public static ImportStatement singleClass(String cls) {
|
||||
ImportStatement is = new ImportStatement();
|
||||
int lastDot = cls.lastIndexOf('.');
|
||||
is.className = lastDot >= 0 ? cls.substring(lastDot+1) : cls;
|
||||
is.packageName = lastDot >= 0 ? cls.substring(0, lastDot) : "";
|
||||
is.isClass = true;
|
||||
return is;
|
||||
}
|
||||
public static ImportStatement singleClass(String cls) {
|
||||
ImportStatement is = new ImportStatement();
|
||||
int lastDot = cls.lastIndexOf('.');
|
||||
is.className = lastDot >= 0 ? cls.substring(lastDot+1) : cls;
|
||||
is.packageName = lastDot >= 0 ? cls.substring(0, lastDot) : "";
|
||||
is.isClass = true;
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static ImportStatement parse(String importString) {
|
||||
Matcher matcher = SourceUtils.IMPORT_REGEX_NO_KEYWORD.matcher(importString);
|
||||
if (!matcher.find()) return null;
|
||||
public static ImportStatement parse(String importString) {
|
||||
Matcher matcher = SourceUtils.IMPORT_REGEX_NO_KEYWORD.matcher(importString);
|
||||
if (!matcher.find()) return null;
|
||||
|
||||
return parse(matcher.toMatchResult());
|
||||
}
|
||||
return parse(matcher.toMatchResult());
|
||||
}
|
||||
|
||||
public static ImportStatement parse(MatchResult match) {
|
||||
ImportStatement is = new ImportStatement();
|
||||
public static ImportStatement parse(MatchResult match) {
|
||||
ImportStatement is = new ImportStatement();
|
||||
|
||||
is.isStatic = match.group(2) != null;
|
||||
String pckg = match.group(3);
|
||||
pckg = (pckg == null) ? "" : pckg.replaceAll("\\s","");
|
||||
is.packageName = pckg.endsWith(".") ?
|
||||
pckg.substring(0, pckg.length()-1) :
|
||||
pckg;
|
||||
is.isStatic = match.group(2) != null;
|
||||
String pckg = match.group(3);
|
||||
pckg = (pckg == null) ? "" : pckg.replaceAll("\\s","");
|
||||
is.packageName = pckg.endsWith(".") ?
|
||||
pckg.substring(0, pckg.length()-1) :
|
||||
pckg;
|
||||
|
||||
is.className = match.group(4);
|
||||
is.isStarred = is.className.equals("*");
|
||||
is.className = match.group(4);
|
||||
is.isStarred = is.className.equals("*");
|
||||
|
||||
return is;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getFullSourceLine() {
|
||||
return importKw + " " + (isStatic ? (staticKw + " ") : "") + packageName + "." + className + ";";
|
||||
}
|
||||
public String getFullSourceLine() {
|
||||
return importKw + " " + (isStatic ? (staticKw + " ") : "") + packageName + "." + className + ";";
|
||||
}
|
||||
|
||||
public String getFullClassName(){
|
||||
return packageName + "." + className;
|
||||
}
|
||||
public String getFullClassName(){
|
||||
return packageName + "." + className;
|
||||
}
|
||||
|
||||
public String getClassName(){
|
||||
return className;
|
||||
}
|
||||
public String getClassName(){
|
||||
return className;
|
||||
}
|
||||
|
||||
public String getPackageName(){
|
||||
return packageName;
|
||||
}
|
||||
public String getPackageName(){
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public boolean isStarredImport() {
|
||||
return isStarred;
|
||||
}
|
||||
public boolean isStarredImport() {
|
||||
return isStarred;
|
||||
}
|
||||
|
||||
public boolean isStaticImport() {
|
||||
return isStatic;
|
||||
}
|
||||
public boolean isStaticImport() {
|
||||
return isStatic;
|
||||
}
|
||||
|
||||
public boolean isSameAs(ImportStatement is) {
|
||||
return packageName.equals(is.packageName) &&
|
||||
className.equals(is.className) &&
|
||||
isStatic == is.isStatic;
|
||||
}
|
||||
public boolean isSameAs(ImportStatement is) {
|
||||
return packageName.equals(is.packageName) &&
|
||||
className.equals(is.className) &&
|
||||
isStatic == is.isStatic;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user