|
|
|
@ -1,4 +1,4 @@ |
|
|
|
|
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
|
|
|
|
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
|
|
|
|
package org.jetbrains.java.decompiler.main; |
|
|
|
|
|
|
|
|
|
import org.jetbrains.java.decompiler.main.collectors.BytecodeSourceMapper; |
|
|
|
@ -10,8 +10,6 @@ import org.jetbrains.java.decompiler.modules.decompiler.vars.VarProcessor; |
|
|
|
|
import org.jetbrains.java.decompiler.modules.renamer.PoolInterceptor; |
|
|
|
|
import org.jetbrains.java.decompiler.struct.StructContext; |
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Locale; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
@ -21,8 +19,6 @@ public class DecompilerContext { |
|
|
|
|
public static final String CURRENT_CLASS_NODE = "CURRENT_CLASS_NODE"; |
|
|
|
|
public static final String CURRENT_METHOD_WRAPPER = "CURRENT_METHOD_WRAPPER"; |
|
|
|
|
|
|
|
|
|
private static volatile DecompilerContext currentContext = null; |
|
|
|
|
|
|
|
|
|
private final Map<String, Object> properties; |
|
|
|
|
private final IFernflowerLogger logger; |
|
|
|
|
private final StructContext structContext; |
|
|
|
@ -33,11 +29,16 @@ public class DecompilerContext { |
|
|
|
|
private CounterContainer counterContainer; |
|
|
|
|
private BytecodeSourceMapper bytecodeSourceMapper; |
|
|
|
|
|
|
|
|
|
private DecompilerContext(Map<String, Object> properties, |
|
|
|
|
IFernflowerLogger logger, |
|
|
|
|
StructContext structContext, |
|
|
|
|
ClassesProcessor classProcessor, |
|
|
|
|
PoolInterceptor interceptor) { |
|
|
|
|
public DecompilerContext(Map<String, Object> properties, |
|
|
|
|
IFernflowerLogger logger, |
|
|
|
|
StructContext structContext, |
|
|
|
|
ClassesProcessor classProcessor, |
|
|
|
|
PoolInterceptor interceptor) { |
|
|
|
|
Objects.requireNonNull(properties); |
|
|
|
|
Objects.requireNonNull(logger); |
|
|
|
|
Objects.requireNonNull(structContext); |
|
|
|
|
Objects.requireNonNull(classProcessor); |
|
|
|
|
|
|
|
|
|
this.properties = properties; |
|
|
|
|
this.logger = logger; |
|
|
|
|
this.structContext = structContext; |
|
|
|
@ -50,48 +51,31 @@ public class DecompilerContext { |
|
|
|
|
// context setup and update
|
|
|
|
|
// *****************************************************************************
|
|
|
|
|
|
|
|
|
|
public static void initContext(Map<String, Object> customProperties, |
|
|
|
|
IFernflowerLogger logger, |
|
|
|
|
StructContext structContext, |
|
|
|
|
ClassesProcessor classProcessor, |
|
|
|
|
PoolInterceptor interceptor) { |
|
|
|
|
Objects.requireNonNull(logger); |
|
|
|
|
Objects.requireNonNull(structContext); |
|
|
|
|
Objects.requireNonNull(classProcessor); |
|
|
|
|
|
|
|
|
|
Map<String, Object> properties = new HashMap<>(IFernflowerPreferences.DEFAULTS); |
|
|
|
|
if (customProperties != null) { |
|
|
|
|
properties.putAll(customProperties); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String level = (String)properties.get(IFernflowerPreferences.LOG_LEVEL); |
|
|
|
|
if (level != null) { |
|
|
|
|
try { |
|
|
|
|
logger.setSeverity(IFernflowerLogger.Severity.valueOf(level.toUpperCase(Locale.US))); |
|
|
|
|
} |
|
|
|
|
catch (IllegalArgumentException ignore) { } |
|
|
|
|
} |
|
|
|
|
private static final ThreadLocal<DecompilerContext> currentContext = new ThreadLocal<>(); |
|
|
|
|
|
|
|
|
|
currentContext = new DecompilerContext(properties, logger, structContext, classProcessor, interceptor); |
|
|
|
|
public static DecompilerContext getCurrentContext() { |
|
|
|
|
return currentContext.get(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void clearContext() { |
|
|
|
|
currentContext = null; |
|
|
|
|
public static void setCurrentContext(DecompilerContext context) { |
|
|
|
|
currentContext.set(context); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void setProperty(String key, Object value) { |
|
|
|
|
currentContext.properties.put(key, value); |
|
|
|
|
getCurrentContext().properties.put(key, value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void startClass(ImportCollector importCollector) { |
|
|
|
|
currentContext.importCollector = importCollector; |
|
|
|
|
currentContext.counterContainer = new CounterContainer(); |
|
|
|
|
currentContext.bytecodeSourceMapper = new BytecodeSourceMapper(); |
|
|
|
|
DecompilerContext context = getCurrentContext(); |
|
|
|
|
context.importCollector = importCollector; |
|
|
|
|
context.counterContainer = new CounterContainer(); |
|
|
|
|
context.bytecodeSourceMapper = new BytecodeSourceMapper(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void startMethod(VarProcessor varProcessor) { |
|
|
|
|
currentContext.varProcessor = varProcessor; |
|
|
|
|
currentContext.counterContainer = new CounterContainer(); |
|
|
|
|
DecompilerContext context = getCurrentContext(); |
|
|
|
|
context.varProcessor = varProcessor; |
|
|
|
|
context.counterContainer = new CounterContainer(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
@ -99,7 +83,7 @@ public class DecompilerContext { |
|
|
|
|
// *****************************************************************************
|
|
|
|
|
|
|
|
|
|
public static Object getProperty(String key) { |
|
|
|
|
return currentContext.properties.get(key); |
|
|
|
|
return getCurrentContext().properties.get(key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static boolean getOption(String key) { |
|
|
|
@ -112,34 +96,34 @@ public class DecompilerContext { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static IFernflowerLogger getLogger() { |
|
|
|
|
return currentContext.logger; |
|
|
|
|
return getCurrentContext().logger; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static StructContext getStructContext() { |
|
|
|
|
return currentContext.structContext; |
|
|
|
|
return getCurrentContext().structContext; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static ClassesProcessor getClassProcessor() { |
|
|
|
|
return currentContext.classProcessor; |
|
|
|
|
return getCurrentContext().classProcessor; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static PoolInterceptor getPoolInterceptor() { |
|
|
|
|
return currentContext.poolInterceptor; |
|
|
|
|
return getCurrentContext().poolInterceptor; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static ImportCollector getImportCollector() { |
|
|
|
|
return currentContext.importCollector; |
|
|
|
|
return getCurrentContext().importCollector; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static VarProcessor getVarProcessor() { |
|
|
|
|
return currentContext.varProcessor; |
|
|
|
|
return getCurrentContext().varProcessor; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static CounterContainer getCounterContainer() { |
|
|
|
|
return currentContext.counterContainer; |
|
|
|
|
return getCurrentContext().counterContainer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static BytecodeSourceMapper getBytecodeSourceMapper() { |
|
|
|
|
return currentContext.bytecodeSourceMapper; |
|
|
|
|
return getCurrentContext().bytecodeSourceMapper; |
|
|
|
|
} |
|
|
|
|
} |