private void handleFlowResults(Queue<Env<AttrContext>> queue, ListBuffer<Element> elems) { for (Env<AttrContext> env: queue) { switch (env.tree.getTag()) { case CLASSDEF: JCClassDecl cdef = (JCClassDecl) env.tree; if (cdef.sym != null) elems.append(cdef.sym); break; case MODULEDEF: JCModuleDecl mod = (JCModuleDecl) env.tree; if (mod.sym != null) elems.append(mod.sym); break; case PACKAGEDEF: JCCompilationUnit unit = env.toplevel; if (unit.packge != null) elems.append(unit.packge); break; } } genList.addAll(queue); }
@Override public void visitModuleDef(JCModuleDecl tree) { sym = Assert.checkNonNull(tree.sym); if (tree.getModuleType() == ModuleKind.OPEN) { sym.flags.add(ModuleFlags.OPEN); } sym.flags_field |= (tree.mods.flags & Flags.DEPRECATED); sym.requires = List.nil(); sym.exports = List.nil(); sym.opens = List.nil(); tree.directives.forEach(t -> t.accept(this)); sym.requires = sym.requires.reverse(); sym.exports = sym.exports.reverse(); sym.opens = sym.opens.reverse(); ensureJavaBase(); }
public Completer getUsesProvidesCompleter() { return sym -> { ModuleSymbol msym = (ModuleSymbol) sym; msym.complete(); Env<AttrContext> env = typeEnvs.get(msym); UsesProvidesVisitor v = new UsesProvidesVisitor(msym, env); JavaFileObject prev = log.useSource(env.toplevel.sourcefile); JCModuleDecl decl = env.toplevel.getModuleDecl(); DiagnosticPosition prevLintPos = deferredLintHandler.setPos(decl.pos()); try { decl.accept(v); } finally { log.useSource(prev); deferredLintHandler.setPos(prevLintPos); } }; }
@Override @SuppressWarnings("unchecked") public void visitModuleDef(JCModuleDecl tree) { msym.directives = List.nil(); msym.provides = List.nil(); msym.uses = List.nil(); tree.directives.forEach(t -> t.accept(this)); msym.directives = msym.directives.reverse(); msym.provides = msym.provides.reverse(); msym.uses = msym.uses.reverse(); if (msym.requires.nonEmpty() && msym.requires.head.flags.contains(RequiresFlag.MANDATED)) msym.directives = msym.directives.prepend(msym.requires.head); msym.directives = msym.directives.appendList(List.from(addReads.getOrDefault(msym, Collections.emptySet()))); checkForCorrectness(); }
private String getModuleName(Location location) throws ToolException { try { JavaFileObject jfo = fm.getJavaFileForInput(location, "module-info", JavaFileObject.Kind.SOURCE); if (jfo != null) { JCCompilationUnit jcu = compiler.parse(jfo); JCModuleDecl module = TreeInfo.getModule(jcu); if (module != null) { return module.getName().toString(); } } } catch (IOException ioe) { String text = messager.getText("main.file.manager.list", location); throw new ToolException(SYSERR, text, ioe); } return null; }
private Completer getSourceCompleter(JCCompilationUnit tree) { return new Completer() { @Override public void complete(Symbol sym) throws CompletionFailure { ModuleSymbol msym = (ModuleSymbol) sym; msym.flags_field |= UNATTRIBUTED; ModuleVisitor v = new ModuleVisitor(); JavaFileObject prev = log.useSource(tree.sourcefile); try { tree.defs.head.accept(v); completeModule(msym); checkCyclicDependencies((JCModuleDecl) tree.defs.head); } finally { log.useSource(prev); msym.flags_field &= ~UNATTRIBUTED; } } @Override public String toString() { return "SourceCompleter: " + tree.sourcefile.getName(); } }; }
protected int diffModuleDef(JCModuleDecl oldT, JCModuleDecl newT, int[] bounds) { int localPointer = bounds[0]; int[] qualBounds = getBounds(oldT.qualId); if (oldT.getModuleType() == newT.getModuleType()) { copyTo(localPointer, qualBounds[0]); } else { if (oldT.getModuleType() == ModuleTree.ModuleKind.OPEN) { //removing "open": moveFwdToToken(tokenSequence, localPointer, JavaTokenId.OPEN); copyTo(localPointer, tokenSequence.offset()); } else { copyTo(localPointer, qualBounds[0]); printer.print("open "); } } localPointer = diffTree(oldT.qualId, newT.qualId, qualBounds); int insertHint = oldT.directives.isEmpty() ? endPos(oldT) - 1 : oldT.directives.get(0).getStartPosition() - 1; tokenSequence.move(insertHint); tokenSequence.moveNext(); insertHint = moveBackToToken(tokenSequence, insertHint, JavaTokenId.LBRACE) + 1; int old = printer.indent(); PositionEstimator est = EstimatorFactory.members(oldT.directives, newT.directives, diffContext); localPointer = copyUpTo(localPointer, insertHint); // diff inner comments insertHint = diffInnerComments(oldT, newT, insertHint); localPointer = diffList(oldT.directives, newT.directives, insertHint, est, Measure.REAL_MEMBER, printer); printer.undent(old); if (localPointer != -1 && localPointer < origText.length()) { if (origText.charAt(localPointer) == '}') { // another stupid hack printer.toLeftMargin(); } copyTo(localPointer, bounds[1]); } return bounds[1]; }
private Name readModuleName(JavaFileObject fo) { return parseAndGetName(fo, t -> { JCModuleDecl md = t.getModuleDecl(); return md != null ? TreeInfo.fullName(md.getName()) : null; }); }
void run(Queue<Env<AttrContext>> list, Iterable<? extends Element> elements) { Set<Element> set = new HashSet<>(); for (Element item: elements) { set.add(item); } ListBuffer<Env<AttrContext>> defer = new ListBuffer<>(); while (list.peek() != null) { Env<AttrContext> env = list.remove(); Symbol test = null; if (env.tree.hasTag(Tag.MODULEDEF)) { test = ((JCModuleDecl) env.tree).sym; } else if (env.tree.hasTag(Tag.PACKAGEDEF)) { test = env.toplevel.packge; } else { ClassSymbol csym = env.enclClass.sym; if (csym != null) test = csym.outermostClass(); } if (test != null && set.contains(test)) process(env); else defer = defer.append(env); } list.addAll(defer); }
private Completer getSourceCompleter(JCCompilationUnit tree) { return new Completer() { @Override public void complete(Symbol sym) throws CompletionFailure { ModuleSymbol msym = (ModuleSymbol) sym; msym.flags_field |= UNATTRIBUTED; ModuleVisitor v = new ModuleVisitor(); JavaFileObject prev = log.useSource(tree.sourcefile); JCModuleDecl moduleDecl = tree.getModuleDecl(); DiagnosticPosition prevLintPos = deferredLintHandler.setPos(moduleDecl.pos()); try { moduleDecl.accept(v); completeModule(msym); checkCyclicDependencies(moduleDecl); } finally { log.useSource(prev); deferredLintHandler.setPos(prevLintPos); msym.flags_field &= ~UNATTRIBUTED; } } @Override public String toString() { return "SourceCompleter: " + tree.sourcefile.getName(); } }; }
private void checkCyclicDependencies(JCModuleDecl mod) { for (JCDirective d : mod.directives) { JCRequires rd; if (!d.hasTag(Tag.REQUIRES) || (rd = (JCRequires) d).directive == null) continue; Set<ModuleSymbol> nonSyntheticDeps = new HashSet<>(); List<ModuleSymbol> queue = List.of(rd.directive.module); while (queue.nonEmpty()) { ModuleSymbol current = queue.head; queue = queue.tail; if (!nonSyntheticDeps.add(current)) continue; current.complete(); if ((current.flags() & Flags.ACYCLIC) != 0) continue; Assert.checkNonNull(current.requires, current::toString); for (RequiresDirective dep : current.requires) { if (!dep.flags.contains(RequiresFlag.EXTRA)) queue = queue.prepend(dep.module); } } if (nonSyntheticDeps.contains(mod.sym)) { log.error(rd.moduleName.pos(), Errors.CyclicRequires(rd.directive.module)); } mod.sym.flags_field |= Flags.ACYCLIC; } }
/** record all tree nodes found by reflection. */ public void reflectiveScan(Object o) { if (o == null) return; if (o instanceof JCTree) { JCTree tree = (JCTree) o; //System.err.println("EXPECT: " + tree.getKind() + " " + trim(tree, 64)); expect.add(tree); for (Field f: getFields(tree)) { if (TypeBoundKind.class.isAssignableFrom(f.getType())) { // not part of public API continue; } try { //System.err.println("FIELD: " + f.getName()); if (tree instanceof JCModuleDecl && f.getName().equals("mods")) { // The modifiers will not found by TreeScanner, // but the embedded annotations will be. reflectiveScan(((JCModuleDecl) tree).mods.annotations); } else { reflectiveScan(f.get(tree)); } } catch (IllegalAccessException e) { error(e.toString()); } } } else if (o instanceof List) { List<?> list = (List<?>) o; for (Object item: list) reflectiveScan(item); } else error("unexpected item: " + o); }
@Override public void visitModuleDef(JCModuleDecl tree) { sym = Assert.checkNonNull(tree.sym); sym.requires = List.nil(); sym.exports = List.nil(); tree.directives.forEach(t -> t.accept(this)); sym.requires = sym.requires.reverse(); sym.exports = sym.exports.reverse(); ensureJavaBase(); }
private void checkCyclicDependencies(JCModuleDecl mod) { for (JCDirective d : mod.directives) { if (!d.hasTag(Tag.REQUIRES)) continue; JCRequires rd = (JCRequires) d; Set<ModuleSymbol> nonSyntheticDeps = new HashSet<>(); List<ModuleSymbol> queue = List.of(rd.directive.module); while (queue.nonEmpty()) { ModuleSymbol current = queue.head; queue = queue.tail; if (!nonSyntheticDeps.add(current)) continue; if ((current.flags() & Flags.ACYCLIC) != 0) continue; current.complete(); Assert.checkNonNull(current.requires, () -> current.toString()); for (RequiresDirective dep : current.requires) { if (!dep.flags.contains(RequiresFlag.EXTRA)) queue = queue.prepend(dep.module); } } if (nonSyntheticDeps.contains(mod.sym)) { log.error(rd.moduleName.pos(), Errors.CyclicRequires(rd.directive.module)); } mod.sym.flags_field |= Flags.ACYCLIC; } }