1 package net.mograsim.plugin.asm.editor;
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;
16 import net.mograsim.plugin.AsmOps;
18 public class AsmContentAssistProcessor implements IContentAssistProcessor
22 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset)
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());
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());
46 // return new ICompletionProposal[0];
48 return AsmOps.ops.stream().map(o -> new AsmOperationProposal(o, "", offset)).toArray(ICompletionProposal[]::new);
52 public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset)
58 public char[] getCompletionProposalAutoActivationCharacters()
60 return new char[] { '\n', '\r' }; // NON-NLS-1
64 public char[] getContextInformationAutoActivationCharacters()
70 public String getErrorMessage()
76 public IContextInformationValidator getContextInformationValidator()
81 private class AsmOperationProposal implements ICompletionProposal, ICompletionProposalExtension4
88 public AsmOperationProposal(String asmOp, String desc, int offset)
96 public boolean isAutoInsertable()
102 public void apply(IDocument document)
106 document.replace(offset, 0, asmOp);
108 catch (BadLocationException e)
115 public Point getSelection(IDocument document)
117 return new Point(offset + asmOp.length(), 0);
121 public String getAdditionalProposalInfo()
127 public String getDisplayString()
133 public Image getImage()
135 return null; // TODO image?
139 public IContextInformation getContextInformation()
141 return new IContextInformation()
145 public String getInformationDisplayString()
147 // TODO Auto-generated method stub
152 public Image getImage()
154 // TODO Auto-generated method stub
159 public String getContextDisplayString()
161 // TODO Auto-generated method stub