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


Java IPath.hasTrailingSeparator方法代码示例

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


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

示例1: getProposals

import org.eclipse.core.runtime.IPath; //导入方法依赖的package包/类
@Override
public IContentProposal[] getProposals(String contents, int position) {
	IContainer proposalRootFolder;

	if (null == rootFolder) {
		return EMPTY_PROPOSAL;
	}

	if (rootFolder.isEmpty()) {
		proposalRootFolder = ResourcesPlugin.getWorkspace().getRoot();
	} else if (rootFolder.segmentCount() == 1) {
		proposalRootFolder = ResourcesPlugin.getWorkspace().getRoot().getProject(rootFolder.segment(0));
	} else {
		proposalRootFolder = findContainerForPath(rootFolder);
	}

	if (null == proposalRootFolder || !proposalRootFolder.exists()) {
		return EMPTY_PROPOSAL;
	}

	// The field content as path
	IPath contentsPath = new Path(contents);

	// The directory to look for prefix matches
	IPath workingDirectoryPath;

	// If the contents path has a trailing separator...
	if (contentsPath.hasTrailingSeparator()) {
		// Use the full content as working directory path
		workingDirectoryPath = contentsPath;
	} else {
		// Otherwise only use complete segments as working directory
		workingDirectoryPath = contentsPath.removeLastSegments(1);
	}

	IContainer workingDirectory;

	if (workingDirectoryPath.segmentCount() > 0) {
		workingDirectory = proposalRootFolder.getFolder(workingDirectoryPath);
	} else {
		workingDirectory = proposalRootFolder;
	}

	// Return an empty proposal list for non-existing working directories
	if (null == workingDirectory || !workingDirectory.exists()) {
		return EMPTY_PROPOSAL;
	}
	try {
		return Arrays.asList(workingDirectory.members()).stream()
				// Only work with files and folders
				.filter(r -> (r instanceof IFile || r instanceof IFolder))
				// Filter by prefix matching
				.filter(resource -> {
					IPath rootRelativePath = resource.getFullPath().makeRelativeTo(rootFolder);
					return rootRelativePath.toString().startsWith(contentsPath.toString());
				})
				// Transform to a ModuleSpecifierProposal
				.map(resource -> {
					// Create proposal path
					IPath proposalPath = resource.getFullPath()
							.makeRelativeTo(proposalRootFolder.getFullPath());
					// Set the proposal type
					ModuleSpecifierProposal.ModuleProposalType type = resource instanceof IFile
							? ModuleSpecifierProposal.ModuleProposalType.MODULE
							: ModuleSpecifierProposal.ModuleProposalType.FOLDER;
					// Create a new module specifier proposal
					return ModuleSpecifierProposal.createFromPath(proposalPath, type);
				})
				.toArray(IContentProposal[]::new);
	} catch (CoreException e) {
		return EMPTY_PROPOSAL;
	}

}
 
开发者ID:eclipse,项目名称:n4js,代码行数:75,代码来源:ModuleSpecifierContentProposalProviderFactory.java


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