KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > attributes > JavaAttributesComputer


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2004 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * 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
21 package ca.mcgill.sable.soot.attributes;
22
23 import java.util.*;
24
25 import org.eclipse.core.resources.*;
26 import org.eclipse.core.runtime.*;
27 import org.eclipse.jdt.core.*;
28 import org.eclipse.ui.*;
29 import org.eclipse.ui.texteditor.*;
30
31
32 public class JavaAttributesComputer extends AbstractAttributesComputer {
33
34     protected ArrayList computeNames(IFile file){
35         IJavaElement jElem = getJavaElement(file);
36         ICompilationUnit cu = (ICompilationUnit)jElem;
37         return getNames(cu);
38     }
39     
40     /**
41      * compute top-level names
42      */

43     protected ArrayList computeNames(AbstractTextEditor editor){
44         IJavaElement jElem = getJavaElement(editor);
45         ArrayList names = new ArrayList();
46         if (jElem instanceof ICompilationUnit){
47             ICompilationUnit cu = (ICompilationUnit)jElem;
48             return getNames(cu);
49         }
50         else {
51             return names;
52         }
53     }
54     
55     private ArrayList getNames(ICompilationUnit cu){
56         ArrayList names = new ArrayList();
57         try {
58             IType [] topLevelDecls = cu.getTypes();
59             for (int i = 0; i < topLevelDecls.length; i++){
60                 names.add(topLevelDecls[i].getFullyQualifiedName());
61             }
62         }
63         catch(JavaModelException e){
64         }
65         return names;
66     }
67     
68     /**
69      * initialize rec and proj
70      */

71     protected void init(AbstractTextEditor editor){
72         IJavaElement jElem = getJavaElement(editor);
73         setProj(jElem.getResource().getProject());
74         setRec(jElem.getResource());
75     }
76     
77     public IJavaElement getJavaElement(AbstractTextEditor textEditor) {
78         IEditorInput input= textEditor.getEditorInput();
79         return (IJavaElement) ((IAdaptable) input).getAdapter(IJavaElement.class);
80     }
81     
82     public IJavaElement getJavaElement(IFile file) {
83         return (IJavaElement) ((IAdaptable) file).getAdapter(IJavaElement.class);
84     }
85     
86     
87 }
88
Popular Tags