@Test public void testGetPackageName() { CompileUnit cu = new CompileUnit("org.big.comp.MyClass"); assertEquals("org.big.comp", cu.getRootPackageName()); cu = new CompileUnit("a.MyClass"); assertEquals("a", cu.getRootPackageName()); cu = new CompileUnit("a.b.MyClass"); assertEquals("a.b", cu.getRootPackageName()); cu = new CompileUnit("MyClass"); assertNull(cu.getRootPackageName()); }
public String getRootPackageName() { int dotPos = classCanonName.lastIndexOf("."); if (dotPos > 0) { return classCanonName.substring(0, dotPos); } else { return null; } }
CompileUnit { public String getRootPackageName() { int dotPos = classCanonName.lastIndexOf("."); if (dotPos > 0) { return classCanonName.substring(0, dotPos); } else { return null; } } }
CompileUnit { public String getRootPackageName() { int dotPos = classCanonName.lastIndexOf("."); if (dotPos > 0) { return classCanonName.substring(0, dotPos); } else { return null; } } CompileUnit(String classCanonName); }
CompileUnit { public String getRootPackageName() { int dotPos = classCanonName.lastIndexOf("."); if (dotPos > 0) { return classCanonName.substring(0, dotPos); } else { return null; } } CompileUnit(String classCanonName); boolean isInitClass(); void setInitClass(boolean initClass); boolean istestInitClass(); void setTestInitClass(boolean testInitClass); void pushType(SimpleType simpleName); void pushType(String name, boolean _static); SimpleType popType(); boolean addProperty(String name, boolean _static, boolean _final); List<SimpleType> getInnerPath(); List<String> getInnerPathNames(); String getRootCanonicalName(); String getRootSimpleName(); String getRootPackageName(); PropertyRegistrationList getRegistrations(); List<CompileProblem> getProblems(); boolean hasErrors(); boolean hasRegistrations(); }
CompileUnit { public String getRootPackageName() { int dotPos = classCanonName.lastIndexOf("."); if (dotPos > 0) { return classCanonName.substring(0, dotPos); } else { return null; } } CompileUnit(String classCanonName); boolean isInitClass(); void setInitClass(boolean initClass); boolean istestInitClass(); void setTestInitClass(boolean testInitClass); void pushType(SimpleType simpleName); void pushType(String name, boolean _static); SimpleType popType(); boolean addProperty(String name, boolean _static, boolean _final); List<SimpleType> getInnerPath(); List<String> getInnerPathNames(); String getRootCanonicalName(); String getRootSimpleName(); String getRootPackageName(); PropertyRegistrationList getRegistrations(); List<CompileProblem> getProblems(); boolean hasErrors(); boolean hasRegistrations();  }