[400105] findTemplate: Use the prefix of the current resource as prefix
for a qualified name relative to the current resource
diff --git a/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandExecutionContextImpl.java b/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandExecutionContextImpl.java
index f7017c1..695fa37 100644
--- a/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandExecutionContextImpl.java
+++ b/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandExecutionContextImpl.java
@@ -282,9 +282,7 @@
}
public XpandResource findTemplate(final String templateName, String[] importedNs) {
- final List<?> possibleNames = typeSystem.getPossibleNames(templateName, importedNs);
- for (final Iterator<?> iter = possibleNames.iterator(); iter.hasNext();) {
- final String element = (String) iter.next();
+ for (String element: getPossibleNames(templateName, importedNs)) {
final XpandResource tpl = (XpandResource) resourceManager.loadResource(element,
XpandUtil.TEMPLATE_EXTENSION);
if (tpl != null)
@@ -292,6 +290,19 @@
}
return null;
}
+
+ private List<String> getPossibleNames (final String templateName, final String[] importedNs) {
+ final List<String> result = new ArrayList<String>(importedNs.length+1);
+ if (currentResource()!=null) {
+ final int offsetNsDelim = currentResource().getFullyQualifiedName().lastIndexOf(SyntaxConstants.NS_DELIM);
+ if (offsetNsDelim>0) {
+ final String resourceRelative = new StringBuilder(currentResource().getFullyQualifiedName().substring(0, offsetNsDelim)).append(SyntaxConstants.NS_DELIM).append(templateName).toString();
+ result.add(resourceRelative);
+ }
+ }
+ result.addAll(typeSystem.getPossibleNames(templateName, importedNs));
+ return result;
+ }
/**
* resolves the correct definition (using parametric polymorphism)