mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
IDEA-CR-57122 use correct class loader to load resource bundles - pass class instead of using reflection
GitOrigin-RevId: d27ee5e7bd7f020ef37556b3e47842b8e98acd12
This commit is contained in:
committed by
intellij-monorepo-bot
parent
eb2f54ab9a
commit
a2562bab13
@@ -22,14 +22,18 @@ import java.util.Set;
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class StringPropertyCodeGenerator extends PropertyCodeGenerator implements Opcodes {
|
||||
public final class StringPropertyCodeGenerator extends PropertyCodeGenerator implements Opcodes {
|
||||
private static final Type myResourceBundleType = Type.getType(ResourceBundle.class);
|
||||
private final Method myGetBundleMethod = Method.getMethod("java.util.ResourceBundle getBundle(java.lang.String)");
|
||||
private final Method myGetStringMethod = Method.getMethod("java.lang.String getString(java.lang.String)");
|
||||
private static final Type stringType = Type.getType(String.class);
|
||||
|
||||
private static final Method myGetBundleMethod = new Method("getBundle", myResourceBundleType,
|
||||
new Type[]{stringType, Type.getType(Class.class)});
|
||||
private static final Method myGetStringMethod = new Method("getString", stringType, new Type[]{stringType});
|
||||
|
||||
private static final Method myLoadLabelTextMethod = new Method(AsmCodeGenerator.LOAD_LABEL_TEXT_METHOD, Type.VOID_TYPE,
|
||||
new Type[] { Type.getType(JLabel.class), Type.getType(String.class) } );
|
||||
new Type[]{Type.getType(JLabel.class), stringType});
|
||||
private static final Method myLoadButtonTextMethod = new Method(AsmCodeGenerator.LOAD_BUTTON_TEXT_METHOD, Type.VOID_TYPE,
|
||||
new Type[] { Type.getType(AbstractButton.class), Type.getType(String.class) } );
|
||||
new Type[]{Type.getType(AbstractButton.class), stringType});
|
||||
|
||||
private final Set<String> myClassesRequiringLoadLabelText = new HashSet<String>();
|
||||
private final Set<String> myClassesRequiringLoadButtonText = new HashSet<String>();
|
||||
@@ -77,8 +81,7 @@ public class StringPropertyCodeGenerator extends PropertyCodeGenerator implement
|
||||
generator.loadLocal(componentLocal);
|
||||
generator.push(textWithMnemonic.myText);
|
||||
generator.invokeVirtual(Type.getType(componentClass.getDescriptor()),
|
||||
new Method(property.getWriteMethodName(),
|
||||
Type.VOID_TYPE, new Type[] { Type.getType(String.class) } ));
|
||||
new Method(property.getWriteMethodName(), Type.VOID_TYPE, new Type[]{stringType}));
|
||||
|
||||
String setMnemonicMethodName;
|
||||
if (abstractButtonClass.isAssignableFrom(componentClass)) {
|
||||
@@ -118,13 +121,16 @@ public class StringPropertyCodeGenerator extends PropertyCodeGenerator implement
|
||||
generator.loadThis();
|
||||
generator.loadLocal(componentLocal);
|
||||
|
||||
Type formClass = Type.getType("L" + formClassName + ";");
|
||||
|
||||
generator.push(propertyValue.getBundleName());
|
||||
generator.push(formClass);
|
||||
generator.invokeStatic(myDynamicBundleType, myGetBundleMethod);
|
||||
|
||||
generator.push(propertyValue.getKey());
|
||||
generator.invokeVirtual(myResourceBundleType, myGetStringMethod);
|
||||
|
||||
generator.invokeVirtual(Type.getType("L" + formClassName + ";"), method);
|
||||
generator.invokeVirtual(formClass, method);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -83,10 +83,18 @@ public abstract class DynamicBundle extends AbstractBundle {
|
||||
* @deprecated used only dy GUI form builder
|
||||
*/
|
||||
@Deprecated
|
||||
public static ResourceBundle getBundle(String baseName) {
|
||||
public static ResourceBundle getBundle(@NotNull String baseName) {
|
||||
Class<?> callerClass = ReflectionUtil.findCallerClass(2);
|
||||
return getBundle(baseName, callerClass == null ? DynamicBundle.class : callerClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated used only dy GUI form builder
|
||||
*/
|
||||
@Deprecated
|
||||
public static ResourceBundle getBundle(@NotNull String baseName, @NotNull Class<?> formClass) {
|
||||
DynamicBundle dynamic = ourBundlesForForms.computeIfAbsent(baseName, s -> new DynamicBundle(s) {});
|
||||
ResourceBundle rb = dynamic.getResourceBundle(callerClass == null ? null : callerClass.getClassLoader());
|
||||
ResourceBundle rb = dynamic.getResourceBundle(formClass.getClassLoader());
|
||||
|
||||
if (BundleBase.SHOW_LOCALIZED_MESSAGES) {
|
||||
return new ResourceBundle() {
|
||||
|
||||
Reference in New Issue
Block a user