Example usage for org.eclipse.jdt.core.dom LambdaExpression hasParentheses

List of usage examples for org.eclipse.jdt.core.dom LambdaExpression hasParentheses

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom LambdaExpression hasParentheses.

Prototype

boolean hasParentheses

To view the source code for org.eclipse.jdt.core.dom LambdaExpression hasParentheses.

Click Source Link

Document

Indicates whether parentheses are present or not.

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(LambdaExpression node) {
    boolean hasParentheses = node.hasParentheses();
    if (hasParentheses)
        this.fBuffer.append('(');
    for (Iterator<? extends VariableDeclaration> it = node.parameters().iterator(); it.hasNext();) {
        VariableDeclaration v = it.next();
        v.accept(this);
        if (it.hasNext()) {
            this.fBuffer.append(",");//$NON-NLS-1$
        }//w w  w.  j  a v  a 2s .c  o m
    }
    if (hasParentheses)
        this.fBuffer.append(')');
    this.fBuffer.append(" -> "); //$NON-NLS-1$
    node.getBody().accept(this);
    return false;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java

License:Open Source License

@Override
public boolean visit(LambdaExpression node) {
    if (node.getBody() instanceof Block) {
        forceContinuousWrapping(node.getBody(), this.tm.firstIndexIn(node, -1));
    }//w  w w.ja v a2  s  .  c o m
    if (node.hasParentheses()) {
        List<VariableDeclaration> parameters = node.parameters();
        // the legacy formatter didn't like wrapping lambda parameters, so neither do we
        this.currentDepth++;
        handleArguments(parameters, this.options.alignment_for_parameters_in_method_declaration);
        this.currentDepth--;
    }
    return true;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java

License:Open Source License

@Override
public boolean visit(LambdaExpression node) {
    handleToken(node, TokenNameARROW, this.options.insert_space_before_lambda_arrow,
            this.options.insert_space_after_lambda_arrow);
    List<VariableDeclaration> parameters = node.parameters();
    if (node.hasParentheses()) {
        if (handleEmptyParens(node, this.options.insert_space_between_empty_parens_in_method_declaration)) {
            handleToken(node, TokenNameLPAREN,
                    this.options.insert_space_before_opening_paren_in_method_declaration, false);
        } else {/*from   w w  w  . ja v a  2s  . c om*/
            handleToken(node, TokenNameLPAREN,
                    this.options.insert_space_before_opening_paren_in_method_declaration,
                    this.options.insert_space_after_opening_paren_in_method_declaration);

            handleTokenBefore(node.getBody(), TokenNameRPAREN,
                    this.options.insert_space_before_closing_paren_in_method_declaration, false);
        }
        handleCommas(parameters, this.options.insert_space_before_comma_in_method_declaration_parameters,
                this.options.insert_space_after_comma_in_method_declaration_parameters);
    }
    return true;
}

From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java

License:Apache License

/** Visitor method for {@link LambdaExpression}s. */
@Override/*from www . j  ava2  s . c o m*/
public boolean visit(LambdaExpression node) {
    sync(node);
    boolean statementBody = node.getBody().getNodeType() == ASTNode.BLOCK;
    builder.open(statementBody ? ZERO : plusFour);
    builder.open(plusFour);
    if (node.hasParentheses()) {
        token("(");
    }
    boolean first = true;
    for (ASTNode parameter : (List<ASTNode>) node.parameters()) {
        if (!first) {
            token(",");
            builder.breakOp(" ");
        }
        parameter.accept(this);
        ;
        first = false;
    }
    if (node.hasParentheses()) {
        token(")");
    }
    builder.close();
    builder.space();
    builder.op("->");
    if (statementBody) {
        builder.space();
    } else {
        builder.breakOp(" ");
    }
    node.getBody().accept(this);
    builder.close();
    return false;
}

From source file:org.codemucker.jmutate.ast.JAstFlattener.java

License:Open Source License

public boolean visit(LambdaExpression node) {
    boolean hasParentheses = node.hasParentheses();
    if (hasParentheses)
        this.buffer.append('(');
    for (Iterator it = node.parameters().iterator(); it.hasNext();) {
        VariableDeclaration v = (VariableDeclaration) it.next();
        v.accept(this);
        if (it.hasNext()) {
            this.buffer.append(",");//$NON-NLS-1$
        }/*ww w  . ja v  a  2  s  .c om*/
    }
    if (hasParentheses)
        this.buffer.append(')');
    this.buffer.append(" -> "); //$NON-NLS-1$
    node.getBody().accept(this);
    return false;
}

From source file:org.whole.lang.java.util.JDTTransformerVisitor.java

License:Open Source License

@Override
public boolean visit(LambdaExpression node) {
    //FIXME workaround for type nesting
    org.whole.lang.java.model.Type type = this.type;
    org.whole.lang.java.model.Name name = this.name;
    org.whole.lang.java.model.TypeParameter typeParameter = this.typeParameter;
    org.whole.lang.java.model.Parameters params = this.params;
    org.whole.lang.java.model.Types thrownExceptions = this.thrownExceptions;
    org.whole.lang.java.model.SingleVariableDeclaration varDecl = this.varDecl;
    org.whole.lang.java.model.Block block = this.block;
    org.whole.lang.java.model.Statement stm = this.stm;
    org.whole.lang.java.model.VariableDeclarationFragment varFrag = this.varFrag;
    org.whole.lang.java.model.CatchClauses catchClauses = this.catchClauses;
    org.whole.lang.java.model.AnonymousClassDeclaration anonymousClassDeclaration = lf
            .create(JavaEntityDescriptorEnum.AnonymousClassDeclaration);

    org.whole.lang.java.model.LambdaExpression lambdaExpression = lf.createLambdaExpression();

    this.params = null;
    if (node.hasParentheses()) {
        Iterator<?> iterator = node.parameters().iterator();
        while (iterator.hasNext()) {
            this.varDecl = null;
            this.varFrag = null;
            acceptChild((ASTNode) iterator.next());
            lambdaExpression.getParameters().wAdd(this.varDecl != null ? this.varDecl : this.varFrag);
        }//w w w  .ja  v  a2 s  .  c  om
        if (EntityUtils.isResolver(lambdaExpression.getParameters()))
            lambdaExpression.setParameters(lf.createParameters(0));
    } else {
        acceptChild((ASTNode) node.parameters().get(0));
        lambdaExpression.setParameters(this.varFrag);
    }

    this.exp = null;
    this.stm = null;
    acceptChild(node.getBody());
    lambdaExpression.setBody(this.stm != null ? this.stm : this.exp);

    exp = lambdaExpression;

    //FIXME workaround for type nesting
    this.type = type;
    this.name = name;
    this.typeParameter = typeParameter;
    this.params = params;
    this.thrownExceptions = thrownExceptions;
    this.varDecl = varDecl;
    this.block = block;
    this.stm = stm;
    this.varFrag = varFrag;
    this.catchClauses = catchClauses;
    this.anonymousClassDeclaration = anonymousClassDeclaration;

    return false;
}

From source file:parser.AnnotationType.java

License:Open Source License

public boolean visit(LambdaExpression node) {
    boolean hasParentheses = node.hasParentheses();
    this.buffer.append(strSplitCharacter);
    if (hasParentheses) {
        this.buffer.append('(');
        this.buffer.append(strSplitCharacter);
    }//from  www. ja va 2  s .  c om
    for (Iterator it = node.parameters().iterator(); it.hasNext();) {

        VariableDeclaration v = (VariableDeclaration) it.next();
        v.accept(this);
        this.buffer.append(strSplitCharacter);
        if (it.hasNext()) {
            this.buffer.append(strSplitCharacter);
            this.buffer.append(",");//$NON-NLS-1$
            this.buffer.append(strSplitCharacter);
        }
    }
    if (hasParentheses) {
        this.buffer.append(strSplitCharacter);
        this.buffer.append(')');
        this.buffer.append(strSplitCharacter);

    }

    this.buffer.append(" -> "); //$NON-NLS-1$
    node.getBody().accept(this);
    this.buffer.append(strSplitCharacter);
    return false;
}