Skip to content

Commit

Permalink
Issue #14911: Added a new section 4.8.5.3 in google style guide imple…
Browse files Browse the repository at this point in the history
…mentation
  • Loading branch information
Zopsss authored and romani committed Jun 17, 2024
1 parent 8408c30 commit 7cbfef2
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/jsoref-spellchecker/whitelist.words
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ methodcount
methodlength
methodname
methodparampad
methodsandconstructorsannotations
methodtypeparametername
MEZk
Micha
Expand Down
1 change: 1 addition & 0 deletions config/sevntu-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<!-- Suppressed alternative method of pulling partial configuration from file -->
<suppress checks="CheckstyleTestMakeup" files="[\\/]RightCurlyTest\.java"/>
<suppress checks="CheckstyleTestMakeup" files="[\\/]ClassAnnotationsTest\.java"/>
<suppress checks="CheckstyleTestMakeup" files="[\\/]MethodsAndConstructorsAnnotationsTest\.java"/>

<!-- No need for constructor with cause -->
<suppress checks="CauseParameterInException" files=".*MetadataGenerationException\.java"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code and other text files for adherence to a set of rules.
// Copyright (C) 2001-2024 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.google.checkstyle.test.chapter4formatting.rule4853methodsandconstructorsannotations;

import org.junit.jupiter.api.Test;

import com.google.checkstyle.test.base.AbstractGoogleModuleTestSupport;

public class MethodsAndConstructorsAnnotationsTest extends AbstractGoogleModuleTestSupport {

@Override
protected String getPackageLocation() {
return "com/google/checkstyle/test/chapter4formatting/"
+ "rule4853methodsandconstructorsannotations";
}

@Test
public void testAnnotation() throws Exception {
final String filePath = getPath("InputMethodsAndConstructorsAnnotations.java");

final String[] listOfModules = {
"AnnotationLocationMostCases",
"InvalidJavadocPosition",
};

verifyWithGoogleConfigParser(listOfModules, filePath);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.google.checkstyle.test.chapter4formatting.rule4853methodsandconstructorsannotations;

public class InputMethodsAndConstructorsAnnotations {
public @interface SomeAnnotation1 { }

public @interface SomeAnnotation2 { }

// ********testing methods.***********

/**
* testing.
*/
@SomeAnnotation1
@SomeAnnotation2
void test1() {}

/**
* testing.
*/
@SomeAnnotation1 void test2() {}

/**
* testing.
*/
@SomeAnnotation1 @SomeAnnotation2
// violation above 'Annotation 'SomeAnnotation2' should be alone on line.'
void test3() {}

@SomeAnnotation1
@SomeAnnotation2
/** // violation 'Javadoc comment is placed in the wrong location.'
* testing.
*/
void test4() {}

@SomeAnnotation1 @SomeAnnotation2
// violation above 'Annotation 'SomeAnnotation2' should be alone on line.'
/** // violation 'Javadoc comment is placed in the wrong location.'
* testing.
*/
void test5() {}

@SomeAnnotation1 @SomeAnnotation2 void test6() {}
// violation above 'Annotation 'SomeAnnotation2' should be alone on line.'

@SuppressWarnings("all") void test7() {}
// violation above 'Annotation 'SuppressWarnings' should be alone on line.'

// ********testing constructors.*********

/**
* testing.
*/
@SomeAnnotation1
@SomeAnnotation2
InputMethodsAndConstructorsAnnotations() {}

/**
* testing.
*/
@SomeAnnotation1 InputMethodsAndConstructorsAnnotations(float f) {}

/**
* testing.
*/
@SomeAnnotation1 @SomeAnnotation2
// violation above 'Annotation 'SomeAnnotation2' should be alone on line.'
InputMethodsAndConstructorsAnnotations(int x) {}

@SomeAnnotation1
@SomeAnnotation2
/** // violation 'Javadoc comment is placed in the wrong location.'
* testing.
*/
InputMethodsAndConstructorsAnnotations(String str) {}

@SomeAnnotation1 @SomeAnnotation2
// violation above 'Annotation 'SomeAnnotation2' should be alone on line.'
/** // violation 'Javadoc comment is placed in the wrong location.'
* testing.
*/
InputMethodsAndConstructorsAnnotations(double d) {}

@SomeAnnotation1 @SomeAnnotation2 InputMethodsAndConstructorsAnnotations(String a,
String b) {}
// violation 2 lines above 'Annotation 'SomeAnnotation2' should be alone on line.'

@SuppressWarnings("all") InputMethodsAndConstructorsAnnotations(int x, int y) {}
// violation above 'Annotation 'SuppressWarnings' should be alone on line.'
}
37 changes: 37 additions & 0 deletions src/xdocs/google_style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,43 @@
test</a>
</td>
</tr>
<tr>
<td><a name="4.8.5.3"/>
<a href="#4.8.5.3">
<span class="wrapper inline">
<img src="images/anchor.png" alt=""/>
</span>
</a>
</td>
<td>
<a href="styleguides/google-java-style-20220203/javaguide.html#s4.8.5.3-method-annotation-style">
4.8.5.3 Methods And Constructors Annotations</a>
</td>
<td>
<span class="wrapper inline">
<img src="images/ok_green.png" alt="" />
</span>
<a href="checks/annotation/annotationlocation.html#AnnotationLocation">
AnnotationLocation</a>
<br />
<br />
<span class="wrapper inline">
<img src="images/ok_green.png" alt="" />
</span>
<a href="checks/javadoc/invalidjavadocposition.html#InvalidJavadocPosition">
InvalidJavadocPosition</a>
</td>
<td>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+AnnotationLocation">
config</a>
<br />
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+InvalidJavadocPosition">
config</a>
<br />
<a href="https://github.com/checkstyle/checkstyle/blob/master/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4853methodsandconstructorsannotations/MethodsAndConstructorsAnnotationsTest.java">
test</a>
</td>
</tr>
<tr>
<td><a name="4.8.6"/>
<a href="#4.8.6">
Expand Down

0 comments on commit 7cbfef2

Please sign in to comment.