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);
}
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;
}
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;
}
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);
}
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);
}
Aggregations