001: package visualdebugger;
002:
003: import java.util.MissingResourceException;
004: import java.util.ResourceBundle;
005:
006: import org.eclipse.core.resources.IProject;
007: import org.eclipse.jdt.core.ICompilationUnit;
008: import org.eclipse.jdt.core.IJavaProject;
009: import org.eclipse.jdt.core.IType;
010: import org.eclipse.jdt.core.JavaModelException;
011: import org.eclipse.jdt.core.dom.*;
012: import org.eclipse.jface.resource.ImageDescriptor;
013: import org.eclipse.ui.plugin.AbstractUIPlugin;
014: import org.osgi.framework.BundleContext;
015:
016: import visualdebugger.views.FindStatementById;
017: import de.uka.ilkd.key.gui.Main;
018: import de.uka.ilkd.key.visualdebugger.SourceElementId;
019:
020: /**
021: * The activator class controls the plug-in life cycle
022: */
023: public class Activator extends AbstractUIPlugin {
024:
025: // The shared instance
026: private static Activator plugin;
027:
028: // The plug-in ID
029: public static final String PLUGIN_ID = "VisualDebugger";
030:
031: /**
032: * Returns the shared instance
033: *
034: * @return the shared instance
035: */
036: public static Activator getDefault() {
037: return plugin;
038: }
039:
040: /**
041: * Returns an image descriptor for the image file at the given plug-in
042: * relative path
043: *
044: * @param path
045: * the path
046: * @return the image descriptor
047: */
048: public static ImageDescriptor getImageDescriptor(String path) {
049: return imageDescriptorFromPlugin(PLUGIN_ID, path);
050: }
051:
052: /**
053: * Returns the string from the plugin's resource bundle, or 'key' if not
054: * found.
055: */
056: public static String getResourceString(String key) {
057: ResourceBundle bundle = getDefault().getResourceBundle();
058: try {
059: return (bundle != null) ? bundle.getString(key) : key;
060: } catch (MissingResourceException e) {
061: return key;
062: }
063: }
064:
065: private IProject iProject = null;
066:
067: private IJavaProject project = null;
068:
069: private ResourceBundle resourceBundle;
070:
071: /**
072: * The constructor
073: */
074: public Activator() {
075: super ();
076: plugin = this ;
077: }
078:
079: public ASTNode getASTNodeForStatementId(SourceElementId id) {
080:
081: assert id != null && id.isStatement();
082:
083: final ICompilationUnit unit = getCompilationUnit(id);
084: if (unit == null) {
085: return null;
086: }
087:
088: final FindStatementById visitor = new FindStatementById(id);
089:
090: findSourceElement(unit, visitor);
091:
092: return visitor.getStatement();
093: }
094:
095: private void findSourceElement(final ICompilationUnit unit,
096: ASTVisitor visitor) {
097: final ASTParser parser = ASTParser.newParser(AST.JLS3);
098: parser.setResolveBindings(true);
099: parser.setSource(unit);
100: parser.createAST(null).accept(visitor);
101: }
102:
103: public ICompilationUnit getCompilationUnit(SourceElementId id) {
104: assert id != null;
105:
106: IType result = null;
107:
108: try {
109: result = project.findType(id.getClassName());
110: } catch (JavaModelException e) {
111: result = null;
112: }
113:
114: if (result == null) {
115: return null;
116: }
117:
118: return result.getCompilationUnit();
119: }
120:
121: public Expression getExpression(SourceElementId id) {
122: assert id != null;
123:
124: final ICompilationUnit unit = getCompilationUnit(id);
125: if (unit == null) {
126: return null;
127: }
128:
129: final FindStatementById visitor = new FindStatementById(id);
130: findSourceElement(unit, visitor);
131:
132: return visitor.getExpression();
133: }
134:
135: public IProject getIProject() {
136: return iProject;
137: }
138:
139: public IJavaProject getProject() {
140: return project;
141: }
142:
143: /**
144: * Returns the plugin's resource bundle,
145: */
146: public ResourceBundle getResourceBundle() {
147: try {
148: if (resourceBundle == null)
149: resourceBundle = ResourceBundle
150: .getBundle("visualdebugger.VisualDebuggerResources");
151: } catch (MissingResourceException x) {
152: resourceBundle = null;
153: }
154: return resourceBundle;
155: }
156:
157: public void setIProject(IProject project) {
158: iProject = project;
159: }
160:
161: public void setProject(IJavaProject project) {
162: this .project = project;
163: }
164:
165: /*
166: * (non-Javadoc)
167: *
168: * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
169: */
170: public void start(BundleContext context) throws Exception {
171: super .start(context);
172: Main.standalone = false;
173: }
174:
175: /*
176: * (non-Javadoc)
177: *
178: * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
179: */
180: public void stop(BundleContext context) throws Exception {
181: super.stop(context);
182: plugin = null;
183: resourceBundle = null;
184: }
185:
186: }
|