1 16 17 package com.google.inject.util; 18 19 import net.sf.cglib.core.NamingPolicy; 20 import net.sf.cglib.core.Predicate; 21 22 27 public class GuiceNamingPolicy implements NamingPolicy { 28 29 public String getClassName(String prefix, String source, Object key, 30 Predicate names) { 31 StringBuffer sb = new StringBuffer (); 32 sb.append( 33 (prefix != null) ? 34 ( 35 prefix.startsWith("java") ? 36 "$" + prefix : prefix 37 ) 38 : "net.sf.cglib.empty.Object" 39 ); 40 sb.append("$$"); 41 sb.append(source.substring(source.lastIndexOf('.') + 1)); 42 sb.append("ByGuice$$"); 43 sb.append(Integer.toHexString(key.hashCode())); 44 String base = sb.toString(); 45 String attempt = base; 46 int index = 2; 47 while (names.evaluate(attempt)) { 48 attempt = base + "_" + index++; 49 } 50 51 return attempt; 52 } 53 } 54 | Popular Tags |