package XAspects.actions; import java.util.Enumeration; import java.util.Iterator; import java.util.List; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import edu.neu.ccs.demeter.aplib.cd.ClassGraph; import XAspectLanguage.AspectLanguage_List; import XAspectLanguage.ClassDictionaryL; import XAspectLanguage.SelectorL; import XAspectLanguage.SemanticChecker; import XAspectLanguage.XAspectLanguage2; import XAspects.XAspectsEditor; import XAspects.XAspectsViewer; /** * Our sample action implements workbench action delegate. * The action proxy will be created by the workbench and * shown in the UI. When the user tries to use the action, * this delegate will be created and execution will be * delegated to it. * @see IWorkbenchWindowActionDelegate */ public class XAspectsSampleAction implements IWorkbenchWindowActionDelegate { private IWorkbenchWindow window; /** * The constructor. */ public XAspectsSampleAction() { } /** * The action has been activated. The argument of the * method represents the 'real' action sitting * in the workbench UI. * @see IWorkbenchWindowActionDelegate#run */ public void run(IAction action) { // grab the workbench page IWorkbenchPage[] wb = window.getPages(); // find the XAspects viewer and clear its current content XAspectsViewer v = (XAspectsViewer) wb[0].findView("XAspects.viewer"); v.clear(); // check if the user has the viewer open // if not, send a message if (v == null) { MessageDialog.openInformation( window.getShell(), "XAspects Plug-in", "No XAspects Viewer!"); } // grab the active editor XAspectsEditor te = (XAspectsEditor) wb[0].getActiveEditor(); te.doSave(null); IEditorInput ei = te.getEditorInput(); // extract the content of the editor in String format String editorText = te.getDocumentProvider().getDocument(ei).get(); try { // parse the editor input into the language object XAspectsEditor.language = XAspectLanguage2.parse(editorText); // grab the class dictionary and traversal aspects from the input AspectLanguage_List l = XAspectsEditor.language.get_aspectlanguage_list(); Enumeration e = l.elements(); ClassDictionaryL cda = (ClassDictionaryL) e.nextElement(); SelectorL ta = (SelectorL) e.nextElement(); // parse and normalize the input class dictionary te.inputCg = ClassGraph.fromString(cda.get_classdict().get_text().toString()); te.inputCg.normalize(); // instantiate and run semantic checker SemanticChecker sc = new SemanticChecker(); sc.generate(cda, ta); List output = sc.check(); // set the semantic checker output to the viewer if (output.size() == 0) { v.add("Semantic check successful."); te.setContentChecked(true); } else { Iterator outputIter = output.listIterator(); while (outputIter.hasNext()) { v.add(outputIter.next().toString()); } } } catch (Exception e) { MessageDialog.openInformation( window.getShell(), "XAspects Plug-in Exception", e.getMessage()); System.out.println(e.getMessage()); } } /** * Selection in the workbench has been changed. We * can change the state of the 'real' action here * if we want, but this can only happen after * the delegate has been created. * @see IWorkbenchWindowActionDelegate#selectionChanged */ public void selectionChanged(IAction action, ISelection selection) { } /** * We can use this method to dispose of any system * resources we previously allocated. * @see IWorkbenchWindowActionDelegate#dispose */ public void dispose() { } /** * We will cache window object in order to * be able to provide parent shell for the message dialog. * @see IWorkbenchWindowActionDelegate#init */ public void init(IWorkbenchWindow window) { this.window = window; } }