From 67d7150d7ee4273e13c4f951b1de9f437bbd4ef0 Mon Sep 17 00:00:00 2001 From: Alexander Zolotov Date: Tue, 26 Apr 2016 21:35:11 +0300 Subject: [PATCH] Naming convention macros should produce empty result on empty string 2 --- .../template/NamingConventionMacrosTest.groovy | 2 +- .../template/macro/ConvertToCamelCaseMacro.java | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/NamingConventionMacrosTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/template/NamingConventionMacrosTest.groovy index a10508864ef7..26180d39fe16 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/NamingConventionMacrosTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/NamingConventionMacrosTest.groovy @@ -41,7 +41,7 @@ class NamingConventionMacrosTest extends TestCase { assert "a_b_c_d_e_f_g" == snakeCase("a-b.c/d|e*f+g") assert "a_b" == snakeCase("a--b") assert "foo_bar" == snakeCase("FOO BAR") - assert "" == snakeCase("0") + assert "" == snakeCase("") } public void "test lowercase and dash"() { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/macro/ConvertToCamelCaseMacro.java b/platform/lang-impl/src/com/intellij/codeInsight/template/macro/ConvertToCamelCaseMacro.java index 3f49b9177c2e..c6b507765294 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/macro/ConvertToCamelCaseMacro.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/macro/ConvertToCamelCaseMacro.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -43,16 +43,13 @@ public class ConvertToCamelCaseMacro extends MacroBase { @Override protected Result calculateResult(@NotNull Expression[] params, ExpressionContext context, boolean quick) { final String text = getTextResult(params, context, true); - if (text != null) { - return convertString(text); - } - return null; + return text != null ? convertString(text) : null; } @SuppressWarnings("StringToUpperCaseOrToLowerCaseWithoutLocale") - @Nullable + @NotNull @VisibleForTesting - public Result convertString(String text) { + public Result convertString(@NotNull String text) { final String[] strings = splitWords(text); if (strings.length > 0) { final StringBuilder buf = new StringBuilder(); @@ -65,7 +62,7 @@ public class ConvertToCamelCaseMacro extends MacroBase { } return new TextResult(buf.toString()); } - return null; + return new TextResult(""); } @NotNull