Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mmews committed Sep 5, 2024
1 parent e04d05a commit b62ad14
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<IEObjectDescription> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,7 +116,7 @@ public static boolean isMainModule(EObject elem) {

/** Returns <code>true</code> 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();
}

Expand All @@ -130,7 +133,7 @@ public static boolean isContainedInDeclaredModule(EObject elem) {

/** Returns <code>true</code> 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;
}
Expand All @@ -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;
}
}

0 comments on commit b62ad14

Please sign in to comment.