private static String removeGenericAnnotations()

in jdk-annotations/astubx-generator/src/main/java/com/uber/nullaway/jdkannotations/AstubxGenerator.java [354:380]


  private static String removeGenericAnnotations(String typeSignature) {
    if (typeSignature.indexOf('<') != -1) {
      StringBuilder withoutGenericAnnotations = new StringBuilder();
      int depth = 0;
      int annotationDepth = 0;
      for (int j = 0; j < typeSignature.length(); j++) {
        char ch = typeSignature.charAt(j);
        if (ch == '<') {
          depth++;
          withoutGenericAnnotations.append(ch);
        } else if (ch == '>') {
          depth = Math.max(0, depth - 1);
          withoutGenericAnnotations.append(ch);
        } else if (depth == 0) {
          withoutGenericAnnotations.append(ch);
        } else if (ch == '@') {
          annotationDepth++;
        } else if (ch == ' ' && annotationDepth != 0) {
          annotationDepth = Math.max(0, annotationDepth - 1);
        } else if (annotationDepth == 0) {
          withoutGenericAnnotations.append(ch);
        }
      }
      typeSignature = withoutGenericAnnotations.toString().trim();
    }
    return typeSignature;
  }