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


Java QualifiedName.getSegment方法代码示例

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


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

示例1: lookupCrossReference

import org.eclipse.xtext.naming.QualifiedName; //导入方法依赖的package包/类
/**
 * Retrieves possible reference targets from scope, including erroneous solutions (e.g., not visible targets). This
 * list is further filtered here. This is a general pattern: Do not change or modify scoping for special content
 * assist requirements, instead filter here.
 *
 * @param proposalFactory
 *            usually this will be an instance of
 *            {@link AbstractJavaBasedContentProposalProvider.DefaultProposalCreator DefaultProposalCreator}.
 * @param filter
 *            by default an instance of {@link N4JSCandidateFilter} will be provided here.
 */
@SuppressWarnings("javadoc")
public void lookupCrossReference(
		EObject model,
		EReference reference,
		ContentAssistContext context,
		ICompletionProposalAcceptor acceptor,
		Predicate<IEObjectDescription> filter,
		Function<IEObjectDescription, ICompletionProposal> proposalFactory) {
	if (model != null) {
		final IScope scope = ((IContentAssistScopeProvider) scopeProvider).getScopeForContentAssist(model,
				reference);

		// iterate over candidates, filter them, and create ICompletionProposals for them
		final Iterable<IEObjectDescription> candidates = scope.getAllElements();
		// don't use candidates.forEach since we want an early exit
		for (IEObjectDescription candidate : candidates) {
			if (!acceptor.canAcceptMoreProposals())
				return;
			if (filter.apply(candidate)) {
				QualifiedName qfn = candidate.getQualifiedName();
				String tmodule = null;

				if (qfn.getSegmentCount() >= 2) {
					tmodule = qfn.getSegment(qfn.getSegmentCount() - 2);
				}
				// In case of main module, adjust the qualified name, e.g. index.Element -> react.Element
				IN4JSProject project = n4jsCore.findProject(candidate.getEObjectURI()).orNull();
				QualifiedName candidateName;
				if (project != null && tmodule != null && tmodule.equals(project.getMainModule())) {
					candidateName = QualifiedName.create(project.getProjectId(),
							candidate.getQualifiedName().getLastSegment().toString());
				} else {
					candidateName = candidate.getQualifiedName();
				}

				final ICompletionProposal proposal = getProposal(candidate,
						model,
						scope,
						reference,
						context,
						filter,
						proposalFactory);
				if (proposal instanceof ConfigurableCompletionProposal
						&& candidate.getName().getSegmentCount() > 1) {
					ConfigurableCompletionProposal castedProposal = (ConfigurableCompletionProposal) proposal;
					castedProposal.setAdditionalData(FQNImporter.KEY_QUALIFIED_NAME,
							candidateName);
					// Original qualified name is the qualified name before adjustment
					castedProposal.setAdditionalData(FQNImporter.KEY_ORIGINAL_QUALIFIED_NAME,
							candidate.getQualifiedName());
				}
				acceptor.accept(proposal);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:68,代码来源:ImportsAwareReferenceProposalCreator.java


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