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


Java IPackageFragmentRoot.getPackageFragment方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.IPackageFragmentRoot.getPackageFragment方法的典型用法代碼示例。如果您正苦於以下問題:Java IPackageFragmentRoot.getPackageFragment方法的具體用法?Java IPackageFragmentRoot.getPackageFragment怎麽用?Java IPackageFragmentRoot.getPackageFragment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.IPackageFragmentRoot的用法示例。


在下文中一共展示了IPackageFragmentRoot.getPackageFragment方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createClassRepo

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
public void createClassRepo(String jarFileName, String Package) {
	ClassRepo.INSTANCE.flusRepo();
	try {
		IPackageFragmentRoot iPackageFragmentRoot = getIPackageFragment(jarFileName);
		if (iPackageFragmentRoot != null) {
			IPackageFragment fragment = iPackageFragmentRoot.getPackageFragment(Package);
			if (fragment != null) {
				for (IClassFile element : fragment.getClassFiles()) {
					ClassRepo.INSTANCE.addClass(element,"","",false);
				}
			} else {
				new CustomMessageBox(SWT.ERROR, Package + " Package not found in jar "
						+ iPackageFragmentRoot.getElementName(), "ERROR").open();
			}
		}
	} catch (JavaModelException e) {
		LOGGER.error("Error occurred while loading class from jar {}", jarFileName, e);
	}
	loadClassesFromSettingsFolder();
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:21,代碼來源:BuildExpressionEditorDataSturcture.java

示例2: getPackageFragmentRoot

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
/**
 * Return package fragment of the passed resource
 * 
 * @param project
 * @param path
 * @return
 * @throws JavaModelException
 */
public static IPackageFragmentRoot getPackageFragmentRoot(IProject project, IPackageFragment pkg)
		throws JavaModelException {
	IJavaProject jproject = JavaCore.create(project);
	IPackageFragmentRoot[] roots = jproject.getPackageFragmentRoots();
	for (int i = 0; i < roots.length; i++) {
		IPackageFragmentRoot root = roots[i];
		IPackageFragment pf = root.getPackageFragment(pkg.getElementName());
		if (pf.equals(pkg))
			return root;
	}
	return null;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:21,代碼來源:ResourceManager.java

示例3: getPackageFragment

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
/**
 * Return package fragment of the passed resource
 * 
 * @param project
 * @param path
 * @return
 * @throws CoreException
 */
public static IPackageFragment getPackageFragment(IProject project, IPath path) throws CoreException {
	IFolder folder = ResourceManager.ensureFolder(project, path.toString(), new NullProgressMonitor());
	IJavaElement element = JavaCore.create(folder);
	if (element instanceof IPackageFragment) {
		return (IPackageFragment) element;
	}
	if (element instanceof IPackageFragmentRoot) {
		IPackageFragmentRoot root = (IPackageFragmentRoot) element;
		element = root.getPackageFragment("");
		return (IPackageFragment) element;
	}
	return null;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:22,代碼來源:ResourceManager.java

示例4: createDummyClass

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
public static IFile createDummyClass(IJavaProject project) throws CoreException, IOException {
	String clazz = "import org.graphwalker.core.machine.ExecutionContext ; public class Dummy extends org.gw4e.core.machine.ExecutionContext {}";
	IFolder folder = project.getProject().getFolder("src/test/java");
	IPackageFragmentRoot srcFolder = project.getPackageFragmentRoot(folder);
	IPackageFragment pkg = srcFolder.getPackageFragment("");
	ICompilationUnit cu = pkg.createCompilationUnit("Dummy.java", clazz, false, new NullProgressMonitor());
	cu.save(new NullProgressMonitor (), true);

	return (IFile) cu.getResource();
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:11,代碼來源:ProjectHelper.java

示例5: createDummyClassWitherror

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
public static IFile createDummyClassWitherror(IJavaProject project) throws CoreException, IOException {
	String clazz = "import org.graphwalker.core.machine.ExecutionContext ; public class Dummy1 extends org.gw4e.core.machine.ExecutionContext {}";
	IFolder folder = project.getProject().getFolder("src/test/java");
	IPackageFragmentRoot srcFolder = project.getPackageFragmentRoot(folder);
	IPackageFragment pkg = srcFolder.getPackageFragment("");
	ICompilationUnit cu = pkg.createCompilationUnit("Dummy.java", clazz, false, new NullProgressMonitor());
	cu.save(new NullProgressMonitor (), true);
	return (IFile) cu.getResource();
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:10,代碼來源:ProjectHelper.java

示例6: getPackages

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的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

示例7: putPackages

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
private void putPackages(Collection<IPackageCoverage> packages,
    IPackageFragmentRoot root) {
  for (IPackageCoverage c : packages) {
    final String name = c.getName().replace('/', '.');
    final IPackageFragment fragment = root.getPackageFragment(name);
    modelcoverage.putFragment(fragment, c);
  }
}
 
開發者ID:eclipse,項目名稱:eclemma,代碼行數:9,代碼來源:SessionAnalyzer.java

示例8: getPackageFragment

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
public static IPackageFragment getPackageFragment(IFile file) throws JavaModelException {
	IPackageFragmentRoot root1 = JDTManager.findPackageFragmentRoot(file.getProject(), file.getFullPath());
	IPath path = file.getParent().getFullPath().makeRelativeTo(root1.getPath());
	IPackageFragment pf =root1.getPackageFragment(path.toString().replace("/", "."));
	return pf;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:7,代碼來源:JDTManager.java

示例9: isClassFilePresentOnBuildPath

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的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

示例10: packageChanged

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
protected IStatus packageChanged() {
	StatusInfo status = new StatusInfo();
	IPackageFragmentRoot root = getPackageFragmentRoot();
	IJavaProject project = root != null ? root.getJavaProject() : null;

	String packName = getPackageText().getText();
	if (packName.length() > 0) {
		IStatus val = validatePackageName(packName, project);
		if (val.getSeverity() == IStatus.ERROR) {
			status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName, val.getMessage()));
			return status;
		} else if (val.getSeverity() == IStatus.WARNING) {
			status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage()));
			// continue
		}
	} else {
		status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged);
	}

	if (project != null) {
		if (project.exists() && packName.length() > 0) {
			try {
				IPath rootPath = root.getPath();
				IPath outputPath = project.getOutputLocation();
				if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
					// if the bin folder is inside of our root, don't allow
					// to name a package
					// like the bin folder
					IPath packagePath = rootPath.append(packName.replace('.', '/'));
					if (outputPath.isPrefixOf(packagePath)) {
						status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation);
						return status;
					}
				}
			} catch (JavaModelException e) {
				JavaPlugin.log(e);
				// let pass
			}
		}

		fCurrPackage = root.getPackageFragment(packName);
		IResource resource = fCurrPackage.getResource();
		if (resource != null) {
			if (resource.isVirtual()) {
				status.setError(NewWizardMessages.NewTypeWizardPage_error_PackageIsVirtual);
				return status;
			}
			if (!ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) {
				status.setError(NewWizardMessages.NewTypeWizardPage_error_PackageNameFiltered);
				return status;
			}
		}
	} else {
		status.setError("");
	}
	return status;
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:58,代碼來源:ExportToJavaBeanWizardPage.java

示例11: createInitialFragment

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
/**
 * Creates a fragment with the same name as the project name.
 * It is used to show an initial package name in the project wizard.
 * 
 * @param name
 *          name of the initial package
 * @return the initial package fragment
 */
private IPackageFragment createInitialFragment(final String name) {
  IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(((NewCheckProjectWizardPage) getPreviousPage()).getProjectName());
  IFolder src = project.getFolder(com.avaloq.tools.ddk.check.ui.wizard.CheckProjectCreator.SRC_ROOT);
  IJavaProject jProject = JavaCore.create(project);
  IPackageFragmentRoot root = jProject.getPackageFragmentRoot(src);
  return root.getPackageFragment(name);
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:16,代碼來源:NewCheckCatalogWizardPage.java


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