diff --git a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/scoping/utils/ProjectImportEnablingScope.java b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/scoping/utils/ProjectImportEnablingScope.java index 43ce6d2d7b..2fddcfbb78 100644 --- a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/scoping/utils/ProjectImportEnablingScope.java +++ b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/scoping/utils/ProjectImportEnablingScope.java @@ -175,10 +175,14 @@ public IEObjectDescription getSingleElement(QualifiedName name) { } else { // if mixed -> filter for module augmentations only // else -> nothing + boolean isAugmentationModuleOrModule = !importOrExportDecl.isPresent() + || DeclMergingUtils.isAugmentationModuleOrModule(importOrExportDecl.get()); List modAugmentations = new ArrayList<>(); - for (IEObjectDescription res : result) { - if (DeclMergingUtils.isAugmentationModuleOrModule(res)) { - modAugmentations.add(res); + if (isAugmentationModuleOrModule) { + for (IEObjectDescription res : result) { + if (DeclMergingUtils.isAugmentationModuleOrModule(res)) { + modAugmentations.add(res); + } } } result = modAugmentations.isEmpty() ? result : modAugmentations; diff --git a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/utils/DeclMergingUtils.java b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/utils/DeclMergingUtils.java index cb28b7557c..b62ba27f09 100644 --- a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/utils/DeclMergingUtils.java +++ b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/utils/DeclMergingUtils.java @@ -17,9 +17,12 @@ import org.eclipse.n4js.AnnotationDefinition; import org.eclipse.n4js.n4JS.IdentifierRef; import org.eclipse.n4js.n4JS.N4JSMetaModelUtils.N4JSMetaModelCache; +import org.eclipse.n4js.n4JS.Script; +import org.eclipse.n4js.n4JS.ScriptElement; import org.eclipse.n4js.resource.N4JSResourceDescriptionStrategy; import org.eclipse.n4js.scoping.utils.QualifiedNameUtils; import org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef; +import org.eclipse.n4js.ts.types.SyntaxRelatedTElement; import org.eclipse.n4js.ts.types.TModule; import org.eclipse.n4js.ts.types.TypesPackage; import org.eclipse.xtext.EcoreUtil2; @@ -113,7 +116,7 @@ public static boolean isMainModule(EObject elem) { /** Returns true iff the given element is the main module of a project or a (transitive) child. */ public static boolean isOrInMainModule(EObject elem) { - TModule tModule = EcoreUtil2.getContainerOfType(elem, TModule.class); + TModule tModule = getTModule(elem); return tModule != null && tModule.isMainModule(); } @@ -130,7 +133,7 @@ public static boolean isContainedInDeclaredModule(EObject elem) { /** Returns true iff the given element is either a non-ambient module or module augmentation. */ public static boolean isAugmentationModuleOrModule(EObject eobj) { - TModule tModule = EcoreUtil2.getContainerOfType(eobj, TModule.class); + TModule tModule = getTModule(eobj); if (tModule == null) { return false; } @@ -147,4 +150,17 @@ public static boolean isAugmentationModuleOrModule(IEObjectDescription descr) { EObject eobj = descr.getEObjectOrProxy(); return isAugmentationModuleOrModule(eobj); } + + /** Returns the TModule of a given T-element or AST-element */ + public static TModule getTModule(EObject eobj) { + if (eobj instanceof SyntaxRelatedTElement) { + return EcoreUtil2.getContainerOfType(eobj, TModule.class); + } else if (eobj instanceof ScriptElement) { + Script script = EcoreUtil2.getContainerOfType(eobj, Script.class); + if (script != null) { + return script.getModule(); + } + } + return null; + } }