<commit_before>////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2019 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
////////////////////////////////////////////////////////////////////////////////

package com.puppycrawl.tools.checkstyle.checks.blocks;

import java.util.Optional;

import com.puppycrawl.tools.checkstyle.StatelessCheck;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;

/**
 * <p>
 * Checks for braces around code blocks.
 * </p>
 * <ul>
 * <li>
 * Property {@code allowSingleLineStatement} - allow single-line statements without braces.
 * Default value is {@code false}.
 * </li>
 * <li>
 * Property {@code allowEmptyLoopBody} - allow loops with empty bodies.
 * Default value is {@code false}.
 * </li>
 * <li>
 * Property {@code tokens} - tokens to check
 * Default value is:
 * <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO">
 * LITERAL_DO</a>,
 * <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">
 * LITERAL_ELSE</a>,
 * <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FOR">
 * LITERAL_FOR</a>,
 * <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">
 * LITERAL_IF</a>,
 * <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_WHILE">
 * LITERAL_WHILE</a>.
 * </li>
 * </ul>
 * <p>
 * To configure the check:
 * </p>
 * <pre>
 * &lt;module name="NeedBraces"/&gt;
 * </pre>
 * <p>
 * To configure the check for {@code if} and {@code else} blocks:
 * </p>
 * <pre>
 * &lt;module name=&quot;NeedBraces&quot;&gt;
 *   &lt;property name=&quot;tokens&quot; value=&quot;LITERAL_IF, LITERAL_ELSE&quot;/&gt;
 * &lt;/module&gt;
 * </pre>
 * <p>
 * To configure the check to allow single-line statements
 * ({@code if, while, do-while, for}) without braces:
 * </p>
 * <pre>
 * &lt;module name=&quot;NeedBraces&quot;&gt;
 *   &lt;property name=&quot;allowSingleLineStatement&quot; value=&quot;true&quot;/&gt;
 * &lt;/module&gt;
 * </pre>
 * <p>
 * Next statements won't be violated by check:
 * </p>
 * <pre>
 * if (obj.isValid()) return true; // OK
 * while (obj.isValid()) return true; // OK
 * do this.notify(); while (o != null); // OK
 * for (int i = 0; ; ) this.notify(); // OK
 * </pre>
 * <p>
 * To configure the check to allow {@code case, default} single-line statements without braces:
 * </p>
 * <pre>
 * &lt;module name=&quot;NeedBraces&quot;&gt;
 *   &lt;property name=&quot;tokens&quot; value=&quot;LITERAL_CASE, LITERAL_DEFAULT&quot;/&gt;
 *   &lt;property name=&quot;allowSingleLineStatement&quot; value=&quot;true&quot;/&gt;
 * &lt;/module&gt;
 * </pre>
 * <p>
 * Next statements won't be violated by check:
 * </p>
 * <pre>
 * switch (num) {
 *   case 1: counter++; break; // OK
 *   case 6: counter += 10; break; // OK
 *   default: counter = 100; break; // OK
 * }
 * </pre>
 * <p>
 * To configure the check to allow loops ({@code while, for}) with empty bodies:
 * </p>
 * <pre>
 * &lt;module name=&quot;NeedBraces&quot;&gt;
 *   &lt;property name=&quot;allowEmptyLoopBody&quot; value=&quot;true&quot;/&gt;
 * &lt;/module&gt;
 * </pre>
 * <p>
 * Next statements won't be violated by check:
 * </p>
 * <pre>
 * while (value.incrementValue() &lt; 5); // OK
 * for(int i = 0; i &lt; 10; value.incrementValue()); // OK
 * </pre>
 * <p>
 * To configure the check to lambdas:
 * </p>
 * <pre>
 * &lt;module name=&quot;NeedBraces&quot;&gt;
 *   &lt;property name=&quot;tokens&quot; value=&quot;LAMBDA&quot;/&gt;
 *   &lt;property name=&quot;allowSingleLineStatement&quot; value=&quot;true&quot;/&gt;
 * &lt;/module&gt;
 * </pre>
 * <p>
 * Results in following:
 * </p>
 * <pre>
 * allowedFuture.addCallback(result -> assertEquals("Invalid response",
 *   EnumSet.of(HttpMethod.GET, HttpMethod.OPTIONS), result), // violation, lambda spans 2 lines
 *   ex -> fail(ex.getMessage())); // OK
 *
 * allowedFuture.addCallback(result -> {
 *   return assertEquals("Invalid response",
 *     EnumSet.of(HttpMethod.GET, HttpMethod.OPTIONS), result);
 *   }, // OK
 *   ex -> fail(ex.getMessage()));
 * </pre>
 *
 * @since 3.0
 */<commit_msg>Issue #6948: javadoc error in NeedBracesCheck.java<commit_after>////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2019 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
////////////////////////////////////////////////////////////////////////////////

package com.puppycrawl.tools.checkstyle.checks.blocks;

import java.util.Optional;

import com.puppycrawl.tools.checkstyle.StatelessCheck;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;

/**
 * <p>
 * Checks for braces around code blocks.
 * </p>
 * <ul>
 * <li>
 * Property {@code allowSingleLineStatement} - allow single-line statements without braces.
 * Default value is {@code false}.
 * </li>
 * <li>
 * Property {@code allowEmptyLoopBody} - allow loops with empty bodies.
 * Default value is {@code false}.
 * </li>
 * <li>
 * Property {@code tokens} - tokens to check
 * Default value is:
 * <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO">
 * LITERAL_DO</a>,
 * <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">
 * LITERAL_ELSE</a>,
 * <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FOR">
 * LITERAL_FOR</a>,
 * <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">
 * LITERAL_IF</a>,
 * <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_WHILE">
 * LITERAL_WHILE</a>.
 * </li>
 * </ul>
 * <p>
 * To configure the check:
 * </p>
 * <pre>
 * &lt;module name="NeedBraces"/&gt;
 * </pre>
 * <p>
 * To configure the check for {@code if} and {@code else} blocks:
 * </p>
 * <pre>
 * &lt;module name=&quot;NeedBraces&quot;&gt;
 *   &lt;property name=&quot;tokens&quot; value=&quot;LITERAL_IF, LITERAL_ELSE&quot;/&gt;
 * &lt;/module&gt;
 * </pre>
 * <p>
 * To configure the check to allow single-line statements
 * ({@code if, while, do-while, for}) without braces:
 * </p>
 * <pre>
 * &lt;module name=&quot;NeedBraces&quot;&gt;
 *   &lt;property name=&quot;allowSingleLineStatement&quot; value=&quot;true&quot;/&gt;
 * &lt;/module&gt;
 * </pre>
 * <p>
 * Next statements won't be violated by check:
 * </p>
 * <pre>
 * if (obj.isValid()) return true; // OK
 * while (obj.isValid()) return true; // OK
 * do this.notify(); while (o != null); // OK
 * for (int i = 0; ; ) this.notify(); // OK
 * </pre>
 * <p>
 * To configure the check to allow {@code case, default} single-line statements without braces:
 * </p>
 * <pre>
 * &lt;module name=&quot;NeedBraces&quot;&gt;
 *   &lt;property name=&quot;tokens&quot; value=&quot;LITERAL_CASE, LITERAL_DEFAULT&quot;/&gt;
 *   &lt;property name=&quot;allowSingleLineStatement&quot; value=&quot;true&quot;/&gt;
 * &lt;/module&gt;
 * </pre>
 * <p>
 * Next statements won't be violated by check:
 * </p>
 * <pre>
 * switch (num) {
 *   case 1: counter++; break; // OK
 *   case 6: counter += 10; break; // OK
 *   default: counter = 100; break; // OK
 * }
 * </pre>
 * <p>
 * To configure the check to allow loops ({@code while, for}) with empty bodies:
 * </p>
 * <pre>
 * &lt;module name=&quot;NeedBraces&quot;&gt;
 *   &lt;property name=&quot;allowEmptyLoopBody&quot; value=&quot;true&quot;/&gt;
 * &lt;/module&gt;
 * </pre>
 * <p>
 * Next statements won't be violated by check:
 * </p>
 * <pre>
 * while (value.incrementValue() &lt; 5); // OK
 * for(int i = 0; i &lt; 10; value.incrementValue()); // OK
 * </pre>
 * <p>
 * To configure the check to lambdas:
 * </p>
 * <pre>
 * &lt;module name=&quot;NeedBraces&quot;&gt;
 *   &lt;property name=&quot;tokens&quot; value=&quot;LAMBDA&quot;/&gt;
 *   &lt;property name=&quot;allowSingleLineStatement&quot; value=&quot;true&quot;/&gt;
 * &lt;/module&gt;
 * </pre>
 * <p>
 * Results in following:
 * </p>
 * <pre>
 * allowedFuture.addCallback(result -&gt; assertEquals("Invalid response",
 *   EnumSet.of(HttpMethod.GET, HttpMethod.OPTIONS), result), // violation, lambda spans 2 lines
 *   ex -&gt; fail(ex.getMessage())); // OK
 *
 * allowedFuture.addCallback(result -&gt; {
 *   return assertEquals("Invalid response",
 *     EnumSet.of(HttpMethod.GET, HttpMethod.OPTIONS), result);
 *   }, // OK
 *   ex -&gt; fail(ex.getMessage()));
 * </pre>
 *
 * @since 3.0
 */
{'fraction_non_alphanumeric': 0.19355144618302514, 'fraction_numerical': 0.0077761972498814605, 'mean_word_length': 3.4591966173361524, 'pattern_counts': {'":': 0, '<': 123, '<?xml version=': 0, '>': 127, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '262324', 'n_tokens_mistral': 3644, 'n_tokens_neox': 3478, 'n_words': 933}