use of org.eclipse.n4js.ts.types.AbstractModule in project n4js by eclipse.
the class ImportHelper method createImportDescriptorFromAST.
/**
* Creates an {@link ImportDescriptor} for a given existing import in the AST.
*
* @param importDecl
* the import declaration. May not be <code>null</code>.
* @param importSpec
* the import specification in case of a named or namespace import; <code>null</code> denotes a bare
* import.
* @param originalIndex
* the original index to set in the newly created {@link ImportDescriptor}. This should usually reflect
* the original order of imports in the AST.
* @return a newly created import descriptor.
*/
public ImportDescriptor createImportDescriptorFromAST(ImportDeclaration importDecl, ImportSpecifier importSpec, int originalIndex) {
Objects.requireNonNull(importDecl);
if (importSpec != null && !importSpec.isFlaggedUsedInCode()) {
throw new IllegalArgumentException("must not create an ImportDescriptor for unused imports");
}
if ((importSpec == null && ImportSpecifiersUtil.isBrokenImport(importDecl)) || (importSpec != null && ImportSpecifiersUtil.isBrokenImport(importSpec))) {
throw new IllegalArgumentException("must not create an ImportDescriptor for broken imports");
}
AbstractModule module = importDecl.getModule();
Optional<N4JSPackageName> targetProjectName = module instanceof TModule ? Optional.of(new N4JSPackageName(((TModule) module).getPackageName())) : // module declaration), so they do not have a targetProjectName:
Optional.absent();
QualifiedName targetModule = qualifiedNameConverter.toQualifiedName(module.getQualifiedName());
String moduleSpecifier = importDecl.getModuleSpecifierAsText();
if (importDecl.isBare()) {
return ImportDescriptor.createBareImport(moduleSpecifier, targetProjectName, targetModule, originalIndex);
} else {
if (importSpec instanceof NamedImportSpecifier) {
NamedImportSpecifier importSpecCasted = (NamedImportSpecifier) importSpec;
if (importSpecCasted.isDefaultImport()) {
String localName = importSpecCasted.getAlias();
return ImportDescriptor.createDefaultImport(localName, moduleSpecifier, targetProjectName, targetModule, originalIndex);
} else {
String elementName = importSpecCasted.getImportedElementAsText();
String alias = importSpecCasted.getAlias();
return ImportDescriptor.createNamedImport(elementName, alias, moduleSpecifier, targetProjectName, targetModule, originalIndex);
}
} else if (importSpec instanceof NamespaceImportSpecifier) {
String localNamespaceName = ((NamespaceImportSpecifier) importSpec).getAlias();
boolean isDynamic = ((NamespaceImportSpecifier) importSpec).isDeclaredDynamic();
return ImportDescriptor.createNamespaceImport(localNamespaceName, isDynamic, moduleSpecifier, targetProjectName, targetModule, originalIndex);
} else if (importSpec != null) {
throw new IllegalArgumentException("unknown subclass of ImportSpecifier: " + importSpec.getClass().getSimpleName());
} else {
throw new IllegalArgumentException("importSpec may be null only if importDecl is a bare import");
}
}
}
use of org.eclipse.n4js.ts.types.AbstractModule in project n4js by eclipse.
the class KeyUtils method nameFromElement.
private static String nameFromElement(RepoRelativePathHolder rrph, IdentifiableElement element) {
if (element instanceof TMember) {
TMember tMember = (TMember) element;
String name = nameFromElement(rrph, tMember.getContainingType());
return name + "#" + element.getName();
}
AbstractModule module = element.getContainingModule();
if (module == null) {
String name = "##global##." + element.getName();
return name;
} else {
String name = module.getModuleSpecifier() + "." + element.getName();
return name;
}
}
use of org.eclipse.n4js.ts.types.AbstractModule in project n4js by eclipse.
the class KeyUtils method getSpecKeyPrefix.
/**
* @return a complete spec key comprised of the whole {@link RepoRelativePath}
*/
public static String getSpecKeyPrefix(RepoRelativePathHolder rrph, IdentifiableElement element) {
if (element instanceof TMember) {
ContainerType<?> containingType = ((TMember) element).getContainingType();
return getSpecKeyPrefix(rrph, containingType);
}
AbstractModule module = element.getContainingModule();
if (module == null) {
return "GLOBAL.";
} else {
RepoRelativePath rrp = rrph.get(element);
String key = rrp.getFullPath();
return key;
}
}
use of org.eclipse.n4js.ts.types.AbstractModule in project n4js by eclipse.
the class ExportDeclarationImpl method setReexportedFrom.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setReexportedFrom(AbstractModule newReexportedFrom) {
AbstractModule oldReexportedFrom = reexportedFrom;
reexportedFrom = newReexportedFrom;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.EXPORT_DECLARATION__REEXPORTED_FROM, oldReexportedFrom, reexportedFrom));
}
use of org.eclipse.n4js.ts.types.AbstractModule in project n4js by eclipse.
the class ModuleNamespaceVirtualTypeImpl method setModule.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setModule(AbstractModule newModule) {
AbstractModule oldModule = module;
module = newModule;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, TypesPackage.MODULE_NAMESPACE_VIRTUAL_TYPE__MODULE, oldModule, module));
}
Aggregations