Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Commit

Permalink
Port: Display of Kotlin enums messages jmix-framework/jmix#204
Browse files Browse the repository at this point in the history
  • Loading branch information
artemglinov committed Jul 5, 2021
1 parent 4fc3ba3 commit 5790ecb
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import org.springframework.stereotype.Component;

import javax.annotation.Nullable;

import org.springframework.beans.factory.annotation.Autowired;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
Expand All @@ -55,8 +57,6 @@ public class CubaMessages {

private static final Logger log = LoggerFactory.getLogger(CubaMessages.class);

protected Pattern enumSubclassPattern = Pattern.compile("\\$[1-9]");

protected String confDir;

protected Map<String, String> strCache = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -101,19 +101,15 @@ public String getMessage(Enum caller) {
public String getMessage(Enum caller, Locale locale) {
checkNotNullArgument(caller, "Enum parameter 'caller' is null");

String className = caller.getClass().getName();
int i = className.lastIndexOf('.');
String declaringClassName = caller.getDeclaringClass().getName();
int i = declaringClassName.lastIndexOf('.');
if (i > -1)
className = className.substring(i + 1);
declaringClassName = declaringClassName.substring(i + 1);
// If enum has inner subclasses, its class name ends with "$1", "$2", ... suffixes. Cut them off.
Matcher matcher = enumSubclassPattern.matcher(className);
if (matcher.find()) {
className = className.substring(0, matcher.start());
}

return getMessage(
getPackName(caller.getClass()),
className + "." + caller.name(),
declaringClassName + "." + caller.name(),
locale
);
}
Expand Down

0 comments on commit 5790ecb

Please sign in to comment.