本文整理汇总了Java中com.sun.tools.javac.util.Convert类的典型用法代码示例。如果您正苦于以下问题:Java Convert类的具体用法?Java Convert怎么用?Java Convert使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Convert类属于com.sun.tools.javac.util包,在下文中一共展示了Convert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enterClassFiles
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
/** Enter a set of generated class files. */
private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
ClassReader reader = ClassReader.instance(context);
Names names = Names.instance(context);
List<ClassSymbol> list = List.nil();
for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) {
Name name = names.fromString(entry.getKey());
JavaFileObject file = entry.getValue();
if (file.getKind() != JavaFileObject.Kind.CLASS)
throw new AssertionError(file);
ClassSymbol cs;
if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
Name packageName = Convert.packagePart(name);
PackageSymbol p = reader.enterPackage(packageName);
if (p.package_info == null)
p.package_info = reader.enterClass(Convert.shortName(name), p);
cs = p.package_info;
if (cs.classfile == null)
cs.classfile = file;
} else
cs = reader.enterClass(name, file);
list = list.prepend(cs);
}
return list.reverse();
}
示例2: getClassSymbol
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
/** Retrieve class symbol by fully-qualified name.
*/
ClassSymbol getClassSymbol(String name) {
// Name may contain nested class qualification.
// Generate candidate flatnames with successively shorter
// package qualifiers and longer nested class qualifiers.
int nameLen = name.length();
char[] nameChars = name.toCharArray();
int idx = name.length();
for (;;) {
Name nameImpl = names.fromChars(nameChars, 0, nameLen);
ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl));
ClassSymbol s = mod != null ? syms.getClass(mod, nameImpl) : null;
if (s != null)
return s; // found it!
idx = name.substring(0, idx).lastIndexOf('.');
if (idx < 0) break;
nameChars[idx] = '$';
}
return null;
}
示例3: testConvertNameCandidates
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
@Test
public void testConvertNameCandidates(Path base) throws Exception {
Context ctx = new Context();
Names names = Names.instance(ctx);
Name name = names.fromString("com.sun.tools.javac.Attr.BreakAttr");
com.sun.tools.javac.util.List<String> actual =
Convert.classCandidates(name).map(n -> n.toString());
List<String> expected = Arrays.asList(
"com.sun$tools$javac$Attr$BreakAttr",
"com.sun.tools$javac$Attr$BreakAttr",
"com.sun.tools.javac$Attr$BreakAttr",
"com.sun.tools.javac.Attr$BreakAttr",
"com.sun.tools.javac.Attr.BreakAttr"
);
if (!expected.equals(actual)) {
throw new Exception("Expected names not generated: " + actual);
}
}
示例4: matchNewClass
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
@Override
public Description matchNewClass(NewClassTree tree, VisitorState state) {
if (ASTHelpers.isSameType(
state.getSymtab().stringBuilderType, ASTHelpers.getType(tree.getIdentifier()), state)
&& tree.getArguments().size() == 1) {
ExpressionTree argument = tree.getArguments().get(0);
Type type = ((JCTree) argument).type;
if (type.getKind() == TypeKind.CHAR) {
if (argument.getKind() == Kind.CHAR_LITERAL) {
char ch = (Character) ((LiteralTree) argument).getValue();
return describeMatch(
tree,
SuggestedFix.replace(argument, "\"" + Convert.quote(Character.toString(ch)) + "\""));
} else {
return describeMatch(
tree,
SuggestedFix.replace(
tree,
"new StringBuilder().append(" + state.getSourceForNode((JCTree) argument) + ")"));
}
}
}
return Description.NO_MATCH;
}
示例5: print
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
/** Print string, replacing all non-ascii character with unicode escapes.
*/
public void print(Object s) throws IOException {
boolean align = needsAlign;
if (needsNewLine && !onNewLine) {
println();
}
if (align && !aligned) {
align();
}
if (needsSpace && !onNewLine && !aligned) {
out.write(' ');
}
needsSpace = false;
out.write(Convert.escapeUnicode(s.toString()));
onNewLine = false;
aligned = false;
}
示例6: quote
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
private static String quote(String val, char keep) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < val.length(); i++) {
char c = val.charAt(i);
if (c != keep) {
sb.append(Convert.quote(c));
} else {
sb.append(c);
}
}
return sb.toString();
}
示例7: enterClassFiles
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
/** Enter a set of generated class files. */
private List<ClassSymbol> enterClassFiles(Map<ModuleSymbol, Map<String, JavaFileObject>> modulesAndClassFiles) {
List<ClassSymbol> list = List.nil();
for (Entry<ModuleSymbol, Map<String, JavaFileObject>> moduleAndClassFiles : modulesAndClassFiles.entrySet()) {
for (Map.Entry<String,JavaFileObject> entry : moduleAndClassFiles.getValue().entrySet()) {
Name name = names.fromString(entry.getKey());
JavaFileObject file = entry.getValue();
if (file.getKind() != JavaFileObject.Kind.CLASS)
throw new AssertionError(file);
ClassSymbol cs;
if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
Name packageName = Convert.packagePart(name);
PackageSymbol p = symtab.enterPackage(moduleAndClassFiles.getKey(), packageName);
if (p.package_info == null)
p.package_info = symtab.enterClass(moduleAndClassFiles.getKey(), Convert.shortName(name), p);
cs = p.package_info;
cs.reset();
if (cs.classfile == null)
cs.classfile = file;
cs.completer = initialCompleter;
} else {
cs = symtab.enterClass(moduleAndClassFiles.getKey(), name);
cs.reset();
cs.classfile = file;
cs.completer = initialCompleter;
cs.owner.members().enter(cs); //XXX - OverwriteBetweenCompilations; syms.getClass is not sufficient anymore
}
list = list.prepend(cs);
}
}
return list.reverse();
}
示例8: enterClass
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
/** Create a new member or toplevel class symbol with given flat name
* and enter in `classes' unless already there.
*/
public ClassSymbol enterClass(ModuleSymbol msym, Name flatname) {
Assert.checkNonNull(msym);
PackageSymbol ps = lookupPackage(msym, Convert.packagePart(flatname));
Assert.checkNonNull(ps);
Assert.checkNonNull(ps.modle);
ClassSymbol c = getClass(ps.modle, flatname);
if (c == null) {
c = defineClass(Convert.shortName(flatname), ps);
doEnterClass(ps.modle, c);
return c;
} else
return c;
}
示例9: getPubApi
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
public PubApi getPubApi(String fullyQualifiedClassName) {
Symtab syms = Symtab.instance(context);
ClassFinder cr = ClassFinder.instance(context);
Names ns = Names.instance(context);
Name n = ns.fromString(fullyQualifiedClassName);
ClassSymbol cs = cr.loadClass(syms.inferModule(Convert.packagePart(n)), n);
PubapiVisitor v = new PubapiVisitor();
v.visit(cs);
return v.getCollectedPubApi();
}
示例10: loadClass
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
/**
* Load a class by qualified name.
*/
public TypeElement loadClass(String name) {
try {
Name nameImpl = names.fromString(name);
ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl));
ClassSymbol c = finder.loadClass(mod != null ? mod : syms.errModule, nameImpl);
return c;
} catch (CompletionFailure ex) {
chk.completionError(null, ex);
return null;
}
}
示例11: loadClass
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
/**
* Load ClassDoc by qualified name.
*/
public ClassDocImpl loadClass(String name) {
try {
Name nameImpl = names.fromString(name);
ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl));
ClassSymbol c = finder.loadClass(mod != null ? mod : syms.errModule, nameImpl);
return getClassDoc(c);
} catch (CompletionFailure ex) {
chk.completionError(null, ex);
return null;
}
}
示例12: printLimitedEscapedString
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
public void printLimitedEscapedString(String label, String text) {
String s = Convert.quote(text);
if (s.length() > maxSrcLength) {
String trim = "[...]";
int head = (maxSrcLength - trim.length()) * 2 / 3;
int tail = maxSrcLength - trim.length() - head;
s = s.substring(0, head) + trim + s.substring(s.length() - tail);
}
printString(label, s);
}
示例13: enterClassFiles
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
/** Enter a set of generated class files. */
private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
List<ClassSymbol> list = List.nil();
for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) {
Name name = names.fromString(entry.getKey());
JavaFileObject file = entry.getValue();
if (file.getKind() != JavaFileObject.Kind.CLASS)
throw new AssertionError(file);
ClassSymbol cs;
// TODO: for now, we assume that generated code is in a default module;
// in time, we need a way to be able to specify the module for generated code
if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
Name packageName = Convert.packagePart(name);
PackageSymbol p = symtab.enterPackage(defaultModule, packageName);
if (p.package_info == null)
p.package_info = symtab.enterClass(defaultModule, Convert.shortName(name), p);
cs = p.package_info;
cs.reset();
if (cs.classfile == null)
cs.classfile = file;
cs.completer = initialCompleter;
} else {
cs = symtab.enterClass(defaultModule, name);
cs.reset();
cs.classfile = file;
cs.completer = initialCompleter;
cs.owner.members().enter(cs); //XXX - OverwriteBetweenCompilations; syms.getClass is not sufficient anymore
}
list = list.prepend(cs);
}
return list.reverse();
}
示例14: visitLiteral
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
public void visitLiteral(JCTree.JCLiteral tree) {
switch (tree.typetag) {
case TypeTags.INT:
ccode.print(tree.value.toString());
break;
case TypeTags.LONG:
ccode.print(tree.value + "LL");
break;
case TypeTags.FLOAT:
ccode.print(tree.value + "F");
break;
case TypeTags.DOUBLE:
ccode.print(tree.value.toString());
break;
case TypeTags.CHAR:
ccode.print("\'" + Convert.quote(String.valueOf((char) ((Number) tree.value).intValue())) + "\'");
break;
case TypeTags.BOOLEAN:
ccode.print(tree.value.toString());
break;
case TypeTags.BOT:
ccode.print("null");
break;
default:
String literal = Convert.quote(tree.value.toString());
String key = conv.getLiteralKey(method.sym.enclClass(), literal);
String className = method.sym.enclClass().fullname.toString().replace('.', '_');
ccode.print("getObjectForCStringLiteral(" + key + ", " + className + ", \"" + literal + "\")");
break;
}
}
示例15: inferModule
import com.sun.tools.javac.util.Convert; //导入依赖的package包/类
/** Infers a module symbol for the given flat class name. */
// TODO(cushon): decide how to provide actual -source 9 module support
public ModuleSymbol inferModule(Name flatName) {
Symtab symtab = getSymtab();
ModuleSymbol result = symtab.inferModule(Convert.packagePart(flatName));
if (result != null) {
return result;
}
return symtab.java_base == symtab.noModule ? symtab.noModule : symtab.unnamedModule;
}