Skip to content

Commit

Permalink
Rename byteCode to bytecode in variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Dec 30, 2015
1 parent 1ccfd7e commit 03e67ae
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 33 deletions.
Expand Up @@ -90,8 +90,8 @@ public T visitMethod(ClassDefinition classDefinition, MethodDefinition methodDef

public T visitNode(BytecodeNode parent, BytecodeNode node)
{
for (BytecodeNode byteCodeNode : node.getChildNodes()) {
byteCodeNode.accept(node, this);
for (BytecodeNode child : node.getChildNodes()) {
child.accept(node, this);
}
return null;
}
Expand Down
Expand Up @@ -55,21 +55,16 @@ public static ClassInfoLoader createClassInfoLoader(Iterable<ClassDefinition> cl
return new ClassInfoLoader(classNodes.build(), ImmutableMap.<ParameterizedType, byte[]>of(), classLoader, true);
}

public static ClassInfoLoader createByteCodeInfoLoader(Map<ParameterizedType, byte[]> byteCodes, ClassLoader classLoader, boolean loadMethodNodes)
{
return new ClassInfoLoader(ImmutableMap.<ParameterizedType, ClassNode>of(), byteCodes, classLoader, loadMethodNodes);
}

private final Map<ParameterizedType, ClassNode> classNodes;
private final Map<ParameterizedType, byte[]> byteCodes;
private final Map<ParameterizedType, byte[]> bytecodes;
private final ClassLoader classLoader;
private final Map<ParameterizedType, ClassInfo> classInfoCache = new HashMap<>();
private final boolean loadMethodNodes;

public ClassInfoLoader(Map<ParameterizedType, ClassNode> classNodes, Map<ParameterizedType, byte[]> byteCodes, ClassLoader classLoader, boolean loadMethodNodes)
public ClassInfoLoader(Map<ParameterizedType, ClassNode> classNodes, Map<ParameterizedType, byte[]> bytecodes, ClassLoader classLoader, boolean loadMethodNodes)
{
this.classNodes = ImmutableMap.copyOf(classNodes);
this.byteCodes = ImmutableMap.copyOf(byteCodes);
this.bytecodes = ImmutableMap.copyOf(bytecodes);
this.classLoader = classLoader;
this.loadMethodNodes = loadMethodNodes;
}
Expand All @@ -94,9 +89,9 @@ private ClassInfo readClassInfoQuick(ParameterizedType type)

// check for user supplied byte code
ClassReader classReader;
byte[] byteCode = byteCodes.get(type);
if (byteCode != null) {
classReader = new ClassReader(byteCode);
byte[] bytecode = bytecodes.get(type);
if (bytecode != null) {
classReader = new ClassReader(bytecode);
}
else {
// load class file from class loader
Expand Down
Expand Up @@ -202,9 +202,9 @@ private void visitBlockContents(BytecodeBlock block)
}

@Override
public Void visitByteCodeExpression(BytecodeNode parent, BytecodeExpression byteCodeExpression)
public Void visitByteCodeExpression(BytecodeNode parent, BytecodeExpression expression)
{
printLine(byteCodeExpression.toString());
printLine(expression.toString());
return null;
}

Expand Down
Expand Up @@ -47,9 +47,9 @@ public DynamicClassLoader(ClassLoader parentClassLoader, Map<Long, MethodHandle>
this.callSiteBindings = ImmutableMap.copyOf(callSiteBindings);
}

public Class<?> defineClass(String className, byte[] byteCode)
public Class<?> defineClass(String className, byte[] bytecode)
{
return defineClass(className, byteCode, 0, byteCode.length);
return defineClass(className, bytecode, 0, bytecode.length);
}

public Map<String, Class<?>> defineClasses(Map<String, byte[]> newClasses)
Expand Down Expand Up @@ -86,12 +86,12 @@ public Map<Long, MethodHandle> getCallSiteBindings()
protected Class<?> findClass(String name)
throws ClassNotFoundException
{
byte[] byteCode = pendingClasses.get(name);
if (byteCode == null) {
byte[] bytecode = pendingClasses.get(name);
if (bytecode == null) {
throw new ClassNotFoundException(name);
}

return defineClass(name, byteCode);
return defineClass(name, bytecode);
}

@Override
Expand Down
Expand Up @@ -29,27 +29,27 @@

public class BytecodeGeneratorContext
{
private final BytecodeExpressionVisitor byteCodeGenerator;
private final BytecodeExpressionVisitor bytecodeGenerator;
private final Scope scope;
private final CallSiteBinder callSiteBinder;
private final CachedInstanceBinder cachedInstanceBinder;
private final FunctionRegistry registry;
private final Variable wasNull;

public BytecodeGeneratorContext(
BytecodeExpressionVisitor byteCodeGenerator,
BytecodeExpressionVisitor bytecodeGenerator,
Scope scope,
CallSiteBinder callSiteBinder,
CachedInstanceBinder cachedInstanceBinder,
FunctionRegistry registry)
{
requireNonNull(byteCodeGenerator, "byteCodeGenerator is null");
requireNonNull(bytecodeGenerator, "bytecodeGenerator is null");
requireNonNull(cachedInstanceBinder, "cachedInstanceBinder is null");
requireNonNull(scope, "scope is null");
requireNonNull(callSiteBinder, "callSiteBinder is null");
requireNonNull(registry, "registry is null");

this.byteCodeGenerator = byteCodeGenerator;
this.bytecodeGenerator = bytecodeGenerator;
this.scope = scope;
this.callSiteBinder = callSiteBinder;
this.cachedInstanceBinder = cachedInstanceBinder;
Expand All @@ -69,7 +69,7 @@ public CallSiteBinder getCallSiteBinder()

public BytecodeNode generate(RowExpression expression)
{
return expression.accept(byteCodeGenerator, scope);
return expression.accept(bytecodeGenerator, scope);
}

public FunctionRegistry getRegistry()
Expand Down
Expand Up @@ -98,7 +98,7 @@ private static Map<String, Class<?>> defineClasses(List<ClassDefinition> classDe
System.out.println(new String(out.toByteArray(), StandardCharsets.UTF_8));
}

Map<String, byte[]> byteCodes = new LinkedHashMap<>();
Map<String, byte[]> bytecodes = new LinkedHashMap<>();
for (ClassDefinition classDefinition : classDefinitions) {
ClassWriter cw = new SmartClassWriter(classInfoLoader);
try {
Expand All @@ -111,17 +111,17 @@ private static Map<String, Class<?>> defineClasses(List<ClassDefinition> classDe
classDefinition.visit(tcv);
throw new IllegalArgumentException("An error occurred while processing classDefinition:" + System.lineSeparator() + stringWriter.toString(), e);
}
byte[] byteCode = cw.toByteArray();
byte[] bytecode = cw.toByteArray();
if (RUN_ASM_VERIFIER) {
ClassReader reader = new ClassReader(byteCode);
ClassReader reader = new ClassReader(bytecode);
CheckClassAdapter.verify(reader, classLoader, true, new PrintWriter(System.out));
}
byteCodes.put(classDefinition.getType().getJavaClassName(), byteCode);
bytecodes.put(classDefinition.getType().getJavaClassName(), bytecode);
}

String dumpClassPath = DUMP_CLASS_FILES_TO.get();
if (dumpClassPath != null) {
for (Map.Entry<String, byte[]> entry : byteCodes.entrySet()) {
for (Map.Entry<String, byte[]> entry : bytecodes.entrySet()) {
File file = new File(dumpClassPath, ParameterizedType.typeFromJavaClassName(entry.getKey()).getClassName() + ".class");
try {
log.debug("ClassFile: " + file.getAbsolutePath());
Expand All @@ -134,12 +134,12 @@ private static Map<String, Class<?>> defineClasses(List<ClassDefinition> classDe
}
}
if (DUMP_BYTE_CODE_RAW) {
for (byte[] byteCode : byteCodes.values()) {
ClassReader classReader = new ClassReader(byteCode);
for (byte[] bytecode : bytecodes.values()) {
ClassReader classReader = new ClassReader(bytecode);
classReader.accept(new TraceClassVisitor(new PrintWriter(System.err)), ClassReader.EXPAND_FRAMES);
}
}
Map<String, Class<?>> classes = classLoader.defineClasses(byteCodes);
Map<String, Class<?>> classes = classLoader.defineClasses(bytecodes);
try {
for (Class<?> clazz : classes.values()) {
Reflection.initialize(clazz);
Expand Down

0 comments on commit 03e67ae

Please sign in to comment.