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

changeset 1570
f91144b7da75
parent 1521
71f35e4b93a5
child 1645
97f6839673d6
equal deleted inserted replaced
1569:475eb15dfdad 1570:f91144b7da75
1 /* 1 /*
2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
25 25
26 package com.sun.tools.javac.code; 26 package com.sun.tools.javac.code;
27 27
28 import java.util.Locale; 28 import java.util.Locale;
29 29
30 import javax.lang.model.type.TypeKind;
31
30 import com.sun.tools.javac.api.Messages; 32 import com.sun.tools.javac.api.Messages;
33 import com.sun.tools.javac.code.Type.AnnotatedType;
31 import com.sun.tools.javac.code.Symbol.*; 34 import com.sun.tools.javac.code.Symbol.*;
32 import com.sun.tools.javac.code.Type.*; 35 import com.sun.tools.javac.code.Type.*;
33 import com.sun.tools.javac.util.List; 36 import com.sun.tools.javac.util.List;
34 import com.sun.tools.javac.util.ListBuffer; 37 import com.sun.tools.javac.util.ListBuffer;
35 38
36 import static com.sun.tools.javac.code.BoundKind.*; 39 import static com.sun.tools.javac.code.BoundKind.*;
37 import static com.sun.tools.javac.code.Flags.*; 40 import static com.sun.tools.javac.code.Flags.*;
38 import static com.sun.tools.javac.code.TypeTag.ARRAY;
39 import static com.sun.tools.javac.code.TypeTag.CLASS; 41 import static com.sun.tools.javac.code.TypeTag.CLASS;
40 import static com.sun.tools.javac.code.TypeTag.FORALL; 42 import static com.sun.tools.javac.code.TypeTag.FORALL;
41 43
42 /** 44 /**
43 * A combined type/symbol visitor for generating non-trivial localized string 45 * A combined type/symbol visitor for generating non-trivial localized string
186 @Override 188 @Override
187 public String visitClassType(ClassType t, Locale locale) { 189 public String visitClassType(ClassType t, Locale locale) {
188 StringBuilder buf = new StringBuilder(); 190 StringBuilder buf = new StringBuilder();
189 if (t.getEnclosingType().tag == CLASS && t.tsym.owner.kind == Kinds.TYP) { 191 if (t.getEnclosingType().tag == CLASS && t.tsym.owner.kind == Kinds.TYP) {
190 buf.append(visit(t.getEnclosingType(), locale)); 192 buf.append(visit(t.getEnclosingType(), locale));
191 buf.append("."); 193 buf.append('.');
192 buf.append(className(t, false, locale)); 194 buf.append(className(t, false, locale));
193 } else { 195 } else {
194 buf.append(className(t, true, locale)); 196 buf.append(className(t, true, locale));
195 } 197 }
196 if (t.getTypeArguments().nonEmpty()) { 198 if (t.getTypeArguments().nonEmpty()) {
197 buf.append('<'); 199 buf.append('<');
198 buf.append(visitTypes(t.getTypeArguments(), locale)); 200 buf.append(visitTypes(t.getTypeArguments(), locale));
199 buf.append(">"); 201 buf.append('>');
200 } 202 }
201 return buf.toString(); 203 return buf.toString();
202 } 204 }
203 205
204 @Override 206 @Override
227 } 229 }
228 230
229 @Override 231 @Override
230 public String visitTypeVar(TypeVar t, Locale locale) { 232 public String visitTypeVar(TypeVar t, Locale locale) {
231 return visitType(t, locale); 233 return visitType(t, locale);
234 }
235
236 @Override
237 public String visitAnnotatedType(AnnotatedType t, Locale locale) {
238 if (t.typeAnnotations != null &&
239 t.typeAnnotations.nonEmpty()) {
240 // TODO: better logic for arrays, ...
241 return "(" + t.typeAnnotations + " :: " + visit(t.underlyingType, locale) + ")";
242 } else {
243 return "({} :: " + visit(t.underlyingType, locale) + ")";
244 }
232 } 245 }
233 246
234 public String visitType(Type t, Locale locale) { 247 public String visitType(Type t, Locale locale) {
235 String s = (t.tsym == null || t.tsym.name == null) 248 String s = (t.tsym == null || t.tsym.name == null)
236 ? localize(locale, "compiler.misc.type.none") 249 ? localize(locale, "compiler.misc.type.none")
294 while (args.tail.nonEmpty()) { 307 while (args.tail.nonEmpty()) {
295 buf.append(visit(args.head, locale)); 308 buf.append(visit(args.head, locale));
296 args = args.tail; 309 args = args.tail;
297 buf.append(','); 310 buf.append(',');
298 } 311 }
299 if (args.head.tag == ARRAY) { 312 if (args.head.unannotatedType().getKind() == TypeKind.ARRAY) {
300 buf.append(visit(((ArrayType) args.head).elemtype, locale)); 313 buf.append(visit(((ArrayType) args.head.unannotatedType()).elemtype, locale));
314 if (args.head.getAnnotations().nonEmpty()) {
315 buf.append(' ');
316 buf.append(args.head.getAnnotations());
317 buf.append(' ');
318 }
301 buf.append("..."); 319 buf.append("...");
302 } else { 320 } else {
303 buf.append(visit(args.head, locale)); 321 buf.append(visit(args.head, locale));
304 } 322 }
305 return buf.toString(); 323 return buf.toString();

mercurial