Search in sources :

Example 1 with ScopeNode

use of com.google.api.generator.engine.ast.ScopeNode in project gapic-generator-java by googleapis.

the class JavaWriterVisitor method visit.

@Override
public void visit(VariableExpr variableExpr) {
    Variable variable = variableExpr.variable();
    TypeNode type = variable.type();
    ScopeNode scope = variableExpr.scope();
    // VariableExpr will handle isDecl and exprReferenceExpr edge cases.
    if (variableExpr.isDecl()) {
        if (!scope.equals(ScopeNode.LOCAL)) {
            scope.accept(this);
            space();
        }
        if (variableExpr.isStatic()) {
            buffer.append(STATIC);
            space();
        }
        if (variableExpr.isFinal()) {
            buffer.append(FINAL);
            space();
        }
        if (variableExpr.isVolatile()) {
            buffer.append(VOLATILE);
            space();
        }
        type.accept(this);
        if (!variableExpr.templateNodes().isEmpty()) {
            leftAngle();
            IntStream.range(0, variableExpr.templateNodes().size()).forEach(i -> {
                variableExpr.templateNodes().get(i).accept(this);
                if (i < variableExpr.templateNodes().size() - 1) {
                    buffer.append(COMMA);
                    space();
                }
            });
            rightAngle();
        }
        space();
    } else {
        // Expression or static reference.
        if (variableExpr.exprReferenceExpr() != null) {
            variableExpr.exprReferenceExpr().accept(this);
            buffer.append(DOT);
        } else if (variableExpr.staticReferenceType() != null) {
            variableExpr.staticReferenceType().accept(this);
            buffer.append(DOT);
        }
    }
    variable.identifier().accept(this);
}
Also used : Variable(com.google.api.generator.engine.ast.Variable) TypeNode(com.google.api.generator.engine.ast.TypeNode) ScopeNode(com.google.api.generator.engine.ast.ScopeNode)

Aggregations

ScopeNode (com.google.api.generator.engine.ast.ScopeNode)1 TypeNode (com.google.api.generator.engine.ast.TypeNode)1 Variable (com.google.api.generator.engine.ast.Variable)1