Skip to content

Commit d53e46f

Browse files
committed
feat: add a method to get the inference container of a resource
1 parent 063b77a commit d53e46f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/modelinference/InferredModelUtil.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.eclipse.emf.ecore.resource.Resource;
1919
import org.eclipse.jdt.annotation.NonNull;
2020
import org.eclipse.jdt.annotation.Nullable;
21-
import org.eclipse.xtext.resource.XtextResource;
21+
import org.eclipse.xtext.resource.XtextResource
2222

2323

2424
/**
@@ -29,6 +29,22 @@ public class InferredModelUtil {
2929
protected InferredModelUtil() { // No public constructor for utility class
3030
}
3131

32+
/**
33+
* Gets the inference container for the given resource.
34+
*
35+
* @param resource
36+
* the resource
37+
* @return the inference container or {@code null} if there aren't any
38+
*/
39+
public static @Nullable InferenceContainer getInferenceContainer(final @NonNull Resource resource) {
40+
for (EObject content: resource.getContents()) {
41+
if (content instanceof InferenceContainer inferenceContainer) {
42+
return inferenceContainer;
43+
}
44+
}
45+
return null;
46+
}
47+
3248
/**
3349
* Gets the model associations corresponding to an EObject.
3450
* <p>

0 commit comments

Comments
 (0)