/* * Replace Placeholders for repeating annotations with their containers */ private <T extends Attribute.Compound> void complete(Annotate.AnnotateRepeatedContext<T> ctx) { Log log = ctx.log; Env<AttrContext> env = ctx.env; JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile); try { // TODO: can we reduce duplication in the following branches? if (ctx.isTypeCompound) { Assert.check(!isTypesEmpty()); if (isTypesEmpty()) { return; } List<Attribute.TypeCompound> result = List.nil(); for (Attribute.TypeCompound a : getTypeAttributes()) { if (a instanceof Placeholder) { @SuppressWarnings("unchecked") Placeholder<Attribute.TypeCompound> ph = (Placeholder<Attribute.TypeCompound>) a; Attribute.TypeCompound replacement = replaceOne(ph, ph.getRepeatedContext()); if (null != replacement) { result = result.prepend(replacement); } } else { result = result.prepend(a); } } type_attributes = result.reverse(); Assert.check(Annotations.this.getTypePlaceholders().isEmpty()); } else { Assert.check(!pendingCompletion()); if (isEmpty()) { return; } List<Attribute.Compound> result = List.nil(); for (Attribute.Compound a : getDeclarationAttributes()) { if (a instanceof Placeholder) { @SuppressWarnings("unchecked") Attribute.Compound replacement = replaceOne((Placeholder<T>) a, ctx); if (null != replacement) { result = result.prepend(replacement); } } else { result = result.prepend(a); } } attributes = result.reverse(); Assert.check(Annotations.this.getPlaceholders().isEmpty()); } } finally { log.useSource(oldSource); } }
public void visitTopLevel(JCCompilationUnit tree) { JavaFileObject prev = log.useSource(tree.sourcefile); boolean addEnv = false; boolean isPkgInfo = tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE); if (tree.pid != null) { tree.packge = reader.enterPackage(TreeInfo.fullName(tree.pid)); if (tree.packageAnnotations.nonEmpty()) { if (isPkgInfo) { addEnv = true; } else { log.error(tree.packageAnnotations.head.pos(), "pkg.annotations.sb.in.package-info.java"); } } } else { tree.packge = syms.unnamedPackage; } tree.packge.complete(); // Find all classes in package. Env<AttrContext> env = topLevelEnv(tree); // Save environment of package-info.java file. if (isPkgInfo) { Env<AttrContext> env0 = typeEnvs.get(tree.packge); if (env0 == null) { typeEnvs.put(tree.packge, env); } else { JCCompilationUnit tree0 = env0.toplevel; if (!fileManager.isSameFile(tree.sourcefile, tree0.sourcefile)) { log.warning( tree.pid != null ? tree.pid.pos() : null, "pkg-info.already.seen", tree.packge); if (addEnv || (tree0.packageAnnotations.isEmpty() && tree.docComments != null && tree.docComments.get(tree) != null)) { typeEnvs.put(tree.packge, env); } } } } classEnter(tree.defs, env); if (addEnv) { todo.append(env); } log.useSource(prev); result = null; }
/** * Main method: enter one class from a list of toplevel trees and place the rest on uncompleted * for later processing. * * @param trees The list of trees to be processed. * @param c The class symbol to be processed. */ public void complete(List<JCCompilationUnit> trees, ClassSymbol c) { annotate.enterStart(); ListBuffer<ClassSymbol> prevUncompleted = uncompleted; if (memberEnter.completionEnabled) uncompleted = new ListBuffer<ClassSymbol>(); try { // enter all classes, and construct uncompleted list classEnter(trees, null); // complete all uncompleted classes in memberEnter if (memberEnter.completionEnabled) { while (uncompleted.nonEmpty()) { ClassSymbol clazz = uncompleted.next(); if (c == null || c == clazz || prevUncompleted == null) clazz.complete(); else // defer prevUncompleted.append(clazz); } // if there remain any unimported toplevels (these must have // no classes at all), process their import statements as well. for (JCCompilationUnit tree : trees) { if (tree.starImportScope.elems == null) { JavaFileObject prev = log.useSource(tree.sourcefile); Env<AttrContext> env = typeEnvs.get(tree); if (env == null) env = topLevelEnv(tree); memberEnter.memberEnter(tree, env); log.useSource(prev); } } } } finally { uncompleted = prevUncompleted; annotate.enterDone(); } }