如何将一些缓存信息附加到Eclipse编辑器或资源?

编程入门 行业动态 更新时间:2024-10-06 04:12:17
本文介绍了如何将一些缓存信息附加到Eclipse编辑器或资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用Eclipse的Xtext框架开发DSL。

对于内容辅助/代码完成,我有一个昂贵的过程,它产生一个字符串列表。

如何缓存该进程的结果?

长篇故事:我的DSL与Groovy脚本接口。脚本提供了我在DSL中某些地方提供的方法。这很慢,即使我使用正则表达式来解析脚本的方法。所以我想缓存脚本分析的结果。

从我的分析中,分析代码在验证期间被调用(所以我并不总是有一个编辑器),当用户打开一个DSL文件时。

无法确定验证结束(代码是私有方法,Xtext开发人员拒绝更改)。但我认为,编写Eclipse编辑器/编译器时,这一定是一个常见的问题。其他人如何解决这个问题?在Eclipse框架中有一些缓存服务吗?

解决方案

可以使用Xtext提供的JVM模型。只要你安装了groovy插件,它的类型和方法应该可以通过它。

缓存:

在资源上有一个缓存,如果有变化,它将被自动驱逐。

((XtextResource)x.eResource())。getCache()。get(myKey,x.eResource(), new Provider< String>>(){ public List< String& ; get(){ return computeGroovyMethodNames(); } })

缓存也可以被注入:

@Inject private IResourceScopeCache cache

I'm developing a DSL using Eclipse's Xtext framework.

For the content assist/code completion, I have an expensive process which generates me a list of strings.

How do I cache the result of that process?

Long story: My DSL interfaces with Groovy scripts. The scripts provide methods which I offer in certain places in my DSL. This is pretty slow, even when I use a regexp to parse the methods of the scripts. So I'd like to cache the results of the script analysis.

From my analysis, the analysis code is called during validation (so I don't always have an editor) and when the user opens a DSL file.

There is no way to tell when the validation is over (the code is in a private method and the Xtext developers refuse to change that). But I figure that this must be a common problem when writing editors/compilers for Eclipse. How do other people solve this problem? Is there some caching service in the Eclipse framework?

解决方案

You could make use of the JVM model Xtext provides. As long as you have the groovy plugin installed, its types and methods should be available through it.

Caching:

On the resource there is a cache which is automatically evicted if there's a change in it.

((XtextResource)x.eResource()).getCache().get(myKey, x.eResource(), new Provider<List<String>>(){ public List<String> get() { return computeGroovyMethodNames(); } })

The cache can also be injected :

@Inject private IResourceScopeCache cache

更多推荐

如何将一些缓存信息附加到Eclipse编辑器或资源?

本文发布于:2023-11-02 06:25:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551618.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编辑器   缓存   如何将   资源   信息

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!