3131 */
3232public class ImportStatement {
3333
34- private static final String importKw = "import" ;
35- private static final String staticKw = "static" ;
34+ private static final String importKw = "import" ;
35+ private static final String staticKw = "static" ;
3636
37- private boolean isClass ;
38- private boolean isStarred ;
39- private boolean isStatic ;
37+ private boolean isClass ;
38+ private boolean isStarred ;
39+ private boolean isStatic ;
4040
41- /**
42- * Full class name of the import with all packages
43- * Ends with star for starred imports
44- */
45- private String className ;
41+ /**
42+ * Full class name of the import with all packages
43+ * Ends with star for starred imports
44+ */
45+ private String className ;
4646
47- /**
48- * Name of the package e.g. everything before last dot
49- */
50- private String packageName ;
47+ /**
48+ * Name of the package e.g. everything before last dot
49+ */
50+ private String packageName ;
5151
52- private ImportStatement () { }
52+ private ImportStatement () { }
5353
54- public static ImportStatement wholePackage (String pckg ) {
55- ImportStatement is = new ImportStatement ();
56- is .packageName = pckg ;
57- is .className = "*" ;
58- is .isStarred = true ;
59- return is ;
60- }
54+ public static ImportStatement wholePackage (String pckg ) {
55+ ImportStatement is = new ImportStatement ();
56+ is .packageName = pckg ;
57+ is .className = "*" ;
58+ is .isStarred = true ;
59+ return is ;
60+ }
6161
62- public static ImportStatement singleClass (String cls ) {
63- ImportStatement is = new ImportStatement ();
64- int lastDot = cls .lastIndexOf ('.' );
65- is .className = lastDot >= 0 ? cls .substring (lastDot +1 ) : cls ;
66- is .packageName = lastDot >= 0 ? cls .substring (0 , lastDot ) : "" ;
67- is .isClass = true ;
68- return is ;
69- }
62+ public static ImportStatement singleClass (String cls ) {
63+ ImportStatement is = new ImportStatement ();
64+ int lastDot = cls .lastIndexOf ('.' );
65+ is .className = lastDot >= 0 ? cls .substring (lastDot +1 ) : cls ;
66+ is .packageName = lastDot >= 0 ? cls .substring (0 , lastDot ) : "" ;
67+ is .isClass = true ;
68+ return is ;
69+ }
7070
7171
7272
73- public static ImportStatement parse (String importString ) {
74- Matcher matcher = SourceUtils .IMPORT_REGEX_NO_KEYWORD .matcher (importString );
75- if (!matcher .find ()) return null ;
73+ public static ImportStatement parse (String importString ) {
74+ Matcher matcher = SourceUtils .IMPORT_REGEX_NO_KEYWORD .matcher (importString );
75+ if (!matcher .find ()) return null ;
7676
77- return parse (matcher .toMatchResult ());
78- }
77+ return parse (matcher .toMatchResult ());
78+ }
7979
80- public static ImportStatement parse (MatchResult match ) {
81- ImportStatement is = new ImportStatement ();
80+ public static ImportStatement parse (MatchResult match ) {
81+ ImportStatement is = new ImportStatement ();
8282
83- is .isStatic = match .group (2 ) != null ;
84- String pckg = match .group (3 );
85- pckg = (pckg == null ) ? "" : pckg .replaceAll ("\\ s" ,"" );
86- is .packageName = pckg .endsWith ("." ) ?
87- pckg .substring (0 , pckg .length ()-1 ) :
88- pckg ;
83+ is .isStatic = match .group (2 ) != null ;
84+ String pckg = match .group (3 );
85+ pckg = (pckg == null ) ? "" : pckg .replaceAll ("\\ s" ,"" );
86+ is .packageName = pckg .endsWith ("." ) ?
87+ pckg .substring (0 , pckg .length ()-1 ) :
88+ pckg ;
8989
90- is .className = match .group (4 );
91- is .isStarred = is .className .equals ("*" );
90+ is .className = match .group (4 );
91+ is .isStarred = is .className .equals ("*" );
9292
93- return is ;
94- }
93+ return is ;
94+ }
9595
9696
9797
98- public String getFullSourceLine () {
99- return importKw + " " + (isStatic ? (staticKw + " " ) : "" ) + packageName + "." + className + ";" ;
100- }
98+ public String getFullSourceLine () {
99+ return importKw + " " + (isStatic ? (staticKw + " " ) : "" ) + packageName + "." + className + ";" ;
100+ }
101101
102- public String getFullClassName (){
103- return packageName + "." + className ;
104- }
102+ public String getFullClassName (){
103+ return packageName + "." + className ;
104+ }
105105
106- public String getClassName (){
107- return className ;
108- }
106+ public String getClassName (){
107+ return className ;
108+ }
109109
110- public String getPackageName (){
111- return packageName ;
112- }
110+ public String getPackageName (){
111+ return packageName ;
112+ }
113113
114- public boolean isStarredImport () {
115- return isStarred ;
116- }
114+ public boolean isStarredImport () {
115+ return isStarred ;
116+ }
117117
118- public boolean isStaticImport () {
119- return isStatic ;
120- }
118+ public boolean isStaticImport () {
119+ return isStatic ;
120+ }
121121
122- public boolean isSameAs (ImportStatement is ) {
123- return packageName .equals (is .packageName ) &&
124- className .equals (is .className ) &&
125- isStatic == is .isStatic ;
126- }
122+ public boolean isSameAs (ImportStatement is ) {
123+ return packageName .equals (is .packageName ) &&
124+ className .equals (is .className ) &&
125+ isStatic == is .isStatic ;
126+ }
127127}
0 commit comments