ClassName { public String getName() { String name = ClassNameUtils.removeCaptureAndWildCard(this.rawName); if (typeIndex >= 0) { final String fst = name.substring(0, typeIndex); if (typeLastIndex > typeIndex) { final String sec = name.substring(typeLastIndex + 1); name = fst + sec; } else { name = fst; } } final int arrayIndex = name.indexOf('['); if (arrayIndex >= 0) { name = name.substring(0, arrayIndex); } return name; } ClassName(String name); boolean hasTypeParameter(); String getName(); @Override String toString(); final String rawName; final int typeIndex; final int typeLastIndex; }
@Test public void getName1() throws Exception { ClassName className = new ClassName("Map.Entry<String, Long>"); String name = className.getName(); assertEquals("Map.Entry", name); }
@Test public void getName2() throws Exception { ClassName className = new ClassName("Map.Entry<String, Long>[]"); String name = className.getName(); assertEquals("Map.Entry", name); }
@Test public void getName3() throws Exception { ClassName className = new ClassName("Map<K, V>.Entry"); String name = className.getName(); assertEquals("Map.Entry", name); }
@Test public void getName4() throws Exception { ClassName className = new ClassName("ThreadLocal<int[]>"); String name = className.getName(); assertEquals("ThreadLocal", name); }
@Test public void getName5() throws Exception { ClassName className = new ClassName("Map<Object[], Void>"); String name = className.getName(); assertEquals("Map", name); }
@Test public void getName6() throws Exception { ClassName className = new ClassName("Map<>"); String name = className.getName(); assertEquals("Map", name); }
@Test public void getName7() throws Exception { ClassName className = new ClassName("Map<K, V>."); String name = className.getName(); assertEquals("Map.", name); }