private void setConstField(ConstantExpression constantExpression) { final Object n = constantExpression.getValue(); if (!(n instanceof Number)) return; if (n instanceof Integer || n instanceof Double) return; if (n instanceof Long && (0L == (Long) n || 1L == (Long) n)) return; // LCONST_0, LCONST_1 boolean isPrimitive = isPrimitiveType(constantExpression.getType()); FieldNode field = isPrimitive ? const2Prims.get(n) : const2Objects.get(n); if (field != null) { constantExpression.setConstantName(field.getName()); return; } String name; do { name = "$const$" + index++; } while (currentClass.getDeclaredField(name) != null); // TODO consider moving initcode to <clinit> and remaking field final field = new FieldNode(name, Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, constantExpression.getType(), currentClass, constantExpression); field.setSynthetic(true); missingFields.add(field); constantExpression.setConstantName(field.getName()); if (isPrimitive) { const2Prims.put(n, field); } else { const2Objects.put(n, field); } }
private void setConstField(ConstantExpression constantExpression) { final Object n = constantExpression.getValue(); if (!(n instanceof Number || n instanceof Character)) return; FieldNode field = (FieldNode) const2Var.get(n); if (field!=null) { constantExpression.setConstantName(field.getName()); return; } final String name = "$const$" + const2Var.size(); //TODO: this part here needs a bit of rethinking. If it can happen that the field is defined already, // then is this code still valid? field = currentClass.getDeclaredField(name); if (field==null) { field = new FieldNode(name, Opcodes.ACC_PRIVATE|Opcodes.ACC_STATIC|Opcodes.ACC_SYNTHETIC| Opcodes.ACC_FINAL, constantExpression.getType(), currentClass, constantExpression ); field.setSynthetic(true); missingFields.add(field); } constantExpression.setConstantName(field.getName()); const2Var.put(n, field); }
private void setConstField(ConstantExpression constantExpression) { final Object n = constantExpression.getValue(); if (!(n instanceof Number || n instanceof Character)) return; if (n instanceof Integer || n instanceof Double) return; FieldNode field = (FieldNode) const2Var.get(n); if (field!=null) { constantExpression.setConstantName(field.getName()); return; } final String name = "$const$" + const2Var.size(); //TODO: this part here needs a bit of rethinking. If it can happen that the field is defined already, // then is this code still valid? field = currentClass.getDeclaredField(name); if (field==null) { field = new FieldNode(name, Opcodes.ACC_PRIVATE|Opcodes.ACC_STATIC|Opcodes.ACC_SYNTHETIC| Opcodes.ACC_FINAL, constantExpression.getType(), currentClass, constantExpression ); field.setSynthetic(true); missingFields.add(field); } constantExpression.setConstantName(field.getName()); const2Var.put(n, field); }
private void setConstField(ConstantExpression constantExpression) { final Object n = constantExpression.getValue(); if (!(n instanceof Number || n instanceof Character)) return; FieldNode field = (FieldNode) const2Var.get(n); if (field!=null) { constantExpression.setConstantName(field.getName()); return; } final String name = "$const$" + const2Var.size(); //TODO: this part here needs a bit of rethinking. If it can happen that the field is defined already, // then is this code still valid? field = currentClass.getDeclaredField(name); if (field==null) { field = new FieldNode(name, Opcodes.ACC_PRIVATE|Opcodes.ACC_STATIC|Opcodes.ACC_SYNTHETIC| Opcodes.ACC_FINAL, constantExpression.getType(), currentClass, constantExpression ); field.setSynthetic(true); missingFields.add(field); } constantExpression.setConstantName(field.getName()); const2Var.put(n, field); }
init)); fn.setInitialValueExpression(null); init.setConstantName(null); methodCode.addStatement(statement);