Here you can find the source of shortenClassName(Class> clazz, int maxLength)
public static String shortenClassName(Class<?> clazz, int maxLength)
//package com.java2s; //License from project: LGPL public class Main { public static String shortenClassName(Class<?> clazz, int maxLength) { String name = clazz.getSimpleName(); Package pkg = clazz.getPackage(); if (pkg == null) { return name; } else {//from ww w.j a va2 s . co m String[] tokens = pkg.getName().split("\\."); boolean shortened = false; for (int i = tokens.length - 1; i > -1; i--) { if (shortened || (name.length() + tokens[i].length() + 1 + (i * 2)) > maxLength) { tokens[i] = tokens[i].substring(0, 1); shortened = true; } name = tokens[i] + "." + name; } } return name; } }