use of org.eclipse.n4js.n4JS.ModuleSpecifierForm in project n4js by eclipse.
the class ImportDeclarationImpl method setModuleSpecifierForm.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setModuleSpecifierForm(ModuleSpecifierForm newModuleSpecifierForm) {
ModuleSpecifierForm oldModuleSpecifierForm = moduleSpecifierForm;
moduleSpecifierForm = newModuleSpecifierForm == null ? MODULE_SPECIFIER_FORM_EDEFAULT : newModuleSpecifierForm;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.IMPORT_DECLARATION__MODULE_SPECIFIER_FORM, oldModuleSpecifierForm, moduleSpecifierForm));
}
use of org.eclipse.n4js.n4JS.ModuleSpecifierForm in project n4js by eclipse.
the class ProjectImportEnablingScope method getElements.
@Override
public Iterable<IEObjectDescription> getElements(QualifiedName name) {
ModuleSpecifierForm moduleSpecifierForm = computeImportType(name, this.contextProject);
storeModuleSpecifierFormInAST(moduleSpecifierForm);
switch(moduleSpecifierForm) {
case PROJECT:
{
final N4JSPackageName firstSegment = new N4JSPackageName(name.getFirstSegment());
return findModulesInProject(Optional.absent(), firstSegment);
}
case COMPLETE:
{
final N4JSPackageName firstSegment = new N4JSPackageName(name.getFirstSegment());
return findModulesInProject(Optional.of(name.skipFirst(1)), firstSegment);
}
case PLAIN:
{
return parent.getElements(name);
}
default:
return Collections.emptyList();
}
}
use of org.eclipse.n4js.n4JS.ModuleSpecifierForm in project n4js by eclipse.
the class ProjectImportEnablingScope method getSingleElement.
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
final List<IEObjectDescription> result = Lists.newArrayList(getElements(name));
int size = result.size();
// handle combination of .js / .cjs / .mjs files with same base name
if (size > 1) {
removeSuperfluousPlainJsFiles(result);
size = result.size();
}
if (size == 1) {
// main case
return result.get(0);
}
// use sorted entries and linked map for determinism in error message
Collections.sort(result, Comparator.comparing(IEObjectDescription::getEObjectURI, Comparator.comparing(URI::toString)));
final Map<IEObjectDescription, N4JSProjectConfigSnapshot> descriptionsToProject = new LinkedHashMap<>();
for (IEObjectDescription objDescr : result) {
URI uri = objDescr.getEObjectURI();
N4JSProjectConfigSnapshot n4jsdProject = workspaceConfigSnapshot.findProjectContaining(uri);
descriptionsToProject.put(objDescr, n4jsdProject);
}
IEObjectDescription overwritingModule = handleCollisions(result, descriptionsToProject);
if (overwritingModule != null) {
return overwritingModule;
}
// if no import declaration was given, we skip the advanced error reporting
if (!importDeclaration.isPresent()) {
return null;
}
// handle special defaults
IEObjectDescription defaultModule = handleDefaults(descriptionsToProject);
if (defaultModule != null) {
return defaultModule;
}
// handle error cases to help user fix the issue
StringBuilder sbErrrorMessage = new StringBuilder("Cannot resolve ");
ModuleSpecifierForm importType = computeImportType(name, this.contextProject);
switch(importType) {
case PROJECT:
sbErrrorMessage.append("project import");
break;
case COMPLETE:
sbErrrorMessage.append("complete module specifier (with project name as first segment)");
break;
case PLAIN:
sbErrrorMessage.append("plain module specifier (without project name as first segment)");
break;
case PROJECT_NO_MAIN:
sbErrrorMessage.append("project import: target project does not define a main module");
break;
default:
sbErrrorMessage.append("module specifier");
break;
}
if (!importType.equals(ModuleSpecifierForm.PROJECT_NO_MAIN)) {
sbErrrorMessage.append(": ");
if (size == 0) {
sbErrrorMessage.append("no matching module found");
} else {
sbErrrorMessage.append("multiple matching modules found: ");
String matchingModules = "";
for (IEObjectDescription descr : descriptionsToProject.keySet()) {
if (!matchingModules.isEmpty()) {
matchingModules += ", ";
}
if (descr.getEObjectURI() != null) {
URI uri = descr.getEObjectURI().trimFragment();
URI relUri = uri.deresolve(workspaceConfigSnapshot.getPath());
Path relPath = Path.of(relUri.toFileString());
relPath = relPath.subpath(1, relPath.getNameCount());
matchingModules += relPath.toString();
} else {
matchingModules += descriptionsToProject.get(descr).getPackageName() + "/" + descr.getQualifiedName().toString();
}
}
sbErrrorMessage.append(matchingModules);
}
}
sbErrrorMessage.append('.');
final EObject originalProxy = (EObject) this.importDeclaration.get().eGet(N4JSPackage.eINSTANCE.getImportDeclaration_Module(), false);
return new IssueCodeBasedEObjectDescription(EObjectDescription.create("impDecl", originalProxy), sbErrrorMessage.toString(), IssueCodes.IMP_UNRESOLVED);
}
Aggregations