ClassNameUtils { public static List<String> parseTypeParameter(final String str) { if (isNull(str) || str.isEmpty()) { return Collections.emptyList(); } final List<String> result = new ArrayList<>(4); final int idx = str.indexOf('<'); if (idx >= 0) { String gen = str.substring(idx + 1, str.length() - 1); int indent = 0; StringBuilder sb = new StringBuilder(16); boolean wild = false; int len = gen.length(); for (int i = 0; i < len; i++) { char c = gen.charAt(i); switch (c) { case '?': if (indent == 0) { sb.append(c); wild = true; } else { sb.append(c); } continue; case '<': sb.append(c); indent++; continue; case '>': indent--; if (indent < 0) { if (sb.length() > 0) { result.add(sb.toString()); } return result; } sb.append(c); continue; case ' ': if (wild) { sb.append(c); } else if (indent > 0) { sb.append(c); } continue; case ',': if (indent == 0 && sb.length() > 0) { wild = false; result.add(sb.toString()); sb.setLength(0); } else { sb.append(c); sb.append(' '); } continue; default: sb.append(c); } } if (sb.length() > 0) { result.add(sb.toString()); } return result; } return Collections.emptyList(); } private  ClassNameUtils(); static boolean isPrimitive(final String className); static boolean isArray(final String name); static String replaceFromMap(final String string, final Map<String, String> replacements); static String replaceDot2FileSep(final String string); static String replaceSlash(String string); static String getParentClass(final String name); static String replaceInnerMark(final String string); static String replaceDotToInnerMark(String string, boolean last); static String removeTypeMark(final String val); static Optional<String> toInnerClassName(final String name); static boolean hasPackage(String name); static String getSimpleName(final String fqcn); static String getPackage(final String fqcn); static Optional<String> getTypeVariable(final String val); static String removeTypeParameter(String name); static String removeTypeAndArray(String name); static List<String> parseTypeParameter(final String str); static String removeCapture(final String name); static String removeCaptureAndWildCard(final String name); static String getAllSimpleName(final String name); static String removeWildcard(final String name); static boolean compareArgumentType(
      List<String> arguments, List<String> parameters, boolean hasVarargs); static boolean isAnonymousClass(final String name); static void replaceDescriptorsType(
      final String nameWithTP, final List<MemberDescriptor> members); static String getClassName(final String s); static final String OBJECT_CLASS; static final String OBJECT; static final String CLASS_TYPE_VARIABLE_MARK; static final String FORMAL_TYPE_VARIABLE_MARK; static final String INNER_MARK; static final String CAPTURE_OF; static final String ARRAY; }
@Test public void parseTypeParameter1() throws Exception { String name = "java.util.stream.BaseStream<T, java.util.stream.Stream<T>>"; List<String> typeParams = ClassNameUtils.parseTypeParameter(name); assertEquals("T", typeParams.get(0)); assertEquals("java.util.stream.Stream<T>", typeParams.get(1)); }
@Test public void parseTypeParameter2() throws Exception { String name = "java.util.Enumeration<? extends ZipEntry>"; List<String> typeParams = ClassNameUtils.parseTypeParameter(name); assertEquals("? extends ZipEntry", typeParams.get(0)); }
@Test public void parseTypeParameter3() throws Exception { String name = "java.util.Map<? extends String, ? extends Long>"; List<String> typeParams = ClassNameUtils.parseTypeParameter(name); assertEquals("? extends String", typeParams.get(0)); assertEquals("? extends Long", typeParams.get(1)); }
@Test public void parseTypeParameter4() throws Exception { String name = "java.util.stream.Stream<java.util.stream.Stream<java.util.List<java.lang.String>>>"; List<String> typeParams = ClassNameUtils.parseTypeParameter(name); assertEquals("java.util.stream.Stream<java.util.List<java.lang.String>>", typeParams.get(0)); }
@Test public void parseTypeParameter5() throws Exception { String name = "java.util.Map<? extends List<String>, ? extends Long>"; List<String> typeParams = ClassNameUtils.parseTypeParameter(name); assertEquals("? extends List<String>", typeParams.get(0)); assertEquals("? extends Long", typeParams.get(1)); }
@Test public void parseTypeParameter6() throws Exception { String name = "java.util.List<java.util.List<? extends String>>"; List<String> typeParams = ClassNameUtils.parseTypeParameter(name); assertEquals("java.util.List<? extends String>", typeParams.get(0)); }
@Test public void parseTypeParameter7() throws Exception { String name = "meghanada.SelfRef1<T>$Ref"; List<String> typeParams = ClassNameUtils.parseTypeParameter(name); assertEquals("T", typeParams.get(0)); }