|
Re: Can't get scoping to work [message #1727782 is a reply to message #1727780] |
Sun, 27 March 2016 15:00 |
|
This will work neither with xtext 284 nor with xtext 2.9.x
If you use xtext 284 or change the parent class to AbstractDeclarativeScopeProvider
Then the method Name is scope_<refereceOwner>_<referenceName>
In xtext 29x you have to override getScope(EObject,EReference) and do if else on the parameters
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
Re: Can't get scoping to work [message #1727787 is a reply to message #1727786] |
Sun, 27 March 2016 15:27 |
|
just a starting point covering only a few cases, the rest is your job
def IScope getVariableScope(EObject context) {
if (context == null) {
return IScope.NULLSCOPE
}
// get the block we are inside
var block = EcoreUtil2.getContainerOfType(context, Block);
if (block != null) {
return Scopes.scopeFor(
// var decls in that block
block.blockStatements.filter(VariableDeclaration),
// use name attribute
QualifiedName.wrapper(SimpleAttributeResolver.NAME_RESOLVER),
// the variable from outer blocks
getVariableScope(block.eContainer)
)
}
// get the module we are inside
var module = EcoreUtil2.getContainerOfType(context, Module)
if (module != null) {
return Scopes.scopeFor(module.statements.filter(VariableDeclaration))
}
//TODO handle possible other cases, handle order if relevant
return IScope.NULLSCOPE
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Re: Can't get scoping to work [message #1727791 is a reply to message #1727790] |
Sun, 27 March 2016 15:46 |
|
guess you missed that one
class MyDslScopeProvider extends AbstractMyDslScopeProvider {
override getScope(EObject context, EReference reference) {
if (reference == MyDslPackage.Literals.VARIABLE_ASSIGNMENT__ASSIGNEE) {
return getVariableScope(context)
}
super.getScope(context, reference)
}
def IScope getVariableScope(EObject context) {
if (context == null) {
return IScope.NULLSCOPE
}
// get the block we are inside
var block = EcoreUtil2.getContainerOfType(context, Block);
if (block != null) {
return Scopes.scopeFor(
// var decls in that block
block.blockStatements.filter(VariableDeclaration),
// use name attribute
QualifiedName.wrapper(SimpleAttributeResolver.NAME_RESOLVER),
// the variable from outer blocks
getVariableScope(block.eContainer)
)
}
// get the module we are inside
var module = EcoreUtil2.getContainerOfType(context, Module)
if (module != null) {
return Scopes.scopeFor(module.statements.filter(VariableDeclaration))
}
//TODO handle possible other cases, handle order if relevant
return IScope.NULLSCOPE
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Re: Can't get scoping to work [message #1727795 is a reply to message #1727794] |
Sun, 27 March 2016 16:20 |
|
i do not understand this question. please elaborate. scoping and names are unique validation have ZERO in common.
names are unque validation is about things haveing names and thus beeing exported from the file.
you include NamesAreUniqueValidator somewhere in your code. (in the workflow or in the scope provider class)
if you want to know how it works debug it and NamesAreUniqueValidationHelper
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Re: Can't get scoping to work [message #1727797 is a reply to message #1727796] |
Sun, 27 March 2016 16:33 |
|
i explained you: the names are unique validation checks if names are you unique.
so you would have to remove it, modify it, or make it unique.
you did no post any attempt yet. so why no
import java.util.List
import org.eclipse.xtext.EcoreUtil2
import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider
import org.eclipse.xtext.naming.QualifiedName
import org.xtext.example.mydsl.myDsl.Block
import org.xtext.example.mydsl.myDsl.Module
class MyQNP extends DefaultDeclarativeQualifiedNameProvider {
def QualifiedName qualifiedName(Block block) {
//TODO make this more elegant
val index = EcoreUtil2.indexOf(block.eContainer.eGet(block.eContainingFeature) as List, block, 0)
val result = if (block.eContainer instanceof Module) {
QualifiedName.create("_"+index)
} else {
getFullyQualifiedName(block.eContainer).append(QualifiedName.create("_"+index))
}
println(result)
return result
}
}
!?!?!?!?!?!?!?
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.13023 seconds