当前位置: 首页>>代码示例>>Java>>正文


Java Convert类代码示例

本文整理汇总了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();
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:27,代码来源:JavacProcessingEnvironment.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:DocEnv.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ConvenientAccessErrorsTest.java

示例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;
}
 
开发者ID:google,项目名称:error-prone,代码行数:25,代码来源:StringBuilderInitWithChar.java

示例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;
}
 
开发者ID:redundent,项目名称:lombok,代码行数:21,代码来源:PrettyCommentsPrinter.java

示例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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:VeryPretty.java

示例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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:JavacProcessingEnvironment.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Symtab.java

示例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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:PubApiExtractor.java

示例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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ToolEnvironment.java

示例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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:DocEnv.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:DPrinter.java

示例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();
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:34,代码来源:JavacProcessingEnvironment.java

示例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;
    }
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:32,代码来源:MethodConverter.java

示例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;
}
 
开发者ID:google,项目名称:error-prone,代码行数:11,代码来源:VisitorState.java


注:本文中的com.sun.tools.javac.util.Convert类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。