mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
support renderers in kotlin, groovy, etc (in correct context)
This commit is contained in:
@@ -148,8 +148,8 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Pair<PsiClass, PsiType> getPsiClassAndType(@Nullable String className, Project project) {
|
||||
PsiClass contextClass = null;
|
||||
public static Pair<PsiElement, PsiType> getPsiClassAndType(@Nullable String className, Project project) {
|
||||
PsiElement contextClass = null;
|
||||
PsiType contextType = null;
|
||||
if (!StringUtil.isEmpty(className)) {
|
||||
PsiPrimitiveType primitiveType = PsiJavaParserFacadeImpl.getPrimitiveType(className);
|
||||
@@ -160,10 +160,10 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{
|
||||
else {
|
||||
contextClass = findClass(className, project, GlobalSearchScope.allScope(project));
|
||||
if (contextClass != null) {
|
||||
contextClass = (PsiClass)contextClass.getNavigationElement();
|
||||
contextClass = contextClass.getNavigationElement();
|
||||
}
|
||||
if (contextClass instanceof PsiCompiledElement) {
|
||||
contextClass = (PsiClass)((PsiCompiledElement)contextClass).getMirror();
|
||||
contextClass = ((PsiCompiledElement)contextClass).getMirror();
|
||||
}
|
||||
contextType = getType(className, project);
|
||||
}
|
||||
|
||||
+3
-6
@@ -29,10 +29,7 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.JavaCodeFragment;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.PsiTypeCodeFragmentImpl;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
@@ -208,8 +205,8 @@ class CompoundRendererConfigurable extends JPanel {
|
||||
ApplicationManager.getApplication().runReadAction(() -> {
|
||||
Project project = myProject;
|
||||
if (project != null) {
|
||||
Pair<PsiClass, PsiType> pair = DebuggerUtilsImpl.getPsiClassAndType(qName, project);
|
||||
PsiClass context = pair.first;
|
||||
Pair<PsiElement, PsiType>pair = DebuggerUtilsImpl.getPsiClassAndType(qName, project);
|
||||
PsiElement context = pair.first;
|
||||
if (context != null) {
|
||||
myLabelEditor.setContext(context);
|
||||
myChildrenEditor.setContext(context);
|
||||
|
||||
+2
-2
@@ -32,8 +32,8 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.JavaCodeFragment;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiCodeFragment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.sun.jdi.Type;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -69,7 +69,7 @@ public class UserExpressionDescriptorImpl extends EvaluationDescriptor implement
|
||||
}
|
||||
|
||||
protected PsiCodeFragment getEvaluationCode(final StackFrameContext context) throws EvaluateException {
|
||||
Pair<PsiClass, PsiType> psiClassAndType = DebuggerUtilsImpl.getPsiClassAndType(myTypeName, myProject);
|
||||
Pair<PsiElement, PsiType> psiClassAndType = DebuggerUtilsImpl.getPsiClassAndType(myTypeName, myProject);
|
||||
if (psiClassAndType.first == null) {
|
||||
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.invalid.type.name", myTypeName));
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public abstract class CachedEvaluator {
|
||||
protected Cache initEvaluatorAndChildrenExpression(final Project project) {
|
||||
final Cache cache = new Cache();
|
||||
try {
|
||||
Pair<PsiClass, PsiType> psiClassAndType = DebuggerUtilsImpl.getPsiClassAndType(getClassName(), project);
|
||||
Pair<PsiElement, PsiType> psiClassAndType = DebuggerUtilsImpl.getPsiClassAndType(getClassName(), project);
|
||||
if (psiClassAndType.first == null) {
|
||||
throw EvaluateExceptionUtil.CANNOT_FIND_SOURCE_CLASS;
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import com.intellij.debugger.settings.NodeRendererSettings;
|
||||
import com.intellij.debugger.ui.impl.watch.UserExpressionDescriptorImpl;
|
||||
import com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.xdebugger.frame.XValue;
|
||||
import com.intellij.xdebugger.frame.XValueNode;
|
||||
@@ -58,7 +58,7 @@ public class CustomFieldInplaceEditor extends XDebuggerTreeInplaceEditor {
|
||||
myExpressionEditor.setExpression(descriptor != null ? TextWithImportsImpl.toXExpression(descriptor.getEvaluationText()) : null);
|
||||
|
||||
ValueDescriptorImpl parentDescriptor = ((JavaValue)((XValueContainerNode)node.getParent()).getValueContainer()).getDescriptor();
|
||||
Pair<PsiClass, PsiType> pair = DebuggerUtilsImpl.getPsiClassAndType(getTypeName(parentDescriptor), getProject());
|
||||
Pair<PsiElement, PsiType> pair = DebuggerUtilsImpl.getPsiClassAndType(getTypeName(parentDescriptor), getProject());
|
||||
if (pair.first != null) {
|
||||
myExpressionEditor.setContext(pair.first);
|
||||
}
|
||||
|
||||
@@ -56,14 +56,19 @@ public class JavaDebuggerEditorsProvider extends XDebuggerEditorsProviderBase {
|
||||
return JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment(text, context, null, isPhysical);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Language> getSupportedLanguages(@Nullable PsiElement context) {
|
||||
return DebuggerUtilsEx.getCodeFragmentFactories(context).stream()
|
||||
.map(factory -> factory.getFileType().getLanguage())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Language> getSupportedLanguages(@NotNull Project project, @Nullable XSourcePosition sourcePosition) {
|
||||
if (sourcePosition != null) {
|
||||
PsiElement context = getContextElement(sourcePosition.getFile(), sourcePosition.getOffset(), project);
|
||||
return DebuggerUtilsEx.getCodeFragmentFactories(context).stream()
|
||||
.map(factory -> factory.getFileType().getLanguage())
|
||||
.collect(Collectors.toList());
|
||||
return getSupportedLanguages(getContextElement(sourcePosition.getFile(), sourcePosition.getOffset(), project));
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
+12
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.xdebugger.evaluation;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -27,6 +28,9 @@ import com.intellij.xdebugger.XSourcePosition;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public abstract class XDebuggerEditorsProviderBase extends XDebuggerEditorsProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -72,6 +76,14 @@ public abstract class XDebuggerEditorsProviderBase extends XDebuggerEditorsProvi
|
||||
return createExpressionCodeFragment(project, expression.getExpression(), context, isPhysical);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<Language> getSupportedLanguages(@Nullable PsiElement context) {
|
||||
if (context != null) {
|
||||
return getSupportedLanguages(context.getProject(), null);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected PsiElement getContextElement(@NotNull VirtualFile virtualFile, int offset, @NotNull Project project) {
|
||||
return XDebuggerUtil.getInstance().findContextElement(virtualFile, offset, project, false);
|
||||
|
||||
+17
-3
@@ -108,7 +108,7 @@ public abstract class XDebuggerEditorBase {
|
||||
|
||||
private ListPopup createLanguagePopup() {
|
||||
DefaultActionGroup actions = new DefaultActionGroup();
|
||||
for (final Language language : getEditorsProvider().getSupportedLanguages(myProject, mySourcePosition)) {
|
||||
for (Language language : getSupportedLanguages()) {
|
||||
//noinspection ConstantConditions
|
||||
actions.add(new AnAction(language.getDisplayName(), null, language.getAssociatedFileType().getIcon()) {
|
||||
@Override
|
||||
@@ -126,6 +126,17 @@ public abstract class XDebuggerEditorBase {
|
||||
false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<Language> getSupportedLanguages() {
|
||||
XDebuggerEditorsProvider editorsProvider = getEditorsProvider();
|
||||
if (myContext != null && editorsProvider instanceof XDebuggerEditorsProviderBase) {
|
||||
return ((XDebuggerEditorsProviderBase)editorsProvider).getSupportedLanguages(myContext);
|
||||
}
|
||||
else {
|
||||
return editorsProvider.getSupportedLanguages(myProject, mySourcePosition);
|
||||
}
|
||||
}
|
||||
|
||||
protected JPanel decorate(JComponent component, boolean multiline, boolean showEditor) {
|
||||
JPanel panel = JBUI.Panels.simplePanel();
|
||||
|
||||
@@ -182,7 +193,10 @@ public abstract class XDebuggerEditorBase {
|
||||
}
|
||||
Language language = text.getLanguage();
|
||||
if (language == null) {
|
||||
if (mySourcePosition != null) {
|
||||
if (myContext != null) {
|
||||
language = myContext.getLanguage();
|
||||
}
|
||||
if (language == null && mySourcePosition != null) {
|
||||
language = LanguageUtil.getFileLanguage(mySourcePosition.getFile());
|
||||
}
|
||||
if (language == null) {
|
||||
@@ -191,7 +205,7 @@ public abstract class XDebuggerEditorBase {
|
||||
text = new XExpressionImpl(text.getExpression(), language, text.getCustomInfo(), text.getMode());
|
||||
}
|
||||
|
||||
Collection<Language> languages = getEditorsProvider().getSupportedLanguages(myProject, mySourcePosition);
|
||||
Collection<Language> languages = getSupportedLanguages();
|
||||
boolean many = languages.size() > 1;
|
||||
|
||||
if (language != null) {
|
||||
|
||||
Reference in New Issue
Block a user