本文整理汇总了Java中com.sun.tools.javac.code.Symbol.PackageSymbol类的典型用法代码示例。如果您正苦于以下问题:Java PackageSymbol类的具体用法?Java PackageSymbol怎么用?Java PackageSymbol使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PackageSymbol类属于com.sun.tools.javac.code.Symbol包,在下文中一共展示了PackageSymbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: javaDocFor
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
/**Get javadoc for given element.
* @deprecated The new DocTree API should be used to traverse Javadoc comments.
* Use {@link DocTrees#getDocCommentTree(javax.lang.model.element.Element)} instead.
*/
@Deprecated
public Doc javaDocFor(Element element) {
if (element != null) {
DocEnv env = DocEnv.instance(ctx);
switch (element.getKind()) {
case ANNOTATION_TYPE:
case CLASS:
case ENUM:
case INTERFACE:
return env.getClassDoc((ClassSymbol)element);
case ENUM_CONSTANT:
case FIELD:
return env.getFieldDoc((VarSymbol)element);
case METHOD:
if (((MethodSymbol)element).enclClass().getKind() == ElementKind.ANNOTATION_TYPE)
return env.getAnnotationTypeElementDoc((MethodSymbol)element);
return env.getMethodDoc((MethodSymbol)element);
case CONSTRUCTOR:
return env.getConstructorDoc((MethodSymbol)element);
case PACKAGE:
return env.getPackageDoc((PackageSymbol)element);
}
}
return null;
}
示例2: inferModule
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
private ModuleSymbol inferModule(String pkg) {
if (modules.getDefaultModule() == syms.noModule)
return modules.getDefaultModule();
Set<ModuleSymbol> rootModules = modules.getRootModules();
if (rootModules.size() == 1) {
return rootModules.iterator().next();
}
PackageSymbol pack = elementUtils.getPackageElement(pkg);
if (pack != null && pack.modle != syms.unnamedModule) {
return pack.modle;
}
return null;
}
示例3: inferModule
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
public ModuleSymbol inferModule(Name packageName) {
if (packageName.isEmpty())
return java_base == noModule ? noModule : unnamedModule;//!
ModuleSymbol msym = null;
Map<ModuleSymbol,PackageSymbol> map = packages.get(packageName);
if (map == null)
return null;
for (Map.Entry<ModuleSymbol,PackageSymbol> e: map.entrySet()) {
if (!e.getValue().members().isEmpty()) {
if (msym == null) {
msym = e.getKey();
} else {
return null;
}
}
}
return msym;
}
示例4: loadClass
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
/** Load a toplevel class with given fully qualified name
* The class is entered into `classes' only if load was successful.
*/
public ClassSymbol loadClass(ModuleSymbol msym, Name flatname) throws CompletionFailure {
Assert.checkNonNull(msym);
Name packageName = Convert.packagePart(flatname);
PackageSymbol ps = syms.lookupPackage(msym, packageName);
Assert.checkNonNull(ps.modle, () -> "msym=" + msym + "; flatName=" + flatname);
boolean absent = syms.getClass(ps.modle, flatname) == null;
ClassSymbol c = syms.enterClass(ps.modle, flatname);
if (c.members_field == null) {
try {
c.complete();
} catch (CompletionFailure ex) {
if (absent) syms.removeClass(ps.modle, flatname);
throw ex;
}
}
return c;
}
示例5: getAllModulePackages
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
private Set<PackageElement> getAllModulePackages(ModuleElement mdle) throws ToolException {
Set<PackageElement> result = new HashSet<>();
ModuleSymbol msym = (ModuleSymbol) mdle;
List<Location> msymlocs = getModuleLocation(locations, msym.name.toString());
for (Location msymloc : msymlocs) {
for (JavaFileObject fo : fmList(msymloc, "", sourceKinds, true)) {
if (fo.getName().endsWith("module-info.java")) {
continue;
}
String binaryName = fm.inferBinaryName(msymloc, fo);
String pn = getPackageName(binaryName);
PackageSymbol psym = syms.enterPackage(msym, names.fromString(pn));
result.add((PackageElement) psym);
}
}
return result;
}
示例6: getLocation
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
private Location getLocation(String packageName) throws IOException {
if (location == StandardLocation.MODULE_SOURCE_PATH) {
// TODO: handle invalid results
Name pack = names.fromString(packageName);
for (ModuleSymbol msym : modules.allModules()) {
PackageSymbol p = syms.getPackage(msym, pack);
if (p != null && !p.members().isEmpty()) {
return fm.getLocationForModule(location, msym.name.toString());
}
}
return null;
} else {
return location;
}
}
示例7: lookupPackage
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
/**
* Look up PackageDoc by qualified name.
*/
public PackageDocImpl lookupPackage(String name) {
//### Jing alleges that class check is needed
//### to avoid a compiler bug. Most likely
//### instead a dummy created for error recovery.
//### Should investigate this.
Name nameImpl = names.fromString(name);
ModuleSymbol mod = syms.inferModule(nameImpl);
PackageSymbol p = mod != null ? syms.getPackage(mod, nameImpl) : null;
ClassSymbol c = getClassSymbol(name);
if (p != null && c == null) {
return getPackageDoc(p);
} else {
return null;
}
}
示例8: complete
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
/** Completion for classes to be loaded. Before a class is loaded
* we make sure its enclosing class (if any) is loaded.
*/
private void complete(Symbol sym) throws CompletionFailure {
if (sym.kind == TYP) {
try {
ClassSymbol c = (ClassSymbol) sym;
dependencies.push(c, CompletionCause.CLASS_READER);
annotate.blockAnnotations();
c.members_field = new Scope.ErrorScope(c); // make sure it's always defined
completeOwners(c.owner);
completeEnclosing(c);
fillIn(c);
} finally {
annotate.unblockAnnotationsNoFlush();
dependencies.pop();
}
} else if (sym.kind == PCK) {
PackageSymbol p = (PackageSymbol)sym;
try {
fillIn(p);
} catch (IOException ex) {
throw new CompletionFailure(sym, ex.getLocalizedMessage()).initCause(ex);
}
}
if (!reader.filling)
annotate.flush(); // finish attaching annotations
}
示例9: importConflicts
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
@Test
public void importConflicts() {
ImportPolicy.bind(context, ImportPolicy.IMPORT_TOP_LEVEL);
context.put(PackageSymbol.class, Symtab.instance(context).rootPackage);
// Test fully qualified class names
inliner.addImport("package.Exception");
assertInlines("Exception", UClassIdent.create("package.Exception"));
// Will import "anotherPackage.Exception" due to conflicts
assertInlines("anotherPackage.Exception", UClassIdent.create("anotherPackage.Exception"));
new EqualsTester()
.addEqualityGroup(inliner.getImportsToAdd(),
ImmutableSet.of("package.Exception"))
.testEquals();
// Test nested class names
inliner.addImport("package.subpackage.Foo.Bar");
// Will import "package.Foo"
assertInlines("Foo.Bar", UClassIdent.create("package.Foo.Bar"));
assertInlines("Bar", UClassIdent.create("package.subpackage.Foo.Bar"));
// Will not import "anotherPackage.Foo" due to conflicts
assertInlines("anotherPackage.Foo.Bar", UClassIdent.create("anotherPackage.Foo.Bar"));
new EqualsTester()
.addEqualityGroup(inliner.getImportsToAdd(),
ImmutableSet.of("package.Exception", "package.subpackage.Foo.Bar", "package.Foo"))
.testEquals();
}
示例10: check
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
private Description check(Tree tree, Name simpleName, VisitorState state) {
Symtab symtab = state.getSymtab();
PackageSymbol javaLang =
symtab.enterPackage(symtab.java_base, Names.instance(state.context).java_lang);
Symbol other =
getFirst(
javaLang.members().getSymbolsByName(simpleName, s -> s.getModifiers().contains(PUBLIC)),
null);
Symbol symbol = ASTHelpers.getSymbol(tree);
if (other == null || other.equals(symbol)) {
return NO_MATCH;
}
return buildDescription(tree)
.setMessage(String.format("%s clashes with %s\n", symbol, other))
.build();
}
示例11: importConflicts
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
@Test
public void importConflicts() {
ImportPolicy.bind(context, ImportPolicy.IMPORT_TOP_LEVEL);
context.put(PackageSymbol.class, Symtab.instance(context).rootPackage);
// Test fully qualified class names
inliner.addImport("package.Exception");
assertInlines("Exception", UClassIdent.create("package.Exception"));
// Will import "anotherPackage.Exception" due to conflicts
assertInlines("anotherPackage.Exception", UClassIdent.create("anotherPackage.Exception"));
new EqualsTester()
.addEqualityGroup(inliner.getImportsToAdd(), ImmutableSet.of("package.Exception"))
.testEquals();
// Test nested class names
inliner.addImport("package.subpackage.Foo.Bar");
// Will import "package.Foo"
assertInlines("Foo.Bar", UClassIdent.create("package.Foo.Bar"));
assertInlines("Bar", UClassIdent.create("package.subpackage.Foo.Bar"));
// Will not import "anotherPackage.Foo" due to conflicts
assertInlines("anotherPackage.Foo.Bar", UClassIdent.create("anotherPackage.Foo.Bar"));
new EqualsTester()
.addEqualityGroup(
inliner.getImportsToAdd(),
ImmutableSet.of("package.Exception", "package.subpackage.Foo.Bar", "package.Foo"))
.testEquals();
}
示例12: importAll
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
/** Import all classes of a class or package on demand.
* @param pos Position to be used for error reporting.
* @param tsym The class or package the members of which are imported.
* @param toScope The (import) scope in which imported classes
* are entered.
*/
private void importAll(int pos,
final TypeSymbol tsym,
Env<AttrContext> env) {
// Check that packages imported from exist (JLS ???).
if (tsym.kind == PCK && tsym.members().elems == null && !tsym.exists()) {
// If we can't find java.lang, exit immediately.
if (((PackageSymbol)tsym).fullname.equals(names.java_lang)) {
JCDiagnostic msg = diags.fragment("fatal.err.no.java.lang");
throw new FatalError(msg);
} else {
log.error(DiagnosticFlag.RESOLVE_ERROR, pos, "doesnt.exist", tsym);
}
}
env.toplevel.starImportScope.importAll(tsym.members());
}
示例13: findPackage
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
/**
* Finds the package with name {@code name}.
*
* @param name the name of the package
* @param path the tree path to the local scope
* @return the {@code PackageSymbol} for the package if it is found, {@code null} otherwise
*/
public PackageSymbol findPackage(String name, TreePath path) {
Log.DiagnosticHandler discardDiagnosticHandler = new Log.DiscardDiagnosticHandler(log);
try {
Env<AttrContext> env = getEnvForPath(path);
Element res =
wrapInvocationOnResolveInstance(FIND_IDENT, env, names.fromString(name), PCK);
// findIdent will return a PackageSymbol even for a symbol that is not a package,
// such as a.b.c.MyClass.myStaticField. "exists()" must be called on it to ensure
// that it exists.
if (res.getKind() == ElementKind.PACKAGE) {
PackageSymbol ps = (PackageSymbol) res;
return ps.exists() ? ps : null;
} else {
return null;
}
} finally {
log.popDiagnosticHandler(discardDiagnosticHandler);
}
}
示例14: findClassInPackage
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
/**
* Finds the class with name {@code name} in a given package.
*
* @param name the name of the class
* @param pck the PackageSymbol for the package
* @param path the tree path to the local scope
* @return the {@code ClassSymbol} for the class if it is found, {@code null} otherwise
*/
public ClassSymbol findClassInPackage(String name, PackageSymbol pck, TreePath path) {
Log.DiagnosticHandler discardDiagnosticHandler = new Log.DiscardDiagnosticHandler(log);
try {
Env<AttrContext> env = getEnvForPath(path);
Element res =
wrapInvocationOnResolveInstance(
FIND_IDENT_IN_PACKAGE, env, pck, names.fromString(name), TYP);
if (res.getKind() == ElementKind.CLASS) {
return (ClassSymbol) res;
} else {
return null;
}
} finally {
log.popDiagnosticHandler(discardDiagnosticHandler);
}
}
示例15: getPackageDoc
import com.sun.tools.javac.code.Symbol.PackageSymbol; //导入依赖的package包/类
/**
* Return the AnnotationTypeElementDoc for a MethodSymbol.
* Should be called only on symbols representing annotation type elements.
*/
@Override
public PackageDocImpl getPackageDoc(PackageSymbol pack) {
PackageDocImpl result = packageMap.get(pack);
if (result != null) return result;
result = new JavaDocPackage(this, pack, ctx);
packageMap.put(pack, result);
return result;
}