diff --git a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java index 1f9d266de19c..a38359dfe9d3 100644 --- a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java +++ b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java @@ -32,6 +32,8 @@ import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.DefaultProjectFactory; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.util.AtomicNotNullLazyValue; +import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; @@ -75,27 +77,24 @@ public class IdeaDecompiler extends ClassFileDecompilers.Light { private static final String LEGAL_NOTICE_KEY = "decompiler.legal.notice.accepted"; - private final IFernflowerLogger myLogger = new IdeaLogger(); - private final Map myOptions; + private final NotNullLazyValue myLogger = new AtomicNotNullLazyValue() { + @NotNull + @Override + protected IFernflowerLogger compute() { + return new IdeaLogger(); + } + }; + private final NotNullLazyValue> myOptions = new AtomicNotNullLazyValue>() { + @NotNull + @Override + protected Map compute() { + return getOptions(); + } + }; private final Map myProgress = ContainerUtil.newConcurrentMap(); private boolean myLegalNoticeAccepted; public IdeaDecompiler() { - Map options = ContainerUtil.newHashMap(); - options.put(IFernflowerPreferences.HIDE_DEFAULT_CONSTRUCTOR, "0"); - options.put(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES, "1"); - options.put(IFernflowerPreferences.REMOVE_SYNTHETIC, "1"); - options.put(IFernflowerPreferences.REMOVE_BRIDGE, "1"); - options.put(IFernflowerPreferences.LITERALS_AS_IS, "1"); - options.put(IFernflowerPreferences.NEW_LINE_SEPARATOR, "1"); - options.put(IFernflowerPreferences.BANNER, BANNER); - options.put(IFernflowerPreferences.MAX_PROCESSING_METHOD, 60); - - Project project = DefaultProjectFactory.getInstance().getDefaultProject(); - CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(project).getCurrentSettings(); - CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptions(JavaFileType.INSTANCE); - options.put(IFernflowerPreferences.INDENT_STRING, StringUtil.repeat(" ", indentOptions.INDENT_SIZE)); - Application app = ApplicationManager.getApplication(); myLegalNoticeAccepted = app.isUnitTestMode() || PropertiesComponent.getInstance().isValueSet(LEGAL_NOTICE_KEY); if (!myLegalNoticeAccepted) { @@ -115,12 +114,30 @@ public class IdeaDecompiler extends ClassFileDecompilers.Light { } }); } + } - if (app.isUnitTestMode()) { + private static Map getOptions() { + Map options = ContainerUtil.newHashMap(); + + options.put(IFernflowerPreferences.HIDE_DEFAULT_CONSTRUCTOR, "0"); + options.put(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES, "1"); + options.put(IFernflowerPreferences.REMOVE_SYNTHETIC, "1"); + options.put(IFernflowerPreferences.REMOVE_BRIDGE, "1"); + options.put(IFernflowerPreferences.LITERALS_AS_IS, "1"); + options.put(IFernflowerPreferences.NEW_LINE_SEPARATOR, "1"); + options.put(IFernflowerPreferences.BANNER, BANNER); + options.put(IFernflowerPreferences.MAX_PROCESSING_METHOD, 60); + + Project project = DefaultProjectFactory.getInstance().getDefaultProject(); + CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(project).getCurrentSettings(); + CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptions(JavaFileType.INSTANCE); + options.put(IFernflowerPreferences.INDENT_STRING, StringUtil.repeat(" ", indentOptions.INDENT_SIZE)); + + if (ApplicationManager.getApplication().isUnitTestMode()) { options.put(IFernflowerPreferences.UNIT_TEST_MODE, "1"); } - myOptions = Collections.unmodifiableMap(options); + return Collections.unmodifiableMap(options); } private void showLegalNotice(final Project project, final VirtualFile file) { @@ -164,7 +181,7 @@ public class IdeaDecompiler extends ClassFileDecompilers.Light { MyBytecodeProvider provider = new MyBytecodeProvider(files); MyResultSaver saver = new MyResultSaver(); - Map options = ContainerUtil.newHashMap(myOptions); + Map options = ContainerUtil.newHashMap(myOptions.getValue()); if (Registry.is("decompiler.use.line.mapping")) { options.put(IFernflowerPreferences.BYTECODE_SOURCE_MAPPING, "1"); options.put(IFernflowerPreferences.USE_DEBUG_LINE_NUMBERS, "0"); @@ -181,7 +198,7 @@ public class IdeaDecompiler extends ClassFileDecompilers.Light { options.put(IFernflowerPreferences.DUMP_ORIGINAL_LINES, "1"); } - BaseDecompiler decompiler = new BaseDecompiler(provider, saver, options, myLogger); + BaseDecompiler decompiler = new BaseDecompiler(provider, saver, options, myLogger.getValue()); for (String path : files.keySet()) { decompiler.addSpace(new File(path), true); } diff --git a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompilerBundle.java b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompilerBundle.java index 7bb0ed4cc028..6530ff8db6cd 100644 --- a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompilerBundle.java +++ b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompilerBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -16,17 +16,19 @@ package org.jetbrains.java.decompiler; import com.intellij.AbstractBundle; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.PropertyKey; public class IdeaDecompilerBundle extends AbstractBundle { - public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) { - return INSTANCE.getMessage(key, params); + private static final String BUNDLE = "messages.Decompiler"; + + private static class Holder { + private static final AbstractBundle INSTANCE = new IdeaDecompilerBundle(); } - public static final AbstractBundle INSTANCE = new IdeaDecompilerBundle(); - @NonNls private static final String BUNDLE = "messages.Decompiler"; + public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) { + return Holder.INSTANCE.getMessage(key, params); + } private IdeaDecompilerBundle() { super(BUNDLE);