001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2003 Jennifer Lhotak
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: */
019:
020: package ca.mcgill.sable.soot.attributes;
021:
022: import java.util.ArrayList;
023:
024: import org.eclipse.jface.text.*;
025: import org.eclipse.jface.text.source.SourceViewer;
026: import org.eclipse.ui.*;
027: import org.eclipse.ui.texteditor.AbstractTextEditor;
028: import org.eclipse.core.resources.*;
029: import org.eclipse.core.runtime.CoreException;
030: import ca.mcgill.sable.soot.SootPlugin;
031:
032: public abstract class AbstractSootAttributesHover implements ITextHover {
033:
034: private IEditorPart editor;
035: private int lineNum;
036: private String fileName;
037: private String packFileName;
038: private ArrayList packFileNames;
039: private boolean editorHasChanged;
040: private String selectedProj;
041: private SootAttributesHandler attrsHandler;
042: private IResource rec;
043: private ITextViewer viewer;
044: private IDocument document;
045: public static final String sep = System
046: .getProperty("file.separator");
047:
048: /**
049: * Method setEditor.
050: * @param ed
051: */
052: public void setEditor(IEditorPart ed) {
053: editor = ed;
054: }
055:
056: /**
057: * Method getAttributes.
058: * @return String
059: * sub classes must implement this method
060: * if more then one attribute return
061: * each attribute separated by newlines
062: */
063: protected abstract String getAttributes(AbstractTextEditor editor);
064:
065: /**
066: * @see org.eclipse.jface.text.ITextHover#getHoverInfo(ITextViewer, IRegion)
067: */
068: public String getHoverInfo(ITextViewer textViewer,
069: org.eclipse.jface.text.IRegion hoverRegion) {
070:
071: // this prevents showing incorrect tags - at least temporaily
072: // and hopefully if the editor has ever changed
073:
074: getHoverRegion(textViewer, hoverRegion.getOffset());
075: String attr = null;
076: attr = getAttributes((AbstractTextEditor) getEditor());
077:
078: return attr;
079:
080: }
081:
082: /**
083: * @see org.eclipse.jface.text.ITextHover#getHoverRegion(ITextViewer, int)
084: */
085: public org.eclipse.jface.text.IRegion getHoverRegion(
086: ITextViewer textViewer, int offset) {
087: try {
088: setLineNum(textViewer.getDocument().getLineOfOffset(offset) + 1);
089: setDocument(textViewer.getDocument());
090: return textViewer.getDocument().getLineInformationOfOffset(
091: offset);
092: } catch (BadLocationException e) {
093: return null;
094: }
095:
096: }
097:
098: /**
099: * Returns the lineNum.
100: * @return int
101: */
102: public int getLineNum() {
103: return lineNum;
104: }
105:
106: /**
107: * Sets the lineNum.
108: * @param lineNum The lineNum to set
109: */
110: public void setLineNum(int lineNum) {
111: this .lineNum = lineNum;
112: }
113:
114: /**
115: * Returns the fileName.
116: * @return String
117: */
118: public String getFileName() {
119: return fileName;
120: }
121:
122: /**
123: * Sets the fileName.
124: * @param fileName The fileName to set
125: */
126: public void setFileName(String fileName) {
127: this .fileName = fileName;
128: }
129:
130: /**
131: * Returns the packFileName.
132: * @return String
133: */
134: public String getPackFileName() {
135: return packFileName;
136: }
137:
138: /**
139: * Sets the packFileName.
140: * @param packFileName The packFileName to set
141: */
142: public void setPackFileName(String packFileName) {
143: this .packFileName = packFileName;
144: }
145:
146: /**
147: * Returns the editorHasChanged.
148: * @return boolean
149: */
150: public boolean isEditorHasChanged() {
151: return editorHasChanged;
152: }
153:
154: /**
155: * Sets the editorHasChanged.
156: * @param editorHasChanged The editorHasChanged to set
157: */
158: public void setEditorHasChanged(boolean editorHasChanged) {
159: this .editorHasChanged = editorHasChanged;
160: }
161:
162: /**
163: * Returns the selectedProj.
164: * @return String
165: */
166: public String getSelectedProj() {
167: return selectedProj;
168: }
169:
170: /**
171: * Sets the selectedProj.
172: * @param selectedProj The selectedProj to set
173: */
174: public void setSelectedProj(String selectedProj) {
175: this .selectedProj = selectedProj;
176: }
177:
178: /**
179: * Returns the attrsHandler.
180: * @return SootAttributesHandler
181: */
182: public SootAttributesHandler getAttrsHandler() {
183: return attrsHandler;
184: }
185:
186: /**
187: * Sets the attrsHandler.
188: * @param attrsHandler The attrsHandler to set
189: */
190: public void setAttrsHandler(SootAttributesHandler attrsHandler) {
191: this .attrsHandler = attrsHandler;
192: }
193:
194: /**
195: * Returns the editor.
196: * @return IEditorPart
197: */
198: public IEditorPart getEditor() {
199: return editor;
200: }
201:
202: /**
203: * Returns the rec.
204: * @return IResource
205: */
206: public IResource getRec() {
207: return rec;
208: }
209:
210: /**
211: * Sets the rec.
212: * @param rec The rec to set
213: */
214: public void setRec(IResource rec) {
215: this .rec = rec;
216: }
217:
218: /**
219: * @return
220: */
221: public IDocument getDocument() {
222: return document;
223: }
224:
225: /**
226: * @return
227: */
228: public ITextViewer getViewer() {
229: return viewer;
230: }
231:
232: /**
233: * @param document
234: */
235: public void setDocument(IDocument document) {
236: this .document = document;
237: }
238:
239: /**
240: * @param viewer
241: */
242: public void setViewer(ITextViewer viewer) {
243: this .viewer = viewer;
244: }
245:
246: /**
247: * @return
248: */
249: public ArrayList getPackFileNames() {
250: return packFileNames;
251: }
252:
253: /**
254: * @param list
255: */
256: public void setPackFileNames(ArrayList list) {
257: packFileNames = list;
258: }
259:
260: }
|