Esempio 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();
   }
 }
Esempio 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();
 }
 @Override
 public String format(JCDiagnostic diag, Locale l) {
   StringBuilder sb = new StringBuilder();
   nameSimplifier = new ClassNameSimplifier();
   for (WhereClauseKind kind : WhereClauseKind.values()) whereClauses.get(kind).clear();
   preprocessDiagnostic(diag);
   sb.append(formatter.format(diag, l));
   if (getConfiguration().isEnabled(RichFormatterFeature.WHERE_CLAUSES)) {
     List<JCDiagnostic> clauses = getWhereClauses();
     String indent = formatter.isRaw() ? "" : formatter.indentString(DetailsInc);
     for (JCDiagnostic d : clauses) {
       String whereClause = formatter.format(d, l);
       if (whereClause.length() > 0) {
         sb.append('\n' + indent + whereClause);
       }
     }
   }
   return sb.toString();
 }
Esempio n. 4
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();
 }
Esempio n. 5
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();
   }
 }
 public String simplify(Symbol s) {
   String name = s.getQualifiedName().toString();
   if (!s.type.isCompound()) {
     List<Symbol> conflicts = nameClashes.get(s.getSimpleName());
     if (conflicts == null || (conflicts.size() == 1 && conflicts.contains(s))) {
       List<Name> l = List.nil();
       Symbol s2 = s;
       while (s2.type.getEnclosingType().tag == CLASS && s2.owner.kind == Kinds.TYP) {
         l = l.prepend(s2.getSimpleName());
         s2 = s2.owner;
       }
       l = l.prepend(s2.getSimpleName());
       StringBuilder buf = new StringBuilder();
       String sep = "";
       for (Name n2 : l) {
         buf.append(sep);
         buf.append(n2);
         sep = ".";
       }
       name = buf.toString();
     }
   }
   return name;
 }
Esempio n. 7
0
 private static String quoteChars(String s) {
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < s.length(); i++) sb.append(quoteChar(s.charAt(i)));
   return sb.toString();
 }