The final restructured version for automatic build using maven tycho
[Mograsim.git] / plugins / net.mograsim.plugin.core / src / net / mograsim / plugin / asm / editor / AsmHoverProvider.java
1 package net.mograsim.plugin.asm.editor;
2
3 import org.eclipse.core.resources.IProjectNatureDescriptor;
4 import org.eclipse.core.resources.IWorkspace;
5 import org.eclipse.core.resources.ResourcesPlugin;
6 import org.eclipse.jface.text.IRegion;
7 import org.eclipse.jface.text.ITextHover;
8 import org.eclipse.jface.text.ITextViewer;
9 import org.eclipse.jface.text.Region;
10
11 public class AsmHoverProvider implements ITextHover
12 {
13
14         @Override
15         public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion)
16         {
17                 // TODO this is logic for .project file to show nature description on hover.
18                 // Replace with your language logic!
19                 String contents = textViewer.getDocument().get();
20                 int offset = hoverRegion.getOffset();
21                 int endIndex = contents.indexOf("</nature>", offset);
22                 if (endIndex == -1)
23                         return "";
24                 int startIndex = contents.substring(0, offset).lastIndexOf("<nature>");
25                 if (startIndex == -1)
26                         return "";
27                 String selection = contents.substring(startIndex + "<nature>".length(), endIndex);
28
29                 IWorkspace workspace = ResourcesPlugin.getWorkspace();
30                 IProjectNatureDescriptor[] natureDescriptors = workspace.getNatureDescriptors();
31                 for (int i = 0; i < natureDescriptors.length; i++)
32                 {
33                         if (natureDescriptors[i].getNatureId().equals(selection))
34                                 return natureDescriptors[i].getLabel();
35                 }
36                 return "";
37         }
38
39         @Override
40         public IRegion getHoverRegion(ITextViewer textViewer, int offset)
41         {
42                 return new Region(offset, 0);
43         }
44 }