< 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         try {
238             if (t.isReferenceProjection()) {
239                 buf.append('.');
240                 buf.append(t.tsym.name.table.names.ref);
241             } else if (t.isValueProjection()) {
242                 buf.append('.');
243                 buf.append(t.tsym.name.table.names.val);
244             }
245         } catch (CompletionFailure cf) {
246             // don't let missing types capsize the boat.
247         }
248 
249         if (t.getTypeArguments().nonEmpty()) {
250             buf.append('<');
251             buf.append(visitTypes(t.getTypeArguments(), locale));
252             buf.append('>');
253         }
254         return buf.toString();
255     }
256 
257     @Override
258     public String visitMethodType(MethodType t, Locale locale) {
259         return "(" + printMethodArgs(t.argtypes, false, locale) + ")" +
260             visit(t.restype, locale);
261     }
262 
263     @Override
264     public String visitPackageType(PackageType t, Locale locale) {
265         return t.tsym.getQualifiedName().toString();
266     }
267 
268     @Override

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