本文整理汇总了Java中org.eclipse.jdt.core.IPackageFragmentRoot.getCorrespondingResource方法的典型用法代码示例。如果您正苦于以下问题:Java IPackageFragmentRoot.getCorrespondingResource方法的具体用法?Java IPackageFragmentRoot.getCorrespondingResource怎么用?Java IPackageFragmentRoot.getCorrespondingResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IPackageFragmentRoot
的用法示例。
在下文中一共展示了IPackageFragmentRoot.getCorrespondingResource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSourceFolders
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
/**
* Returns the list of source folders of the given project as a list of
* absolute workspace paths.
*
* @param project
* a project
* @return a list of absolute workspace paths
*/
public static List<IFolder> getSourceFolders(IProject project) {
List<IFolder> srcFolders = new ArrayList<IFolder>();
try {
IJavaProject javaProject = JavaCore.create(project);
if (!javaProject.exists()) {
return srcFolders;
}
// iterate over package roots
for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
IResource resource = root.getCorrespondingResource();
if (resource != null && resource.getType() == IResource.FOLDER) {
srcFolders.add((IFolder) resource);
}
}
} catch (CoreException e) {
Logger.debug("Get source folder exception: %s", e);
}
return srcFolders;
}
示例2: execute
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException {
boolean autoBuilding = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
IWorkbenchWindow aww = HandlerUtil.getActiveWorkbenchWindow(event);
ISelection sel = HandlerUtil.getCurrentSelection(event);
if (sel.isEmpty())
return null;
if (sel instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) sel;
if (selection != null) {
Object obj = selection.getFirstElement();
if (obj != null) {
try {
IResource selectedResource = null;
if (obj instanceof IJavaProject) {
IJavaProject jp = (IJavaProject) obj;
selectedResource = jp.getProject();
}
if (obj instanceof IPackageFragmentRoot) {
IPackageFragmentRoot pfr = (IPackageFragmentRoot) obj;
selectedResource = pfr.getCorrespondingResource();
}
if (obj instanceof IPackageFragment) {
IPackageFragment pf = (IPackageFragment) obj;
selectedResource = pf.getCorrespondingResource();
}
if (selectedResource != null && !selectedResource.exists())
return null;
// This is where the synchronization is done ...
ResourceManager.setAutoBuilding(false);
GraphWalkerContextManager.synchronizeBuildPolicies(selectedResource, aww);
} catch (Exception e) {
ResourceManager.logException(e);
} finally {
ResourceManager.setAutoBuilding(autoBuilding);
}
}
}
}
return null;
}