private void processLocalVariable(DeclarationExpression de, ClassCodeVisitorSupport visitor) { if (!isEnabled(de)) return; if (de.getRightExpression() instanceof ClosureExpression) { visitor.visitDeclarationExpression(de); } }
private void moveVariableDeclarations(List<Statement> from, List<Statement> to) { for (Statement stat : from) { DeclarationExpression declExpr = AstUtil.getExpression(stat, DeclarationExpression.class); if (declExpr == null) continue; ((ExpressionStatement) stat).setExpression( new BinaryExpression( copyLhsVariableExpressions(declExpr), Token.newSymbol(Types.ASSIGN, -1, -1), declExpr.getRightExpression())); declExpr.setRightExpression(createDefaultValueInitializer(declExpr)); to.add(new ExpressionStatement(declExpr)); } }
@Override public void visitDeclarationExpression(DeclarationExpression expression) { Expression right = expression.getRightExpression(); right.visit(this); ClassNode leftType = typeChooser.resolveType(expression.getLeftExpression(), node); Expression rightExpression = expression.getRightExpression(); ClassNode rightType = optimizeDivWithIntOrLongTarget(rightExpression, leftType); if (rightType==null) rightType = typeChooser.resolveType(expression.getRightExpression(), node); if (isPrimitiveType(leftType) && isPrimitiveType(rightType)) { // if right is a constant, then we optimize only if it makes // a block complete, so we set a maybe if (right instanceof ConstantExpression) { opt.chainCanOptimize(true); } else { opt.chainShouldOptimize(true); } StatementMeta meta = addMeta(expression); ClassNode declarationType = typeChooser.resolveType(expression, node); meta.type = declarationType!=null?declarationType:leftType; opt.chainInvolvedType(leftType); opt.chainInvolvedType(rightType); } }
private void setScriptURIOnDeclaration(final DeclarationExpression de, final AnnotationNode node) { if (de.isMultipleAssignmentDeclaration()) { addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de); return; } if (!(de.getRightExpression() instanceof EmptyExpression)) { addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de); return; } URI uri = getSourceURI(node); if (uri == null) { addError("Unable to get the URI for the source of this script!", de); } else { // Set the RHS to '= URI.create("string for this URI")'. // That may throw an IllegalArgumentExpression wrapping the URISyntaxException. de.setRightExpression(getExpression(uri)); } }
public void visitDeclarationExpression(DeclarationExpression expression) { visitAnnotations(expression); // visit right side first to avoid the usage of a // variable before its declaration expression.getRightExpression().visit(this); if (expression.isMultipleAssignmentDeclaration()) { TupleExpression list = expression.getTupleExpression(); for (Expression e : list.getExpressions()) { declare((VariableExpression) e); } } else { declare(expression.getVariableExpression()); } }
protected Expression transformDeclarationExpression(DeclarationExpression de) { visitAnnotations(de); Expression oldLeft = de.getLeftExpression(); checkingVariableTypeInDeclaration = true; Expression left = transform(oldLeft); checkingVariableTypeInDeclaration = false; if (left instanceof ClassExpression) { ClassExpression ce = (ClassExpression) left; addError("you tried to assign a value to the class " + ce.getType().getName(), oldLeft); return de; } Expression right = transform(de.getRightExpression()); if (right == de.getRightExpression()) { fixDeclaringClass(de); return de; } DeclarationExpression newDeclExpr = new DeclarationExpression(left, de.getOperation(), right); newDeclExpr.setDeclaringClass(de.getDeclaringClass()); fixDeclaringClass(newDeclExpr); newDeclExpr.setSourcePosition(de); newDeclExpr.addAnnotations(de.getAnnotations()); return newDeclExpr; }
public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new DeclarationExpression(transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); ret.addAnnotations(getAnnotations()); ret.setDeclaringClass(getDeclaringClass()); ret.copyNodeMetaData(this); return ret; }
declaration.getLeftExpression(), declaration.getOperation(), declaration.getRightExpression()); assignment.setSourcePosition(declaration); assignment.copyNodeMetaData(declaration);
private void changeBaseScriptTypeFromDeclaration(final DeclarationExpression de, final AnnotationNode node) { if (de.isMultipleAssignmentDeclaration()) { addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de); return; } if (!(de.getRightExpression() instanceof EmptyExpression)) { addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de); return; } Expression value = node.getMember("value"); if (value != null) { addError("Annotation " + MY_TYPE_NAME + " cannot have member 'value' if used on a declaration.", value); return; } ClassNode cNode = de.getDeclaringClass(); ClassNode baseScriptType = de.getVariableExpression().getType().getPlainNodeReference(); de.setRightExpression(new VariableExpression("this")); changeBaseScriptType(de, cNode, baseScriptType); }
de.getLeftExpression(), de.getOperation(), de.getRightExpression()); expressions.set(i, be); de.setRightExpression(ConstantExpression.NULL);
private void changeBaseScriptTypeFromDeclaration(final SourceUnit source, final DeclarationExpression de, final AnnotationNode node) { if (de.isMultipleAssignmentDeclaration()) { addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de); return; } ClassNode cNode = de.getDeclaringClass(); ClassNode baseScriptType = de.getVariableExpression().getType().getPlainNodeReference(); if (baseScriptType.isScript()) { if (!(de.getRightExpression() instanceof EmptyExpression)) { addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de); return; } de.setRightExpression(new VariableExpression("this")); } else { baseScriptType = BASE_SCRIPT_TYPE; } Expression value = node.getMember("value"); if (value != null) { addError("Annotation " + MY_TYPE_NAME + " cannot have member 'value' if used on a declaration.", value); return; } changeBaseScriptType(source, de, cNode, baseScriptType, node); }
variableName = ve.getName(); fieldNode = new FieldNode(variableName, ve.getModifiers(), ve.getType(), null, de.getRightExpression()); fieldNode.setSourcePosition(de); cNode.addField(fieldNode);
candidate = null; Expression left = de.getLeftExpression(); Expression right = transform(de.getRightExpression()); DeclarationExpression newDecl = new DeclarationExpression(left, de.getOperation(), right); newDecl.addAnnotations(de.getAnnotations());
public void setLeftExpression(Expression leftExpression) { check(leftExpression,getRightExpression()); super.setLeftExpression(leftExpression); }
public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new DeclarationExpression((VariableExpression) transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); return ret; } }
public void visitDeclarationExpression(DeclarationExpression expression) { // visit right side first to avoid the usage of a // variable before its declaration expression.getRightExpression().visit(this); // no need to visit left side, just get the variable name VariableExpression vex = expression.getVariableExpression(); vex.setInStaticContext(currentScope.isInStaticContext()); declare(vex); vex.setAccessedVariable(vex); }
@Override public void run() { VariableExpression v = exp.getVariableExpression(); loc(exp); literal(v.getType()); literal(v.getName()); visitAssignmentOrCast(v, exp.getRightExpression()); } });
public Expression transformExpression(ExpressionTransformer transformer) { Expression left = getLeftExpression(); Expression ret = new DeclarationExpression(transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); return ret; }
public Expression transformExpression(ExpressionTransformer transformer) { Expression left = getLeftExpression(); Expression ret = new DeclarationExpression(transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); return ret; }
public Expression transformExpression(ExpressionTransformer transformer) { Expression ret = new DeclarationExpression(transformer.transform(getLeftExpression()), getOperation(), transformer.transform(getRightExpression())); ret.setSourcePosition(this); ret.addAnnotations(getAnnotations()); ret.setDeclaringClass(getDeclaringClass()); return ret; }