当前位置: 首页>>代码示例>>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;未经允许,请勿转载。