From 0df29523b1085ef1d300b3f39498277bc711ea8f Mon Sep 17 00:00:00 2001 From: Danila Ponomarenko Date: Thu, 31 May 2012 20:07:38 +0400 Subject: [PATCH] IDEA-86807 Inconsistent treatment of type parameters in widen (ctrl-w) fixed --- .../MethodOrClassSelectioner.java | 49 +++++++++++++++---- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/wordSelection/MethodOrClassSelectioner.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/wordSelection/MethodOrClassSelectioner.java index 9efaa06d5feb..bc8f8951217b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/wordSelection/MethodOrClassSelectioner.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/wordSelection/MethodOrClassSelectioner.java @@ -19,12 +19,15 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.javadoc.PsiDocComment; +import org.jetbrains.annotations.NotNull; +import java.util.Collection; +import java.util.Collections; import java.util.List; /** - * - */ + * + */ public class MethodOrClassSelectioner extends BasicSelectioner { @Override @@ -69,16 +72,44 @@ public class MethodOrClassSelectioner extends BasicSelectioner { } if (e instanceof PsiClass) { - int start = CodeBlockOrInitializerSelectioner.findOpeningBrace(children); - // in non-Java PsiClasses, there can be no opening brace - if (start != 0) { - int end = CodeBlockOrInitializerSelectioner.findClosingBrace(children, start); - - result.addAll(expandToWholeLine(editorText, new TextRange(start, end))); - } + result.addAll(selectWithTypeParameters((PsiClass)e)); + result.addAll(selectBetweenBracesLines(children, editorText)); } return result; } + + private static Collection selectWithTypeParameters(@NotNull PsiClass psiClass) { + final PsiIdentifier identifier = psiClass.getNameIdentifier(); + final PsiTypeParameterList list = psiClass.getTypeParameterList(); + if (identifier != null && list != null) { + return Collections.singletonList(new TextRange(identifier.getTextRange().getStartOffset(), list.getTextRange().getEndOffset())); + } + return Collections.emptyList(); + } + + private static Collection selectBetweenBracesLines(@NotNull PsiElement[] children, + @NotNull CharSequence editorText) { + int start = CodeBlockOrInitializerSelectioner.findOpeningBrace(children); + // in non-Java PsiClasses, there can be no opening brace + if (start != 0) { + int end = CodeBlockOrInitializerSelectioner.findClosingBrace(children, start); + + return expandToWholeLine(editorText, new TextRange(start, end)); + } + return Collections.emptyList(); + } + + private static Collection selectWithoutDocComment(@NotNull PsiElement[] children, + @NotNull CharSequence editorText) { + int start = CodeBlockOrInitializerSelectioner.findOpeningBrace(children); + // in non-Java PsiClasses, there can be no opening brace + if (start != 0) { + int end = CodeBlockOrInitializerSelectioner.findClosingBrace(children, start); + + return expandToWholeLine(editorText, new TextRange(start, end)); + } + return Collections.emptyList(); + } }