• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package spechelper;
17 
18 import org.eclipse.jface.text.BadLocationException;
19 import org.eclipse.jface.text.IDocument;
20 import org.eclipse.jface.text.contentassist.ICompletionProposal;
21 import org.eclipse.jface.text.contentassist.IContextInformation;
22 import org.eclipse.swt.graphics.Image;
23 import org.eclipse.swt.graphics.Point;
24 
25 public class MyCompletion implements ICompletionProposal {
26 
27     private String m_displ;
28     private String m_replace;
29     private int m_offset;
30     private int m_replacelen;
31     private int m_cursorpos;
32     private Image m_img;
33     private IContextInformation m_context;
34     private String m_addinfo;
35     private String fBuffer;
36 
MyCompletion(String buffer, String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString, IContextInformation contextInformation, String additionalProposalInfo)37     public MyCompletion(String buffer, String replacementString,
38             int replacementOffset, int replacementLength, int cursorPosition,
39             Image image, String displayString,
40             IContextInformation contextInformation,
41             String additionalProposalInfo) {
42         m_replace = replacementString;
43         m_offset = replacementOffset;
44         m_replacelen = replacementLength;
45         m_cursorpos = cursorPosition;
46         m_img = image;
47         fBuffer = buffer;
48         m_displ = displayString;
49         m_context = contextInformation;
50         m_addinfo = additionalProposalInfo;
51     }
52 
apply(IDocument document)53     public void apply(IDocument document) {
54         try {
55             MethodSelector ms = new MethodSelector();
56             String replace = ms.obtainReplacement(fBuffer);
57             if (replace == null) {
58                 m_cursorpos = 0;
59                 return;
60             }
61             m_cursorpos = replace.length();
62             document.replace(m_offset, m_replacelen, replace);
63         } catch (BadLocationException x) {
64             // ignore
65         }
66     }
67 
getSelection(IDocument document)68     public Point getSelection(IDocument document) {
69         return new Point(m_offset + m_cursorpos, 0);
70     }
71 
getContextInformation()72     public IContextInformation getContextInformation() {
73         return m_context;
74     }
75 
getImage()76     public Image getImage() {
77         return m_img;
78     }
79 
getDisplayString()80     public String getDisplayString() {
81         if (m_displ != null) return m_displ;
82         return m_replace;
83     }
84 
getAdditionalProposalInfo()85     public String getAdditionalProposalInfo() {
86         return m_addinfo;
87     }
88 }
89