|
import static com.intellij.openapi.actionSystem.LangDataKeys.* |
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////// |
|
metaClass.propertyMissing = {name -> |
|
switch (name) { |
|
case "application": return com.intellij.openapi.application.ApplicationManager.getApplication() |
|
case "project": return com.intellij.openapi.project.ProjectManager.getInstance().getOpenProjects()[0] |
|
case "INDEX": return com.intellij.psi.search.FilenameIndex |
|
case "GSS": return com.intellij.psi.search.GlobalSearchScope |
|
case "EXT": return com.intellij.openapi.extensions.Extensions |
|
default: |
|
def variants = [] |
|
for (t in [IDE.project, IDE.application]) { |
|
for (obj in t.picoContainer.componentKeyToAdapterCache.keySet()) { |
|
def key = obj instanceof String ? obj : obj instanceof Class ? obj.getName() : null |
|
if (key == null) continue |
|
def match = key =~ /[\.]([^\.]+?)(Service|Manager|Helper|Factory)?$/ |
|
def groups = match.size()? match[0][1..-1] : [key, null] |
|
def singular = groups[1..-1][0] == null |
|
def words = com.intellij.psi.codeStyle.NameUtil.nameToWords(groups[0]) |
|
def short0 = [words[0].toLowerCase(), words.length==1? "" : words[1..-1]].flatten().join() |
|
def shortName = singular? short0 : com.intellij.openapi.util.text.StringUtil.pluralize(short0) |
|
if (shortName.equals(name)) return t.picoContainer.getComponentInstance(obj); |
|
if (com.intellij.openapi.util.text.StringUtil.containsIgnoreCase(groups[0], name)) variants.add(shortName) |
|
} |
|
} |
|
throw new MissingPropertyException("Service or Component '$name' not found. Variants: $variants") |
|
} |
|
} |
|
|
|
String.class.metaClass.file = {-> virtualFiles.findFileByUrl(com.intellij.openapi.vfs.VfsUtil.pathToUrl(delegate))} |
|
String.class.metaClass.file2 = {-> def name = delegate; fileEditors.getOpenFiles().find {file -> file.getName().equals(name) }} |
|
String.class.metaClass.findPsi = {-> INDEX.getFilesByName(project, delegate, GSS.allScope(project)) } |
|
String.class.metaClass.findFile = {-> INDEX.getVirtualFilesByName(project, delegate, GSS.allScope(project)) } |
|
String.class.metaClass.firstPsi = {-> delegate.findPsi()[0] } |
|
String.class.metaClass.firstFile = {-> delegate.findFile()[0] } |
|
String.class.metaClass.ep = {-> EXT.getArea(null).getExtensionPoint(delegate) } |
|
com.intellij.openapi.actionSystem.DataKey.class.metaClass.from = {e -> delegate.getData(e.getDataContext()) } |
|
|
|
def virtualFileMetaClass = com.intellij.openapi.vfs.VirtualFile.class.metaClass |
|
virtualFileMetaClass.psi = {-> psiManager.findFile(delegate)} |
|
virtualFileMetaClass.document = {-> fileDocuments.getDocument(delegate)} |
|
virtualFileMetaClass.editor = {-> fileEditors.getSelectedEditor(delegate)?.getEditor()} |
|
|
|
def psiMetaClass = com.intellij.psi.PsiElement.class.metaClass |
|
psiMetaClass.document = {-> psiDocuments.getDocument(delegate)} |
|
psiMetaClass.file = {-> delegate.getContainingFile().getVirtualFile()} |
|
psiMetaClass.editor = {-> fileEditors.getSelectedEditor(delegate.file())?.getEditor()} |
|
|
|
write = { c -> application.runWriteAction(c)} |
|
read = { c -> application.runReadAction(c)} |
|
pool = { c -> application.executeOnPooledThread(c)} |
|
swing = { c -> com.intellij.util.ui.UIUtil.invokeLaterIfNeeded(c)} |
|
|
|
action = { name, shortcut = null, perform = null -> |
|
actions.unregisterAction(name) |
|
keymaps.getActiveKeymap().removeAllActionShortcuts(name) |
|
|
|
if (perform == null) return |
|
actions.registerAction(name, new com.intellij.openapi.actionSystem.AnAction(name, name, null) { |
|
@Override |
|
void actionPerformed(com.intellij.openapi.actionSystem.AnActionEvent e) { |
|
perform(e) |
|
} }) |
|
if (shortcut != null) { |
|
keymaps.getActiveKeymap().addShortcut(name, new com.intellij.openapi.actionSystem.KeyboardShortcut( |
|
javax.swing.KeyStroke.getKeyStroke(shortcut), null)) |
|
} |
|
} |
|
|
|
timer = {name, delay = 1, perform = null -> |
|
dispose(name) |
|
if (perform == null) return |
|
def h = new com.intellij.util.Alarm(project) |
|
def r = new Runnable() { public void run() {perform(); h.addRequest(this, delay); }} |
|
h.addRequest(r, delay) |
|
IDE.put(name, h) |
|
} |
|
dispose = { h -> |
|
t = h instanceof com.intellij.openapi.Disposable ? h : IDE.put(h, null) |
|
if (t != null) com.intellij.openapi.util.Disposer.dispose(t) |
|
} |
|
|
|
editor = { -> try {windows.getFocusedComponent(project).getEditor()} catch(e){}} |
IDE.print
is no longer functional. It does not display to the run toolwindow and no console appears. Additionally the static method is private and constructing the IDE instance manually yields no results.Fallback, although not pretty, is to open up File I/O directly and e.g.
tail -f <yourfile>