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 public class AsmContentAssistProcessor implements IContentAssistProcessor
20 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset)
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());
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());
44 // return new ICompletionProposal[0];
46 return new ICompletionProposal[] { new AsmOperationProposal("ADD", "Addition operation", offset),
47 new AsmOperationProposal("MUL", "Multiplication operation", offset) };
51 public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset)
57 public char[] getCompletionProposalAutoActivationCharacters()
59 return new char[] { '\t' }; // NON-NLS-1
63 public char[] getContextInformationAutoActivationCharacters()
69 public String getErrorMessage()
75 public IContextInformationValidator getContextInformationValidator()
80 private class AsmOperationProposal implements ICompletionProposal, ICompletionProposalExtension4
87 public AsmOperationProposal(String asmOp, String desc, int offset)
95 public boolean isAutoInsertable()
101 public void apply(IDocument document)
105 document.replace(offset, 0, asmOp);
107 catch (BadLocationException e)
114 public Point getSelection(IDocument document)
116 return new Point(offset + asmOp.length(), 0);
120 public String getAdditionalProposalInfo()
126 public String getDisplayString()
132 public Image getImage()
134 return null; // TODO image?
138 public IContextInformation getContextInformation()
140 return new IContextInformation()
144 public String getInformationDisplayString()
146 // TODO Auto-generated method stub
151 public Image getImage()
153 // TODO Auto-generated method stub
158 public String getContextDisplayString()
160 // TODO Auto-generated method stub