本文整理汇总了Java中org.eclipse.jdt.core.IPackageFragment.exists方法的典型用法代码示例。如果您正苦于以下问题:Java IPackageFragment.exists方法的具体用法?Java IPackageFragment.exists怎么用?Java IPackageFragment.exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IPackageFragment
的用法示例。
在下文中一共展示了IPackageFragment.exists方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findType
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
public static IType findType(IJavaProject javaProject, String qualifiedName) throws JavaModelException {
if(qualifiedName == null || qualifiedName.length() == 0) return null;
IType type = javaProject.findType(qualifiedName);
if(type != null) return type;
int dot = qualifiedName.lastIndexOf('.');
String packageName = (dot < 0) ? "" : qualifiedName.substring(0, dot);
String shortName = qualifiedName.substring(dot + 1);
IPackageFragmentRoot[] rs = javaProject.getPackageFragmentRoots();
for (int i = 0; i < rs.length; i++) {
IPackageFragment f = rs[i].getPackageFragment(packageName);
if(f == null || !f.exists()) continue;
ICompilationUnit[] us = f.getCompilationUnits();
for (int j = 0; j < us.length; j++) {
IType t = us[j].getType(shortName);
if(t != null && t.exists()) return t;
}
}
return null;
}
示例2: getPackages
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
public static List<Object> getPackages(final IPackage paccage) {
final ILibrary library = paccage.getLibrary();
final List<Object> eclipseTypes = new ArrayList<>();
if (library instanceof IProject) {
final List<IJavaProject> eclipseProjects = getProjects((IProject) library);
try {
for (final IJavaProject javaProject : eclipseProjects) {
final IPackageFragmentRoot[] allPackageFragmentRoots = javaProject.getAllPackageFragmentRoots();
for (final IPackageFragmentRoot packageFragmentRoot : allPackageFragmentRoots) {
if (packageFragmentRoot instanceof JarPackageFragmentRoot) {
continue;
}
if (packageFragmentRoot instanceof ExternalPackageFragmentRoot) {
continue;
}
final IPackageFragment packageFragment = packageFragmentRoot.getPackageFragment(paccage.getName());
if (packageFragment.exists()) {
eclipseTypes.add(packageFragment);
}
}
}
} catch (final JavaModelException e) {
// nothing to do
}
}
return eclipseTypes;
}
示例3: isClassFilePresentOnBuildPath
import org.eclipse.jdt.core.IPackageFragment; //导入方法依赖的package包/类
/**
* This method checks if java file is present under source folder or not.
* @param filePath java file path.
* @return true if file is present otherwise false.
*/
public boolean isClassFilePresentOnBuildPath(String filePath)
{
if(filePath.contains("."))
{
String packageName=filePath.substring(0, filePath.lastIndexOf('.'));
String JavaFileName=filePath.substring(filePath.lastIndexOf('.')+1);
IJavaProject javaProject=null;
ISelectionService selectionService = Workbench.getInstance().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
if(selection instanceof IStructuredSelection)
{
Object element = ((IStructuredSelection)selection).getFirstElement();
if(element instanceof IResource)
{
IProject project= ((IResource)element).getProject();
javaProject = JavaCore.create(project);
}
else
{
javaProject=createJavaProjectThroughActiveEditor();
}
}
else if(selection instanceof TextSelection)
{
javaProject=createJavaProjectThroughActiveEditor();
}
IPackageFragmentRoot[] ipackageFragmentRootList=null;
try {
ipackageFragmentRootList = javaProject.getPackageFragmentRoots();
} catch (JavaModelException e) {
logger.error("Unable to get jars which are on build path of project " ,e );
}
for(IPackageFragmentRoot tempIpackageFragmentRoot:ipackageFragmentRootList)
{
if(!tempIpackageFragmentRoot.getElementName().contains("-sources"))
{
IPackageFragment packageFragment=tempIpackageFragmentRoot.getPackageFragment(packageName);
if(!packageFragment.exists())
continue;
else
{
if(packageFragment.getCompilationUnit(JavaFileName+".java").exists()
||packageFragment.getClassFile(JavaFileName+".class").exists()
)
return true;
}
}
}
}
return false;
}