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


Java QualifiedName.getSegmentCount方法代码示例

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


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

示例1: getActualReplacementString

import org.eclipse.xtext.naming.QualifiedName; //导入方法依赖的package包/类
/**
 * Return the to-be-inserted string if an existing import is present.
 */
@Override
public String getActualReplacementString(ConfigurableCompletionProposal proposal) {
	String syntacticReplacementString = proposal.getReplacementString();
	if (scope != null) {
		final QualifiedName qualifiedName = applyValueConverter(syntacticReplacementString);
		if (qualifiedName.getSegmentCount() == 1) {
			return syntacticReplacementString;
		}
		final IEObjectDescription element = scope.getSingleElement(qualifiedName);
		if (element != null) {
			EObject resolved = EcoreUtil.resolve(element.getEObjectOrProxy(), context);
			if (!resolved.eIsProxy()) {
				IEObjectDescription description = findApplicableDescription(resolved, qualifiedName, true);
				if (description != null) {
					String multisegmentProposal = applyValueConverter(description.getName());
					return multisegmentProposal;
				}
			}
		}
	}
	return syntacticReplacementString;

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

示例2: isPolyfill

import org.eclipse.xtext.naming.QualifiedName; //导入方法依赖的package包/类
/**
 * Returns true if the given name describes a polyfill, that is if it's second last segment matches
 * {@link #POLYFILL_SEGMENT}.
 */
public static boolean isPolyfill(QualifiedName name) {
	if (name == null || name.getSegmentCount() < 2) {
		return false;
	}
	// as long as Module-polyfill is not enforced, we check for presence and then adapt:
	int polyModuleOffest = isModulePolyfill(name) ? 1 : 0;
	return POLYFILL_SEGMENT.equals(name.getSegment(name.getSegmentCount() - (2 + polyModuleOffest)));
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:13,代码来源:N4TSQualifiedNameProvider.java

示例3: toStaticPolyfillFQN

import org.eclipse.xtext.naming.QualifiedName; //导入方法依赖的package包/类
/**
 * Return corresponding FQN for staticPolyfill (prefixed with !MPOLY
 *
 * @param name
 *            non-filled name
 * @return fqn of filling, not present if name itself denotes a static polyfill or is null.
 */
public static Optional<QualifiedName> toStaticPolyfillFQN(QualifiedName name) {
	if (name != null
			&& name.getSegmentCount() > 0
			&& !MODULE_POLYFILL_SEGMENT.equals(name.getSegment(0))) {
		return Optional.of(prepend(MODULE_POLYFILL_SEGMENT, name));
	} else
		return Optional.empty();
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:16,代码来源:N4TSQualifiedNameProvider.java

示例4: getAliasedDescription

import org.eclipse.xtext.naming.QualifiedName; //导入方法依赖的package包/类
/**
 * Creates proposal taking semantics of the N4JS imports into account.
 *
 * @param candidate
 *            the original input for which we create proposal
 * @param reference
 *            the reference
 * @param context
 *            the context
 * @return candidate proposal adjusted to the N4JS imports
 */
private IEObjectDescription getAliasedDescription(IEObjectDescription candidate, EReference reference,
		ContentAssistContext context) {

	// Content assist at a location where only simple names are allowed:
	// We found a qualified name and we'd need an import to be allowed to use
	// that name. Consider only the simple name of the element from the index
	// and make sure that the import is inserted as soon as the proposal is applied
	QualifiedName inputQN = candidate.getName();
	int inputNameSegmentCount = inputQN.getSegmentCount();
	if (reference == N4JSPackage.Literals.IDENTIFIER_REF__ID && inputNameSegmentCount > 1)
		return new AliasedEObjectDescription(QualifiedName.create(inputQN.getLastSegment()), candidate);

	// filter out non-importable things:
	// globally provided things should never be imported:
	if (inputNameSegmentCount == 2 && N4TSQualifiedNameProvider.GLOBAL_NAMESPACE_SEGMENT
			.equals(inputQN.getFirstSegment()))
		return new AliasedEObjectDescription(QualifiedName.create(inputQN.getLastSegment()), candidate);

	// special handling for default imports:
	if (inputQN.getLastSegment().equals(N4JSLanguageConstants.EXPORT_DEFAULT_NAME)) {
		EObject element = candidate.getEObjectOrProxy();
		if (element instanceof TExportableElement) {
			TExportableElement exported = (TExportableElement) element;
			if (N4JSLanguageConstants.EXPORT_DEFAULT_NAME.equals(exported.getExportedName())) {
				return new AliasedEObjectDescription(inputQN, candidate);
			}
		}
		// not accessed via namespace
		QualifiedName nameNoDefault = inputQN.skipLast(1);
		QualifiedName moduleName = nameNoDefault.getSegmentCount() > 1
				? QualifiedName.create(nameNoDefault.getLastSegment()) : nameNoDefault;
		return new AliasedEObjectDescription(moduleName, candidate);
	}
	// no special handling, return original input
	return candidate;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:48,代码来源:ImportsAwareReferenceProposalCreator.java

示例5: computeImportType

import org.eclipse.xtext.naming.QualifiedName; //导入方法依赖的package包/类
/**
 * Computes {@link ImportType} for a given name in the given project.
 *
 * @param name
 *            for which import specifier type is computed
 * @param useProjectId
 *            flag if project name should be taken into consideration
 * @param project
 *            the project from which import will be specified
 * @return the {@link ImportType}
 */
public static ImportType computeImportType(QualifiedName name, boolean useProjectId,
		IN4JSProject project) {
	if (useProjectId) {
		// PRIORITY 1: 'name' is a complete module specifier, i.e. projectId+'/'+moduleSpecifier
		// -> search all Xtext index entries that match moduleSpecifier and filter by projectId
		final QualifiedName moduleSpecifier;
		if (name.getSegmentCount() == 1) {
			// special case: no module specifier given (only a project ID), i.e. we have a pure project import
			// -> interpret this as an import of the target project's main module
			moduleSpecifier = getMainModuleOfProject(project);
			if (moduleSpecifier == null) {
				// error: we have a project import to a project that does not define a main module via
				// the 'MainModule' property in the manifest -> unresolved reference error
				return ImportType.PROJECT_IMPORT_NO_MAIN;
			} else {
				return ImportType.PROJECT_IMPORT;
			}
		} else {
			return ImportType.COMPLETE_IMPORT;
		}
	}
	// PRIORITY 2: interpret 'name' as a plain module specifier (i.e. without project ID)
	// -> simplest case, because this is exactly how elements are identified within the Xtext index,
	// so we can simply forward this request to the parent scope
	return ImportType.SIMPLE_IMPORT;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:38,代码来源:ImportSpecifierUtil.java

示例6: 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

示例7: getSingleLocalElementByName

import org.eclipse.xtext.naming.QualifiedName; //导入方法依赖的package包/类
@Override
protected IEObjectDescription getSingleLocalElementByName(QualifiedName name) {
	if (name.getSegmentCount() != 1) {
		return null;
	}
	final String nameAsString = name.getFirstSegment();

	// both read/write required
	if (ExpressionExtensions.isBothReadFromAndWrittenTo(context)) {
		TMember reader = findMember(nameAsString, false, staticAccess);
		TMember writer = findMember(nameAsString, true, staticAccess);
		if (null == reader && null == writer) {
			// will be caught as error "Could not resolve reference"
			return null;
		}
		if (null == reader) {
			return new UnsatisfiedRWAccessDescription(EObjectDescription.create(writer.getName(), writer), true);
		}
		if (null == writer) {
			return new UnsatisfiedRWAccessDescription(EObjectDescription.create(reader.getName(), reader), false);
		}
		// pick arbitrarily the setter
		return createSingleElementDescription(writer);
	}

	// either read or write requirement that moreover is satisfied
	final boolean accessForWriteOperation = ExpressionExtensions.isLeftHandSide(context);
	TMember existingMember = findMember(nameAsString, accessForWriteOperation, staticAccess);
	if (existingMember != null) {
		return createSingleElementDescription(existingMember);
	}

	// wrong read/write
	existingMember = findMember(nameAsString, !accessForWriteOperation, staticAccess);
	if (existingMember != null) {

		// allowed special case: writing in the ctor to a final field that lacks init value
		final boolean isAssOfFinalInCtor = N4JSASTUtils
				.isSemiLegalAssignmentToFinalFieldInCtor(context.eContainer(), existingMember);
		final boolean isLegalAssOfFinalInCtor = isAssOfFinalInCtor && !((TField) existingMember).isHasExpression();
		if (isLegalAssOfFinalInCtor) {
			return createSingleElementDescription(existingMember);
		}

		// allowed special case: wrong read/write in a mode other than N4JS
		if (jsVariantHelper.allowWrongReadWrite(context)) { // cf. sec. 13.1
			return createSingleElementDescription(existingMember);
		}

		return new WrongWriteAccessDescription(
				EObjectDescription.create(existingMember.getName(), existingMember),
				accessForWriteOperation, isAssOfFinalInCtor);
	}

	// wrong static / non-static
	existingMember = findMember(nameAsString, accessForWriteOperation, !staticAccess);
	if (existingMember == null) {
		// if both read/write access and static access are wrong, we want to
		// complain (only) about "wrong static access" -> so include this case here
		existingMember = findMember(nameAsString, !accessForWriteOperation, !staticAccess);
	}
	if (existingMember != null) {
		return new WrongStaticAccessDescription(
				EObjectDescription.create(existingMember.getName(), existingMember),
				staticAccess);
	}

	return null;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:70,代码来源:AbstractMemberScope.java

示例8: isModulePolyfill

import org.eclipse.xtext.naming.QualifiedName; //导入方法依赖的package包/类
/**
 * Checks if this qualified name denotes an element inside of a polyfill module.
 *
 * @param name
 *            to investigate.
 * @return <code>true</code> if the first segment of name is {@link #MODULE_POLYFILL_SEGMENT}
 */
public static boolean isModulePolyfill(QualifiedName name) {
	if (name == null || name.getSegmentCount() < 1)
		return false;
	return MODULE_POLYFILL_SEGMENT.equals(name.getSegment(0));
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:13,代码来源:N4TSQualifiedNameProvider.java


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