Xtext和Plugin:获取EObject并返回文件中写入的前10个字符

时间:2016-12-15 15:03:57

标签: eclipse plugins xtext

我正在为我在xtext中编写的DSL语言编写插件。

在我的插件中,我查看当前文件的XtextResource中的所有变量,如下所示:

  public void calculateVarsNamesList(XtextResource resource) {

  EObject content = resource.getContents().get(0);
  EList<EObject> ListOfEObject = content.eContents();

  for (int i=0; i < ListOfEObject.size(); i++){
       if (ListOfEObject.get(i) instanceof Var){
          Var v = (Var) ListOfEObject.get(i);
          String name = v.getName();
          if (name == null){
          // ***I want to get the first 10 chars of v (like it's written in the file)***
           }
      }}}

我如何做我在评论中所写的内容?感谢!!!

1 个答案:

答案 0 :(得分:0)

查看NodeModelUtils。该类使您可以访问将跟踪保留到原始文件的基础节点模型。