private MethodReference createMethodReference(String className, MethodDescriptor method) { return referenceCache.getCached(className, method); } }
public ValueType parseValueTypeCached(String value) { ValueType result = valueTypeParseCache.get(value); if (result == null) { result = getCached(ValueType.parse(value)); valueTypeParseCache.put(value, result); } return result; } }
public MethodReference getExactMethod(int index) { long item = exactMethods[index]; int classIndex = (int) (item >>> 32); int methodIndex = (int) item; return referenceCache.getCached(classNames[classIndex], referenceCache.parseDescriptorCached( methods[methodIndex])); }
public void updateReference(ReferenceCache cache) { MethodReference reference = getReference(); if (reference != null) { this.reference = cache.getCached(reference); } }
private String renameClass(String name) { for (Transformation transformation : transformations) { if (name.startsWith(transformation.fullPrefix)) { int index = name.lastIndexOf('.'); String className = name.substring(index + 1); String packageName = name.substring(0, index); if (className.startsWith(transformation.classPrefix)) { String newName = packageName.substring(transformation.packagePrefix.length()) + "." + className.substring(transformation.classPrefix.length()); return referenceCache.getCached(newName); } } } return name; }
private ValueType[] parseSignature(String desc) { ValueType[] signature = MethodDescriptor.parseSignature(desc); for (int i = 0; i < signature.length; ++i) { signature[i] = referenceCache.getCached(signature[i]); } return signature; }
public MethodDescriptor parseDescriptorCached(String value) { MethodDescriptor result = descriptorParseCache.get(value); if (result == null) { result = getCached(MethodDescriptor.parse(value)); descriptorParseCache.put(value, result); } return result; }
public void updateReference(ReferenceCache cache) { FieldReference reference = getReference(); if (reference != null) { this.reference = cache.getCached(reference); } } }
public MethodReference[] getOverridingMethods(int index) { if (index < 0 || index > offsets.length - 1) { return new MethodReference[0]; } int start = offsets[index]; int end = offsets[index + 1]; MethodReference[] references = new MethodReference[end - start]; for (int i = 0; i < references.length; ++i) { long item = exactMethods[data[start + i]]; int classIndex = (int) (item >>> 32); int methodIndex = (int) item; references[i] = referenceCache.getCached(classNames[classIndex], referenceCache.parseDescriptorCached(methods[methodIndex])); } return references; } }
private ValueType parseType(String type) { if (type.startsWith("[")) { return referenceCache.parseValueTypeCached(type); } else { return referenceCache.getCached(ValueType.object(type.replace('/', '.'))); } }
public MethodReference getCached(MethodReference reference) { return getCached(reference.getClassName(), reference.getDescriptor()); }
public FieldReference getCached(FieldReference reference) { FieldReference result = fieldRefenceCache.get(reference); if (result == null) { result = reference; String classNameCached = getCached(reference.getClassName()); String fieldNameCached = getCached(reference.getFieldName()); if (classNameCached != reference.getClassName() || fieldNameCached != reference.getFieldName()) { result = new FieldReference(classNameCached, fieldNameCached); } fieldRefenceCache.put(result, result); } return result; }
private ValueType rename(ValueType type) { if (type instanceof ValueType.Array) { ValueType itemType = ((ValueType.Array) type).getItemType(); return referenceCache.getCached(ValueType.arrayOf(rename(itemType))); } else if (type instanceof ValueType.Object) { String className = ((ValueType.Object) type).getClassName(); return referenceCache.getCached(ValueType.object(classNameMapper.map(className))); } else { return type; } }
public MethodReference getMethodAt(GeneratedLocation generatedLocation) { String className = componentByKey(classMapping, classNames, generatedLocation); if (className == null) { return null; } String method = componentByKey(methodMapping, methods, generatedLocation); if (method == null) { return null; } return referenceCache.getCached(className, referenceCache.parseDescriptorCached(method)); }
public FieldHolder parseField(FieldNode node) { FieldHolder field = new FieldHolder(referenceCache.getCached(node.name)); field.setType(referenceCache.getCached(ValueType.parse(node.desc))); field.setInitialValue(node.value); parseModifiers(node.access, field, DECL_FIELD); parseAnnotations(field.getAnnotations(), node.visibleAnnotations, node.invisibleAnnotations); return field; }
private ValueEmitter appendArgument(ValueEmitter sb, ValueType type, ValueEmitter argument) { if (!(type instanceof ValueType.Primitive)) { type = ValueType.object("java.lang.Object"); } MethodReference method = referenceCache.getCached(new MethodReference(STRING_BUILDER, "append", type, ValueType.object(STRING_BUILDER))); return sb.invokeSpecial(method, argument); }
private Variable unwrap(Variable var, String methodName, ValueType argType, ValueType resultType, TextLocation location) { if (!argType.isObject(JSObject.class.getName())) { Variable castValue = program.createVariable(); CastInstruction castInsn = new CastInstruction(); castInsn.setValue(var); castInsn.setReceiver(castValue); castInsn.setLocation(location); castInsn.setTargetType(argType); replacement.add(castInsn); var = castValue; } Variable result = program.createVariable(); InvokeInstruction insn = new InvokeInstruction(); insn.setMethod(referenceCache.getCached(referenceCache.getCached(new MethodReference( JS.class.getName(), methodName, argType, resultType)))); insn.setArguments(var); insn.setReceiver(result); insn.setType(InvocationType.SPECIAL); insn.setLocation(location); replacement.add(insn); return result; }
@Override public void visit(GetFieldInstruction insn) { String className = classNameMapper.map(insn.getField().getClassName()); insn.setField(referenceCache.getCached(new FieldReference(className, insn.getField().getFieldName()))); }
@Override public void visit(PutFieldInstruction insn) { String className = classNameMapper.map(insn.getField().getClassName()); if (className != insn.getField().getClassName()) { insn.setField(referenceCache.getCached(new FieldReference(className, insn.getField().getFieldName()))); } } @Override
@Override public void visit(InvokeInstruction insn) { String className = classNameMapper.map(insn.getMethod().getClassName()); ValueType[] signature = insn.getMethod().getSignature(); boolean changed = true; for (int i = 0; i < signature.length; ++i) { ValueType type = signature[i]; ValueType newType = rename(type); if (newType != null) { changed = true; } signature[i] = newType; } if (changed) { insn.setMethod(referenceCache.getCached(new MethodReference(className, new MethodDescriptor(insn.getMethod().getName(), signature)))); } }