Ejemplo n.º 1
0
 /**
  * Converts a class name into a (possibly localized) string. Anonymous inner classes gets
  * converted into a localized string.
  *
  * @param t the type of the class whose name is to be rendered
  * @param longform if set, the class' fullname is displayed - if unset the short name is chosen
  *     (w/o package)
  * @param locale the locale in which the string is to be rendered
  * @return localized string representation
  */
 protected String className(ClassType t, boolean longform, Locale locale) {
   Symbol sym = t.tsym;
   if (sym.name.length() == 0 && (sym.flags() & COMPOUND) != 0) {
     StringBuilder s = new StringBuilder(visit(t.supertype_field, locale));
     for (List<Type> is = t.interfaces_field; is.nonEmpty(); is = is.tail) {
       s.append("&");
       s.append(visit(is.head, locale));
     }
     return s.toString();
   } else if (sym.name.length() == 0) {
     String s;
     ClassType norm = (ClassType) t.tsym.type;
     if (norm == null) {
       s = localize(locale, "compiler.misc.anonymous.class", (Object) null);
     } else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
       s =
           localize(
               locale, "compiler.misc.anonymous.class", visit(norm.interfaces_field.head, locale));
     } else {
       s = localize(locale, "compiler.misc.anonymous.class", visit(norm.supertype_field, locale));
     }
     return s;
   } else if (longform) {
     return sym.getQualifiedName().toString();
   } else {
     return sym.name.toString();
   }
 }
Ejemplo n.º 2
0
 @Override
 public String visitWildcardType(WildcardType t, Locale locale) {
   StringBuilder s = new StringBuilder();
   s.append(t.kind);
   if (t.kind != UNBOUND) {
     s.append(visit(t.type, locale));
   }
   return s.toString();
 }
Ejemplo n.º 3
0
 @Override
 public String visitClassType(ClassType t, Locale locale) {
   StringBuilder buf = new StringBuilder();
   if (t.getEnclosingType().tag == CLASS && t.tsym.owner.kind == Kinds.TYP) {
     buf.append(visit(t.getEnclosingType(), locale));
     buf.append('.');
     buf.append(className(t, false, locale));
   } else {
     buf.append(className(t, true, locale));
   }
   if (t.getTypeArguments().nonEmpty()) {
     buf.append('<');
     buf.append(visitTypes(t.getTypeArguments(), locale));
     buf.append('>');
   }
   return buf.toString();
 }
Ejemplo n.º 4
0
 /**
  * Converts a set of method argument types into their corresponding localized string
  * representation.
  *
  * @param args arguments to be rendered
  * @param varArgs if true, the last method argument is regarded as a vararg
  * @param locale the locale in which the string is to be rendered
  * @return localized string representation
  */
 protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) {
   if (!varArgs) {
     return visitTypes(args, locale);
   } else {
     StringBuilder buf = new StringBuilder();
     while (args.tail.nonEmpty()) {
       buf.append(visit(args.head, locale));
       args = args.tail;
       buf.append(',');
     }
     if (args.head.unannotatedType().getKind() == TypeKind.ARRAY) {
       buf.append(visit(((ArrayType) args.head.unannotatedType()).elemtype, locale));
       if (args.head.getAnnotations().nonEmpty()) {
         buf.append(' ');
         buf.append(args.head.getAnnotations());
         buf.append(' ');
       }
       buf.append("...");
     } else {
       buf.append(visit(args.head, locale));
     }
     return buf.toString();
   }
 }