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


Java JavaFileObject.toUri方法代码示例

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


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

示例1: getResourceName

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
@CheckForNull
private static String getResourceName (@NullAllowed final CompilationUnitTree cu) {
    if (cu instanceof JCTree.JCCompilationUnit) {
        JavaFileObject jfo = ((JCTree.JCCompilationUnit)cu).sourcefile;
        if (jfo != null) {
            URI uri = jfo.toUri();
            if (uri != null && uri.isAbsolute()) {
                try {
                    FileObject fo = URLMapper.findFileObject(uri.toURL());
                    if (fo != null) {
                        ClassPath cp = ClassPath.getClassPath(fo,ClassPath.SOURCE);
                        if (cp != null) {
                            return cp.getResourceName(fo,'.',false);
                        }
                    }
                } catch (MalformedURLException e) {
                    Exceptions.printStackTrace(e);
                }
            }
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:SourceAnalyzerFactory.java

示例2: error

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
@Override
public void error(
        final DiagnosticPosition pos,
        final String key,
        final Object ... args) {
    if (ERR_NOT_IN_PROFILE.equals(key)) {
        final JavaFileObject currentFile = currentSourceFile();
        if (currentFile != null) {
            final URI uri = currentFile.toUri();
            Symbol.ClassSymbol type = (Symbol.ClassSymbol) args[0];
            Collection<Symbol.ClassSymbol> types = notInProfiles.get(uri);
            if (types == null) {
                types = new ArrayList<>();
                notInProfiles.put(uri,types);
            }
            types.add(type);
        }
    }
    super.error(pos, key, args);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:NBMessager.java

示例3: deriveClassOutputPath

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
private String deriveClassOutputPath()
{
  try
  {
    String ping = "__dummy__";
    //JavaFileObject classFile = _jpe.getFiler().createClassFile( ping );
    JavaFileObject classFile = _javacTask.getContext().get( JavaFileManager.class ).getJavaFileForOutput( StandardLocation.CLASS_OUTPUT, ping, JavaFileObject.Kind.CLASS, null );
    if( !isPhysicalFile( classFile ) )
    {
      return "";
    }
    File dummyFile = new File( classFile.toUri() );
    String path = dummyFile.getAbsolutePath();
    path = path.substring( 0, path.length() - (File.separatorChar + ping + ".class").length() );
    return path;
  }
  catch( IOException e )
  {
    throw new RuntimeException( e );
  }
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:22,代码来源:JavacPlugin.java

示例4: 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

示例5: checkBridges

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
/**
 * Check that every bridge in the generated classfile has a matching bridge
 * annotation in the bridge map
 */
protected void checkBridges(JavaFileObject jfo) {
    try (InputStream is = jfo.openInputStream()) {
        ClassFile cf = ClassFile.read(is);
        System.err.println("checking: " + cf.getName());

        List<Bridge> bridgeList = bridgesMap.get(cf.getName());
        if (bridgeList == null) {
            //no bridges - nothing to check;
            bridgeList = List.nil();
        }

        for (Method m : cf.methods) {
            if (m.access_flags.is(AccessFlags.ACC_SYNTHETIC | AccessFlags.ACC_BRIDGE)) {
                //this is a bridge - see if there's a match in the bridge list
                Bridge match = null;
                for (Bridge b : bridgeList) {
                    if (b.value().equals(descriptor(m, cf.constant_pool))) {
                        match = b;
                        break;
                    }
                }
                if (match == null) {
                    error("No annotation for bridge method: " + descriptor(m, cf.constant_pool));
                } else {
                    bridgeList = drop(bridgeList, match);
                }
            }
        }
        if (bridgeList.nonEmpty()) {
            error("Redundant bridge annotation found: " + bridgeList.head.value());
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + jfo.toUri() +": " + e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:BridgeHarness.java

示例6: fillIn

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
/**
 * Fill in definition of class `c' from corresponding class or
 * source file.
 */
private void fillIn(ClassSymbol c) {
    if (completionFailureName == c.fullname) {
        throw new CompletionFailure(c, "user-selected completion failure by class name");
    }
    currentOwner = c;
    warnedAttrs.clear();
    JavaFileObject classfile = c.classfile;
    if (classfile != null) {
        JavaFileObject previousClassFile = currentClassFile;
        try {
            if (filling) {
                Assert.error("Filling " + classfile.toUri() + " during " + previousClassFile);
            }
            currentClassFile = classfile;
            if (verbose) {
                log.printVerbose("loading", currentClassFile.toString());
            }
            if (classfile.getKind() == JavaFileObject.Kind.CLASS) {
                filling = true;
                try {
                    bp = 0;
                    buf = readInputStream(buf, classfile.openInputStream());
                    readClassFile(c);
                    if (!missingTypeVariables.isEmpty() && !foundTypeVariables.isEmpty()) {
                        List<Type> missing = missingTypeVariables;
                        List<Type> found = foundTypeVariables;
                        missingTypeVariables = List.nil();
                        foundTypeVariables = List.nil();
                        filling = false;
                        ClassType ct = (ClassType) currentOwner.type;
                        ct.supertype_field =
                                types.subst(ct.supertype_field, missing, found);
                        ct.interfaces_field =
                                types.subst(ct.interfaces_field, missing, found);
                    } else if (missingTypeVariables.isEmpty() !=
                            foundTypeVariables.isEmpty()) {
                        Name name = missingTypeVariables.head.tsym.name;
                        throw badClassFile("undecl.type.var", name);
                    }
                } finally {
                    missingTypeVariables = List.nil();
                    foundTypeVariables = List.nil();
                    filling = false;
                }
            } else {
                if (sourceCompleter != null) {
                    sourceCompleter.complete(c);
                } else {
                    throw new IllegalStateException("Source completer required to read "
                            + classfile.toUri());
                }
            }
            return;
        } catch (IOException ex) {
            throw badClassFile("unable.to.access.file", ex.getMessage());
        } finally {
            currentClassFile = previousClassFile;
        }
    } else {
        JCDiagnostic diag =
                diagFactory.fragment("class.file.not.found", c.flatname);
        throw
                newCompletionFailure(c, diag);
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:70,代码来源:ClassReader.java

示例7: fillIn

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
/** Fill in definition of class `c' from corresponding class or
 *  source file.
 */
private void fillIn(ClassSymbol c) {
    if (completionFailureName == c.fullname) {
        throw new CompletionFailure(c, "user-selected completion failure by class name");
    }
    currentOwner = c;
    warnedAttrs.clear();
    JavaFileObject classfile = c.classfile;
    if (classfile != null) {
        JavaFileObject previousClassFile = currentClassFile;
        try {
            if (filling) {
                Assert.error("Filling " + classfile.toUri() + " during " + previousClassFile);
            }
            currentClassFile = classfile;
            if (verbose) {
                log.printVerbose("loading", currentClassFile.toString());
            }
            if (classfile.getKind() == JavaFileObject.Kind.CLASS) {
                filling = true;
                try {
                    bp = 0;
                    buf = readInputStream(buf, classfile.openInputStream());
                    readClassFile(c);
                    if (!missingTypeVariables.isEmpty() && !foundTypeVariables.isEmpty()) {
                        List<Type> missing = missingTypeVariables;
                        List<Type> found = foundTypeVariables;
                        missingTypeVariables = List.nil();
                        foundTypeVariables = List.nil();
                        filling = false;
                        ClassType ct = (ClassType)currentOwner.type;
                        ct.supertype_field =
                            types.subst(ct.supertype_field, missing, found);
                        ct.interfaces_field =
                            types.subst(ct.interfaces_field, missing, found);
                    } else if (missingTypeVariables.isEmpty() !=
                               foundTypeVariables.isEmpty()) {
                        Name name = missingTypeVariables.head.tsym.name;
                        throw badClassFile("undecl.type.var", name);
                    }
                } finally {
                    missingTypeVariables = List.nil();
                    foundTypeVariables = List.nil();
                    filling = false;
                }
            } else {
                if (sourceCompleter != null) {
                    sourceCompleter.complete(c);
                } else {
                    throw new IllegalStateException("Source completer required to read "
                                                    + classfile.toUri());
                }
            }
            return;
        } catch (IOException ex) {
            throw badClassFile("unable.to.access.file", ex.getMessage());
        } finally {
            currentClassFile = previousClassFile;
        }
    } else {
        JCDiagnostic diag =
            diagFactory.fragment("class.file.not.found", c.flatname);
        throw
            newCompletionFailure(c, diag);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:69,代码来源:ClassReader.java

示例8: fillIn

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
/** Fill in definition of class `c' from corresponding class or
 *  source file.
 */
void fillIn(ClassSymbol c) {
    if (completionFailureName == c.fullname) {
        JCDiagnostic msg =
                diagFactory.fragment(Fragments.UserSelectedCompletionFailure);
        throw new CompletionFailure(c, msg);
    }
    currentOwner = c;
    JavaFileObject classfile = c.classfile;
    if (classfile != null) {
        JavaFileObject previousClassFile = currentClassFile;
        Symbol prevOwner = c.owner;
        Name prevName = c.fullname;
        try {
            if (reader.filling) {
                Assert.error("Filling " + classfile.toUri() + " during " + previousClassFile);
            }
            currentClassFile = classfile;
            if (verbose) {
                log.printVerbose("loading", currentClassFile.getName());
            }
            if (classfile.getKind() == JavaFileObject.Kind.CLASS ||
                classfile.getKind() == JavaFileObject.Kind.OTHER) {
                reader.readClassFile(c);
                c.flags_field |= getSupplementaryFlags(c);
            } else {
                if (!sourceCompleter.isTerminal()) {
                    sourceCompleter.complete(c);
                } else {
                    throw new IllegalStateException("Source completer required to read "
                                                    + classfile.toUri());
                }
            }
        } catch (BadClassFile cf) {
            //the symbol may be partially initialized, purge it:
            c.owner = prevOwner;
            c.members_field.getSymbols(sym -> sym.kind == TYP).forEach(sym -> {
                ClassSymbol csym = (ClassSymbol) sym;
                csym.owner = sym.packge();
                csym.owner.members().enter(sym);
                csym.fullname = sym.flatName();
                csym.name = Convert.shortName(sym.flatName());
                csym.reset();
            });
            c.fullname = prevName;
            c.name = Convert.shortName(prevName);
            c.reset();
            throw cf;
        } finally {
            currentClassFile = previousClassFile;
        }
    } else {
        throw classFileNotFound(c);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:58,代码来源:ClassFinder.java

示例9: isPhysicalFile

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean isPhysicalFile( JavaFileObject inputFile )
{
  URI uri = inputFile.toUri();
  return uri != null && uri.getScheme() != null && uri.getScheme().equalsIgnoreCase( "file" );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:7,代码来源:JavacPlugin.java


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