當前位置: 首頁>>代碼示例>>Java>>正文


Java IPackageFragment.exists方法代碼示例

本文整理匯總了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;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:21,代碼來源:EclipseJavaUtil.java

示例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;
}
 
開發者ID:AndreasWBartels,項目名稱:libraries,代碼行數:28,代碼來源:WorkspaceUtilities.java

示例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;
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:62,代碼來源:ValidatorUtility.java


注:本文中的org.eclipse.jdt.core.IPackageFragment.exists方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。