Skip to content

Commit 4f4e08a

Browse files
committed
Ignore fully-qualified annotation in attribute value concision check
Closes gh-455
1 parent 3a3e69d commit 4f4e08a

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringAnnotationAttributeConciseValueCheck.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,26 @@ private void visitMemberValuePair(DetailAST annotationValue) {
9595
}
9696

9797
private void visitValueExpression(DetailAST valueExpression, DetailAST annotation, String attributeName) {
98-
if (valueExpression != null && valueExpression.getChildCount() == 1) {
99-
List<String> expressionComponents = dotSeparatedComponents(valueExpression.getFirstChild());
100-
if (expressionComponents != null && expressionComponents.size() > 2) {
101-
String outerTypeName = expressionComponents.get(0);
102-
String annotationName = annotation.findFirstToken(TokenTypes.IDENT).getText();
103-
if (outerTypeName.equals(annotationName)) {
104-
String innerTypeName = expressionComponents.get(1);
105-
if (!existingClashingImport(outerTypeName, innerTypeName)) {
106-
String toImport = outerTypeName + "." + innerTypeName;
107-
String replacement = String.join(".", expressionComponents.subList(1, expressionComponents.size()));
108-
log(valueExpression.getLineNo(), valueExpression.getColumnNo(),
109-
"annotation.attribute.overlyVerboseValue", attributeName, toImport, replacement);
110-
}
111-
}
98+
if (valueExpression == null || valueExpression.getChildCount() != 1) {
99+
return;
100+
}
101+
List<String> expressionComponents = dotSeparatedComponents(valueExpression.getFirstChild());
102+
if (expressionComponents == null || expressionComponents.size() <= 2) {
103+
return;
104+
}
105+
String outerTypeName = expressionComponents.get(0);
106+
DetailAST annotationIdent = annotation.findFirstToken(TokenTypes.IDENT);
107+
if (annotationIdent == null) {
108+
return;
109+
}
110+
String annotationName = annotationIdent.getText();
111+
if (outerTypeName.equals(annotationName)) {
112+
String innerTypeName = expressionComponents.get(1);
113+
if (!existingClashingImport(outerTypeName, innerTypeName)) {
114+
String toImport = outerTypeName + "." + innerTypeName;
115+
String replacement = String.join(".", expressionComponents.subList(1, expressionComponents.size()));
116+
log(valueExpression.getLineNo(), valueExpression.getColumnNo(),
117+
"annotation.attribute.overlyVerboseValue", attributeName, toImport, replacement);
112118
}
113119
}
114120
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
+0 errors
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2017-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
@com.example.web.condition.ConditionalOnWebApplicationType(type = WebApplicationType.A.B.C.D.SERVLET)
18+
public class AnnotationWithFullyQualifiedNameAndNamedAttributeWithValueThatHasConciseReferenceToContainedEnumValue {
19+
20+
}

0 commit comments

Comments
 (0)