本文整理匯總了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;
}