@Override public void visitProperty(PropertyNode node) { final FieldNode field = node.getField(); final Expression init = field.getInitialExpression(); field.setInitialValueExpression(null); super.visitProperty(node); field.setInitialValueExpression(init); }
public void visitField(FieldNode node) { visitAnnotations(node); Expression init = node.getInitialExpression(); node.setInitialValueExpression(transform(init)); }
private void moveInitializer(Field field, Method method, int position) { method.getFirstBlock().getAst().add(position, new ExpressionStatement( new FieldInitializationExpression(field.getAst()))); field.getAst().setInitialValueExpression(null); }
private void setScriptURIOnField(final FieldNode fieldNode, final AnnotationNode node) { if (fieldNode.hasInitialExpression()) { addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", fieldNode); return; } URI uri = getSourceURI(node); if (uri == null) { addError("Unable to get the URI for the source of this class!", fieldNode); } else { // Set the RHS to '= URI.create("string for this URI")'. // That may throw an IllegalArgumentExpression wrapping the URISyntaxException. fieldNode.setInitialValueExpression(getExpression(uri)); } }
private static Expression getInitExpr(ErrorCollecting xform, FieldNode fieldNode) { Expression initExpr = fieldNode.getInitialValueExpression(); fieldNode.setInitialValueExpression(null); if (initExpr == null || initExpr instanceof EmptyExpression) { if (fieldNode.getType().isAbstract()) { xform.addError("You cannot lazily initialize '" + fieldNode.getName() + "' from the abstract class '" + fieldNode.getType().getName() + "'", fieldNode); } initExpr = ctorX(fieldNode.getType()); } return initExpr; } }
cexp = transformToPrimitiveConstantIfPossible(cexp); if (fieldNode.isFinal() && ClassHelper.isStaticConstantInitializerType(cexp.getType()) && cexp.getType().equals(fieldNode.getType())) { fieldNode.setInitialValueExpression(transformed); return; // GROOVY-5150: primitive type constants will be initialized directly staticList.add(statement); fieldNode.setInitialValueExpression(null); // to avoid double initialization in case of several constructors
public PropertyNode addProperty(String name, int modifiers, ClassNode type, Expression initialValueExpression, Statement getterBlock, Statement setterBlock) { for (PropertyNode pn : getProperties()) { if (pn.getName().equals(name)) { if (pn.getInitialExpression() == null && initialValueExpression != null) pn.getField().setInitialValueExpression(initialValueExpression); if (pn.getGetterBlock() == null && getterBlock != null) pn.setGetterBlock(getterBlock); if (pn.getSetterBlock() == null && setterBlock != null) pn.setSetterBlock(setterBlock); return pn; } } PropertyNode node = new PropertyNode(name, modifiers, type, redirect(), initialValueExpression, getterBlock, setterBlock); addProperty(node); return node; }
private static Statement createConstructorStatementDefault(FieldNode fNode, boolean namedArgs) { final ClassNode fType = fNode.getType(); final Expression fieldExpr = propX(varX("this"), fNode.getName()); Expression initExpr = fNode.getInitialValueExpression(); Statement assignInit; if (initExpr == null || (initExpr instanceof ConstantExpression && ((ConstantExpression)initExpr).isNullExpression())) { if (ClassHelper.isPrimitiveType(fType)) { assignInit = EmptyStatement.INSTANCE; } else { assignInit = assignS(fieldExpr, ConstantExpression.EMPTY_EXPRESSION); } } else { assignInit = assignS(fieldExpr, initExpr); } fNode.setInitialValueExpression(null); Expression param = getParam(fNode, namedArgs); Statement assignStmt = assignS(fieldExpr, castX(fType, param)); return assignWithDefault(namedArgs, assignInit, param, assignStmt); }
public static Statement createConstructorStatementDefault(FieldNode fNode) { final String name = fNode.getName(); final ClassNode fType = fNode.getType(); final Expression fieldExpr = propX(varX("this"), name); Expression initExpr = fNode.getInitialValueExpression(); Statement assignInit; if (initExpr == null || (initExpr instanceof ConstantExpression && ((ConstantExpression)initExpr).isNullExpression())) { if (ClassHelper.isPrimitiveType(fType)) { assignInit = EmptyStatement.INSTANCE; } else { assignInit = assignS(fieldExpr, ConstantExpression.EMPTY_EXPRESSION); } } else { assignInit = assignS(fieldExpr, initExpr); } fNode.setInitialValueExpression(null); Expression value = findArg(name); return ifElseS(equalsNullX(value), assignInit, assignS(fieldExpr, castX(fType, value))); }
Token.newSymbol(Types.EQUAL, fn.getLineNumber(), fn.getColumnNumber()), init)); fn.setInitialValueExpression(null); methodCode.addStatement(statement); swapInitRequired = true;
field.setInitialValueExpression(null); block.add( new ExpressionStatement(
@Override public void visitProperty(PropertyNode node) { final FieldNode field = node.getField(); final Expression init = field.getInitialExpression(); field.setInitialValueExpression(null); super.visitProperty(node); field.setInitialValueExpression(init); }
public void visitField(FieldNode node) { visitAnnotations(node); Expression init = node.getInitialExpression(); node.setInitialValueExpression(transform(init)); }
public void visitField(FieldNode node) { visitAnnotations(node); Expression init = node.getInitialExpression(); node.setInitialValueExpression(transform(init)); }
public void visitField(FieldNode node) { visitAnnotations(node); Expression init = node.getInitialExpression(); node.setInitialValueExpression(transform(init)); }
public void visitField(FieldNode node) { visitAnnotations(node); Expression init = node.getInitialExpression(); node.setInitialValueExpression(transform(init)); }
private Expression getInitExpr(FieldNode fieldNode) { Expression initExpr = fieldNode.getInitialValueExpression(); fieldNode.setInitialValueExpression(null); if (initExpr == null) initExpr = new ConstructorCallExpression(fieldNode.getType(), new ArgumentListExpression()); return initExpr; } }
private Expression getInitExpr(FieldNode fieldNode) { Expression initExpr = fieldNode.getInitialValueExpression(); fieldNode.setInitialValueExpression(null); if (initExpr == null) initExpr = new ConstructorCallExpression(fieldNode.getType(), new ArgumentListExpression()); return initExpr; } }
private Expression getInitExpr(FieldNode fieldNode) { Expression initExpr = fieldNode.getInitialValueExpression(); fieldNode.setInitialValueExpression(null); if (initExpr == null) initExpr = new ConstructorCallExpression(fieldNode.getType(), new ArgumentListExpression()); return initExpr; } }
public void visit(ASTNode[] nodes, SourceUnit source) { if (nodes.length == 0 || !(nodes[0] instanceof ModuleNode)) { source.getErrorCollector().addError(new SimpleMessage( "internal error in DetectorTransform", source)); return; } ModuleNode module = (ModuleNode)nodes[0]; for (ClassNode clazz : (List<ClassNode>)module.getClasses()) { FieldNode field = clazz.getField(VERSION_FIELD_NAME); if (field != null) { field.setInitialValueExpression(new ConstantExpression(ReleaseInfo.getVersion())); break; } } } }