The secret behind OutlineView in Eclipse - Delta
来源:互联网 发布:java默认构造器 编辑:程序博客网 时间:2024/05/16 18:26
(All is under the scope of JAVA, the provided example is applied in plugin development)
Everyone uses eclipse must know what is OutlineView. If you could not find it, choose "Window->show view->outline". This view shows the skeleton of the currently opened java file. The most interesting thing is not what it shows, but the synchronization functionality. How the view reflect what you are editing so fast? Activate the outline view, press "shift+alt+F1", wow! a plugin-spy appears. Let's choose the JavaOutlinePage and continue our adventure.
From our experience, we could know
1. Caculating this change is much lighter than buiding a full model; Otherwise, the view won't change simultaneously.
2. The synchronzation is triggered by some kind of event. Because everytime you stop typing for some seconds, then the view start to change. Lucky we, we can find a "ElementChangedListener" at the top of body. It sounds like what we are looking for and actually it is.
This listener caputres a "ElementChangedEvent", and extract a "delta" from the event by the code "e.getDelta()". This delta is the key for the secret.
In math, delta means difference. It stands for the distance between two discrete points. Here, delta is the changes between two versions of code. Let me give you a intuition that what it looks like. Add the following code fragment.
During the runtime, I change a function name from "getZero" to "getZer". Then I see such infomation in console
[Working copy] T.java[*]: {CHILDREN | FINE GRAINED | AST AFFECTED}
T[*]: {CHILDREN | FINE GRAINED}
getZer()[+]: {}
getZero()[-]: {}
It tells what has been changed in the previous version. From top to bottom, it's a path of changes. "T.java" is a file, "T" is the class in "T.java", then "getZer()" is added and "getZero()" is deleted which can be read from "[+]" and "[-]". Then let's see what is delta and how it is created?
The type of delta is "JavaElementDelta", it extends SimpleDelta and implements IJavaElementDelta. From the constructor
we could assume it's nothing but a decorator of IJavaElement. Acctually, JavaElementDelta is "changed IJavaElement".
To build a "JavaElementDelta"[code], we have to use "JavaElementDeltaBuilder"[code], I spent several days reading it and finally had a clear view of the approximate work flow.
1. Old JavaElement information is recorded in Map infos. Start to find addtions.
2. Read the current code, if corresponding element exists in infos, that means this element is not changed. Then delete the element from Map. If it doesn't exist, that means it's a new element and a delta should be created.
3. During the creation of delta, actually it's a delta tree. The process traces back and records all its parents. Then wrap every JavaElement into JavaElementDelta and insert it into some appropriate place in the tree.
4. Find additions is finised and start to find deletions. All elements left in infos are deleted from the orignal code.
5. If a deleted element is found, a new delta should be inserted to the current delta tree. The place where it should be added is where it existed (which is its dierct parent).
6. Checking position ordering changes.
This is how the delta is created. Actually, it's a descriptive information showing changes. The OutlineView apply this delta by "reconcile(delta)", old model changes accordingly so new one doesn't need to be created fully.
But somehow, deleting a letter inside the method body could not be sensed by delta. For answering this question, I'll introduce JavaElement in the next article. Briefly speaking, as I said, delta is a changed Java element. If the change is not Java element, of course it couldn't be a delta.
- The secret behind OutlineView in Eclipse - Delta
- how do exceptions work (behind the scenes) in c++
- SAP BW – Implementing Delta Updates in the Financial Domain
- Installing the Eclipse RCP Delta pack (for beginners)
- 20150514: Opinion: The secret corporate takeover hidden in the TPP
- The Secret
- What's the Secret between Message and Handle in Windows?
- The Secret Garden——2、Mary in Yorkshire
- once his body was hidden in the secret alcove it
- Delta Mush in Houdini
- Behind the mask
- Behind the Contry Names
- 幕后 behind-the-scenes
- II-Behind the Scenes
- hama程序出现Messages must never be behind the vertex in ID问题解决
- Principles behind the Agile Manifesto
- Principles behind the Agile Manifesto
- The story behind Google Chrome
- int 转换为 char*
- c版快速排序 + 随机产生一组测试数据
- 2009.8.25日记
- 详解 Oracle 分布式系统数据复制技术(转)
- JAVA面试题解惑系列____作者:臧圩人(zangweiren)
- The secret behind OutlineView in Eclipse - Delta
- 治疗网瘾,宜堵还是宜疏?
- 该关注一下个人的健康了
- 重写Calendar类
- C++中全局变量的问题
- Zigbee休眠(cc2430)
- QT 中关闭窗口后 进程仍然存在
- 祝福大家情人节快乐
- import和__import__(8/27补充)