本文整理匯總了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;
}