|
Re: Xtext imports [message #1414156 is a reply to message #1413972] |
Sat, 30 August 2014 12:46 |
|
Hi,
i am not sure if i understand your question. if you want to do implicit imports in the dsl then
have a look at org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.getImplicitImports(boolean)
if it is about generating then i do not understand the problem
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Xtext imports [message #1417749 is a reply to message #1414156] |
Sat, 06 September 2014 00:32 |
Marko Markovic Messages: 35 Registered: August 2014 |
Member |
|
|
Thank you very much Christian,
I use xbase and I tried example from attach but it doesn't work because xtext 2.6 have no LocalVariableScopeContext.
Instead next codes:
@Override
protected IScope createLocalVarScope(IScope parentScope,
LocalVariableScopeContext scopeContext) {
if (scopeContext != null && scopeContext.getContext() != null) {
EObject context = scopeContext.getContext();
if (context instanceof Model) {
Model model = (Model) context;
return Scopes.scopeFor(model.getVarDeclarations());
}
}
return super.createLocalVarScope(parentScope, scopeContext);
}
I wrote:
@Override
protected List<ImportNormalizer> getImplicitImports(boolean ignoreCase) {
List<ImportNormalizer> temp=new ArrayList();
temp.add(new ImportNormalizer(QualifiedName.create("builtin","types","namespace"), true, ignoreCase));
return temp;
}
and
public class HelloXvarsRuntimeModule extends
org.xtext.example.helloxvars.AbstractHelloXvarsRuntimeModule {
@Override
public Class<? extends IScopeProvider> bindIScopeProvider() {
return HelloXvarsScopeProvider.class;
}
}
but it doesn't work. Can I call getImplicitImports(...) maybe in inferr class or something other?
Sorry if my questions are stupid, I'm still a begginer.
Thank you in advance very much,
Marko
-
Attachment: example.txt
(Size: 0.03KB, Downloaded 285 times)
|
|
|
Re: Xtext imports [message #1417891 is a reply to message #1417749] |
Sat, 06 September 2014 06:06 |
|
Hi,
i think this is about imports and not vars ?!?
first: xbased stuff works totally different from non xbase stuff. xbase uses XImportSectionNamespaceScopeProvider.
there you have a org.eclipse.xtext.xbase.scoping.XImportSectionNamespaceScopeProvider.getImplicitImports(boolean) as well
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Re: Xtext imports [message #1418798 is a reply to message #1418335] |
Sun, 07 September 2014 17:12 |
|
you should test it with something that works with imports from java lang e.g. the domain model example.
i dont know what todo either, but i thought it would work to do
protected List<ImportNormalizer> getImplicitImports(boolean ignoreCase) {
return Lists.<ImportNormalizer>newArrayList(
doCreateImportNormalizer(JAVA_LANG, true, false),
doCreateImportNormalizer(QualifiedName.create("your","package"), true, false),
doCreateImportNormalizer(XBASE_LIB, true, false));
}
but maybe it dont understand your problem in the first place
and it is in deed about generating and not about default imports ?!?
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Xtext imports [message #1420429 is a reply to message #1418798] |
Wed, 10 September 2014 01:15 |
Marko Markovic Messages: 35 Registered: August 2014 |
Member |
|
|
Hi Christian,
Thank you very much for your answer! I tried it on next way:
in class MyDsl2ScopeProvider.xtend I have:
class MyDsl2ScopeProvider extends org.eclipse.xtext.xbase.scoping.XImportSectionNamespaceScopeProvider
{
override protected List<ImportNormalizer> getImplicitImports(boolean ignoreCase) {
System.out.println("Program is here...###########################")
return Lists.<ImportNormalizer>newArrayList(
doCreateImportNormalizer(JAVA_LANG, true, false),
doCreateImportNormalizer(QualifiedName.create("your","package"), true, false),
doCreateImportNormalizer(XBASE_LIB, true, false));
}
}
In class AbstractMyDsl2RuntimeModule.java instead
public void configureIScopeProviderDelegate(com.google.inject.Binder binder) {
binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class).annotatedWith(Names.named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE)). to(org.eclipse.xtext.xbase.scoping.XImportSectionNamespaceScopeProvider.class);
}
I write:
public void configureIScopeProviderDelegate(com.google.inject.Binder binder) {
binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class).annotatedWith(Names.named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE)). to(org.xtext.example.mydsl2.scoping.MyDsl2ScopeProvider.class);
}
Program enters in class MyDsl2ScopeProvider in method getImplicitImports (in my console I can see "Program is here...###########################") but in my generated java class have no implicit imports.
Also, I tried and next code in class MyDsl2RuntimeModule.java but unsuccessfully:
public class MyDsl2RuntimeModule extends org.xtext.example.mydsl2.AbstractMyDsl2RuntimeModule {
// @Override
@SuppressWarnings("restriction")
public Class<? extends org.eclipse.xtext.xbase.scoping.XImportSectionNamespaceScopeProvider> getImplicitImports(boolean ignoreCase) {
return MyDsl2ScopeProvider.class;
}
}
Do I need to change my xtext grammar or something else?
Also, importSection doesn't work.
grammar org.xtext.example.mydsl2.MyDsl2 with org.eclipse.xtext.xbase.Xbase
generate myDsl2 "http://www.xtext.org/example/mydsl2/MyDsl2"
Domainmodel:
importSection=XImportSection?
elements+=AbstractElement*;
AbstractElement:
PackageDeclaration | Entity;
PackageDeclaration:
'package' name=QualifiedName '{'
elements+=AbstractElement*
'}';
Entity:
'entity' name=ValidID
('extends' superType=JvmTypeReference)? '{'
features+=Feature*
'}';
Feature:
Property | Operation;
Property:
name=ValidID ':' type=JvmTypeReference;
Operation:
'op' name=ValidID
'('(params+=FullJvmFormalParameter
(',' params+=FullJvmFormalParameter)*)?')'
':' type=JvmTypeReference
body=XBlockExpression;
Sorry for long text,
Thank you in advance,
Marko
|
|
|
Re: Xtext imports [message #1420516 is a reply to message #1420429] |
Wed, 10 September 2014 04:47 |
|
Hi,
i dont understand what you want to do.
the implicit imports makes the stuff available in the dsl. so when you use it, it will be here (if you do the inferrer right)
so you want to hardcode the imports? why do you want to have imports you dont use?!?
so why do you need the import in the generated file????
i asked in the very first place if this is about generation or about imports in the dsl
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Re: Xtext imports [message #1420892 is a reply to message #1420886] |
Wed, 10 September 2014 16:33 |
|
the following works for me in the domain model example
members += entity.toMethod("lala", entity.newTypeRef("java.util.List",entity.newTypeRef("java.lang.String"))) [
body = '''
return new «entity.newTypeRef("java.util.ArrayList",entity.newTypeRef("java.lang.String"))»();
'''
]
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03266 seconds