protected void printSymbol(String label, Symbol sym, Details details) { if (sym == null) { printNull(label); } else { switch (details) { case SUMMARY: printString(label, toString(sym)); break; case FULL: indent(); out.print(label); out.println( ": " + info( sym.getClass(), String.format("0x%x--%s", sym.kind.ordinal(), Kinds.kindName(sym)), sym.getKind()) + " " + sym.name + " " + hashString(sym)); indent(+1); if (showSrc) { JCTree tree = (JCTree) trees.getTree(sym); if (tree != null) printSource("src", tree); } printString( "flags", String.format("0x%x--%s", sym.flags_field, Flags.toString(sym.flags_field))); printObject("completer", sym.completer, Details.SUMMARY); // what if too long? printSymbol("owner", sym.owner, Details.SUMMARY); printType("type", sym.type, Details.SUMMARY); printType("erasure", sym.erasure_field, Details.SUMMARY); sym.accept(symVisitor, null); printAnnotations("annotations", sym.getMetadata(), Details.SUMMARY); indent(-1); } } }
@Override public Void visitTypeVar(TypeVar t, Void ignored) { if (indexOf(t, WhereClauseKind.TYPEVAR) == -1) { // access the bound type and skip error types Type bound = t.bound; while ((bound instanceof ErrorType)) bound = ((ErrorType) bound).getOriginalType(); // retrieve the bound list - if the type variable // has not been attributed the bound is not set List<Type> bounds = (bound != null && bound.tsym != null) ? types.getBounds(t) : List.<Type>nil(); nameSimplifier.addUsage(t.tsym); boolean boundErroneous = bounds.head == null || bounds.head.tag == NONE || bounds.head.tag == ERROR; if ((t.tsym.flags() & SYNTHETIC) == 0) { // this is a true typevar JCDiagnostic d = diags.fragment( "where.typevar" + (boundErroneous ? ".1" : ""), t, bounds, Kinds.kindName(t.tsym.location()), t.tsym.location()); whereClauses.get(WhereClauseKind.TYPEVAR).put(t, d); symbolPreprocessor.visit(t.tsym.location(), null); visit(bounds); } else { Assert.check(!boundErroneous); // this is a fresh (synthetic) tvar JCDiagnostic d = diags.fragment("where.fresh.typevar", t, bounds); whereClauses.get(WhereClauseKind.TYPEVAR).put(t, d); visit(bounds); } } return null; }
Attribute enterAttributeValue(Type expected, JCExpression tree, Env<AttrContext> env) { // first, try completing the attribution value sym - if a completion // error is thrown, we should recover gracefully, and display an // ordinary resolution diagnostic. try { expected.tsym.complete(); } catch (CompletionFailure e) { log.error(tree.pos(), "cant.resolve", Kinds.kindName(e.sym), e.sym); return new Attribute.Error(expected); } if (expected.isPrimitive() || types.isSameType(expected, syms.stringType)) { Type result = attr.attribExpr(tree, env, expected); if (result.isErroneous()) return new Attribute.Error(expected); if (result.constValue() == null) { log.error(tree.pos(), "attribute.value.must.be.constant"); return new Attribute.Error(expected); } result = cfolder.coerce(result, expected); return new Attribute.Constant(expected, result.constValue()); } if (expected.tsym == syms.classType.tsym) { Type result = attr.attribExpr(tree, env, expected); if (result.isErroneous()) return new Attribute.Error(expected); if (TreeInfo.name(tree) != names._class) { log.error(tree.pos(), "annotation.value.must.be.class.literal"); return new Attribute.Error(expected); } return new Attribute.Class(types, (((JCFieldAccess) tree).selected).type); } if ((expected.tsym.flags() & Flags.ANNOTATION) != 0 || types.isSameType(expected, syms.annotationType)) { if (tree.getTag() != JCTree.ANNOTATION) { log.error(tree.pos(), "annotation.value.must.be.annotation"); expected = syms.errorType; } return enterAnnotation((JCAnnotation) tree, expected, env); } if (expected.tag == TypeTags.ARRAY) { // should really be isArray() if (tree.getTag() != JCTree.NEWARRAY) { tree = make.at(tree.pos).NewArray(null, List.<JCExpression>nil(), List.of(tree)); } JCNewArray na = (JCNewArray) tree; if (na.elemtype != null) { log.error(na.elemtype.pos(), "new.not.allowed.in.annotation"); return new Attribute.Error(expected); } ListBuffer<Attribute> buf = new ListBuffer<Attribute>(); for (List<JCExpression> l = na.elems; l.nonEmpty(); l = l.tail) { buf.append(enterAttributeValue(types.elemtype(expected), l.head, env)); } na.type = expected; return new Attribute.Array(expected, buf.toArray(new Attribute[buf.length()])); } if (expected.tag == TypeTags.CLASS && (expected.tsym.flags() & Flags.ENUM) != 0) { attr.attribExpr(tree, env, expected); Symbol sym = TreeInfo.symbol(tree); if (sym == null || TreeInfo.nonstaticSelect(tree) || sym.kind != Kinds.VAR || (sym.flags() & Flags.ENUM) == 0) { log.error(tree.pos(), "enum.annotation.must.be.enum.constant"); return new Attribute.Error(expected); } VarSymbol enumerator = (VarSymbol) sym; return new Attribute.Enum(expected, enumerator); } if (!expected.isErroneous()) log.error(tree.pos(), "annotation.value.not.allowable.type"); return new Attribute.Error(attr.attribExpr(tree, env, expected)); }