Java Code Examples for org.eclipse.xtext.naming.QualifiedName.create()

The following are Jave code examples for showing how to use create() of the org.eclipse.xtext.naming.QualifiedName class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: n4js   File: IntersectionMemberScope.java   Source Code and License Vote up 6 votes
@Override
protected IEObjectDescription getCheckedDescription(String name, TMember member) {
	IEObjectDescription description = EObjectDescription.create(member.getName(), member);

	QualifiedName qn = QualifiedName.create(name);
	boolean allDescrWithError = true;
	for (IScope currSubScope : subScopes) {
		IEObjectDescription subDescription = currSubScope.getSingleElement(qn);
		boolean descrWithError = subDescription == null || subDescription instanceof IEObjectDescriptionWithError;
		allDescrWithError &= descrWithError;
	}
	if (allDescrWithError) {
		return createComposedMemberDescriptionWithErrors(description);
	}

	return description;
}
 
Example 2
Project: n4js   File: UnionMemberScope.java   Source Code and License Vote up 6 votes
@Override
protected IEObjectDescription getCheckedDescription(String name, TMember member) {
	IEObjectDescription description = EObjectDescription.create(member.getName(), member);

	QualifiedName qn = QualifiedName.create(name);
	for (IScope currSubScope : subScopes) {
		IEObjectDescription subDescription = currSubScope.getSingleElement(qn);

		boolean descrWithError = subDescription == null || subDescription instanceof IEObjectDescriptionWithError;
		if (descrWithError) {
			return createComposedMemberDescriptionWithErrors(description);
		}
	}

	return description;
}
 
Example 3
Project: n4js   File: N4TSQualifiedNameProvider.java   Source Code and License Vote up 5 votes
/**
 * Null-safe appending of segments. If segment is null, null is returned. If prefix is null, a new qualified name
 * (with non-null segment) is created.
 */
protected static QualifiedName append(QualifiedName prefix, String segment) {
	if (segment == null) {
		return null;
	}
	if (prefix == null) {
		return QualifiedName.create(segment);
	}
	return prefix.append(segment);
}
 
Example 4
Project: n4js   File: N4TSQualifiedNameProvider.java   Source Code and License Vote up 5 votes
/**
 * Prefixing a qualified name. If the prefix segment is null, the suffix is returned, else if the suffix is null a
 * QN with only one segment is returned. Otherwise segment gets prefixed to suffix.
 */
protected static QualifiedName prepend(String segment, QualifiedName suffix) {
	if (segment == null) {
		return suffix;
	}
	QualifiedName qn = QualifiedName.create(segment);
	if (suffix != null) {
		qn = qn.append(suffix);
	}
	return qn;
}
 
Example 5
Project: n4js   File: ImportsAwareReferenceProposalCreator.java   Source Code and License Vote up 5 votes
/**
 * 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;
}
 
Example 6
Project: n4js   File: N4JSDReader.java   Source Code and License Vote up 5 votes
private SpecTestInfo createTestSpecInfo(String testeeName, Doclet doclet, TMember testMember,
		RepoRelativePath rrp) {
	return new SpecTestInfo(
			testeeName,
			QualifiedName.create(testMember.getContainingModule().getModuleSpecifier(),
					testMember.getContainingType().getName(), testMember.getName()),
			doclet,
			rrp != null ? rrp.withLine(testMember) : null);
}
 
Example 7
Project: n4js   File: ImportSpecifierUtil.java   Source Code and License Vote up 5 votes
/** returns qualified name of the {@link IN4JSProject#getMainModule() } */
public static QualifiedName getMainModuleOfProject(IN4JSProject project) {
	if (project != null) {
		final String mainModuleSpec = project.getMainModule();
		if (mainModuleSpec != null) {
			final QualifiedName mainModuleQN = QualifiedName.create(
					mainModuleSpec.split(N4JSQualifiedNameConverter.DELIMITER));
			return mainModuleQN;
		}
	}
	return null;
}
 
Example 8
Project: lcdsl   File: LcDslQualifiedNameProvider.java   Source Code and License Vote up 5 votes
protected QualifiedName qualifiedName(LaunchConfig config) {
    if (config.isQualify()) {
        if (config.getQualifierId() != null) {
            return QualifiedName.create(Splitter.on('.').splitToList(config.getQualifierId())).append(config.getName());
        }

        IFile f = ResourcesPlugin.getWorkspace().getRoot()
                .getFile(new Path(config.eResource().getURI().toPlatformString(true)));
        if (f != null && f.exists()) {
            return QualifiedName.create(Splitter.on('.').splitToList(f.getProject().getName())).append(config.getName());
        }
    }

    return QualifiedName.create(config.getName());
}
 
Example 9
Project: n4js   File: ImportsAwareReferenceProposalCreator.java   Source Code and License Vote up 4 votes
/**
 * 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);
			}
		}
	}
}