1 package net.sourceforge.importscrubber; 2 3 6 public class PackageStmt 7 { 8 public static final String MARKER = "package "; 9 10 private final String _stmt; 11 private final boolean _isInDefaultPackage; 12 private final String _myPkg; 13 14 19 public PackageStmt(String stmt) 20 { 21 this(stmt, false); 22 } 23 24 27 public PackageStmt() 28 { 29 this(null, true); 30 } 31 32 private PackageStmt(String stmt, boolean inDefaultPackage) 33 { 34 _stmt = stmt; 35 _isInDefaultPackage = inDefaultPackage; 36 if (!_isInDefaultPackage) { 37 int firstSpace = _stmt.indexOf(" ") + 1; 38 int semiColon = _stmt.indexOf(";"); 39 _myPkg = _stmt.substring(firstSpace, semiColon); 40 } else { 41 _myPkg = null; 42 } 43 } 44 45 public String getPkg() 46 { 47 return _myPkg; 48 } 49 50 public boolean isInSamePackageAs(ImportStatement importStmt) 51 { 52 if (_isInDefaultPackage) { 53 return false; } 55 return importStmt.getPackage().compareTo(_myPkg) == 0; 56 } 57 58 public StringBuffer getOutput() 59 { 60 StringBuffer buffer = new StringBuffer (64); 61 if (_isInDefaultPackage) { 62 return buffer; 63 } 64 buffer.append(_stmt); 65 buffer.append(ImportScrubber.LINE_SEPARATOR); 66 buffer.append(ImportScrubber.LINE_SEPARATOR); 67 return buffer; 68 } 69 } 70 71 72 | Popular Tags |