本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}