Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eclipse plugin 将操作悬停在Eclipse中自己的注释上(插件)_Eclipse Plugin_Annotations_Hover_Mouseover - Fatal编程技术网

Eclipse plugin 将操作悬停在Eclipse中自己的注释上(插件)

Eclipse plugin 将操作悬停在Eclipse中自己的注释上(插件),eclipse-plugin,annotations,hover,mouseover,Eclipse Plugin,Annotations,Hover,Mouseover,我创建了一个插件,它使用自己的注释标记。现在我想添加一个特殊的悬停动作,当我将鼠标移到这个特殊的标记上时。我真的不知道在哪里添加此操作。我已经阅读了IANotationHover接口,但是如何访问普通工作台文本编辑器的垂直标尺来添加/更改注释Hover p、 s:更准确地说,我使用Eclipse的通用编辑器,而不是自己的编辑器。。。所以我认为我不应该覆盖SourceViewerConfiguration或iAnotationHover 到目前为止有什么想法吗?下面是在默认Java编辑器上创建自定

我创建了一个插件,它使用自己的注释标记。现在我想添加一个特殊的悬停动作,当我将鼠标移到这个特殊的标记上时。我真的不知道在哪里添加此操作。我已经阅读了IANotationHover接口,但是如何访问普通工作台文本编辑器的垂直标尺来添加/更改注释Hover

p、 s:更准确地说,我使用Eclipse的通用编辑器,而不是自己的编辑器。。。所以我认为我不应该覆盖SourceViewerConfiguration或iAnotationHover 到目前为止有什么想法吗?

下面是在默认Java编辑器上创建自定义悬停的步骤

下面是@PKeidel的LangHover类的一个自定义实现,该类来自于针对您的特定用例的问题,并结合了。请注意,您应该将
ANNOTATION\u NAME
的值更改为自定义注释的值,并将
getHoverInfo
的返回值更改为自定义悬停包含的任何内容

公共类LangHover实现IJavaEditorTextHover
{
公共静态最终字符串注释\u NAME=“YourCustomAnnotation”;
@禁止警告(“限制”)
公共静态ICodeAssist getCodeAssist(IEditorPart fEditor)
{
if(fEditor!=null){
IEditorInput输入=fEditor.getEditorInput();
if(IClassFileEditorInput的输入实例){
IClassFileEditorInput CFEIInput=(IClassFileEditorInput)输入;
返回cfeInput.getClassFile();
}
WorkingCopyManager=JavaPlugin.getDefault().getWorkingCopyManager();
returnmanager.getWorkingCopy(输入,false);
}
返回null;
}
公共静态IEditorPart getActiveEditor()
{
IWorkbenchWindow=PlatformUI.getWorkbench().getActiveWorkbenchWindow();
如果(窗口!=null){
IWorkbenchPage=window.getActivePage();
如果(第页!=null){
返回page.getActiveEditor();
}
}
返回null;
} 
//当返回true时,应显示自定义悬停。
公共静态布尔元素为自定义注释(ITextViewer textViewer,IRegion hoverRegion)
{
IEditorPart activeEditor=getActiveEditor();
ICodeAssist resolve=getCodeAssist(activeEditor);
IJavaElement[]检测到的javaElements=null;
if(解析!=null)
{
尝试
{
detectedJavaElements=resolve.codeSelect(hoverRegion.getOffset(),hoverRegion.getLength());
}
捕获(JavaModelException x)
{
System.out.println(“发生JavaModelException”);
}
}
for(IJavaElement javaElement:detectedJavaElements)
{
//如果我找到类型为IJavaElement.ANNOTATION的元素
//其名称等于注释名称,返回true
if(javaElement.getElementType()==IJavaElement.ANNOTATION&&javaElement.getElementName().equals(ANNOTATION_NAME))
{
返回true;
}
}
返回false;
}
@凌驾
公共字符串getHoverInfo(ITextViewer textviewer,IRegion区域)
{
if(元素自定义注释(文本查看器,区域))
{
返回“您自己的悬停文本在此处”;
}
return null;//显示默认悬停(Java文档)
}
}
基本上,这里发生的是
elementIsCustomAnnotation
检查用户悬停的java元素,将它们放入
detectedJavaElements
数组中,然后检查该数组以查找名称等于
Annotation\u name
的注释