Skip to content

Latest commit

 

History

History

Hover

More gentle way to show java doc when hover on .

Features

- 显示字段的注释,如果你比较懒(我就是-.-),没给get和set 复制 注释
- Getter 没有注解的话,优先使用返回类型的注释
- 直接显示get set 的源代码
- 附加显示:字段上的注解(annotation),当类是JPA实体的时候特别有用
- 附加显示:interface上的注解(annotation)
- 显示枚举值的构造函数
- 显示final字段的直接赋值
- 如果get方法字段也没有注释,并且字段不java内建类型,则尝试显示返回值类型的注释

Example

you generate a pojo class.

You MAY ONLY write some javadoc on private field because this is a boring work.

you reference pojo object method.

you cannot see any java doc outside the pojo class.until write javadoc on getter or setter(you need write javadoc three times).

with this plugin you can see pojo field java doc .

Use Case

如果方法调用对象是一个pojo(@Entity,或者名字叫dto,vo,或者没有spring的@Service 注解)
如果调用了get 或者set,
如果没有写文档
那么就从字段上取文档,
如果字段上没有写文档就找 单行,双行注释

如果一个方法返回值是boolean,方法只有10行,那么可以直接在窗口中显示布尔表达式

开发注记

原本,直接使用fragment就可以的,但是hover是一个数组,排序不可控,pref 上也没有一个调整顺序的功能。
只有使用plugin才可以保证出现在内置hover的前头。

hover 的初始化位置在

org.eclipse.jdt.internal.ui.JavaPlugin.getJavaEditorTextHoverDescriptors()

调用hover的位置在:

org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo(ITextViewer, IRegion)

preference page:

org.eclipse.jdt.internal.ui.preferences.JavaEditorHoverConfigurationBlock.getContributedHovers()

plugins to check map key to bean property copy are equal.

<extension
         point="org.eclipse.jdt.ui.javaEditorTextHovers">
      <hover
            label="%sequentialHover"
            description="%sequentialHoverDescription"
            class="org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover"
            id="org.eclipse.jdt.ui.BestMatchHover">
      </hover>
      <hover
            label="%problemHover"
            description="%problemHoverDescription"
            class="org.eclipse.jdt.internal.ui.text.java.hover.ProblemHover"
            id="org.eclipse.jdt.ui.ProblemHover">
      </hover>
      <hover
            label="%nlsStringHover"
            description="%nlsStringHoverDescription"
            class="org.eclipse.jdt.internal.ui.text.java.hover.NLSStringHover"
            id="org.eclipse.jdt.ui.NLSStringHover">
      </hover>
      <hover
            label="%javadocHover"
            description="%javadocHoverDescription"
            class="org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover"
            id="org.eclipse.jdt.ui.JavadocHover">
      </hover>
      <hover
            label="%annotationHover"
            description="%annotationHoverDescription"
            class="org.eclipse.jdt.internal.ui.text.java.hover.AnnotationHover"
            id="org.eclipse.jdt.ui.AnnotationHover">
      </hover>
      <hover
            label="%sourceHover"
            description="%sourceHoverDescription"
            class="org.eclipse.jdt.internal.ui.text.java.hover.JavaSourceHover"
            id="org.eclipse.jdt.ui.JavaSourceHover">
      </hover>
   </extension>
<html><head><style CHARSET="ISO-8859-1" TYPE="text/css">/* Font definitions */
html         { font-family: '.SF NS Text',sans-serif; font-size: 13px; font-style: normal; font-weight: normal; }
body, h1, h2, h3, h4, h5, h6, p, table, td, caption, th, ul, ol, dl, li, dd, dt { font-size: 1em; }
pre          { font-family: monospace; }

/* Margins */
body       { overflow: auto; margin-top: 0px; margin-bottom: 0.5em; margin-left: 0.3em; margin-right: 0px; }
h1           { margin-top: 0.3em; margin-bottom: 0.04em; }  
h2           { margin-top: 2em; margin-bottom: 0.25em; }
h3           { margin-top: 1.7em; margin-bottom: 0.25em; }
h4           { margin-top: 2em; margin-bottom: 0.3em; }
h5           { margin-top: 0px; margin-bottom: 0px; }
p            { margin-top: 1em; margin-bottom: 1em; }
pre          { margin-left: 0.6em; }
ul           { margin-top: 0px; margin-bottom: 1em; margin-left: 1em; padding-left: 1em;}
li           { margin-top: 0px; margin-bottom: 0px; } 
li p       { margin-top: 0px; margin-bottom: 0px; } 
ol           { margin-top: 0px; margin-bottom: 1em; margin-left: 1em; padding-left: 1em; }
dl           { margin-top: 0px; margin-bottom: 1em; }
dt           { margin-top: 0px; margin-bottom: 0px; font-weight: bold; }
dd           { margin-top: 0px; margin-bottom: 0px; }

/* Styles and colors */
a:link       { color: #0000FF; }
a:hover      { color: #000080; }
a:visited    { text-decoration: underline; }
a.header:link    { text-decoration: none; color: #000000 }
a.header:visited { text-decoration: none; color: #000000 }
a.header:hover   { text-decoration: underline; color: #000080; }
h4           { font-style: italic; }
strong       { font-weight: bold; }
em           { font-style: italic; }
var          { font-style: italic; }
th           { font-weight: bold; }

/* Workarounds for new Javadoc stylesheet (1.7) */ 
ul.blockList li.blockList, ul.blockListLast li.blockList {
    list-style:none;
}
ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast {
    list-style:none;
}
</style>
<base href='file:/Users/lxb/workspace1/jpa-demo/jpa-relation-demo/src/main/java/cn/devit/demo/Leaf.java'>
</head><body text="#000000" bgcolor="#ecebec"><h5><div style='word-wrap: break-word; position: relative; margin-left: 20px; padding-top: 2px; '><a href='eclipse-open:%E2%98%82=jpa-relation-demo/src%5C/main%5C/java%3Ccn.devit.demo%7BLeaf.java%E2%98%83Leaf%5Ebranch'><!--[if lte IE 6]><![if gte IE 5.5]>
<span alt='Open Declaration' style="border:none; position: absolute; width: 16px; height: 16px; left: -21px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='file:/Users/lxb/runtime-all/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png')"></span>
<![endif]><![endif]-->
<!--[if !IE]>-->
<img alt='Open Declaration' style='border:none; position: absolute; width: 16px; height: 16px; left: -21px; ' src='file:/Users/lxb/runtime-all/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png'/>
<!--<![endif]-->
<!--[if gte IE 7]>
<img alt='Open Declaration' style='border:none; position: absolute; width: 16px; height: 16px; left: -21px; ' src='file:/Users/lxb/runtime-all/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png'/>
<![endif]-->
</a><a class='header' href='eclipse-javadoc:%E2%98%82=jpa-relation-demo/src%5C/main%5C/java%3Ccn.devit.demo%7BLeaf.java%E2%98%83Leaf%5Ebranch%E2%98%82Branch'>Branch</a> <a class='header' href='eclipse-javadoc:%E2%98%82=jpa-relation-demo/src%5C/main%5C/java%3Ccn'>cn</a>.<a class='header' href='eclipse-javadoc:%E2%98%82=jpa-relation-demo/src%5C/main%5C/java%3Ccn.devit'>devit</a>.<a class='header' href='eclipse-javadoc:%E2%98%82=jpa-relation-demo/src%5C/main%5C/java%3Ccn.devit.demo'>demo</a>.<a class='header' href='eclipse-javadoc:%E2%98%82=jpa-relation-demo/src%5C/main%5C/java%3Ccn.devit.demo%7BLeaf.java%E2%98%83Leaf'>Leaf</a>.branch</div></h5><br>
<div style='margin-bottom: 5px;'>@<a href='eclipse-javadoc:%E2%98%82=jpa-relation-demo/%5C/Users%5C/lxb%5C/.m2%5C/repository%5C/org%5C/hibernate%5C/javax%5C/persistence%5C/hibernate-jpa-2.1-api%5C/1.0.0.Final%5C/hibernate-jpa-2.1-api-1.0.0.Final.jar%3Cjavax.persistence(ManyToOne.class%E2%98%83ManyToOne'>ManyToOne</a><br>
@<a href='eclipse-javadoc:%E2%98%82=jpa-relation-demo/%5C/Users%5C/lxb%5C/.m2%5C/repository%5C/org%5C/hibernate%5C/javax%5C/persistence%5C/hibernate-jpa-2.1-api%5C/1.0.0.Final%5C/hibernate-jpa-2.1-api-1.0.0.Final.jar%3Cjavax.persistence(JoinColumn.class%E2%98%83JoinColumn'>JoinColumn</a>(<a href='eclipse-javadoc:%E2%98%82=jpa-relation-demo/%5C/Users%5C/lxb%5C/.m2%5C/repository%5C/org%5C/hibernate%5C/javax%5C/persistence%5C/hibernate-jpa-2.1-api%5C/1.0.0.Final%5C/hibernate-jpa-2.1-api-1.0.0.Final.jar%3Cjavax.persistence(JoinColumn.class%E2%98%83JoinColumn~name'>name</a>="branch_id")<br></div><p>branch</body></html>
显示interface注释
<html><head><style CHARSET="ISO-8859-1" TYPE="text/css">/* Font definitions */
html         { font-family: '.SF NS Text',sans-serif; font-size: 11px; font-style: normal; font-weight: normal; }
body, h1, h2, h3, h4, h5, h6, p, table, td, caption, th, ul, ol, dl, li, dd, dt { font-size: 1em; }
pre          { font-family: monospace; }

/* Margins */
body       { overflow: auto; margin-top: 0px; margin-bottom: 0.5em; margin-left: 0.3em; margin-right: 0px; }
h1           { margin-top: 0.3em; margin-bottom: 0.04em; }  
h2           { margin-top: 2em; margin-bottom: 0.25em; }
h3           { margin-top: 1.7em; margin-bottom: 0.25em; }
h4           { margin-top: 2em; margin-bottom: 0.3em; }
h5           { margin-top: 0px; margin-bottom: 0px; }
p            { margin-top: 1em; margin-bottom: 1em; }
pre          { margin-left: 0.6em; }
ul           { margin-top: 0px; margin-bottom: 1em; margin-left: 1em; padding-left: 1em;}
li           { margin-top: 0px; margin-bottom: 0px; } 
li p       { margin-top: 0px; margin-bottom: 0px; } 
ol           { margin-top: 0px; margin-bottom: 1em; margin-left: 1em; padding-left: 1em; }
dl           { margin-top: 0px; margin-bottom: 1em; }
dt           { margin-top: 0px; margin-bottom: 0px; font-weight: bold; }
dd           { margin-top: 0px; margin-bottom: 0px; }

/* Styles and colors */
a:link       { color: #0069d9; } /* get's replaced with actual color */
a:hover      { color: #004a98; } /* get's replaced with actual color */
a:visited    { text-decoration: underline; }
a.header:link    { text-decoration: none; color: #000000 }
a.header:visited { text-decoration: none; color: #000000 }
a.header:hover   { text-decoration: underline; color: #004a98; } /* get's replaced with actual color */
h4           { font-style: italic; }
strong       { font-weight: bold; }
em           { font-style: italic; }
var          { font-style: italic; }
th           { font-weight: bold; }

/* Workarounds for new Javadoc stylesheet (1.7) */ 
ul.blockList li.blockList, ul.blockListLast li.blockList {
    list-style:none;
}
ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast {
    list-style:none;
}
</style>
<base href='file:/Users/lxb/runtime-devit-jdt/java/src/cn/devit/demo/ObjectLevel4.java'>
</head><body text="#000000" bgcolor="#ecebec"><h5><div style='word-wrap: break-word; position: relative; margin-left: 20px; padding-top: 2px; '><a href='eclipse-open:%E2%98%82=java/src%3Ccn.devit.demo%7BObjectLevel4.java%E2%98%83ObjectLevel4~morning'><!--[if lte IE 6]><![if gte IE 5.5]>
<span alt='Open Declaration' style="border:none; position: absolute; width: 16px; height: 16px; left: -21px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='file:/Users/lxb/runtime-devit-jdt/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png')"></span>
<![endif]><![endif]-->
<!--[if !IE]>-->
<img alt='Open Declaration' style='border:none; position: absolute; width: 16px; height: 16px; left: -21px; ' src='file:/Users/lxb/runtime-devit-jdt/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png'/>
<!--<![endif]-->
<!--[if gte IE 7]>
<img alt='Open Declaration' style='border:none; position: absolute; width: 16px; height: 16px; left: -21px; ' src='file:/Users/lxb/runtime-devit-jdt/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png'/>
<![endif]-->
</a><a class='header' href='eclipse-javadoc:%E2%98%82=java/src%3Ccn.devit.demo%7BObjectLevel4.java%E2%98%83ObjectLevel4~morning%E2%98%82FlightNumber'>FlightNumber</a> <a class='header' href='eclipse-javadoc:%E2%98%82=java/src%3Ccn'>cn</a>.<a class='header' href='eclipse-javadoc:%E2%98%82=java/src%3Ccn.devit'>devit</a>.<a class='header' href='eclipse-javadoc:%E2%98%82=java/src%3Ccn.devit.demo'>demo</a>.<a class='header' href='eclipse-javadoc:%E2%98%82=java/src%3Ccn.devit.demo%7BObjectLevel4.java%E2%98%83ObjectLevel4'>ObjectLevel4</a>.morning()</div></h5><br><div style='margin-bottom: 5px;'>@<a href='eclipse-javadoc:%E2%98%82=java/%5C/Library%5C/Java%5C/JavaVirtualMachines%5C/jdk1.8.0_102.jdk%5C/Contents%5C/Home%5C/jre%5C/lib%5C/rt.jar%3Cjava.lang(Override.class%E2%98%83Override'>Override</a><br></div><p>航班号<div><b>Specified by:</b> <a href='eclipse-javadoc:%E2%98%82=java/src%3Ccn.devit.demo%7BInterfaceLevel0.java%E2%98%83InterfaceLevel0~morning'>morning()</a> in <a href='eclipse-javadoc:%E2%98%82=java/src%3Ccn.devit.demo%7BInterfaceLevel0.java%E2%98%83InterfaceLevel0'>InterfaceLevel0</a></div></body></html>