Search in sources :

Example 1 with AbstractModule

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");
        }
    }
}
Also used : NamedImportSpecifier(org.eclipse.n4js.n4JS.NamedImportSpecifier) N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName) NamespaceImportSpecifier(org.eclipse.n4js.n4JS.NamespaceImportSpecifier) QualifiedName(org.eclipse.xtext.naming.QualifiedName) TModule(org.eclipse.n4js.ts.types.TModule) AbstractModule(org.eclipse.n4js.ts.types.AbstractModule)

Example 2 with AbstractModule

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;
    }
}
Also used : TMember(org.eclipse.n4js.ts.types.TMember) AbstractModule(org.eclipse.n4js.ts.types.AbstractModule)

Example 3 with AbstractModule

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;
    }
}
Also used : TMember(org.eclipse.n4js.ts.types.TMember) AbstractModule(org.eclipse.n4js.ts.types.AbstractModule)

Example 4 with AbstractModule

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));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) AbstractModule(org.eclipse.n4js.ts.types.AbstractModule)

Example 5 with AbstractModule

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));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) AbstractModule(org.eclipse.n4js.ts.types.AbstractModule)

Aggregations

AbstractModule (org.eclipse.n4js.ts.types.AbstractModule)15 TModule (org.eclipse.n4js.ts.types.TModule)5 TMember (org.eclipse.n4js.ts.types.TMember)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 LinkedHashSet (java.util.LinkedHashSet)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 XMIResource (org.eclipse.emf.ecore.xmi.XMIResource)1 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)1 RepoRelativePath (org.eclipse.n4js.jsdoc2spec.RepoRelativePath)1 ImportDeclaration (org.eclipse.n4js.n4JS.ImportDeclaration)1 NamedImportSpecifier (org.eclipse.n4js.n4JS.NamedImportSpecifier)1 NamespaceImportSpecifier (org.eclipse.n4js.n4JS.NamespaceImportSpecifier)1 Script (org.eclipse.n4js.n4JS.Script)1 ScriptElement (org.eclipse.n4js.n4JS.ScriptElement)1 N4JSResource (org.eclipse.n4js.resource.N4JSResource)1 ProjectComparisonEntry (org.eclipse.n4js.tooling.compare.ProjectComparisonEntry)1