|
|
|
Re: Implicit imports based on type [message #734546 is a reply to message #734544] |
Sat, 08 October 2011 14:42 |
|
Hi,
maybe your term constructor is totally wrong chosen: it is a LITERAL.
so the question in your case:
consider you have another enum
enum Bool2 {
true;
false;
null;
}
so if you write
and you use Bool and Bool2 should this be Bool.true or Bool2.true?
thus i would solve this either by
(1) using local scoping for the true
(2) try to adopt org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.internalGetImportedNamespaceResolvers(EObject, boolean) (based on a reference to the enum Bool + maybe nodemodel to find out that bool is used and not bool2 - but i dont know if this will work)
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Sat, 08 October 2011 14:53] Report message to a moderator
|
|
|
|
Re: Implicit imports based on type [message #734549 is a reply to message #734548] |
Sat, 08 October 2011 15:09 |
|
Hi,
yes and no, i mean something like
public class MyDslImportedNamespaceAwareLocalScopeProvider extends ImportedNamespaceAwareLocalScopeProvider {
@Override
protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(
EObject context, boolean ignoreCase) {
List<ImportNormalizer> result = super.internalGetImportedNamespaceResolvers(context, ignoreCase);
if (context instanceof Function) {
Function function = (Function) context;
String value = NodeModelUtils.findNodesForFeature(function, MyDslPackage.Literals.FUNCTION__RETURN_TYPE).get(0).getText();
ImportNormalizer resolver = createImportedNamespaceResolver(value+".*", ignoreCase);
if (resolver != null)
result.add(resolver);
}
return result;
}
}
cause you do not the resolving stuff you might be way more performant.
here is my test grammar
Model:
elements+=Element*;
Element:
Enum | Class
;
Enum:
"enum" name=ID "{"
literals+=Literal*
"}"
;
Literal:
name=ID ";"
;
Class:
"class" name=ID "{"
functions+=Function*
"}"
;
Function:
"function" name=ID "()" ":" returnType=[Enum] "{"
statements+=Statement*
"}"
;
Statement:
"return" ref=[Literal] ";"
;
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Sat, 08 October 2011 15:09] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Re: Implicit imports based on type [message #735855 is a reply to message #735845] |
Wed, 12 October 2011 21:51 |
eecolor Messages: 36 Registered: September 2011 |
Member |
|
|
For now I solved it by overriding the createImportScope method of the ImportedNamespaceAwareLocalScopeProvider class.
protected ImportScope createImportScope(IScope parent, List<ImportNormalizer> namespaceResolvers, ISelectable importFrom, EClass type, boolean ignoreCase) {
List<ImportNormalizer> newNamespaceResolvers = namespaceResolvers;
if (isFeature(type)) {
newNamespaceResolvers = Lists.newArrayList(namespaceResolvers);
try {
importedNamespacePrefixField.setAccessible(true);
for (ImportNormalizer namespaceResolver : namespaceResolvers) {
QualifiedName qn = (QualifiedName) importedNamespacePrefixField.get(namespaceResolver);
IEObjectDescription singleElement = parent.getSingleElement(qn);
if (singleElement != null && isEnum(singleElement)) {
newNamespaceResolvers.add(new ImportNormalizer(qn, true, ignoreCase));
}
}
importedNamespacePrefixField.setAccessible(false);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return super.createImportScope(parent, newNamespaceResolvers, importFrom, type, ignoreCase);
}
As you can see this requires some reflection. I will file a feature request that asks for a getImportedNamespace() or getImportedNamespacePrefix() method on ImportNormalizer
|
|
|
|
Powered by
FUDForum. Page generated in 0.03945 seconds