Skip to content

Commit

Permalink
Issue #13100: Create tests from InnerTypeLast xdoc examples
Browse files Browse the repository at this point in the history
  • Loading branch information
stoyanK7 authored and romani committed Jul 29, 2023
1 parent f5cbb24 commit f9d79d0
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 30 deletions.
Expand Up @@ -35,32 +35,6 @@
* method, constructor and field declarations.
* </p>
* <p>
* To configure the check:
* </p>
* <pre>
* &lt;module name=&quot;InnerTypeLast&quot;/&gt;
* </pre>
* <p>Example:</p>
* <pre>
* class Test {
* private String s; // OK
* class InnerTest1 {}
* public void test() {} // violation, method should be declared before inner types.
* }
*
* class Test2 {
* static {}; // OK
* class InnerTest1 {}
* public Test2() {} // violation, constructor should be declared before inner types.
* }
*
* class Test3 {
* private String s; // OK
* public void test() {} // OK
* class InnerTest1 {}
* }
* </pre>
* <p>
* Parent is {@code com.puppycrawl.tools.checkstyle.TreeWalker}
* </p>
* <p>
Expand Down
Expand Up @@ -116,7 +116,8 @@ public class XdocsJavaDocsTest extends AbstractModuleTestSupport {
// We skip validation of examples section on modules that have this section generated
// until https://github.com/checkstyle/checkstyle/issues/13429
private static final Set<String> MODULES_EXAMPLES_TO_SKIP = Set.of(
"WhitespaceAfter"
"WhitespaceAfter",
"InnerTypeLast"
);

private static final List<List<Node>> CHECK_PROPERTIES = new ArrayList<>();
Expand Down
@@ -0,0 +1,47 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code and other text files for adherence to a set of rules.
// Copyright (C) 2001-2023 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.design;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;

@Disabled("until https://github.com/checkstyle/checkstyle/issues/13345")
public class InnerTypeLastCheckExamplesTest extends AbstractModuleTestSupport {
@Override
protected String getResourceLocation() {
return "xdocs-examples";
}

@Override
protected String getPackageLocation() {
return "com/puppycrawl/tools/checkstyle/checks/design/innertypelast";
}

@Test
public void testExample1() throws Exception {
final String[] expected = {

};

verifyWithInlineConfigParser(getPath("Example1.txt"), expected);
}
}
@@ -0,0 +1,27 @@
/*xml
<module name="Checker">
<module name="TreeWalker">
<module name="InnerTypeLast"/>
</module>
</module>
*/

// xdoc section -- start
class Test {
private String s; // OK
class InnerTest1 {}
public void test() {} // violation, method should be declared before inner types.
}

class Test2 {
static {}; // OK
class InnerTest1 {}
public Test2() {} // violation, constructor should be declared before inner types.
}

class Test3 {
private String s; // OK
public void test() {} // OK
class InnerTest1 {}
}
// xdoc section -- end
10 changes: 7 additions & 3 deletions src/xdocs/checks/design/innertypelast.xml
Expand Up @@ -17,13 +17,17 @@
</subsection>

<subsection name="Examples" id="Examples">
<p>
<p id="Example1-config">
To configure the check:
</p>
<source>
&lt;module name="InnerTypeLast"/&gt;
&lt;module name=&quot;Checker&quot;&gt;
&lt;module name=&quot;TreeWalker&quot;&gt;
&lt;module name=&quot;InnerTypeLast&quot;/&gt;
&lt;/module&gt;
&lt;/module&gt;
</source>
<p>Example:</p>
<p id="Example1-code">Example:</p>
<source>
class Test {
private String s; // OK
Expand Down
72 changes: 72 additions & 0 deletions src/xdocs/checks/design/innertypelast.xml.template
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<document xmlns="http://maven.apache.org/XDOC/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 https://maven.apache.org/xsd/xdoc-2.0.xsd">
<head>
<title>InnerTypeLast</title>
</head>
<body>
<section name="InnerTypeLast">
<p>Since Checkstyle 5.2</p>
<subsection name="Description" id="Description">
<p>
Checks nested (internal) classes/interfaces are declared at the bottom of the
primary (top-level) class after all init and static init blocks,
method, constructor and field declarations.
</p>
</subsection>

<subsection name="Examples" id="Examples">
<p id="Example1-config">
To configure the check:
</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/checks/design/innertypelast/Example1.txt"/>
<param name="type" value="config"/>
</macro>
<p id="Example1-code">Example:</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/checks/design/innertypelast/Example1.txt"/>
<param name="type" value="code"/>
</macro>
</subsection>

<subsection name="Example of Usage" id="Example_of_Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig%20path%3A**%2Fcheckstyle-checks.xml+repo%3Acheckstyle%2Fcheckstyle+InnerTypeLast">
Checkstyle Style</a>
</li>
</ul>
</subsection>

<subsection name="Violation Messages" id="Violation_Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fdesign%20path%3A**%2Fmessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22arrangement.members.before.inner%22">
arrangement.members.before.inner</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="../../config.html#Custom_messages">see the documentation</a>
to learn how to.
</p>
</subsection>

<subsection name="Package" id="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.design
</p>
</subsection>

<subsection name="Parent Module" id="Parent_Module">
<p>
<a href="../../config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
</body>
</document>

0 comments on commit f9d79d0

Please sign in to comment.