当前位置: 首页>>代码示例>>Java>>正文


Java IJavaProject.getPackageFragments方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.IJavaProject.getPackageFragments方法的典型用法代码示例。如果您正苦于以下问题:Java IJavaProject.getPackageFragments方法的具体用法?Java IJavaProject.getPackageFragments怎么用?Java IJavaProject.getPackageFragments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.IJavaProject的用法示例。


在下文中一共展示了IJavaProject.getPackageFragments方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: collectAllCompilationUnits

import org.eclipse.jdt.core.IJavaProject; //导入方法依赖的package包/类
/**
 * Collects all compilation units within the project.
 * @return the collection of the compilation units
 */
public static List<ICompilationUnit> collectAllCompilationUnits() {
    List<ICompilationUnit> units = new ArrayList<ICompilationUnit>();
    
    try {
        IProject[] projects =  getWorkspace().getRoot().getProjects();
        for (int i = 0; i < projects.length; i++) {
            IJavaProject project = (IJavaProject)JavaCore.create((IProject)projects[i]);
            
            IPackageFragment[] packages = project.getPackageFragments();
            for (int j = 0; j < packages.length; j++) {
                
                ICompilationUnit[] cus = packages[j].getCompilationUnits();
                for (int k = 0; k < cus.length; k++) {
                    IResource res = cus[k].getResource();
                    if (res.getType() == IResource.FILE) {
                        String name = cus[k].getPath().toString();
                        if (name.endsWith(".java")) { 
                            units.add(cus[k]);
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
    
    return units;
}
 
开发者ID:liaoziyang,项目名称:ContentAssist,代码行数:34,代码来源:WorkspaceUtilities.java

示例2: findClassesWithAnnotation

import org.eclipse.jdt.core.IJavaProject; //导入方法依赖的package包/类
/**
 * @param projectName
 * @return
 * @throws JavaModelException
 */
private static List<IType> findClassesWithAnnotation(String projectName, Class annotationClass, String attributName,
		boolean valued) throws JavaModelException {
	List<IType> classList = new ArrayList<IType>();
	IProject project = ResourceManager.getProject(projectName);
	IJavaProject javaProject = JavaCore.create(project);
	IPackageFragment[] packages = javaProject.getPackageFragments();
	for (IPackageFragment packageFragment : packages) {
		for (final ICompilationUnit compilationUnit : packageFragment.getCompilationUnits()) {
			if (compilationUnit.exists()) {
				IType type = getClassesWithAnnotation(compilationUnit, annotationClass, attributName, valued);
				if (type != null)
					classList.add(type);
			}
		}
	}
	return classList;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:23,代码来源:JDTManager.java

示例3: getIFileFromQualifiedName

import org.eclipse.jdt.core.IJavaProject; //导入方法依赖的package包/类
/**
 * @param project
 * @param qualifiedName
 * @return
 * @throws CoreException
 */
public static IFile getIFileFromQualifiedName(String projectname, String qualifiedName) throws CoreException {
	IProject project = getProject(projectname);
	IJavaProject jproject = JavaCore.create(project);
	IPackageFragment[] pkgs = jproject.getPackageFragments();
	String spath = qualifiedName.replace(".", "/");
	for (int i = 0; i < pkgs.length; i++) {
		if (pkgs[i].getKind() != IPackageFragmentRoot.K_SOURCE)
			continue;
		IPath path = pkgs[i].getPath().append(spath);
		IFile iFile = (IFile) ResourceManager.getResource(path.toString() + ".java");
		if (iFile != null && iFile.exists())
			return iFile;
	}
	return null;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:22,代码来源:ResourceManager.java

示例4: getPathWithinPackageFragment

import org.eclipse.jdt.core.IJavaProject; //导入方法依赖的package包/类
/**
 * Return a path relative to its package fragment root
 * 
 * @param project
 * @param path
 * @return
 * @throws JavaModelException
 */
public static IPath getPathWithinPackageFragment(IResource ifile) throws JavaModelException {
	IProject project = ifile.getProject();
	IPath path = ifile.getFullPath();
	String[] segments = path.segments();
	IJavaProject jproject = JavaCore.create(project);
	IPackageFragment[] pkgs = jproject.getPackageFragments();
	IPath p = new Path("/");
	for (int i = 0; i < segments.length; i++) {
		for (int j = 0; j < pkgs.length; j++) {
			if (pkgs[j].getPath().equals(p)) {
				IPath ret = path.makeRelativeTo(pkgs[j].getPath());
				return ret;
			}
		}
		p = p.append(segments[i]);
	}
	return null;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:27,代码来源:ResourceManager.java

示例5: getFiles

import org.eclipse.jdt.core.IJavaProject; //导入方法依赖的package包/类
private static Set<ICompilationUnit> getFiles(String projname) throws CoreException {
	IWorkspaceRoot ws = ResourcesPlugin.getWorkspace().getRoot();
	IProject proj = ws.getProject(projname);
	IJavaProject javaProject = JavaCore.create(proj);
	Set<ICompilationUnit> files = new HashSet<ICompilationUnit>();
	javaProject.open(new NullProgressMonitor());
	for( IPackageFragment packFrag : javaProject.getPackageFragments()) {
		for (ICompilationUnit icu : packFrag.getCompilationUnits()) {
			files.add(icu);
		}
	}
	javaProject.close();
	return files;
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:15,代码来源:LSDiffRunner.java


注:本文中的org.eclipse.jdt.core.IJavaProject.getPackageFragments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。