|
|
|
@ -4,142 +4,142 @@ package org.jetbrains.java.decompiler.main; |
|
|
|
|
import org.jetbrains.java.decompiler.main.collectors.BytecodeSourceMapper; |
|
|
|
|
import org.jetbrains.java.decompiler.main.collectors.CounterContainer; |
|
|
|
|
import org.jetbrains.java.decompiler.main.collectors.ImportCollector; |
|
|
|
|
import org.jetbrains.java.decompiler.main.collectors.VarNamesCollector; |
|
|
|
|
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger; |
|
|
|
|
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences; |
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
public class DecompilerContext { |
|
|
|
|
public static final String CURRENT_CLASS = "CURRENT_CLASS"; |
|
|
|
|
public static final String CURRENT_CLASS_WRAPPER = "CURRENT_CLASS_WRAPPER"; |
|
|
|
|
public static final String CURRENT_CLASS_NODE = "CURRENT_CLASS_NODE"; |
|
|
|
|
public static final String CURRENT_METHOD_WRAPPER = "CURRENT_METHOD_WRAPPER"; |
|
|
|
|
public static final String CURRENT_VAR_PROCESSOR = "CURRENT_VAR_PROCESSOR"; |
|
|
|
|
|
|
|
|
|
private static final ThreadLocal<DecompilerContext> currentContext = new ThreadLocal<>(); |
|
|
|
|
private static volatile DecompilerContext currentContext = null; |
|
|
|
|
|
|
|
|
|
private final Map<String, Object> properties; |
|
|
|
|
private StructContext structContext; |
|
|
|
|
private final IFernflowerLogger logger; |
|
|
|
|
private final StructContext structContext; |
|
|
|
|
private final ClassesProcessor classProcessor; |
|
|
|
|
private final PoolInterceptor poolInterceptor; |
|
|
|
|
private ImportCollector importCollector; |
|
|
|
|
private VarNamesCollector varNamescollector; |
|
|
|
|
private VarProcessor varProcessor; |
|
|
|
|
private CounterContainer counterContainer; |
|
|
|
|
private ClassesProcessor classProcessor; |
|
|
|
|
private PoolInterceptor poolInterceptor; |
|
|
|
|
private IFernflowerLogger logger; |
|
|
|
|
private BytecodeSourceMapper bytecodeSourceMapper; |
|
|
|
|
|
|
|
|
|
private DecompilerContext(Map<String, Object> properties) { |
|
|
|
|
private DecompilerContext(Map<String, Object> properties, |
|
|
|
|
IFernflowerLogger logger, |
|
|
|
|
StructContext structContext, |
|
|
|
|
ClassesProcessor classProcessor, |
|
|
|
|
PoolInterceptor interceptor) { |
|
|
|
|
this.properties = properties; |
|
|
|
|
} |
|
|
|
|
this.logger = logger; |
|
|
|
|
this.structContext = structContext; |
|
|
|
|
this.classProcessor = classProcessor; |
|
|
|
|
this.poolInterceptor = interceptor; |
|
|
|
|
this.counterContainer = new CounterContainer(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
|
// 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); |
|
|
|
|
|
|
|
|
|
public static void initContext(Map<String, Object> propertiesCustom) { |
|
|
|
|
Map<String, Object> properties = new HashMap<>(IFernflowerPreferences.DEFAULTS); |
|
|
|
|
if (propertiesCustom != null) { |
|
|
|
|
properties.putAll(propertiesCustom); |
|
|
|
|
if (customProperties != null) { |
|
|
|
|
properties.putAll(customProperties); |
|
|
|
|
} |
|
|
|
|
currentContext.set(new DecompilerContext(properties)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static DecompilerContext getCurrentContext() { |
|
|
|
|
return currentContext.get(); |
|
|
|
|
} |
|
|
|
|
String level = (String)properties.get(IFernflowerPreferences.LOG_LEVEL); |
|
|
|
|
if (level != null) { |
|
|
|
|
try { |
|
|
|
|
logger.setSeverity(IFernflowerLogger.Severity.valueOf(level.toUpperCase(Locale.US))); |
|
|
|
|
} |
|
|
|
|
catch (IllegalArgumentException ignore) { } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void setCurrentContext(DecompilerContext context) { |
|
|
|
|
currentContext.set(context); |
|
|
|
|
currentContext = new DecompilerContext(properties, logger, structContext, classProcessor, interceptor); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static Object getProperty(String key) { |
|
|
|
|
return getCurrentContext().properties.get(key); |
|
|
|
|
public static void clearContext() { |
|
|
|
|
currentContext = null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void setProperty(String key, Object value) { |
|
|
|
|
getCurrentContext().properties.put(key, value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static boolean getOption(String key) { |
|
|
|
|
return "1".equals(getCurrentContext().properties.get(key)); |
|
|
|
|
currentContext.properties.put(key, value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static ImportCollector getImportCollector() { |
|
|
|
|
return getCurrentContext().importCollector; |
|
|
|
|
public static void startClass(ImportCollector importCollector) { |
|
|
|
|
currentContext.importCollector = importCollector; |
|
|
|
|
currentContext.counterContainer = new CounterContainer(); |
|
|
|
|
currentContext.bytecodeSourceMapper = new BytecodeSourceMapper(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void setImportCollector(ImportCollector importCollector) { |
|
|
|
|
getCurrentContext().importCollector = importCollector; |
|
|
|
|
public static void startMethod(VarProcessor varProcessor) { |
|
|
|
|
currentContext.varProcessor = varProcessor; |
|
|
|
|
currentContext.counterContainer = new CounterContainer(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static VarNamesCollector getVarNamesCollector() { |
|
|
|
|
return getCurrentContext().varNamescollector; |
|
|
|
|
} |
|
|
|
|
// *****************************************************************************
|
|
|
|
|
// context access
|
|
|
|
|
// *****************************************************************************
|
|
|
|
|
|
|
|
|
|
public static void setVarNamesCollector(VarNamesCollector varNamesCollector) { |
|
|
|
|
getCurrentContext().varNamescollector = varNamesCollector; |
|
|
|
|
public static Object getProperty(String key) { |
|
|
|
|
return currentContext.properties.get(key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static StructContext getStructContext() { |
|
|
|
|
return getCurrentContext().structContext; |
|
|
|
|
public static boolean getOption(String key) { |
|
|
|
|
return "1".equals(getProperty(key)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void setStructContext(StructContext structContext) { |
|
|
|
|
getCurrentContext().structContext = structContext; |
|
|
|
|
public static String getNewLineSeparator() { |
|
|
|
|
return getOption(IFernflowerPreferences.NEW_LINE_SEPARATOR) ? |
|
|
|
|
IFernflowerPreferences.LINE_SEPARATOR_UNX : IFernflowerPreferences.LINE_SEPARATOR_WIN; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static CounterContainer getCounterContainer() { |
|
|
|
|
return getCurrentContext().counterContainer; |
|
|
|
|
public static IFernflowerLogger getLogger() { |
|
|
|
|
return currentContext.logger; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void setCounterContainer(CounterContainer counterContainer) { |
|
|
|
|
getCurrentContext().counterContainer = counterContainer; |
|
|
|
|
public static StructContext getStructContext() { |
|
|
|
|
return currentContext.structContext; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static ClassesProcessor getClassProcessor() { |
|
|
|
|
return getCurrentContext().classProcessor; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void setClassProcessor(ClassesProcessor classProcessor) { |
|
|
|
|
getCurrentContext().classProcessor = classProcessor; |
|
|
|
|
return currentContext.classProcessor; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static PoolInterceptor getPoolInterceptor() { |
|
|
|
|
return getCurrentContext().poolInterceptor; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void setPoolInterceptor(PoolInterceptor poolinterceptor) { |
|
|
|
|
getCurrentContext().poolInterceptor = poolinterceptor; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static BytecodeSourceMapper getBytecodeSourceMapper() { |
|
|
|
|
return getCurrentContext().bytecodeSourceMapper; |
|
|
|
|
return currentContext.poolInterceptor; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void setBytecodeSourceMapper(BytecodeSourceMapper bytecodeSourceMapper) { |
|
|
|
|
getCurrentContext().bytecodeSourceMapper = bytecodeSourceMapper; |
|
|
|
|
public static ImportCollector getImportCollector() { |
|
|
|
|
return currentContext.importCollector; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static IFernflowerLogger getLogger() { |
|
|
|
|
return getCurrentContext().logger; |
|
|
|
|
public static VarProcessor getVarProcessor() { |
|
|
|
|
return currentContext.varProcessor; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void setLogger(IFernflowerLogger logger) { |
|
|
|
|
if (logger != null) { |
|
|
|
|
String level = (String)getProperty(IFernflowerPreferences.LOG_LEVEL); |
|
|
|
|
if (level != null) { |
|
|
|
|
try { |
|
|
|
|
logger.setSeverity(IFernflowerLogger.Severity.valueOf(level.toUpperCase(Locale.US))); |
|
|
|
|
} |
|
|
|
|
catch (IllegalArgumentException ignore) { } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
getCurrentContext().logger = logger; |
|
|
|
|
public static CounterContainer getCounterContainer() { |
|
|
|
|
return currentContext.counterContainer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static String getNewLineSeparator() { |
|
|
|
|
return getOption(IFernflowerPreferences.NEW_LINE_SEPARATOR) ? |
|
|
|
|
IFernflowerPreferences.LINE_SEPARATOR_UNX : IFernflowerPreferences.LINE_SEPARATOR_WIN; |
|
|
|
|
public static BytecodeSourceMapper getBytecodeSourceMapper() { |
|
|
|
|
return currentContext.bytecodeSourceMapper; |
|
|
|
|
} |
|
|
|
|
} |