本文整理汇总了Java中org.eclipse.jdt.core.IJavaProject.getPackageFragmentRoots方法的典型用法代码示例。如果您正苦于以下问题:Java IJavaProject.getPackageFragmentRoots方法的具体用法?Java IJavaProject.getPackageFragmentRoots怎么用?Java IJavaProject.getPackageFragmentRoots使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IJavaProject
的用法示例。
在下文中一共展示了IJavaProject.getPackageFragmentRoots方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertHasSourceFolders
import org.eclipse.jdt.core.IJavaProject; //导入方法依赖的package包/类
public void assertHasSourceFolders(String[] folders) throws JavaModelException {
IProject project = getRoot().getProject(this.projectName);
IJavaProject jproject = JavaCore.create(project);
IPackageFragmentRoot[] pkgs = jproject.getPackageFragmentRoots();
for (int i = 0; i < folders.length; i++) {
String folder = folders[i];
boolean found = false;
for (int j = 0; j < pkgs.length; j++) {
IPackageFragmentRoot pkg = pkgs[j];
IPath path = new Path("/").append(this.projectName).append(folder);
if (pkg.getPath().toString().equalsIgnoreCase(path.toString())) {
found = true;
}
;
}
assertTrue("Expected folder: " + folder, found);
}
}
示例2: getPackageFragmentRoot
import org.eclipse.jdt.core.IJavaProject; //导入方法依赖的package包/类
/**
* Return a package fragment with the passed path
*
* @param project
* @param path
* @return
* @throws JavaModelException
*/
public static IPackageFragmentRoot getPackageFragmentRoot(IProject project, IPath path) throws JavaModelException {
IJavaProject javaProject = JavaCore.create(project);
IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
for (int i = 0; i < roots.length; i++) {
if (roots[i].getPath().equals(path))
return roots[i];
}
return null;
}
示例3: findPackageFragmentRoot
import org.eclipse.jdt.core.IJavaProject; //导入方法依赖的package包/类
public static IPackageFragmentRoot findPackageFragmentRoot(IProject project, IPath path) throws JavaModelException {
IJavaProject javaProject = JavaCore.create(project);
IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
for (int i = 0; i < roots.length; i++) {
if (roots[i].getPath().isPrefixOf(path))
return roots[i];
}
return null;
}
示例4: removePackageFragmentRoot
import org.eclipse.jdt.core.IJavaProject; //导入方法依赖的package包/类
public static IPath removePackageFragmentRoot(IProject project, IPath path) throws JavaModelException {
IJavaProject javaProject = JavaCore.create(project);
IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
for (int i = 0; i < roots.length; i++) {
if (roots[i].getPath().isPrefixOf(path))
return path.makeRelativeTo(roots[i].getPath());
}
return null;
}
示例5: getPackageFragmentRoot
import org.eclipse.jdt.core.IJavaProject; //导入方法依赖的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;
}
示例6: isClassFilePresentOnBuildPath
import org.eclipse.jdt.core.IJavaProject; //导入方法依赖的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;
}
示例7: SourceViewer
import org.eclipse.jdt.core.IJavaProject; //导入方法依赖的package包/类
public SourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
boolean showAnnotationsOverview, int styles, IAnnotationAccess annotationAccess, ISharedTextColors sharedColors,
IDocument document)
{
super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, SWT.BOLD);
int id = currentId++;
filename = VIEWER_CLASS_NAME + id++ + ".java";
this.sharedColors=sharedColors;
this.annotationAccess=annotationAccess;
this.fOverviewRuler=overviewRuler;
oldAnnotations= new HashMap<ProjectionAnnotation, Position>();
IJavaProject javaProject = JavaCore.create(BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject());
try
{
IPackageFragmentRoot[] ipackageFragmentRootList=javaProject.getPackageFragmentRoots();
IPackageFragmentRoot ipackageFragmentRoot=null;
for(IPackageFragmentRoot tempIpackageFragmentRoot:ipackageFragmentRootList)
{
if(tempIpackageFragmentRoot.getKind()==IPackageFragmentRoot.K_SOURCE
&& StringUtils.equals(PathConstant.TEMP_BUILD_PATH_SETTINGS_FOLDER,tempIpackageFragmentRoot.getPath().removeFirstSegments(1).toString()))
{
ipackageFragmentRoot=tempIpackageFragmentRoot;
break;
}
}
IPackageFragment compilationUnitPackage= ipackageFragmentRoot.createPackageFragment(HYDROGRAPH_COMPILATIONUNIT_PACKAGE, true, new NullProgressMonitor());
compilatioUnit= compilationUnitPackage.createCompilationUnit(filename,document.get(),true, new NullProgressMonitor());
}
catch (Exception exception) {
LOGGER.warn("Exception occurred while initializing source viewer", exception);
} finally {
if (javaProject != null) {
try {
javaProject.close();
} catch (JavaModelException javaModelException) {
LOGGER.warn("Exception occurred while closing java-project", javaModelException);
}
}
}
initializeViewer(document);
updateContents();
}
示例8: getSourceContainers
import org.eclipse.jdt.core.IJavaProject; //导入方法依赖的package包/类
private static ISourceContainer[] getSourceContainers(IJavaProject project, Set<IRuntimeClasspathEntry> calculated) {
if (project == null || !project.exists()) {
return new ISourceContainer[0];
}
try {
IRuntimeClasspathEntry[] unresolved = JavaRuntime.computeUnresolvedRuntimeClasspath(project);
List<IRuntimeClasspathEntry> resolved = new ArrayList<>();
for (IRuntimeClasspathEntry entry : unresolved) {
for (IRuntimeClasspathEntry resolvedEntry : JavaRuntime.resolveRuntimeClasspathEntry(entry, project)) {
if (!calculated.contains(resolvedEntry)) {
calculated.add(resolvedEntry);
resolved.add(resolvedEntry);
}
}
}
Set<ISourceContainer> containers = new LinkedHashSet<>();
containers.addAll(Arrays.asList(
JavaRuntime.getSourceContainers(resolved.toArray(new IRuntimeClasspathEntry[0]))));
// Due to a known jdt java 9 support bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=525840,
// it would miss some JRE libraries source containers when the debugger is running on JDK9.
// As a workaround, recompute the possible source containers for JDK9 jrt-fs.jar libraries.
IRuntimeClasspathEntry jrtFs = resolved.stream().filter(entry -> {
return entry.getType() == IRuntimeClasspathEntry.ARCHIVE && entry.getPath().lastSegment().equals("jrt-fs.jar");
}).findFirst().orElse(null);
if (jrtFs != null && project.isOpen()) {
IPackageFragmentRoot[] allRoots = project.getPackageFragmentRoots();
for (IPackageFragmentRoot root : allRoots) {
if (root.getPath().equals(jrtFs.getPath()) && isSourceAttachmentEqual(root, jrtFs)) {
containers.add(new PackageFragmentRootSourceContainer(root));
}
}
}
return containers.toArray(new ISourceContainer[0]);
} catch (CoreException ex) {
// do nothing.
}
return new ISourceContainer[0];
}