Java 在Xtext大纲视图中隐藏父节点
我正在使用Xtext解析器,遇到了一个问题:使用Eclipse的IDE插件,特别是Outline视图,它倾向于显示Java 在Xtext大纲视图中隐藏父节点,java,eclipse,eclipse-plugin,xtext,Java,Eclipse,Eclipse Plugin,Xtext,我正在使用Xtext解析器,遇到了一个问题:使用Eclipse的IDE插件,特别是Outline视图,它倾向于显示节点,我不想显示这些节点 目前,节点如下所示: SourceFile(仅指我当前使用的文件名) TopLevelStatement 申报 结构声明 结构创建者 name=Identifier-与下面相同的标识符 类声明 类创建者 name=Identifier-与下面相同的标识符 标识符 ID(Xtext附带的终端) 如果我做了一些事情,比如: c
节点,我不想显示这些节点
目前,节点如下所示:
- SourceFile(仅指我当前使用的文件名)
- TopLevelStatement
- 申报
- 结构声明
- 结构创建者
-与下面相同的标识符name=Identifier
- 结构创建者
- 类声明
- 类创建者
-与下面相同的标识符name=Identifier
- 类创建者
- 结构声明
- 标识符
- ID(Xtext附带的
)终端
- ID(Xtext附带的
- 申报
- TopLevelStatement
class TestClass {}
struct TestStruct {}
我希望:
- 源文件
- 测试类
- 测试结构
- 源文件
- 测试类
- 测试结构
节点,因为这对我不希望出现某些内容的每种情况都是有益的,但是如果不可能,我只想隐藏上面的特定节点。我尝试了文档,但似乎找不到任何关于隐藏特定节点的信息,尤其是当它有多种类型的子节点时
这是我的语法代码:
SourceFile:
(statements+=TopLevelStatement)*
;
TopLevelStatement:
statement=(Declaration)
;
Declaration:
declare=(StructDeclaration|ClassDeclaration)
;
StructDeclaration:
declare=StructCreator '{' '}' ';'?
;
ClassDeclaration:
declare=ClassCreator '{' '}' ';'?
;
StructCreator:
'struct' id=Identifier
;
ClassCreator:
'class' id=Identifier
;
Identifier:
ID
;
您可以查看上面的代码,并询问我为什么不将类和结构创建者合并为一个,但我不能。我将为类和结构提供更多的规则,我没有添加这些规则,因为它们不会导致问题。首先,我不理解您创建的有线对象结构。你有什么理由这样做吗 步骤一:实现标签提供程序
class MyDslLabelProvider extends DefaultEObjectLabelProvider {
@Inject
new(AdapterFactoryLabelProvider delegate) {
super(delegate);
}
// xtext does reflective polymorphic dispatch on params
def text(StructCreator ele) {
ele.id
}
def text(ClassCreator ele) {
ele.id
}
}
第二步:实现大纲树提供程序
class MyDslOutlineTreeProvider extends DefaultOutlineTreeProvider {
// xtext does reflective polymorphic dispatch on params
def protected _createChildren(IOutlineNode parentNode, SourceFile modelElement) {
for (s : modelElement.statements) {
val firstDecl = s.statement?.declare
if (firstDecl instanceof StructDeclaration) {
val secondDecl = firstDecl.declare
if (secondDecl !== null) {
createNode(parentNode, secondDecl)
}
} else if (firstDecl instanceof ClassDeclaration) {
val secondDecl = firstDecl.declare
if (secondDecl !== null) {
createNode(parentNode, secondDecl)
}
}
}
}
}
备选方案0:更改语法和命名约定
SourceFile:
(statements+=TopLevelStatement)*
;
TopLevelStatement:
Declaration
;
Declaration:
StructDeclaration|ClassDeclaration
;
StructDeclaration:
'struct' name=Identifier '{' '}' ';'?
;
ClassDeclaration:
'class' name=Identifier '{' '}' ';'?
;
Identifier:
ID
;
首先,我不理解你创建的有线对象结构。你有什么理由这样做吗 步骤一:实现标签提供程序
class MyDslLabelProvider extends DefaultEObjectLabelProvider {
@Inject
new(AdapterFactoryLabelProvider delegate) {
super(delegate);
}
// xtext does reflective polymorphic dispatch on params
def text(StructCreator ele) {
ele.id
}
def text(ClassCreator ele) {
ele.id
}
}
第二步:实现大纲树提供程序
class MyDslOutlineTreeProvider extends DefaultOutlineTreeProvider {
// xtext does reflective polymorphic dispatch on params
def protected _createChildren(IOutlineNode parentNode, SourceFile modelElement) {
for (s : modelElement.statements) {
val firstDecl = s.statement?.declare
if (firstDecl instanceof StructDeclaration) {
val secondDecl = firstDecl.declare
if (secondDecl !== null) {
createNode(parentNode, secondDecl)
}
} else if (firstDecl instanceof ClassDeclaration) {
val secondDecl = firstDecl.declare
if (secondDecl !== null) {
createNode(parentNode, secondDecl)
}
}
}
}
}
备选方案0:更改语法和命名约定
SourceFile:
(statements+=TopLevelStatement)*
;
TopLevelStatement:
Declaration
;
Declaration:
StructDeclaration|ClassDeclaration
;
StructDeclaration:
'struct' name=Identifier '{' '}' ';'?
;
ClassDeclaration:
'class' name=Identifier '{' '}' ';'?
;
Identifier:
ID
;
我这样做是“像有线的”,因为我还将使用非
{和}
标记,用分号替换它们。缺少与问题无关的整个分支模式。我只是决定把他们排除在外,因为他们没有贡献,让事情看起来更混乱。克里斯蒂安又一次这样做了。谢谢你!你已经成为我的指路明灯Christian,我只是想知道,有没有一种简单的方法可以将一个节点从一个父节点移动到另一个完整的父节点?我可以再问一个问题,让别人回答,但你对每件事都有正确的答案!我们来看看大纲树提供程序是做什么的。在这里,您实际上正在构建树。=>你需要在那里实现它,我这样做是“有线的”,因为我还将使用非{和}
标记,用分号替换它们。缺少与问题无关的整个分支模式。我只是决定把他们排除在外,因为他们没有贡献,让事情看起来更混乱。克里斯蒂安又一次这样做了。谢谢你!你已经成为我的指路明灯Christian,我只是想知道,有没有一种简单的方法可以将一个节点从一个父节点移动到另一个完整的父节点?我可以再问一个问题,让别人回答,但你对每件事都有正确的答案!我们来看看大纲树提供程序是做什么的。在这里,您实际上正在构建树。=>你需要在那里实现它