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.*;
023:
024: import org.eclipse.core.resources.*;
025: import org.eclipse.jdt.core.*;
026: import org.eclipse.jface.text.source.IVerticalRulerInfo;
027: import org.eclipse.ui.PartInitException;
028: import org.eclipse.ui.texteditor.AbstractTextEditor;
029: import org.eclipse.ui.texteditor.ITextEditor;
030: import org.eclipse.ui.part.*;
031:
032: import ca.mcgill.sable.soot.SootPlugin;
033:
034: public class SootAttributeJavaSelectAction extends
035: SootAttributeSelectAction {
036:
037: public SootAttributeJavaSelectAction(ResourceBundle bundle,
038: String prefix, ITextEditor editor,
039: IVerticalRulerInfo rulerInfo) {
040: super (bundle, prefix, editor, rulerInfo);
041: }
042:
043: /* (non-Javadoc)
044: * @see ca.mcgill.sable.soot.attributes.SootAttributeSelectAction#getMarkerLinks()
045: */
046: public ArrayList getMarkerLinks() {
047: SootAttributesHandler handler = SootPlugin.getDefault()
048: .getManager().getAttributesHandlerForFile(
049: (IFile) getResource(getEditor()));
050: ArrayList links = handler.getJavaLinks(getLineNumber() + 1);
051: Iterator it = links.iterator();
052:
053: return links;
054: }
055:
056: protected int getLinkLine(LinkAttribute la) {
057: return la.getJavaLink();
058: }
059:
060: public void findClass(String className) {
061: setLinkToEditor(getEditor());
062: String resource = removeExt(getResource(getEditor()).getName());
063:
064: String ext = getResource(getEditor()).getFileExtension();
065:
066: IProject proj = getResource(getEditor()).getProject();
067: String slashedClassName = className.replaceAll("\\.", System
068: .getProperty("file.separator"));
069: String classNameToFind = slashedClassName + "." + ext;
070: IJavaProject jProj = JavaCore.create(proj);
071: try {
072:
073: IPackageFragmentRoot[] roots = jProj
074: .getAllPackageFragmentRoots();
075: for (int i = 0; i < roots.length; i++) {
076: if (!(roots[i].getResource() instanceof IContainer))
077: continue;
078: IResource fileToFind = ((IContainer) roots[i]
079: .getResource()).findMember(classNameToFind);
080: if (fileToFind == null)
081: continue;
082:
083: if (!fileToFind.equals(resource)) {
084: try {
085: setLinkToEditor((AbstractTextEditor) SootPlugin
086: .getDefault().getWorkbench()
087: .getActiveWorkbenchWindow()
088: .getActivePage().openEditor(
089: new FileEditorInput(
090: (IFile) fileToFind),
091: fileToFind.getName()));
092: } catch (PartInitException e) {
093: }
094: }
095: }
096: } catch (JavaModelException e) {
097: setLinkToEditor(getEditor());
098: }
099:
100: }
101: }
|