< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Printer.java

Print this page

217         Type arrel = t;
218         while (arrel.hasTag(TypeTag.ARRAY)) {
219             sb.append(printAnnotations(arrel, true));
220             sb.append("[]");
221             arrel = ((ArrayType) arrel).elemtype;
222         }
223     }
224 
225     @Override
226     public String visitClassType(ClassType t, Locale locale) {
227         StringBuilder buf = new StringBuilder();
228         if (t.getEnclosingType().hasTag(CLASS) && t.tsym.owner.kind == TYP) {
229             buf.append(visit(t.getEnclosingType(), locale));
230             buf.append('.');
231             buf.append(printAnnotations(t));
232             buf.append(className(t, false, locale));
233         } else {
234             buf.append(printAnnotations(t));
235             buf.append(className(t, true, locale));
236         }










237         if (t.getTypeArguments().nonEmpty()) {
238             buf.append('<');
239             buf.append(visitTypes(t.getTypeArguments(), locale));
240             buf.append('>');
241         }
242         return buf.toString();
243     }
244 
245     @Override
246     public String visitMethodType(MethodType t, Locale locale) {
247         return "(" + printMethodArgs(t.argtypes, false, locale) + ")" +
248             visit(t.restype, locale);
249     }
250 
251     @Override
252     public String visitPackageType(PackageType t, Locale locale) {
253         return t.tsym.getQualifiedName().toString();
254     }
255 
256     @Override

301         if (sym.name.length() == 0 && (sym.flags() & COMPOUND) != 0) {
302             StringBuilder s = new StringBuilder(visit(t.supertype_field, locale));
303             for (List<Type> is = t.interfaces_field; is.nonEmpty(); is = is.tail) {
304                 s.append('&');
305                 s.append(visit(is.head, locale));
306             }
307             return s.toString();
308         } else if (sym.name.length() == 0) {
309             String s;
310             ClassType norm = (ClassType) t.tsym.type;
311             if (norm == null) {
312                 s = localize(locale, "compiler.misc.anonymous.class", (Object) null);
313             } else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
314                 s = localize(locale, "compiler.misc.anonymous.class",
315                         visit(norm.interfaces_field.head, locale));
316             } else {
317                 s = localize(locale, "compiler.misc.anonymous.class",
318                         visit(norm.supertype_field, locale));
319             }
320             return s;
321         } else if (longform) {
322             return sym.getQualifiedName().toString();


323         } else {
324             return sym.name.toString();
325         }


326     }
327 
328     /**
329      * Converts a set of method argument types into their corresponding
330      * localized string representation.
331      *
332      * @param args arguments to be rendered
333      * @param varArgs if true, the last method argument is regarded as a vararg
334      * @param locale the locale in which the string is to be rendered
335      * @return localized string representation
336      */
337     protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) {
338         if (!varArgs) {
339             return visitTypes(args, locale);
340         } else {
341             StringBuilder buf = new StringBuilder();
342             while (args.tail.nonEmpty()) {
343                 buf.append(visit(args.head, locale));
344                 args = args.tail;
345                 buf.append(',');

217         Type arrel = t;
218         while (arrel.hasTag(TypeTag.ARRAY)) {
219             sb.append(printAnnotations(arrel, true));
220             sb.append("[]");
221             arrel = ((ArrayType) arrel).elemtype;
222         }
223     }
224 
225     @Override
226     public String visitClassType(ClassType t, Locale locale) {
227         StringBuilder buf = new StringBuilder();
228         if (t.getEnclosingType().hasTag(CLASS) && t.tsym.owner.kind == TYP) {
229             buf.append(visit(t.getEnclosingType(), locale));
230             buf.append('.');
231             buf.append(printAnnotations(t));
232             buf.append(className(t, false, locale));
233         } else {
234             buf.append(printAnnotations(t));
235             buf.append(className(t, true, locale));
236         }
237         boolean isReferenceProjection;
238         try {
239             isReferenceProjection = t.isReferenceProjection();
240         } catch (CompletionFailure cf) {
241             isReferenceProjection = false; // handle missing types gracefully.
242         }
243         if (isReferenceProjection) {
244             buf.append('.');
245             buf.append(t.tsym.name.table.names.ref);
246         }
247         if (t.getTypeArguments().nonEmpty()) {
248             buf.append('<');
249             buf.append(visitTypes(t.getTypeArguments(), locale));
250             buf.append('>');
251         }
252         return buf.toString();
253     }
254 
255     @Override
256     public String visitMethodType(MethodType t, Locale locale) {
257         return "(" + printMethodArgs(t.argtypes, false, locale) + ")" +
258             visit(t.restype, locale);
259     }
260 
261     @Override
262     public String visitPackageType(PackageType t, Locale locale) {
263         return t.tsym.getQualifiedName().toString();
264     }
265 
266     @Override

311         if (sym.name.length() == 0 && (sym.flags() & COMPOUND) != 0) {
312             StringBuilder s = new StringBuilder(visit(t.supertype_field, locale));
313             for (List<Type> is = t.interfaces_field; is.nonEmpty(); is = is.tail) {
314                 s.append('&');
315                 s.append(visit(is.head, locale));
316             }
317             return s.toString();
318         } else if (sym.name.length() == 0) {
319             String s;
320             ClassType norm = (ClassType) t.tsym.type;
321             if (norm == null) {
322                 s = localize(locale, "compiler.misc.anonymous.class", (Object) null);
323             } else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
324                 s = localize(locale, "compiler.misc.anonymous.class",
325                         visit(norm.interfaces_field.head, locale));
326             } else {
327                 s = localize(locale, "compiler.misc.anonymous.class",
328                         visit(norm.supertype_field, locale));
329             }
330             return s;
331         }
332         String s;
333         if (longform) {
334              s =  sym.getQualifiedName().toString();
335         } else {
336             s =  sym.name.toString();
337         }
338 
339         return s;
340     }
341 
342     /**
343      * Converts a set of method argument types into their corresponding
344      * localized string representation.
345      *
346      * @param args arguments to be rendered
347      * @param varArgs if true, the last method argument is regarded as a vararg
348      * @param locale the locale in which the string is to be rendered
349      * @return localized string representation
350      */
351     protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) {
352         if (!varArgs) {
353             return visitTypes(args, locale);
354         } else {
355             StringBuilder buf = new StringBuilder();
356             while (args.tail.nonEmpty()) {
357                 buf.append(visit(args.head, locale));
358                 args = args.tail;
359                 buf.append(',');
< prev index next >