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


Java JavaFileObject.getName方法代码示例

本文整理汇总了Java中javax.tools.JavaFileObject.getName方法的典型用法代码示例。如果您正苦于以下问题:Java JavaFileObject.getName方法的具体用法?Java JavaFileObject.getName怎么用?Java JavaFileObject.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.tools.JavaFileObject的用法示例。


在下文中一共展示了JavaFileObject.getName方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSrcSpan

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
public static Spannable createSrcSpan(Resources resources, @NonNull Diagnostic diagnostic) {
    if (diagnostic.getSource() == null) {
        return new SpannableString("Unknown");
    }
    if (!(diagnostic.getSource() instanceof JavaFileObject)) {
        return new SpannableString(diagnostic.getSource().toString());
    }
    try {
        JavaFileObject source = (JavaFileObject) diagnostic.getSource();
        File file = new File(source.getName());
        String name = file.getName();
        String line = diagnostic.getLineNumber() + ":" + diagnostic.getColumnNumber();
        SpannableString span = new SpannableString(name + ":" + line);
        span.setSpan(new ForegroundColorSpan(resources.getColor(R.color.dark_color_diagnostic_file)),
                0, span.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return span;
    } catch (Exception e) {

    }
    return new SpannableString(diagnostic.getSource().toString());
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:22,代码来源:SpanUtil.java

示例2: getTypeForFile

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
private String getTypeForFile( JavaFileObject file )
{
  URI uri = file.toUri();
  if( !uri.getScheme().equalsIgnoreCase( "file" ) )
  {
    return makeTypeName( file.getName() );
  }
  IFile iFile = ManifoldHost.getFileSystem().getIFile( new File( file.getName() ) );
  List<IDirectory> sourcePath = ManifoldHost.getGlobalModule().getSourcePath();
  for( IDirectory dir : sourcePath )
  {
    if( iFile.isDescendantOf( dir ) )
    {
      return makeTypeName( iFile.getName().substring( dir.getName().length() ) );
    }
  }
  throw new IllegalStateException( "Could not infer type name from: " + file.getName() );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:19,代码来源:JavaParser.java

示例3: formatSource

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
public String formatSource(JCDiagnostic d, boolean fullname, Locale l) {
    JavaFileObject fo = d.getSource();
    if (fo == null)
        throw new IllegalArgumentException(); // d should have source set
    if (fullname)
        return fo.getName();
    else if (fo instanceof BaseFileObject)
        return ((BaseFileObject) fo).getShortName();
    else
        return BaseFileObject.getSimpleName(fo);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:12,代码来源:AbstractDiagnosticFormatter.java

示例4: inferBinaryName

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
@Override
public String inferBinaryName(Location loc, JavaFileObject file) {
    if (file instanceof JavaFileObjectImpl) {
        return file.getName();
    }

    return super.inferBinaryName(loc, file);
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:9,代码来源:JavaFileManagerImpl.java

示例5: matchClassNames

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
@SuppressWarnings("serial")
private static void matchClassNames(List<String> ret, final String className)
        throws IOException {
    String packageName = className.substring(0, className.lastIndexOf('.'));
    String relativedName = className.substring(
            className.lastIndexOf('.') + 1, className.length());
    String patName = relativedName.replace("*", "(\\w+)");
    Pattern pat = Pattern.compile(patName);

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    JavaFileManager fm = compiler.getStandardFileManager(
            new DiagnosticCollector<JavaFileObject>(), null, null);
    HashSet<JavaFileObject.Kind> kind = new HashSet<JavaFileObject.Kind>() {
        {
            add(JavaFileObject.Kind.CLASS);
        }
    };

    for (JavaFileObject f : fm.list(StandardLocation.PLATFORM_CLASS_PATH, packageName, kind, false)) {
        String relatived0 = f.getName();
        String name0 = relatived0.substring(0, relatived0.length() - ".class".length());
        Matcher m = pat.matcher(name0);
        if (m.matches()) {
            String name = packageName + '.' + name0;
            if (!ret.contains(name)) {
                ret.add(name);
            }
        }
    }
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:31,代码来源:TemplatePrecompiler.java

示例6: formatSource

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
public String formatSource(JCDiagnostic d, boolean fullname, Locale l) {
    JavaFileObject fo = d.getSource();
    if (fo == null)
        throw new IllegalArgumentException(); // d should have source set
    if (fullname)
        return fo.getName();
    else if (fo instanceof PathFileObject)
        return ((PathFileObject) fo).getShortName();
    else
        return PathFileObject.getSimpleName(fo);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:AbstractDiagnosticFormatter.java

示例7: test

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
void test(String... args) throws IOException {
    JavaFileObject file = fm.getJavaFileForInput(PLATFORM_CLASS_PATH,
                                                 "java.lang.Object",
                                                 CLASS);
    String fileName = file.getName();
    if (!fileName.matches(".*java/lang/Object.class\\)?")) {
        System.err.println(fileName);
        throw new AssertionError(file);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:T6411310.java

示例8: printTestSrc

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
private static void printTestSrc(Iterable<? extends JavaFileObject> files) {
    for (JavaFileObject f : files) {
        System.out.println("Test file " + f.getName() + ":");
        try {
            System.out.println("" + f.getCharContent(true));
        } catch (IOException e) {
            throw new RuntimeException(
                    "Exception when printing test src contents for class " +
                            f.getName(), e);
        }
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ReflectionTest.java

示例9: makeNames

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
private Set<String> makeNames( Iterable<JavaFileObject> list )
{
  HashSet<String> set = new HashSet<>();
  for( JavaFileObject file : list )
  {
    String name = file.getName();
    if( name.endsWith( ".java" ) )
    {
      set.add( name.substring( name.lastIndexOf( File.separatorChar ) + 1, name.lastIndexOf( '.' ) ) );
    }
  }
  return set;
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:14,代码来源:ManifoldJavaFileManager.java

示例10: inferBinaryName

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
@Override
public String inferBinaryName(Location loc, JavaFileObject file) {
    if (file instanceof JavaFileObjectImpl)
        return file.getName();
    return super.inferBinaryName(loc, file);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:7,代码来源:JdkCompiler.java

示例11: toString

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
String toString(JavaFileObject fo) {
    return (fo == null) ? "--" : fo.getName();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:Modules.java

示例12: testCanCompileAgainstExplodedImage

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
void testCanCompileAgainstExplodedImage(String loc) throws IOException {
    System.err.println("testCanCompileAgainstExplodedImage(" + loc + ")");
    Path javaHome = prepareJavaHome();
    Path targetPath = javaHome.resolve(loc.replace("*", "/java.base").replace("/", sep));
    try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
        for (String pack : REQUIRED_PACKAGES) {
            Iterable<JavaFileObject> content = fm.list(StandardLocation.PLATFORM_CLASS_PATH,
                                                       pack,
                                                       EnumSet.allOf(JavaFileObject.Kind.class),
                                                       false);

            for (JavaFileObject jfo : content) {
                String name = jfo.getName();
                int lastSlash = name.lastIndexOf('/');
                name = lastSlash >= 0 ? name.substring(lastSlash + 1) : name;
                Path target = targetPath.resolve(pack.replace(".", sep) + sep + name);
                Files.createDirectories(target.getParent());
                try (InputStream in = jfo.openInputStream()) {
                    Files.copy(in, target);
                }
            }
        }
    }

    System.setProperty("java.home", javaHome.toString());

    try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
        DiagnosticListener<JavaFileObject> noErrors = d -> {
            if (d.getKind() == Diagnostic.Kind.ERROR)
                throw new IllegalStateException("Unexpected error: " + d);
        };
        ToolBox.JavaSource inputFile =
                new ToolBox.JavaSource("import java.util.List; class Test { List l; }");
        List<JavaFileObject> inputFiles = Arrays.asList(inputFile);
        boolean result =
                javaCompiler.getTask(null, fm, noErrors, null, null, inputFiles).call();
        if (!result) {
            throw new IllegalStateException("Could not compile correctly!");
        }
        JavacTask task =
                (JavacTask) javaCompiler.getTask(null, fm, noErrors, null, null, inputFiles);
        task.parse();
        TypeElement juList = task.getElements().getTypeElement("java.util.List");
        if (juList == null)
            throw new IllegalStateException("Cannot resolve java.util.List!");
        URI listSource = ((ClassSymbol) juList).classfile.toUri();
        if (!listSource.toString().startsWith(javaHome.toUri().toString()))
            throw new IllegalStateException(  "Did not load java.util.List from correct place, " +
                                              "actual location: " + listSource.toString() +
                                            "; expected prefix: " + javaHome.toUri());
    }

    System.err.println("finished.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:55,代码来源:ExplodedImage.java


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