Search in sources :

Example 6 with TModule

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

the class AmbiguousImportDescription method getMessage.

@Override
public String getMessage() {
    StringBuilder typeListStr = new StringBuilder();
    IdentifiableElement first = (IdentifiableElement) EcoreUtil.resolve(getEObjectOrProxy(), context);
    String typeIdent = first instanceof Type ? "type" : "variable";
    TModule module = (TModule) first.eContainer();
    typeListStr.append(module.getQualifiedName());
    Set<IdentifiableElement> uniqueTypes = Sets.newLinkedHashSet(elements);
    uniqueTypes.remove(first);
    Iterator<IdentifiableElement> iter = uniqueTypes.iterator();
    while (iter.hasNext()) {
        IdentifiableElement type = iter.next();
        if (iter.hasNext()) {
            typeListStr.append(", ");
        } else {
            typeListStr.append(" and ");
        }
        typeListStr.append(((TModule) type.eContainer()).getQualifiedName());
    }
    if (this.issueCode == IssueCodes.IMP_AMBIGUOUS_WILDCARD) {
        return IssueCodes.getMessageForIMP_AMBIGUOUS_WILDCARD(typeIdent, getName(), typeListStr.toString());
    } else if (this.issueCode == IssueCodes.IMP_AMBIGUOUS) {
        return IssueCodes.getMessageForIMP_AMBIGUOUS(typeIdent, getName(), typeListStr.toString());
    } else if (this.issueCode == IssueCodes.IMP_DUPLICATE_NAMESPACE) {
        return IssueCodes.getMessageForIMP_DUPLICATE_NAMESPACE(getName(), "stub");
    }
    return "Unknown ambiguous import issue: " + this.issueCode + " for " + context + ".";
}
Also used : Type(org.eclipse.n4js.ts.types.Type) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) TModule(org.eclipse.n4js.ts.types.TModule)

Example 7 with TModule

use of org.eclipse.n4js.ts.types.TModule 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 8 with TModule

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

the class ImportsFactory method createImportDeclaration.

private ImportDeclaration createImportDeclaration(Adapter nodelessMarker, String moduleName) {
    ImportDeclaration ret = N4JS_FACTORY.createImportDeclaration();
    TModule tmodule = TYPES_FACTORY.createTModule();
    tmodule.setQualifiedName(moduleName);
    ret.setModule(tmodule);
    ret.eAdapters().add(nodelessMarker);
    return ret;
}
Also used : ImportDeclaration(org.eclipse.n4js.n4JS.ImportDeclaration) TModule(org.eclipse.n4js.ts.types.TModule)

Example 9 with TModule

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

the class ImportsFactory method createNamedImport.

/**
 * Creates a new named import of 'name' from 'module'
 */
private ImportDeclaration createNamedImport(String name, IN4JSProject contextProject, TExportableElement te, Adapter nodelessMarker) {
    TModule tmodule = te.getContainingModule();
    IN4JSProject targetProject = core.findProject(te.eResource().getURI()).orNull();
    String moduleQN;
    if (targetProject != null && tmodule.getQualifiedName().toString().equals(targetProject.getMainModule())) {
        // If the project has a main module, use project import instead.
        moduleQN = targetProject.getProjectId();
    } else {
        // Standard case
        moduleQN = te.getContainingModule().getQualifiedName();
    }
    QualifiedName qn = qualifiedNameConverter.toQualifiedName(moduleQN);
    String firstSegment = qn.getFirstSegment();
    IN4JSProject project = ImportSpecifierUtil.getDependencyWithID(firstSegment, contextProject);
    return createImportDeclaration(qn, name, project, nodelessMarker, this::addNamedImport);
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) TModule(org.eclipse.n4js.ts.types.TModule)

Example 10 with TModule

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

the class ProjectCompareHelper method findImplementation.

private TModule findImplementation(TModule moduleApi, IN4JSProject projectImpl, ResourceSet resourceSet, IResourceDescriptions index) {
    final String fqnStr = moduleApi.getQualifiedName();
    final URI uri = artifactHelper.findArtifact(projectImpl, fqnStr, Optional.of(N4JSGlobals.N4JS_FILE_EXTENSION));
    if (uri == null)
        return null;
    final IResourceDescription resDesc = index.getResourceDescription(uri);
    if (resDesc == null)
        return null;
    final TModule moduleImpl = getModuleFrom(resourceSet, resDesc);
    return moduleImpl;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) TModule(org.eclipse.n4js.ts.types.TModule) URI(org.eclipse.emf.common.util.URI)

Aggregations

TModule (org.eclipse.n4js.ts.types.TModule)48 EObject (org.eclipse.emf.ecore.EObject)12 Resource (org.eclipse.emf.ecore.resource.Resource)8 URI (org.eclipse.emf.common.util.URI)7 Type (org.eclipse.n4js.ts.types.Type)7 TMember (org.eclipse.n4js.ts.types.TMember)6 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)5 InternalEObject (org.eclipse.emf.ecore.InternalEObject)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)4 Script (org.eclipse.n4js.n4JS.Script)4 IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)4 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)4 N4JSResource (org.eclipse.n4js.resource.N4JSResource)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CoreException (org.eclipse.core.runtime.CoreException)2 XMIResource (org.eclipse.emf.ecore.xmi.XMIResource)2 XMIResourceImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)2 ImportDeclaration (org.eclipse.n4js.n4JS.ImportDeclaration)2 ContainerType (org.eclipse.n4js.ts.types.ContainerType)2