Removed some more warnings and cleaned more SWT listeners
[Mograsim.git] / plugins / net.mograsim.plugin.core / src / net / mograsim / plugin / asm / editor / AsmContentAssistProcessor.java
1 package net.mograsim.plugin.asm.editor;
2
3 import org.eclipse.core.resources.IWorkspace;
4 import org.eclipse.core.resources.ResourcesPlugin;
5 import org.eclipse.jface.text.BadLocationException;
6 import org.eclipse.jface.text.IDocument;
7 import org.eclipse.jface.text.ITextViewer;
8 import org.eclipse.jface.text.contentassist.ICompletionProposal;
9 import org.eclipse.jface.text.contentassist.ICompletionProposalExtension4;
10 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
11 import org.eclipse.jface.text.contentassist.IContextInformation;
12 import org.eclipse.jface.text.contentassist.IContextInformationValidator;
13 import org.eclipse.swt.graphics.Image;
14 import org.eclipse.swt.graphics.Point;
15
16 import net.mograsim.plugin.AsmOps;
17
18 public class AsmContentAssistProcessor implements IContentAssistProcessor
19 {
20
21         @Override
22         public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset)
23         {
24                 String text = viewer.getDocument().get();
25                 IWorkspace workspace = ResourcesPlugin.getWorkspace();
26 //              if (text.length() >= natureTag.length()
27 //                              && text.substring(offset - natureTag.length(), offset).equals(natureTag)) {
28 //                      IProjectNatureDescriptor[] natureDescriptors = workspace.getNatureDescriptors();
29 //                      ICompletionProposal[] proposals = new ICompletionProposal[natureDescriptors.length];
30 //                      for (int i = 0; i < natureDescriptors.length; i++) {
31 //                              IProjectNatureDescriptor descriptor = natureDescriptors[i];
32 //                              proposals[i] = new CompletionProposal(descriptor.getNatureId(), offset, 0,
33 //                                              descriptor.getNatureId().length());
34 //                      }
35 //                      return proposals;
36 //              }
37 //              if (text.length() >= projectReferenceTag.length()
38 //                              && text.substring(offset - projectReferenceTag.length(), offset).equals(projectReferenceTag)) {
39 //                      IProject[] projects = workspace.getRoot().getProjects();
40 //                      ICompletionProposal[] proposals = new ICompletionProposal[projects.length];
41 //                      for (int i = 0; i < projects.length; i++) {
42 //                              proposals[i] = new CompletionProposal(projects[i].getName(), offset, 0, projects[i].getName().length());
43 //                      }
44 //                      return proposals;
45 //              }
46 //              return new ICompletionProposal[0];
47 //              text.
48                 return AsmOps.ops.stream().map(o -> new AsmOperationProposal(o, "", offset)).toArray(ICompletionProposal[]::new);
49         }
50
51         @Override
52         public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset)
53         {
54                 return null;
55         }
56
57         @Override
58         public char[] getCompletionProposalAutoActivationCharacters()
59         {
60                 return new char[] { '\n', '\r' }; // NON-NLS-1
61         }
62
63         @Override
64         public char[] getContextInformationAutoActivationCharacters()
65         {
66                 return null;
67         }
68
69         @Override
70         public String getErrorMessage()
71         {
72                 return null;
73         }
74
75         @Override
76         public IContextInformationValidator getContextInformationValidator()
77         {
78                 return null;
79         }
80
81         private class AsmOperationProposal implements ICompletionProposal, ICompletionProposalExtension4
82         {
83
84                 private String asmOp;
85                 private String desc;
86                 private int offset;
87
88                 public AsmOperationProposal(String asmOp, String desc, int offset)
89                 {
90                         this.asmOp = asmOp;
91                         this.desc = desc;
92                         this.offset = offset;
93                 }
94
95                 @Override
96                 public boolean isAutoInsertable()
97                 {
98                         return true;
99                 }
100
101                 @Override
102                 public void apply(IDocument document)
103                 {
104                         try
105                         {
106                                 document.replace(offset, 0, asmOp);
107                         }
108                         catch (@SuppressWarnings("unused") BadLocationException e)
109                         {
110                                 // ignore
111                         }
112                 }
113
114                 @Override
115                 public Point getSelection(IDocument document)
116                 {
117                         return new Point(offset + asmOp.length(), 0);
118                 }
119
120                 @Override
121                 public String getAdditionalProposalInfo()
122                 {
123                         return desc;
124                 }
125
126                 @Override
127                 public String getDisplayString()
128                 {
129                         return asmOp;
130                 }
131
132                 @Override
133                 public Image getImage()
134                 {
135                         return null; // TODO image?
136                 }
137
138                 @Override
139                 public IContextInformation getContextInformation()
140                 {
141                         return new IContextInformation()
142                         {
143
144                                 @Override
145                                 public String getInformationDisplayString()
146                                 {
147                                         // TODO Auto-generated method stub
148                                         return null;
149                                 }
150
151                                 @Override
152                                 public Image getImage()
153                                 {
154                                         // TODO Auto-generated method stub
155                                         return null;
156                                 }
157
158                                 @Override
159                                 public String getContextDisplayString()
160                                 {
161                                         // TODO Auto-generated method stub
162                                         return null;
163                                 }
164                         };
165                 }
166
167         }
168
169 }