本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCModuleDecl类的典型用法代码示例。如果您正苦于以下问题:Java JCModuleDecl类的具体用法?Java JCModuleDecl怎么用?Java JCModuleDecl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JCModuleDecl类属于com.sun.tools.javac.tree.JCTree包,在下文中一共展示了JCModuleDecl类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleFlowResults
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; //导入依赖的package包/类
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);
}
示例2: visitModuleDef
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; //导入依赖的package包/类
@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();
}
示例3: getUsesProvidesCompleter
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; //导入依赖的package包/类
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);
}
};
}
示例4: getModuleName
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; //导入依赖的package包/类
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;
}
示例5: getSourceCompleter
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; //导入依赖的package包/类
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();
}
};
}
示例6: visitModuleDef
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; //导入依赖的package包/类
@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();
}
示例7: diffModuleDef
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; //导入依赖的package包/类
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];
}
示例8: readModuleName
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; //导入依赖的package包/类
private Name readModuleName(JavaFileObject fo) {
return parseAndGetName(fo, t -> {
JCModuleDecl md = t.getModuleDecl();
return md != null ? TreeInfo.fullName(md.getName()) : null;
});
}
示例9: run
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; //导入依赖的package包/类
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);
}
示例10: getSourceCompleter
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; //导入依赖的package包/类
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();
}
};
}
示例11: checkCyclicDependencies
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; //导入依赖的package包/类
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;
}
}
示例12: reflectiveScan
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; //导入依赖的package包/类
/** 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);
}
示例13: checkCyclicDependencies
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; //导入依赖的package包/类
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;
}
}