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


Java IJavaProject.getPackageFragmentRoots方法代碼示例

本文整理匯總了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);
	}
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:20,代碼來源:GW4EProject.java

示例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;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:18,代碼來源:JDTManager.java

示例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;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:10,代碼來源:JDTManager.java

示例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;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:10,代碼來源:JDTManager.java

示例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;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:21,代碼來源:ResourceManager.java

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

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

示例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];
}
 
開發者ID:Microsoft,項目名稱:java-debug,代碼行數:43,代碼來源:JdtUtils.java


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