Merge branch 'development' of https://gitlab.lrz.de/lrr-tum/students/eragp-misim...
[Mograsim.git] / 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 public class AsmContentAssistProcessor implements IContentAssistProcessor
17 {
18
19         @Override
20         public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset)
21         {
22                 String text = viewer.getDocument().get();
23                 IWorkspace workspace = ResourcesPlugin.getWorkspace();
24 //              if (text.length() >= natureTag.length()
25 //                              && text.substring(offset - natureTag.length(), offset).equals(natureTag)) {
26 //                      IProjectNatureDescriptor[] natureDescriptors = workspace.getNatureDescriptors();
27 //                      ICompletionProposal[] proposals = new ICompletionProposal[natureDescriptors.length];
28 //                      for (int i = 0; i < natureDescriptors.length; i++) {
29 //                              IProjectNatureDescriptor descriptor = natureDescriptors[i];
30 //                              proposals[i] = new CompletionProposal(descriptor.getNatureId(), offset, 0,
31 //                                              descriptor.getNatureId().length());
32 //                      }
33 //                      return proposals;
34 //              }
35 //              if (text.length() >= projectReferenceTag.length()
36 //                              && text.substring(offset - projectReferenceTag.length(), offset).equals(projectReferenceTag)) {
37 //                      IProject[] projects = workspace.getRoot().getProjects();
38 //                      ICompletionProposal[] proposals = new ICompletionProposal[projects.length];
39 //                      for (int i = 0; i < projects.length; i++) {
40 //                              proposals[i] = new CompletionProposal(projects[i].getName(), offset, 0, projects[i].getName().length());
41 //                      }
42 //                      return proposals;
43 //              }
44 //              return new ICompletionProposal[0];
45 //              text.
46                 return new ICompletionProposal[] { new AsmOperationProposal("ADD", "Addition operation", offset),
47                                 new AsmOperationProposal("MUL", "Multiplication operation", offset) };
48         }
49
50         @Override
51         public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset)
52         {
53                 return null;
54         }
55
56         @Override
57         public char[] getCompletionProposalAutoActivationCharacters()
58         {
59                 return new char[] { '\t' }; // NON-NLS-1
60         }
61
62         @Override
63         public char[] getContextInformationAutoActivationCharacters()
64         {
65                 return null;
66         }
67
68         @Override
69         public String getErrorMessage()
70         {
71                 return null;
72         }
73
74         @Override
75         public IContextInformationValidator getContextInformationValidator()
76         {
77                 return null;
78         }
79
80         private class AsmOperationProposal implements ICompletionProposal, ICompletionProposalExtension4
81         {
82
83                 private String asmOp;
84                 private String desc;
85                 private int offset;
86
87                 public AsmOperationProposal(String asmOp, String desc, int offset)
88                 {
89                         this.asmOp = asmOp;
90                         this.desc = desc;
91                         this.offset = offset;
92                 }
93
94                 @Override
95                 public boolean isAutoInsertable()
96                 {
97                         return true;
98                 }
99
100                 @Override
101                 public void apply(IDocument document)
102                 {
103                         try
104                         {
105                                 document.replace(offset, 0, asmOp);
106                         }
107                         catch (BadLocationException e)
108                         {
109                                 // ignore
110                         }
111                 }
112
113                 @Override
114                 public Point getSelection(IDocument document)
115                 {
116                         return new Point(offset + asmOp.length(), 0);
117                 }
118
119                 @Override
120                 public String getAdditionalProposalInfo()
121                 {
122                         return desc;
123                 }
124
125                 @Override
126                 public String getDisplayString()
127                 {
128                         return asmOp;
129                 }
130
131                 @Override
132                 public Image getImage()
133                 {
134                         return null; // TODO image?
135                 }
136
137                 @Override
138                 public IContextInformation getContextInformation()
139                 {
140                         return new IContextInformation()
141                         {
142
143                                 @Override
144                                 public String getInformationDisplayString()
145                                 {
146                                         // TODO Auto-generated method stub
147                                         return null;
148                                 }
149
150                                 @Override
151                                 public Image getImage()
152                                 {
153                                         // TODO Auto-generated method stub
154                                         return null;
155                                 }
156
157                                 @Override
158                                 public String getContextDisplayString()
159                                 {
160                                         // TODO Auto-generated method stub
161                                         return null;
162                                 }
163                         };
164                 }
165
166         }
167
168 }