Skip to content

Commit 76500d2

Browse files
committed
apply new checkstyle rules
1 parent c069b5a commit 76500d2

35 files changed

Lines changed: 148 additions & 147 deletions

File tree

src/main/java/org/mapstruct/intellij/codeinsight/references/MappingTargetReferenceProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
*/
66
package org.mapstruct.intellij.codeinsight.references;
77

8+
import java.util.function.Function;
9+
810
import com.intellij.psi.PsiElement;
911
import com.intellij.psi.PsiReference;
1012
import com.intellij.psi.PsiReferenceProvider;
1113
import com.intellij.util.ProcessingContext;
1214
import org.jetbrains.annotations.NotNull;
1315

14-
import java.util.function.Function;
15-
1616
/**
1717
* {@link PsiReferenceProvider} for references in target / source properties of {@link org.mapstruct.Mapping}.
1818
*

src/main/java/org/mapstruct/intellij/codeinsight/references/MapstructMappingQualifiedByNameReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
import static com.intellij.codeInsight.AnnotationUtil.findAnnotation;
3232
import static com.intellij.codeInsight.AnnotationUtil.getStringAttributeValue;
3333
import static org.mapstruct.intellij.util.MapstructAnnotationUtils.findReferencedMapperClasses;
34-
import static org.mapstruct.intellij.util.MapstructUtil.NAMED_ANNOTATION_FQN;
3534
import static org.mapstruct.intellij.util.MapstructUtil.MAPPER_ANNOTATION_FQN;
3635
import static org.mapstruct.intellij.util.MapstructUtil.MAPPER_CONFIG_ANNOTATION_FQN;
36+
import static org.mapstruct.intellij.util.MapstructUtil.NAMED_ANNOTATION_FQN;
3737
import static org.mapstruct.intellij.util.MapstructUtil.asLookupWithRepresentableText;
3838

3939
/**

src/main/java/org/mapstruct/intellij/codeinsight/references/MapstructSourceReference.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
package org.mapstruct.intellij.codeinsight.references;
77

8+
import java.util.Objects;
9+
import java.util.stream.Stream;
10+
811
import com.intellij.codeInsight.lookup.LookupElement;
912
import com.intellij.openapi.util.TextRange;
1013
import com.intellij.psi.PsiClass;
@@ -21,9 +24,6 @@
2124
import org.jetbrains.annotations.Nullable;
2225
import org.mapstruct.intellij.util.MapstructUtil;
2326

24-
import java.util.Objects;
25-
import java.util.stream.Stream;
26-
2727
import static org.mapstruct.intellij.util.MapstructUtil.asLookup;
2828
import static org.mapstruct.intellij.util.MapstructUtil.findRecordComponent;
2929
import static org.mapstruct.intellij.util.MapstructUtil.isPublicNonStatic;

src/main/java/org/mapstruct/intellij/codeinsight/references/MapstructTargetReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Object[] getVariantsInternal(@NotNull PsiType psiType) {
167167
mappingMethod
168168
);
169169

170-
if (mappingMethod != null) {
170+
if ( mappingMethod != null ) {
171171
Stream<String> allDefinedMappingTargets = findAllDefinedMappingTargets( mappingMethod );
172172
allDefinedMappingTargets.forEach( accessors::remove );
173173
}

src/main/java/org/mapstruct/intellij/expression/JavaExpressionInjector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull
180180
if ( resolved instanceof PsiMethod resolvedPsiMethod ) {
181181
PsiParameter[] psiParameters =
182182
resolvedPsiMethod.getParameterList().getParameters();
183-
if ( psiParameters.length > 0) {
183+
if ( psiParameters.length > 0 ) {
184184
targetType = psiParameters[0].getType();
185185
}
186186
}

src/main/java/org/mapstruct/intellij/inspection/FromMapMappingMapTypeInspection.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
package org.mapstruct.intellij.inspection;
77

8+
import java.util.Set;
9+
810
import com.intellij.codeInspection.LocalQuickFixOnPsiElement;
911
import com.intellij.codeInspection.ProblemsHolder;
1012
import com.intellij.codeInspection.util.IntentionFamilyName;
@@ -23,8 +25,6 @@
2325
import org.mapstruct.intellij.util.MapStructVersion;
2426
import org.mapstruct.intellij.util.MapstructUtil;
2527

26-
import java.util.Set;
27-
2828
import static com.intellij.psi.PsiElementFactory.getInstance;
2929
import static org.mapstruct.intellij.util.MapstructUtil.getSourceParameters;
3030
import static org.mapstruct.intellij.util.SourceUtils.findAllDefinedMappingSources;
@@ -63,21 +63,21 @@ private MyJavaElementVisitor(ProblemsHolder holder, MapStructVersion mapStructVe
6363
public void visitMethod(@NotNull PsiMethod method) {
6464
super.visitMethod( method );
6565

66-
if (!MapstructUtil.isMapper( method.getContainingClass() ) ) {
66+
if ( !MapstructUtil.isMapper( method.getContainingClass() ) ) {
6767
return;
6868
}
6969

7070
PsiType targetType = getTargetType( method );
71-
if (targetType == null) {
71+
if ( targetType == null ) {
7272
return;
7373
}
7474

7575
PsiParameter fromMapMappingParameter = getFromMapMappingParameter( method );
76-
if (fromMapMappingParameter == null) {
76+
if ( fromMapMappingParameter == null ) {
7777
return;
7878
}
7979
PsiType[] parameters = getGenericTypes( fromMapMappingParameter );
80-
if (parameters == null) {
80+
if ( parameters == null ) {
8181
return;
8282
}
8383
Set<String> allTargetProperties = findAllTargetProperties(
@@ -93,13 +93,13 @@ public void visitMethod(@NotNull PsiMethod method) {
9393
.anyMatch( source -> fromMapMappingParameter.getName().equals( source ) ) ) {
9494
return;
9595
}
96-
if (parameters.length == 0) {
96+
if ( parameters.length == 0 ) {
9797
// handle raw type
9898
holder.registerProblem( fromMapMappingParameter,
9999
MapStructBundle.message( "inspection.wrong.map.mapping.map.type.raw" ),
100100
new ReplaceByStringStringMapTypeFix( fromMapMappingParameter ) );
101101
}
102-
else if (parameters.length == 2) {
102+
else if ( parameters.length == 2 ) {
103103
// only if both parameters of the map are set
104104
PsiType keyParameter = parameters[0];
105105
if ( !keyParameter.equalsToText( "java.lang.String" ) ) {
@@ -114,9 +114,9 @@ else if (parameters.length == 2) {
114114
@Nullable
115115
private static PsiParameter getFromMapMappingParameter(@NotNull PsiMethod method) {
116116
PsiParameter[] sourceParameters = getSourceParameters( method );
117-
if (sourceParameters.length == 1) {
117+
if ( sourceParameters.length == 1 ) {
118118
PsiParameter parameter = sourceParameters[0];
119-
if (parameter != null && PsiType.getTypeByName( "java.util.Map", method.getProject(),
119+
if ( parameter != null && PsiType.getTypeByName( "java.util.Map", method.getProject(),
120120
method.getResolveScope() ).isAssignableFrom( parameter.getType() ) ) {
121121
return parameter;
122122
}
@@ -142,10 +142,10 @@ private ReplaceByStringStringMapTypeFix(@NotNull PsiParameter element) {
142142
@Override
143143
public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file,
144144
@NotNull PsiElement startElement, @NotNull PsiElement endElement) {
145-
if (!super.isAvailable( project, file, startElement, endElement ) ) {
145+
if ( !super.isAvailable( project, file, startElement, endElement ) ) {
146146
return false;
147147
}
148-
if (startElement instanceof PsiParameter parameter) {
148+
if ( startElement instanceof PsiParameter parameter ) {
149149
PsiType[] parameters = getGenericTypes( parameter );
150150
return parameters != null && parameters.length == 0;
151151
}
@@ -155,7 +155,7 @@ public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file,
155155
@Override
156156
public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @NotNull PsiElement psiElement,
157157
@NotNull PsiElement psiElement1) {
158-
if (psiElement instanceof PsiParameter) {
158+
if ( psiElement instanceof PsiParameter ) {
159159
String mapText = psiElement.getText();
160160
String prefix = mapText.substring( 0, mapText.indexOf( ' ' ) );
161161
String end = mapText.substring( mapText.lastIndexOf( ' ' ) );
@@ -187,12 +187,12 @@ private ReplaceMapKeyByStringTypeFix(@NotNull PsiParameter element) {
187187
@Override
188188
public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file,
189189
@NotNull PsiElement startElement, @NotNull PsiElement endElement) {
190-
if (!super.isAvailable( project, file, startElement, endElement ) ) {
190+
if ( !super.isAvailable( project, file, startElement, endElement ) ) {
191191
return false;
192192
}
193-
if (startElement instanceof PsiParameter parameter) {
193+
if ( startElement instanceof PsiParameter parameter ) {
194194
PsiType[] parameters = getGenericTypes( parameter );
195-
if (parameters == null || parameters.length != 2) {
195+
if ( parameters == null || parameters.length != 2 ) {
196196
return false;
197197
}
198198
return !parameters[0].equalsToText( "java.lang.String" );
@@ -203,7 +203,7 @@ public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file,
203203
@Override
204204
public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @NotNull PsiElement psiElement,
205205
@NotNull PsiElement psiElement1) {
206-
if (psiElement instanceof PsiParameter) {
206+
if ( psiElement instanceof PsiParameter ) {
207207
String mapText = psiElement.getText();
208208
String prefix = mapText.substring( 0, mapText.indexOf( '<' ) + 1 );
209209
String end = mapText.substring( mapText.indexOf( ',' ) );

src/main/java/org/mapstruct/intellij/inspection/JavaExpressionUnnecessaryWhitespacesInspector.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private void inspectUnnecessaryWhitespaces(@NotNull ProblemsHolder problemsHolde
4444
if ( !JAVA_EXPRESSION.matcher( text ).matches() ) {
4545
return;
4646
}
47-
if ( text.charAt( 1 ) == '"') {
47+
if ( text.charAt( 1 ) == '"' ) {
4848
// Text-Block
4949
return;
5050
}
@@ -54,7 +54,7 @@ private void inspectUnnecessaryWhitespaces(@NotNull ProblemsHolder problemsHolde
5454
"before", property.getAttributeName() ),
5555
ProblemHighlightType.WEAK_WARNING, new RemoveWhitespacesBefore(property) );
5656
}
57-
if ( text.lastIndexOf( ')' ) < text.length() - 2) {
57+
if ( text.lastIndexOf( ')' ) < text.length() - 2 ) {
5858
problemsHolder.registerProblem( property,
5959
MapStructBundle.message( "inspection.java.expression.unnecessary.whitespace",
6060
"after", property.getAttributeName() ),
@@ -80,9 +80,9 @@ private RemoveWhitespacesBefore(@NotNull PsiNameValuePair element) {
8080
@Override
8181
public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @NotNull PsiElement psiElement,
8282
@NotNull PsiElement psiElement1) {
83-
if (psiElement instanceof PsiNameValuePair psiNameValuePair) {
83+
if ( psiElement instanceof PsiNameValuePair psiNameValuePair ) {
8484
PsiAnnotationMemberValue value = psiNameValuePair.getValue();
85-
if (value != null) {
85+
if ( value != null ) {
8686
String text = value.getText();
8787
psiNameValuePair.setValue( getInstance( project )
8888
.createExpressionFromText( "\"" + text.substring( text.indexOf( "java(" ) ), value ) );
@@ -125,9 +125,9 @@ private RemoveWhitespacesAfter(@NotNull PsiNameValuePair element) {
125125
@Override
126126
public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @NotNull PsiElement psiElement,
127127
@NotNull PsiElement psiElement1) {
128-
if (psiElement instanceof PsiNameValuePair psiNameValuePair) {
128+
if ( psiElement instanceof PsiNameValuePair psiNameValuePair ) {
129129
PsiAnnotationMemberValue value = psiNameValuePair.getValue();
130-
if (value != null) {
130+
if ( value != null ) {
131131
String text = value.getText();
132132
psiNameValuePair.setValue( getInstance( project ).createExpressionFromText(
133133
text.substring( 0, text.lastIndexOf( ')' ) + 1 ) + "\"", value ) );

src/main/java/org/mapstruct/intellij/inspection/MappingAnnotationInspectionBase.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ private MyJavaElementVisitor( ProblemsHolder problemsHolder ) {
4040
@Override
4141
public void visitAnnotation(@NotNull PsiAnnotation annotation ) {
4242
super.visitAnnotation( annotation );
43-
if (annotation.hasQualifiedName( MapstructUtil.MAPPING_ANNOTATION_FQN )) {
43+
if ( annotation.hasQualifiedName( MapstructUtil.MAPPING_ANNOTATION_FQN ) ) {
4444
MappingAnnotation mappingAnnotation = new MappingAnnotation();
45-
for (JvmAnnotationAttribute annotationAttribute : annotation.getAttributes()) {
45+
for ( JvmAnnotationAttribute annotationAttribute : annotation.getAttributes() ) {
4646
// exclude not written attributes. They result in a syntax error
47-
if (annotationAttribute instanceof PsiNameValuePair nameValuePair
48-
&& annotationAttribute.getAttributeValue() != null) {
49-
switch (nameValuePair.getAttributeName()) {
47+
if ( annotationAttribute instanceof PsiNameValuePair nameValuePair
48+
&& annotationAttribute.getAttributeValue() != null ) {
49+
switch ( nameValuePair.getAttributeName() ) {
5050
case "target" :
5151
mappingAnnotation.setTargetProperty( nameValuePair );
5252
break;
@@ -284,7 +284,7 @@ public boolean isAvailable( @NotNull Project project, @NotNull PsiFile file, @No
284284
@Override
285285
public void invoke( @NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement,
286286
@NotNull PsiElement endElement ) {
287-
if (endElement instanceof PsiNameValuePair end) {
287+
if ( endElement instanceof PsiNameValuePair end ) {
288288
PsiAnnotationParamListImpl parent = (PsiAnnotationParamListImpl) end.getParent();
289289
PsiElement parent1 = parent.getParent();
290290

src/main/java/org/mapstruct/intellij/inspection/MapstructReferenceInspection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ private MapstructReferenceVisitor(ProblemsHolder holder) {
4444
*/
4545
@Override
4646
public void visitElement(@NotNull PsiElement element) {
47-
if (element instanceof ContributedReferenceHost r && element instanceof PsiLanguageInjectionHost) {
48-
for (PsiReference psiReference : r.getReferences()) {
47+
if ( element instanceof ContributedReferenceHost r && element instanceof PsiLanguageInjectionHost ) {
48+
for ( PsiReference psiReference : r.getReferences() ) {
4949
if ( psiReference instanceof BaseReference baseReference && psiReference.resolve() == null ) {
5050
TextRange range = psiReference.getRangeInElement();
51-
if (range.isEmpty() && range.getStartOffset() == 1 && "\"\"".equals( element.getText() ) ) {
51+
if ( range.isEmpty() && range.getStartOffset() == 1 && "\"\"".equals( element.getText() ) ) {
5252
String message = ProblemsHolder.unresolvedReferenceMessage( baseReference );
5353
holder.registerProblem( element, message, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL,
5454
TextRange.create( 0, 2 ) );

src/main/java/org/mapstruct/intellij/inspection/MoreThanOneDefaultSourcePropertyDefinedInspection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class MoreThanOneDefaultSourcePropertyDefinedInspection extends MappingAn
2121
void visitMappingAnnotation( @NotNull ProblemsHolder problemsHolder, @NotNull PsiAnnotation psiAnnotation,
2222
@NotNull MappingAnnotation mappingAnnotation ) {
2323
// only apply if source property is defined
24-
if (mappingAnnotation.getSourceProperty() != null && mappingAnnotation.getDefaultValueProperty() != null
25-
&& mappingAnnotation.getDefaultExpressionProperty() != null) {
24+
if ( mappingAnnotation.getSourceProperty() != null && mappingAnnotation.getDefaultValueProperty() != null
25+
&& mappingAnnotation.getDefaultExpressionProperty() != null ) {
2626
String family = MapStructBundle.message( "intention.more.than.one.default.source.property" );
2727
problemsHolder.registerProblem( psiAnnotation,
2828
MapStructBundle.message( "inspection.more.than.one.default.source.property" ),

0 commit comments

Comments
 (0)