Search in sources :

Example 1 with TExportableElement

use of org.eclipse.n4js.ts.types.TExportableElement in project n4js by eclipse.

the class ImportProvidedElementLabelprovider method getText.

@Override
public String getText(Object element) {
    if (element instanceof ImportableObject) {
        ImportableObject io = (ImportableObject) element;
        return getText(io.getTe());
    }
    if (element instanceof ImportProvidedElement) {
        ImportProvidedElement ele = ((ImportProvidedElement) element);
        TModule tm = ((ImportDeclaration) ele.getImportSpecifier().eContainer()).getModule();
        return ele.getLocalName() + " from " + findLocation(tm);
    }
    if (element instanceof IEObjectDescription) {
        IEObjectDescription ieod = (IEObjectDescription) element;
        EObject eo = ieod.getEObjectOrProxy();
        if (eo instanceof TExportableElement && !eo.eIsProxy()) {
            return getText(eo);
        }
        return ieod.getName().getLastSegment() + " from " + qualifiedNameConverter.toString(ieod.getName().skipLast(1));
    }
    if (element instanceof TExportableElement) {
        TExportableElement te = (TExportableElement) element;
        return te.getName() + " (exported as " + te.getExportedName() + ") from " + findLocation(te.getContainingModule());
    }
    return n4Labelprovider.getText(element);
}
Also used : ImportProvidedElement(org.eclipse.n4js.organize.imports.ImportProvidedElement) TExportableElement(org.eclipse.n4js.ts.types.TExportableElement) EObject(org.eclipse.emf.ecore.EObject) ImportDeclaration(org.eclipse.n4js.n4JS.ImportDeclaration) TModule(org.eclipse.n4js.ts.types.TModule) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 2 with TExportableElement

use of org.eclipse.n4js.ts.types.TExportableElement in project n4js by eclipse.

the class ImportsFactory method addNamedImport.

private ImportDeclaration addNamedImport(String name, ImportDeclaration importDeclaration) {
    NamedImportSpecifier namedImportSpec = N4JS_FACTORY.createNamedImportSpecifier();
    TExportableElement importetElement = TYPES_FACTORY.createTExportableElement();
    importetElement.setName(name);
    namedImportSpec.setImportedElement(importetElement);
    importDeclaration.getImportSpecifiers().add(namedImportSpec);
    return importDeclaration;
}
Also used : NamedImportSpecifier(org.eclipse.n4js.n4JS.NamedImportSpecifier) TExportableElement(org.eclipse.n4js.ts.types.TExportableElement)

Example 3 with TExportableElement

use of org.eclipse.n4js.ts.types.TExportableElement in project n4js by eclipse.

the class ImportsAwareReferenceProposalCreator method getAliasedDescription.

/**
 * 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);
    // 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;
}
Also used : AliasedEObjectDescription(org.eclipse.xtext.resource.impl.AliasedEObjectDescription) TExportableElement(org.eclipse.n4js.ts.types.TExportableElement) QualifiedName(org.eclipse.xtext.naming.QualifiedName) EObject(org.eclipse.emf.ecore.EObject)

Example 4 with TExportableElement

use of org.eclipse.n4js.ts.types.TExportableElement in project n4js by eclipse.

the class N4IDLTranspilerUtils method getVersionedInternalName.

/**
 * Returns the internal versioned name of the given {@link NamedImportSpecifier}.
 *
 * This method is aware of aliases. If the specifier does not import a {@link TVersionable} element, this method
 * returns the plain name.
 *
 * @param specifier
 *            The {@link NamedImportSpecifier} to compute the versioned internal name for.
 */
public static String getVersionedInternalName(NamedImportSpecifier specifier) {
    final TExportableElement importedElement = specifier.getImportedElement();
    final String alias = specifier.getAlias();
    final String importedName = null != alias ? alias : importedElement.getExportedName();
    // for non-versionable elements apply
    if (!VersionUtils.isTVersionable(importedElement)) {
        return importedName;
    }
    final int version = ((TVersionable) importedElement).getVersion();
    return getVersionedInternalName(importedName, version);
}
Also used : TVersionable(org.eclipse.n4js.ts.types.TVersionable) TExportableElement(org.eclipse.n4js.ts.types.TExportableElement)

Example 5 with TExportableElement

use of org.eclipse.n4js.ts.types.TExportableElement in project n4js by eclipse.

the class ImportRewriter method addImportSpecifier.

private void addImportSpecifier(ImportDeclaration importDeclaration, QualifiedName qualifiedName, String optionalAlias) {
    boolean isDefaultExport = N4JSLanguageUtils.isDefaultExport(qualifiedName);
    NamedImportSpecifier specifier = null;
    specifier = isDefaultExport ? N4JSFactory.eINSTANCE.createDefaultImportSpecifier() : N4JSFactory.eINSTANCE.createNamedImportSpecifier();
    // not only types, but also variables ...
    Iterable<TExportableElement> topLevelTypes = Iterables.concat(importDeclaration.getModule().getTopLevelTypes(), importDeclaration.getModule().getVariables());
    for (TExportableElement t : topLevelTypes) {
        if (t.getExportedName().equals(qualifiedName.getLastSegment())) {
            specifier.setImportedElement(t);
            specifier.setAlias(optionalAlias);
            if (optionalAlias == null && isDefaultExport) {
                // set to
                specifier.setAlias(qualifiedName.getSegment(qualifiedName.getSegmentCount() - 2));
            // module-name
            }
            break;
        }
    }
    if (isDefaultExport)
        // to Front
        importDeclaration.getImportSpecifiers().add(0, specifier);
    else
        importDeclaration.getImportSpecifiers().add(specifier);
}
Also used : NamedImportSpecifier(org.eclipse.n4js.n4JS.NamedImportSpecifier) TExportableElement(org.eclipse.n4js.ts.types.TExportableElement)

Aggregations

TExportableElement (org.eclipse.n4js.ts.types.TExportableElement)7 EObject (org.eclipse.emf.ecore.EObject)2 NamedImportSpecifier (org.eclipse.n4js.n4JS.NamedImportSpecifier)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 DefaultImportSpecifier (org.eclipse.n4js.n4JS.DefaultImportSpecifier)1 ImportDeclaration (org.eclipse.n4js.n4JS.ImportDeclaration)1 ImportProvidedElement (org.eclipse.n4js.organize.imports.ImportProvidedElement)1 TModule (org.eclipse.n4js.ts.types.TModule)1 TVersionable (org.eclipse.n4js.ts.types.TVersionable)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 AliasedEObjectDescription (org.eclipse.xtext.resource.impl.AliasedEObjectDescription)1