public String getLabelExpression(Field field) { Expression label = field.getLabel(); if (label == null) return null; StringBuilder builder = new StringBuilder(); AST labelBase = label.getNextSibling(); if (labelBase != null) { String name = labelBase.getText(); builder.append("(("); builder.append(name); builder.append(")__cc.find(\""); builder.append(name); builder.append("\"))."); } builder.append("__fpos + 8*"); String labelExpr = exprEmitter.emit(label); builder.append(labelExpr); return builder.toString(); }
/** * Recursively traverses a label expression to construct the setter name for the label. We rely * on the results of the ExpressionEvaluator in assuming that the expression type is either DOT * or ID, and that an ID always resolved to a Field in the expression scope. * * @param buffer string buffer used for appending the partial result * @param expr subexpression of current label expression */ private void appendLabelSetter(StringBuilder buffer, Expression expr) { if (expr.getType() == DataScriptParserTokenTypes.DOT) { Expression op1 = expr.op1(); String symbol = op1.getText(); Field f = (Field) op1.getScope().getTypeOrSymbol(symbol); String getter = AccessorNameEmitter.getGetterName(f); buffer.append(getter); buffer.append("()."); appendLabelSetter(buffer, expr.op2()); } else { Field f = (Field) expr.getScope().getTypeOrSymbol(expr.getText()); buffer.append(AccessorNameEmitter.getSetterName(f)); } }