本文整理汇总了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()]);
}