From 5f7efad07bbe010c85b27b86d3f81e9a298025c3 Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Wed, 22 Apr 2020 15:32:05 +0300 Subject: [PATCH] IDEA-238356 Generic classes don't work in renderers - validation GitOrigin-RevId: 2517d517f0c28463c43273345273bcdd39875cdc --- .../CompoundRendererConfigurable.java | 37 +++++++++++-------- .../messages/JavaDebuggerBundle.properties | 1 + 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/settings/CompoundRendererConfigurable.java b/java/debugger/impl/src/com/intellij/debugger/settings/CompoundRendererConfigurable.java index 7fe61c2d88d4..dafe4d54cdfc 100644 --- a/java/debugger/impl/src/com/intellij/debugger/settings/CompoundRendererConfigurable.java +++ b/java/debugger/impl/src/com/intellij/debugger/settings/CompoundRendererConfigurable.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.debugger.settings; import com.intellij.debugger.JavaDebuggerBundle; @@ -27,8 +13,13 @@ import com.intellij.debugger.ui.JavaDebuggerSupport; import com.intellij.debugger.ui.tree.render.*; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.editor.event.DocumentEvent; +import com.intellij.openapi.editor.event.DocumentListener; import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.ComponentValidator; +import com.intellij.openapi.ui.ValidationInfo; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.impl.source.PsiTypeCodeFragmentImpl; import com.intellij.ui.*; @@ -129,12 +120,26 @@ class CompoundRendererConfigurable extends JPanel { } } }, myProject); - myClassNameField.getEditorTextField().addFocusListener(new FocusAdapter() { + EditorTextField editorTextField = myClassNameField.getEditorTextField(); + editorTextField.addFocusListener(new FocusAdapter() { @Override public void focusLost(@NotNull FocusEvent e) { updateContext(myClassNameField.getText()); } }); + ComponentValidator validator = new ComponentValidator(myProject).withValidator(() -> { + String text = myClassNameField.getText(); + if (StringUtil.containsAnyChar(text, "<>")) { + return new ValidationInfo(JavaDebuggerBundle.message("error.compound.renderer.configurable.fqn.generic"), editorTextField); + } + return null; + }).installOn(editorTextField); + myClassNameField.addDocumentListener(new DocumentListener() { + @Override + public void documentChanged(@NotNull DocumentEvent event) { + validator.revalidate(); + } + }); myAppendDefaultChildren = new JBCheckBox(JavaDebuggerBundle.message("label.compound.renderer.configurable.append.default.children")); diff --git a/java/debugger/openapi/resources/messages/JavaDebuggerBundle.properties b/java/debugger/openapi/resources/messages/JavaDebuggerBundle.properties index d9a1efd0e7d4..f0faf5cecf6f 100644 --- a/java/debugger/openapi/resources/messages/JavaDebuggerBundle.properties +++ b/java/debugger/openapi/resources/messages/JavaDebuggerBundle.properties @@ -220,6 +220,7 @@ label.compound.renderer.configurable.use.default.renderer=Use default renderer label.compound.renderer.configurable.use.expression=Use following expression: label.compound.renderer.configurable.use.expression.list=Use list of expressions: label.compound.renderer.configurable.apply.to=Apply renderer to objects of type (fully-qualified name): +error.compound.renderer.configurable.fqn.generic=Generic type is not allowed label.compound.renderer.configurable.when.rendering=When rendering a node label.compound.renderer.configurable.when.expanding=When expanding a node label.compound.renderer.configurable.test.can.expand=Test if a node can be expanded (optional):