mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Byte code viewer shows byte code for groovy scripts
This commit is contained in:
@@ -5,11 +5,17 @@
|
||||
<description>Viewing java bytecode inside IntelliJ IDEA.</description>
|
||||
<vendor>JetBrains</vendor>
|
||||
|
||||
<extensionPoints>
|
||||
<extensionPoint name="classSearcher" interface="com.intellij.byteCodeViewer.ClassSearcher"/>
|
||||
</extensionPoints>
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<errorHandler implementation="com.intellij.diagnostic.ITNReporter"/>
|
||||
<projectService serviceInterface="com.intellij.byteCodeViewer.ByteCodeViewerManager"
|
||||
serviceImplementation="com.intellij.byteCodeViewer.ByteCodeViewerManager"/>
|
||||
</extensions>
|
||||
<extensions>
|
||||
<ByteCodeViewer.classSearcher implementation="com.intellij.byteCodeViewer.DefaultClassSearcher"/>
|
||||
</extensions>
|
||||
<actions>
|
||||
<group>
|
||||
<action id="ByteCodeViewer" class="com.intellij.byteCodeViewer.ShowByteCodeAction" text="Show Byte Code"/>
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.ide.util.JavaAnonymousClassesHelper;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -35,6 +36,8 @@ import java.io.StringWriter;
|
||||
* Date: 5/7/12
|
||||
*/
|
||||
public class ByteCodeViewerManager extends DockablePopupManager<ByteCodeViewerComponent> {
|
||||
private static final ExtensionPointName<ClassSearcher> CLASS_SEARCHER_EP = ExtensionPointName.create("ByteCodeViewer.classSearcher");
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#" + ByteCodeViewerManager.class.getName());
|
||||
|
||||
public static final String TOOLWINDOW_ID = "Byte Code Viewer";
|
||||
@@ -232,13 +235,13 @@ public class ByteCodeViewerManager extends DockablePopupManager<ByteCodeViewerCo
|
||||
return ClassUtil.getJVMClassName(containingClass);
|
||||
}
|
||||
|
||||
private static PsiClass getContainingClass(PsiElement psiElement) {
|
||||
PsiClass containingClass = PsiTreeUtil.getParentOfType(psiElement, PsiClass.class, false);
|
||||
while (containingClass instanceof PsiTypeParameter) {
|
||||
containingClass = PsiTreeUtil.getParentOfType(containingClass, PsiClass.class);
|
||||
public static PsiClass getContainingClass(PsiElement psiElement) {
|
||||
for (ClassSearcher searcher : CLASS_SEARCHER_EP.getExtensions()) {
|
||||
PsiClass aClass = searcher.findClass(psiElement);
|
||||
if (aClass != null) {
|
||||
return aClass;
|
||||
}
|
||||
}
|
||||
if (containingClass == null) return null;
|
||||
|
||||
return containingClass;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.intellij.byteCodeViewer;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Created by Max Medvedev on 8/23/13
|
||||
*/
|
||||
public interface ClassSearcher {
|
||||
@Nullable
|
||||
PsiClass findClass(@NotNull PsiElement place);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.intellij.byteCodeViewer;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiTypeParameter;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Created by Max Medvedev on 8/23/13
|
||||
*/
|
||||
public class DefaultClassSearcher implements ClassSearcher {
|
||||
@Override
|
||||
public PsiClass findClass(@NotNull PsiElement psiElement) {
|
||||
PsiClass containingClass = PsiTreeUtil.getParentOfType(psiElement, PsiClass.class, false);
|
||||
while (containingClass instanceof PsiTypeParameter) {
|
||||
containingClass = PsiTreeUtil.getParentOfType(containingClass, PsiClass.class);
|
||||
}
|
||||
if (containingClass == null) return null;
|
||||
|
||||
return containingClass;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.ui.popup.NotLookupOrSearchCondition;
|
||||
@@ -43,7 +42,7 @@ public class ShowByteCodeAction extends AnAction {
|
||||
final PsiElement psiElement = getPsiElement(e.getDataContext(), project, e.getData(PlatformDataKeys.EDITOR));
|
||||
if (psiElement != null) {
|
||||
if (psiElement.getContainingFile() instanceof PsiClassOwner &&
|
||||
PsiTreeUtil.getParentOfType(psiElement, PsiClass.class, false) != null) {
|
||||
ByteCodeViewerManager.getContainingClass(psiElement) != null) {
|
||||
e.getPresentation().setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
<orderEntry type="module" module-name="junit" scope="TEST" />
|
||||
<orderEntry type="module" module-name="java-indexing-api" />
|
||||
<orderEntry type="module" module-name="groovy-jps-plugin" />
|
||||
<orderEntry type="module" module-name="ByteCodeViewer" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
<depends optional="true" config-file="intellilang-groovy-support.xml">org.intellij.intelliLang</depends>
|
||||
<depends optional="true">AntSupport</depends>
|
||||
<depends optional="true">cucumber</depends>
|
||||
<depends optional="true">ByteCodeViewer</depends>
|
||||
|
||||
<extensionPoints>
|
||||
<extensionPoint name="methodComparator" interface="org.jetbrains.plugins.groovy.lang.resolve.GrMethodComparator"/>
|
||||
@@ -1429,6 +1430,10 @@
|
||||
<codeFragmentFactory implementation="org.jetbrains.plugins.groovy.debugger.GroovyCodeFragmentFactory"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="ByteCodeViewer">
|
||||
<classSearcher implementation="org.jetbrains.plugins.groovy.byteCodeViewer.GroovyScriptClassSearcher"/>
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
<action id="Groovy.Shell.Execute" class="com.intellij.openapi.actionSystem.EmptyAction" text="Execute Groovy Code"
|
||||
description="Execute Groovy code in console">
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.byteCodeViewer;
|
||||
|
||||
import com.intellij.byteCodeViewer.ClassSearcher;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiTypeParameter;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.GroovyFileType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
|
||||
/**
|
||||
* Created by Max Medvedev on 8/23/13
|
||||
*/
|
||||
public class GroovyScriptClassSearcher implements ClassSearcher {
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiClass findClass(@NotNull PsiElement place) {
|
||||
if (place.getLanguage() == GroovyFileType.GROOVY_LANGUAGE) {
|
||||
PsiClass containingClass = PsiTreeUtil.getParentOfType(place, PsiClass.class, false);
|
||||
while (containingClass instanceof PsiTypeParameter) {
|
||||
containingClass = PsiTreeUtil.getParentOfType(containingClass, PsiClass.class);
|
||||
}
|
||||
if (containingClass != null) return containingClass;
|
||||
|
||||
PsiFile file = place.getContainingFile();
|
||||
if (file instanceof GroovyFile && ((GroovyFile)file).isScript()) {
|
||||
return ((GroovyFile)file).getScriptClass();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user