use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class ImportsAwareReferenceProposalCreator method lookupCrossReference.
/**
* 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);
}
}
}
}
use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class ExternalLibraryTreeContentProvider method updateElement.
@Override
public void updateElement(final Object parent, final int index) {
if (treeViewerRef.isPresent()) {
final TreeViewer treeViewer = treeViewerRef.get();
if (parent instanceof Iterable) {
final Object child = Iterables.get((Iterable<?>) parent, index);
treeViewer.replace(parent, index, child);
if (child instanceof URI) {
treeViewer.setChildCount(child, Iterables.size(getProjects((URI) child)));
}
} else if (parent instanceof URI) {
final IN4JSProject child = Iterables.get(getProjects((URI) parent), index);
treeViewer.replace(parent, index, child);
}
}
}
use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class ProjectCompareHelper method createEntries.
// may be made public later
private ProjectComparisonEntry createEntries(ProjectComparison root, IN4JSProject api, IN4JSProject[] impls, ResourceSet resourceSet, IResourceDescriptions index) {
final ProjectComparisonEntry entry = new ProjectComparisonEntry(root, api, impls);
for (IN4JSSourceContainer currSrcConti : api.getSourceContainers()) {
for (URI uri : currSrcConti) {
final String uriStr = uri.toString();
if (uriStr.endsWith("." + N4JSGlobals.N4JS_FILE_EXTENSION) || uriStr.endsWith("." + N4JSGlobals.N4JSD_FILE_EXTENSION)) {
final IResourceDescription resDesc = index.getResourceDescription(uri);
final TModule moduleApi = getModuleFrom(resourceSet, resDesc);
if (moduleApi != null) {
final TModule[] moduleImpls = new TModule[impls.length];
for (int idx = 0; idx < impls.length; idx++) {
final IN4JSProject projectImpl = impls[idx];
if (projectImpl != null)
moduleImpls[idx] = findImplementation(moduleApi, projectImpl, resourceSet, index);
else
moduleImpls[idx] = null;
}
createEntries(entry, -1, moduleApi, moduleImpls, false);
}
}
}
}
return entry;
}
use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class ProjectCompareHelper method createComparison.
/**
* First step in comparing API and implementation projects. This method will collect all API projects, the types
* declared there and their members and relate them to the corresponding types and members in all available
* implementation projects.
* <p>
* The second step of comparison is to compare an individual type/member to a corresponding type/member of a
* particular implementation via method {@link #compareApiImpl(ProjectComparisonEntry, int)}.
* <p>
* Usually, this second step is performed lazily when method <code>#compareApiImpl()</code> is invoked; however, by
* setting <code>fullCompare</code> to <code>true</code>, this is performed up-front here causing all results to be
* stored in a cache in the entries, and then subsequent calls to <code>#compareApiImpl()</code> will just read from
* that cache.
* <p>
* Returns <code>null</code> in case of error and adds human-readable error messages to the given list.
*/
public ProjectComparison createComparison(boolean fullCompare, List<String> addErrorMessagesHere) {
final ResourceSet resourceSet = n4jsCore.createResourceSet(Optional.absent());
final IResourceDescriptions index = n4jsCore.getXtextIndex(resourceSet);
final ApiImplMapping mapping = ApiImplMapping.of(n4jsCore);
if (mapping.hasErrors()) {
if (addErrorMessagesHere != null)
addErrorMessagesHere.addAll(mapping.getErrorMessages());
return null;
}
final List<String> allImplIds = mapping.getAllImplIds();
final int implCount = allImplIds.size();
final ProjectComparison root = new ProjectComparison(allImplIds.toArray(new String[implCount]));
for (String currApiId : mapping.getApiIds()) {
final IN4JSProject currApi = mapping.getApi(currApiId);
final IN4JSProject[] currImpls = new IN4JSProject[implCount];
for (int idx = 0; idx < implCount; idx++) {
final String currImplId = allImplIds.get(idx);
currImpls[idx] = mapping.getImpl(currApiId, currImplId);
}
createEntries(root, currApi, currImpls, resourceSet, index);
}
// compare all implementations in all entries and store in cache (if requested)
if (fullCompare) {
root.getAllEntries().forEach(currE -> {
for (int implIdx = 0; implIdx < implCount; implIdx++) compareApiImpl(currE, implIdx);
});
}
return root;
}
use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class ApiImplMapping method getErrorMessages.
/**
* In {@link #hasErrors() case of error}, returns human-readable error messages. Otherwise, an empty list will be
* returned.
*/
public List<String> getErrorMessages() {
final List<String> msgs = new ArrayList<>();
for (IN4JSProject p : projectsWithUndefImplIds) {
msgs.add("project '" + p.getProjectId() + "' does not define an ImplementationId in its manifest");
}
for (Map.Entry<Pair<String, String>, Set<IN4JSProject>> currConflict : conflicts.entrySet()) {
final String apiId = currConflict.getKey().getKey();
final String implId = currConflict.getKey().getValue();
final Set<IN4JSProject> culprits = currConflict.getValue();
final String culpritsStr = " - " + culprits.stream().map(c -> c.getProjectId()).collect(Collectors.joining("\n - "));
msgs.add("several projects define an implementation for API project '" + apiId + "' with implementation ID '" + implId + "':\n" + culpritsStr);
}
return msgs;
}
Aggregations