本文整理汇总了Java中org.eclipse.jdt.core.IClassFile.exists方法的典型用法代码示例。如果您正苦于以下问题:Java IClassFile.exists方法的具体用法?Java IClassFile.exists怎么用?Java IClassFile.exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IClassFile
的用法示例。
在下文中一共展示了IClassFile.exists方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveFileOnPackageFragment
import org.eclipse.jdt.core.IClassFile; //导入方法依赖的package包/类
/**
* Returns the given file or JAR entry if it is on the given package fragment. The file can be a Java file, class
* file, or a non-Java resource.
* <p>
* This method returns null for .java files or .class files inside JARs.
*
* @param fileName
* the file name
* @param pckgFragment
* the package fragment to search
* @return the file as an IResource or IJarEntryResource, or null
* @throws JavaModelException
*/
public static IStorage resolveFileOnPackageFragment(String fileName, IPackageFragment pckgFragment)
throws JavaModelException {
boolean isJavaFile = JavaCore.isJavaLikeFileName(fileName);
boolean isClassFile = ResourceUtils.endsWith(fileName, ".class");
// Check the non-Java resources first
Object[] nonJavaResources = pckgFragment.getNonJavaResources();
for (Object nonJavaResource : nonJavaResources) {
if (nonJavaResource instanceof IFile) {
IFile file = (IFile) nonJavaResource;
String resFileName = file.getName();
if (ResourceUtils.areFilenamesEqual(resFileName, fileName)) {
// Java source files that have been excluded from the build path
// show up as non-Java resources, but we'll ignore them since
// they're not available on the classpath.
if (!JavaCore.isJavaLikeFileName(resFileName)) {
return file;
} else {
return null;
}
}
}
// JAR resources are not IResource's, so we need to handle them
// differently
if (nonJavaResource instanceof IJarEntryResource) {
IJarEntryResource jarEntry = (IJarEntryResource) nonJavaResource;
if (jarEntry.isFile() && ResourceUtils.areFilenamesEqual(jarEntry.getName(), fileName)) {
return jarEntry;
}
}
}
// If we're looking for a .java or .class file, we can use the regular
// Java Model methods.
if (isJavaFile) {
ICompilationUnit cu = pckgFragment.getCompilationUnit(fileName);
if (cu.exists()) {
return (IFile) cu.getCorrespondingResource();
}
}
if (isClassFile) {
IClassFile cf = pckgFragment.getClassFile(fileName);
if (cf.exists()) {
return (IFile) cf.getCorrespondingResource();
}
}
return null;
}