public void doBuild(InstructionBuilder builder) { Class rawFieldType = field.getType(); String rawTypeName = PlasticUtils.toTypeName(rawFieldType); String containingClassName = field.getDeclaringClass().getName(); String fieldName = field.getName(); if (isStatic(field)) { // We've gone to the trouble of loading the root object, or navigated to some other object, // but we don't need or want the instance, since it's a static field we're accessing. // Ideally, we would optimize this, and only generate and invoke the getRoot() and nav() methods as needed, but // access to public fields is relatively rare, and the cost is just the unused bytecode. builder.pop(); builder.getStaticField(containingClassName, fieldName, rawTypeName); } else { builder.getField(containingClassName, fieldName, rawTypeName); } castToGenericType(builder, rawFieldType, fieldType); }
private Type implementListConstructor(InstructionBuilder builder, Tree listNode) { // First, create an empty instance of ArrayList int count = listNode.getChildCount(); builder.newInstance(ArrayList.class); builder.dupe().loadConstant(count).invokeConstructor(ArrayList.class, int.class); for (int i = 0; i < count; i++) { builder.dupe(); // the ArrayList Type expressionType = implementSubexpression(builder, null, listNode.getChild(i)); boxIfPrimitive(builder, GenericsUtils.asClass(expressionType)); // Add the value to the array, then pop off the returned boolean builder.invoke(ArrayListMethods.ADD).pop(); } return ArrayList.class; }
private Type implementMapConstructor(InstructionBuilder builder, Tree mapNode) { int count = mapNode.getChildCount(); builder.newInstance(HashMap.class); builder.dupe().loadConstant(count).invokeConstructor(HashMap.class, int.class); for (int i = 0; i < count; i += 2) { builder.dupe(); //build the key: Type keyType = implementSubexpression(builder, null, mapNode.getChild(i)); boxIfPrimitive(builder, GenericsUtils.asClass(keyType)); //and the value: Type valueType = implementSubexpression(builder, null, mapNode.getChild(i + 1)); boxIfPrimitive(builder, GenericsUtils.asClass(valueType)); //put the value into the array, then pop off the returned object. builder.invoke(HashMapMethods.PUT).pop(); } return HashMap.class; }
builder.dupeWide().loadThis().dupe(2).pop(); } else
builder.dupeWide().loadThis().dupe(2).pop(); } else