本文整理匯總了Java中org.eclipse.core.resources.IWorkspaceRoot.getContainerForLocation方法的典型用法代碼示例。如果您正苦於以下問題:Java IWorkspaceRoot.getContainerForLocation方法的具體用法?Java IWorkspaceRoot.getContainerForLocation怎麽用?Java IWorkspaceRoot.getContainerForLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.core.resources.IWorkspaceRoot
的用法示例。
在下文中一共展示了IWorkspaceRoot.getContainerForLocation方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getJavaProject
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
public static IJavaProject getJavaProject(final IPath path) {
final IJavaProject[] javaProjects = getJavaProjects();
for (final IJavaProject javaProject : javaProjects) {
final IPath fullPath = javaProject.getProject().getFullPath();
if (fullPath.equals(path)) {
return javaProject;
}
}
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IContainer container = root.getContainerForLocation(path);
if (container != null) {
return getJavaProject(container);
}
container = root.getContainerForLocation(root.getLocation().append(path));
return getJavaProject(container);
}
示例2: getResource
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
/**
* get the IResource corresponding to the given file. Given file does not
* need to exist.
*
* @param file
* @param isDirectory
* if true, an IContainer will be returned, otherwise an IFile
* will be returned
* @return
*/
public static IResource getResource(File file, boolean isDirectory) {
if (file == null) return null;
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot workspaceRoot = workspace.getRoot();
IPath pathEclipse = new Path(file.getAbsolutePath());
IResource resource = null;
if (isDirectory) {
resource = workspaceRoot.getContainerForLocation(pathEclipse);
} else {
resource = workspaceRoot.getFileForLocation(pathEclipse);
}
return resource;
}
示例3: find
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
private String find(IPath styles) {
String name = styles.lastSegment();
IPath base = styles.removeLastSegments(1);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IContainer dir = root.getContainerForLocation(base);
while (dir != null && dir.getType() != IResource.ROOT) {
IResource member = dir.findMember(name);
if (member != null) {
return root.getLocation().append(member.getFullPath()).toFile().toURI().toString();
}
dir = dir.getParent();
}
return null;
}
示例4: shouldPend
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
@Override
public boolean shouldPend(final File file, final OfflineChangeType changeType, final ItemType serverItemType) {
if (filter == null) {
return true;
}
final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
final IPath path = new Path(file.getAbsolutePath());
IResource resource = null;
/*
* If the change type is a delete, then the local item doesn't exist
* (because it was deleted!), so test whether the corresponding server
* item is a folder so we test the filter with the correct resource type
* (it matters).
*/
if ((changeType == OfflineChangeType.DELETE && serverItemType == ItemType.FOLDER) || file.isDirectory()) {
resource = workspaceRoot.getContainerForLocation(path);
} else {
resource = workspaceRoot.getFileForLocation(path);
}
/*
* We should really never get null back for this even if it doesn't
* exist.
*/
if (resource == null) {
log.info(MessageFormat.format("Could not obtain resource for {0} (not analyzing offline state)", path)); //$NON-NLS-1$
return false;
}
return filter.filter(resource).isAccept();
}
示例5: LocationInfo
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
public LocationInfo(final IPath location) {
Check.notNull(location, "location"); //$NON-NLS-1$
this.location = location;
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
file = root.getFileForLocation(location);
container = root.getContainerForLocation(location);
files = root.findFilesForLocation(location);
containers = root.findContainersForLocation(location);
}
示例6: getResourceForLocation
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
@Override
public IResource getResourceForLocation(
final IPath location,
final IWorkspaceRoot root,
final boolean mustExist) {
IContainer container = root.getContainerForLocation(location);
if (mustExist && container != null && !container.exists()) {
container = null;
}
return container;
}
示例7: importToWorkspace
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
@Override
@SuppressWarnings("restriction")
public void importToWorkspace(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
JavaLanguageServerPlugin.logInfo("Importing Maven project(s)");
MavenConfigurationImpl configurationImpl = (MavenConfigurationImpl)MavenPlugin.getMavenConfiguration();
configurationImpl.setDownloadSources(true);
configurationImpl.setNotCoveredMojoExecutionSeverity(ProblemSeverity.ignore.toString());
SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
Set<MavenProjectInfo> files = getMavenProjectInfo(subMonitor.split(5));
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
Collection<IProject> projects = new LinkedHashSet<>();
Collection<MavenProjectInfo> toImport = new LinkedHashSet<>();
//Separate existing projects from new ones
for (MavenProjectInfo projectInfo : files) {
File pom = projectInfo.getPomFile();
IContainer container = root.getContainerForLocation(new Path(pom.getAbsolutePath()));
if (container == null) {
toImport.add(projectInfo);
} else {
IProject project = container.getProject();
if (ProjectUtils.isMavenProject(project)) {
projects.add(container.getProject());
} else if (project != null) {
//Project doesn't have the Maven nature, so we (re)import it
toImport.add(projectInfo);
}
}
}
if (!toImport.isEmpty()) {
ProjectImportConfiguration importConfig = new ProjectImportConfiguration();
configurationManager.importProjects(toImport, importConfig, subMonitor.split(95));
}
updateProjects(projects, monitor);
}
示例8: getAffectedResources
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
/**
* Determine the local workspace resource for a given GetOperation. Note
* that a get operation CAN affect multiple resources, in the case of a
* rename. (sourceLocalItem != targetLocalItem)
*
* @param operation
* An AGetOperation to get the resource for
* @return All IResources for the file/folder represented by the operation
*/
private IResource[] getAffectedResources(final GetOperation operation) {
final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
List<String> localPaths = new ArrayList<String>();
final List<IResource> localResources = new ArrayList<IResource>();
// on a delete, our local resource is the source item
if (operation.getCurrentLocalItem() != null && operation.getTargetLocalItem() == null) {
localPaths.add(operation.getCurrentLocalItem());
}
// on an add, our local resource is going to be the target item
else if (operation.getCurrentLocalItem() == null && operation.getTargetLocalItem() != null) {
localPaths.add(operation.getTargetLocalItem());
}
// on a rename, our local resource is the target item
// (the source will be implicated in a delete)
else if (!operation.getCurrentLocalItem().equals(operation.getTargetLocalItem())) {
localPaths.add(operation.getCurrentLocalItem());
localPaths.add(operation.getTargetLocalItem());
}
else {
localPaths.add(operation.getCurrentLocalItem());
}
// get the unique paths from all these...
localPaths = getUniquePaths(localPaths);
// convert local paths to local resources
for (final String tfsPath : localPaths) {
final Path local = new Path(LocalPath.tfsToNative(tfsPath));
IResource resource;
if (operation.getItemType() == ItemType.FILE) {
resource = workspaceRoot.getFileForLocation(local);
} else {
resource = workspaceRoot.getContainerForLocation(local);
}
if (resource != null) {
localResources.add(resource);
}
}
return localResources.toArray(new IResource[localResources.size()]);
}