本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCCompilationUnit类的典型用法代码示例。如果您正苦于以下问题:Java JCCompilationUnit类的具体用法?Java JCCompilationUnit怎么用?Java JCCompilationUnit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JCCompilationUnit类属于com.sun.tools.javac.tree.JCTree包,在下文中一共展示了JCCompilationUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DiffContext
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的package包/类
public DiffContext(CompilationInfo copy, Set<Tree> syntheticTrees) {
this.tokenSequence = copy.getTokenHierarchy().tokenSequence(JavaTokenId.language());
this.mainCode = this.origText = copy.getText();
this.style = getCodeStyle(copy);
this.context = JavaSourceAccessor.getINSTANCE().getJavacTask(copy).getContext();
this.mainUnit = this.origUnit = (JCCompilationUnit) copy.getCompilationUnit();
this.trees = copy.getTrees();
this.doc = copy.getSnapshot().getSource().getDocument(false); //TODO: true or false?
this.positionConverter = copy.getPositionConverter();
this.file = copy.getFileObject();
this.syntheticTrees = syntheticTrees;
this.textLength = copy.getSnapshot() == null ? Integer.MAX_VALUE : copy.getSnapshot().getOriginalOffset(copy.getSnapshot().getText().length());
this.blockSequences = new BlockSequences(this.tokenSequence, doc, textLength);
this.forceInitialComment = false;
}
示例2: parseArbitrarySource
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的package包/类
public static CompilationUnitTree parseArbitrarySource(JavacTask task, JavaFileObject file) throws IOException {
JavacTaskImpl taskImpl = (JavacTaskImpl) task;
com.sun.tools.javac.util.Context context = taskImpl.getContext();
Log log = Log.instance(context);
JavaFileObject prevSource = log.useSource(file);
try {
ParserFactory fac = ParserFactory.instance(context);
JCCompilationUnit cut = fac.newParser(file.getCharContent(true), true, true, true).parseCompilationUnit();
cut.sourcefile = file;
return cut;
} finally {
log.useSource(prevSource);
}
}
示例3: resolveIdent
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的package包/类
/**
* Resolve an identifier.
*
* @param name The identifier to resolve
*/
public Symbol resolveIdent(String name) {
if (name.equals(""))
return syms.errSymbol;
JavaFileObject prev = log.useSource(null);
try {
JCExpression tree = null;
for (String s : name.split("\\.", -1)) {
if (!SourceVersion.isIdentifier(s)) // TODO: check for keywords
return syms.errSymbol;
tree = (tree == null) ? make.Ident(names.fromString(s))
: make.Select(tree, names.fromString(s));
}
JCCompilationUnit toplevel =
make.TopLevel(List.<JCAnnotation>nil(), null, List.<JCTree>nil());
toplevel.packge = syms.unnamedPackage;
return attr.attribIdent(tree, toplevel);
} finally {
log.useSource(prev);
}
}
示例4: parseFiles
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的package包/类
/**
* Parses a list of files.
*/
public List<JCCompilationUnit> parseFiles(Iterable<JavaFileObject> fileObjects) {
if (shouldStop(CompileState.PARSE))
return List.nil();
//parse all files
ListBuffer<JCCompilationUnit> trees = lb();
Set<JavaFileObject> filesSoFar = new HashSet<JavaFileObject>();
for (JavaFileObject fileObject : fileObjects) {
if (!filesSoFar.contains(fileObject)) {
filesSoFar.add(fileObject);
trees.append(parse(fileObject));
}
}
return trees.toList();
}
示例5: resolveIdent
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的package包/类
/** Resolve an identifier.
* @param msym The module in which the search should be performed
* @param name The identifier to resolve
*/
public Symbol resolveIdent(ModuleSymbol msym, String name) {
if (name.equals(""))
return syms.errSymbol;
JavaFileObject prev = log.useSource(null);
try {
JCExpression tree = null;
for (String s : name.split("\\.", -1)) {
if (!SourceVersion.isIdentifier(s)) // TODO: check for keywords
return syms.errSymbol;
tree = (tree == null) ? make.Ident(names.fromString(s))
: make.Select(tree, names.fromString(s));
}
JCCompilationUnit toplevel =
make.TopLevel(List.nil());
toplevel.modle = msym;
toplevel.packge = msym.unnamedPackage;
return attr.attribIdent(tree, toplevel);
} finally {
log.useSource(prev);
}
}
示例6: parseFiles
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的package包/类
/**
* Parses a list of files.
*/
public List<JCCompilationUnit> parseFiles(Iterable<JavaFileObject> fileObjects) {
if (shouldStop(CompileState.PARSE))
return List.nil();
//parse all files
ListBuffer<JCCompilationUnit> trees = new ListBuffer<>();
Set<JavaFileObject> filesSoFar = new HashSet<>();
for (JavaFileObject fileObject : fileObjects) {
if (!filesSoFar.contains(fileObject)) {
filesSoFar.add(fileObject);
trees.append(parse(fileObject));
}
}
return trees.toList();
}
示例7: parseInternal
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的package包/类
private Iterable<? extends CompilationUnitTree> parseInternal() {
try {
prepareCompiler(true);
List<JCCompilationUnit> units = compiler.parseFiles(args.getFileObjects());
for (JCCompilationUnit unit: units) {
JavaFileObject file = unit.getSourceFile();
if (notYetEntered.containsKey(file))
notYetEntered.put(file, unit);
}
return units;
}
finally {
parsed = true;
if (compiler != null && compiler.log != null)
compiler.log.flush();
}
}
示例8: handleFlowResults
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的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);
}
示例9: initModules
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的package包/类
public void initModules(List<JCCompilationUnit> trees) {
Assert.check(!inInitModules);
try {
inInitModules = true;
Assert.checkNull(rootModules);
enter(trees, modules -> {
Assert.checkNull(rootModules);
Assert.checkNull(allModules);
this.rootModules = modules;
setupAllModules(); //initialize the module graph
Assert.checkNonNull(allModules);
inInitModules = false;
}, null);
} finally {
inInitModules = false;
}
}
示例10: finished
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的package包/类
@Override
@DefinedBy(Api.COMPILER_TREE)
public void finished(TaskEvent e) {
switch (e.getKind()) {
case ANALYZE:
collectClassSymbols((JCCompilationUnit) e.getCompilationUnit());
break;
case COMPILATION:
Log.debug("Compilation finished");
Log.debug("Extracting pub APIs for the following symbols:");
for (ClassSymbol cs : classSymbols)
Log.debug(" " + cs.fullname);
extractPubApis();
// Save result for later retrieval. (Important that we do this
// before we return from this method, because we may not access
// symbols after compilation is finished.)
PubAPIs pa = PubAPIs.instance(context);
explicitPubApis = pa.getPubapis(explicitJFOs, true);
nonExplicitPubApis = pa.getPubapis(explicitJFOs, false);
Log.debug("done");
break;
}
}
示例11: getModuleName
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的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;
}
示例12: gatherTreeSpans
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的package包/类
public List<int[]> gatherTreeSpans(File file, String content) throws IOException {
JCCompilationUnit unit = read(file.toURI(), content);
List<int[]> spans = new ArrayList<>();
new TreePathScanner<Void, Void>() {
@Override
public Void scan(Tree tree, Void p) {
if (tree != null) {
int start = ((JCTree) tree).getStartPosition();
int end = ((JCTree) tree).getEndPosition(unit.endPositions);
spans.add(new int[] {start, end});
}
return super.scan(tree, p);
}
}.scan(unit, null);
return spans;
}
示例13: read
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的package包/类
/**
* Read a file.
* @param file the file to be read
* @return the tree for the content of the file
* @throws IOException if any IO errors occur
* @throws TreePosTest.ParseException if any errors occur while parsing the file
*/
JCCompilationUnit read(File file) throws IOException, ParseException {
JavacTool tool = JavacTool.create();
r.errors = 0;
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
JavacTask task = tool.getTask(pw, fm, r, Collections.<String>emptyList(), null, files);
Iterable<? extends CompilationUnitTree> trees = task.parse();
pw.flush();
if (r.errors > 0)
throw new ParseException(sw.toString());
Iterator<? extends CompilationUnitTree> iter = trees.iterator();
if (!iter.hasNext())
throw new Error("no trees found");
JCCompilationUnit t = (JCCompilationUnit) iter.next();
if (iter.hasNext())
throw new Error("too many trees found");
return t;
}
示例14: read
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的package包/类
/**
* Read a file.
* @param file the file to be read
* @return the tree for the content of the file
* @throws IOException if any IO errors occur
* @throws TreePosTest.ParseException if any errors occur while parsing the file
*/
JCCompilationUnit read(File file) throws IOException, ParseException {
JavacTool tool = JavacTool.create();
r.errors = 0;
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
JavacTask task = tool.getTask(pw, fm, r, List.of("-proc:none"), null, files);
Iterable<? extends CompilationUnitTree> trees = task.parse();
pw.flush();
if (r.errors > 0)
throw new ParseException(sw.toString());
Iterator<? extends CompilationUnitTree> iter = trees.iterator();
if (!iter.hasNext())
throw new Error("no trees found");
JCCompilationUnit t = (JCCompilationUnit) iter.next();
if (iter.hasNext())
throw new Error("too many trees found");
return t;
}
示例15: resolveIdent
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; //导入依赖的package包/类
/** Resolve an identifier.
* @param msym The module in which the search should be performed
* @param name The identifier to resolve
*/
public Symbol resolveIdent(ModuleSymbol msym, String name) {
if (name.equals(""))
return syms.errSymbol;
JavaFileObject prev = log.useSource(null);
try {
JCExpression tree = null;
for (String s : name.split("\\.", -1)) {
if (!SourceVersion.isIdentifier(s)) // TODO: check for keywords
return syms.errSymbol;
tree = (tree == null) ? make.Ident(names.fromString(s))
: make.Select(tree, names.fromString(s));
}
JCCompilationUnit toplevel =
make.TopLevel(List.<JCTree>nil());
toplevel.modle = msym;
toplevel.packge = msym.unnamedPackage;
return attr.attribIdent(tree, toplevel);
} finally {
log.useSource(prev);
}
}