如何将一些缓存信息附加到Eclipse编辑器或资源? [英] How do I attach some cached information to an Eclipse editor or resource?

查看:190
本文介绍了如何将一些缓存信息附加到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编辑器或资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆