01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 2004 Jennifer Lhotak
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: */
19:
20: package ca.mcgill.sable.soot.attributes;
21:
22: import java.util.*;
23:
24: import org.eclipse.core.resources.*;
25: import org.eclipse.core.runtime.*;
26: import org.eclipse.jdt.core.*;
27: import org.eclipse.ui.*;
28: import org.eclipse.ui.texteditor.*;
29:
30: public class JavaAttributesComputer extends AbstractAttributesComputer {
31:
32: protected ArrayList computeNames(IFile file) {
33: IJavaElement jElem = getJavaElement(file);
34: ICompilationUnit cu = (ICompilationUnit) jElem;
35: return getNames(cu);
36: }
37:
38: /**
39: * compute top-level names
40: */
41: protected ArrayList computeNames(AbstractTextEditor editor) {
42: IJavaElement jElem = getJavaElement(editor);
43: ArrayList names = new ArrayList();
44: if (jElem instanceof ICompilationUnit) {
45: ICompilationUnit cu = (ICompilationUnit) jElem;
46: return getNames(cu);
47: } else {
48: return names;
49: }
50: }
51:
52: private ArrayList getNames(ICompilationUnit cu) {
53: ArrayList names = new ArrayList();
54: try {
55: IType[] topLevelDecls = cu.getTypes();
56: for (int i = 0; i < topLevelDecls.length; i++) {
57: names.add(topLevelDecls[i].getFullyQualifiedName());
58: }
59: } catch (JavaModelException e) {
60: }
61: return names;
62: }
63:
64: /**
65: * initialize rec and proj
66: */
67: protected void init(AbstractTextEditor editor) {
68: IJavaElement jElem = getJavaElement(editor);
69: setProj(jElem.getResource().getProject());
70: setRec(jElem.getResource());
71: }
72:
73: public IJavaElement getJavaElement(AbstractTextEditor textEditor) {
74: IEditorInput input = textEditor.getEditorInput();
75: return (IJavaElement) ((IAdaptable) input)
76: .getAdapter(IJavaElement.class);
77: }
78:
79: public IJavaElement getJavaElement(IFile file) {
80: return (IJavaElement) ((IAdaptable) file)
81: .getAdapter(IJavaElement.class);
82: }
83:
84: }
|