KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 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.jdt.core.*;
27 import org.eclipse.jface.text.source.IVerticalRulerInfo;
28 import org.eclipse.ui.PartInitException;
29 import org.eclipse.ui.texteditor.AbstractTextEditor;
30 import org.eclipse.ui.texteditor.ITextEditor;
31 import org.eclipse.ui.part.*;
32
33 import ca.mcgill.sable.soot.SootPlugin;
34
35
36 public class SootAttributeJavaSelectAction extends SootAttributeSelectAction {
37
38     public SootAttributeJavaSelectAction(ResourceBundle bundle, String JavaDoc prefix, ITextEditor editor, IVerticalRulerInfo rulerInfo) {
39         super(bundle, prefix, editor, rulerInfo);
40     }
41
42     /* (non-Javadoc)
43      * @see ca.mcgill.sable.soot.attributes.SootAttributeSelectAction#getMarkerLinks()
44      */

45     public ArrayList getMarkerLinks(){
46         SootAttributesHandler handler = SootPlugin.getDefault().getManager().getAttributesHandlerForFile((IFile)getResource(getEditor()));
47         ArrayList links = handler.getJavaLinks(getLineNumber()+1);
48         Iterator it = links.iterator();
49         
50         return links;
51     }
52     
53     protected int getLinkLine(LinkAttribute la){
54         return la.getJavaLink();
55     }
56
57     
58     public void findClass(String JavaDoc className){
59         setLinkToEditor(getEditor());
60         String JavaDoc resource = removeExt(getResource(getEditor()).getName());
61         
62         String JavaDoc ext = getResource(getEditor()).getFileExtension();
63     
64         IProject proj = getResource(getEditor()).getProject();
65         String JavaDoc slashedClassName = className.replaceAll("\\.", System.getProperty("file.separator"));
66         String JavaDoc classNameToFind = slashedClassName+"."+ext;
67         IJavaProject jProj = JavaCore.create(proj);
68         try {
69     
70             IPackageFragmentRoot [] roots = jProj.getAllPackageFragmentRoots();
71             for (int i = 0; i < roots.length; i++){
72                 if (!(roots[i].getResource() instanceof IContainer)) continue;
73                 IResource fileToFind = ((IContainer)roots[i].getResource()).findMember(classNameToFind);
74                 if (fileToFind == null) continue;
75             
76                 if (!fileToFind.equals(resource)){
77                     try {
78                         setLinkToEditor((AbstractTextEditor)SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new FileEditorInput((IFile)fileToFind), fileToFind.getName()));
79                     }
80                     catch (PartInitException e){
81                     }
82                 }
83             }
84         }
85         catch (JavaModelException e){
86             setLinkToEditor(getEditor());
87         }
88     
89     }
90 }
91
Popular Tags