Skip to content

Commit e0586d7

Browse files
authored
Upgrade to Java 17 (#202)
1 parent e7a24b4 commit e0586d7

19 files changed

+328
-323
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ jobs:
88
fail-fast: false
99
matrix:
1010
version:
11-
- { jdk: 11, idea: 2022.1 }
1211
- { jdk: 17, idea: 2022.2 }
1312
- { jdk: 17, idea: 2022.3 }
1413
- { jdk: 17, idea: 2023.1 }

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ apply plugin: 'license'
1818
apply plugin: 'checkstyle'
1919
apply plugin: 'jacoco'
2020

21-
sourceCompatibility = 11
22-
targetCompatibility = 11
21+
sourceCompatibility = 17
22+
targetCompatibility = 17
2323

2424
repositories {
2525
mavenLocal()

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# https://www.jetbrains.com/intellij-repository/releases
33
# https://www.jetbrains.com/intellij-repository/snapshots
44

5-
ideaVersion = 2022.1
5+
ideaVersion = 2022.2
66
ideaType = IC
77
sources = true
88
isEAP = false

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ static <T extends MapstructBaseReference> PsiReference[] create(PsiElement psiEl
170170
ReferenceCreator<T> creator, boolean supportsNested) {
171171
String targetValue;
172172
Function<String, TextRange> rangeCreator;
173-
if ( psiElement instanceof PsiReferenceExpression ) {
174-
PsiElement resolvedPsiElement = ( (PsiReferenceExpression) psiElement ).resolve();
173+
if ( psiElement instanceof PsiReferenceExpression psiReferenceExpression ) {
174+
PsiElement resolvedPsiElement = psiReferenceExpression.resolve();
175175

176176
PsiLiteralExpression expression = PsiTreeUtil.findChildOfType(
177177
resolvedPsiElement,

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,17 @@ Object[] getVariantsInternal(@NotNull PsiMethod mappingMethod) {
125125
PsiType resolvedType() {
126126
PsiElement element = resolve();
127127

128-
if ( element instanceof PsiMethod ) {
129-
return ( (PsiMethod) element ).getReturnType();
128+
if ( element instanceof PsiMethod psiMethod ) {
129+
return psiMethod.getReturnType();
130130
}
131-
else if ( element instanceof PsiParameter ) {
132-
return ( (PsiParameter) element ).getType();
131+
else if ( element instanceof PsiParameter psiParameter ) {
132+
return psiParameter.getType();
133133
}
134-
else if ( element instanceof PsiRecordComponent ) {
135-
return ( (PsiRecordComponent) element ).getType();
134+
else if ( element instanceof PsiRecordComponent psiRecordComponent ) {
135+
return psiRecordComponent.getType();
136136
}
137-
else if ( element instanceof PsiField ) {
138-
return ( (PsiField) element ).getType();
137+
else if ( element instanceof PsiField psiField ) {
138+
return psiField.getType();
139139
}
140140

141141
return null;
@@ -160,11 +160,11 @@ static PsiReference[] createNonNested(PsiElement psiElement) {
160160
}
161161

162162
private static PsiType memberPsiType(PsiElement psiMember) {
163-
if ( psiMember instanceof PsiMethod ) {
164-
return ( (PsiMethod) psiMember ).getReturnType();
163+
if ( psiMember instanceof PsiMethod psiMemberMethod ) {
164+
return psiMemberMethod.getReturnType();
165165
}
166-
else if ( psiMember instanceof PsiVariable ) {
167-
return ( (PsiVariable) psiMember ).getType();
166+
else if ( psiMember instanceof PsiVariable psiMemberVariable ) {
167+
return psiMemberVariable.getType();
168168
}
169169
else {
170170
return null;

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,17 @@ Object[] getVariantsInternal(@NotNull PsiMethod mappingMethod) {
191191
PsiType resolvedType() {
192192
PsiElement element = resolve();
193193

194-
if ( element instanceof PsiMethod ) {
195-
return firstParameterPsiType( (PsiMethod) element );
194+
if ( element instanceof PsiMethod psiMethod ) {
195+
return firstParameterPsiType( psiMethod );
196196
}
197-
else if ( element instanceof PsiParameter ) {
198-
return ( (PsiParameter) element ).getType();
197+
else if ( element instanceof PsiParameter psiParameter ) {
198+
return psiParameter.getType();
199199
}
200-
else if ( element instanceof PsiRecordComponent ) {
201-
return ( (PsiRecordComponent) element ).getType();
200+
else if ( element instanceof PsiRecordComponent psiRecordComponent ) {
201+
return psiRecordComponent.getType();
202202
}
203-
else if ( element instanceof PsiField ) {
204-
return ( (PsiField) element ).getType();
203+
else if ( element instanceof PsiField psiField ) {
204+
return psiField.getType();
205205
}
206206

207207
return null;
@@ -217,11 +217,11 @@ static PsiReference[] create(PsiElement psiElement) {
217217
}
218218

219219
private static PsiType memberPsiType(PsiElement psiMember) {
220-
if ( psiMember instanceof PsiMethod ) {
221-
return firstParameterPsiType( (PsiMethod) psiMember );
220+
if ( psiMember instanceof PsiMethod psiMemberMethod ) {
221+
return firstParameterPsiType( psiMemberMethod );
222222
}
223-
else if ( psiMember instanceof PsiVariable ) {
224-
return ( (PsiVariable) psiMember ).getType();
223+
else if ( psiMember instanceof PsiVariable psiMemberVariable ) {
224+
return psiMemberVariable.getType();
225225
}
226226
else {
227227
return null;

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,10 @@ private void importIfNecessary(PsiClass cls, @NotNull Set<String> imports) {
7070

7171
private void appendType(@NotNull StringBuilder sb, @NotNull Set<String> imports, @NotNull PsiType type) {
7272
importIfNecessary( PsiUtil.resolveClassInType( type ), imports );
73-
if ( !( type instanceof PsiClassType ) ) {
73+
if ( !( type instanceof PsiClassType ct ) ) {
7474
sb.append( type.getPresentableText() );
7575
return;
7676
}
77-
PsiClassType ct = (PsiClassType) type;
7877
sb.append( ct.getName() );
7978
PsiType[] typeParameters = ct.getParameters();
8079
if ( typeParameters.length == 0 ) {
@@ -178,18 +177,18 @@ public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull
178177
attributeValue );
179178
if ( references.length > 0 ) {
180179
PsiElement resolved = references[0].resolve();
181-
if ( resolved instanceof PsiMethod ) {
180+
if ( resolved instanceof PsiMethod resolvedPsiMethod ) {
182181
PsiParameter[] psiParameters =
183-
((PsiMethod) resolved).getParameterList().getParameters();
182+
resolvedPsiMethod.getParameterList().getParameters();
184183
if ( psiParameters.length > 0) {
185184
targetType = psiParameters[0].getType();
186185
}
187186
}
188-
else if ( resolved instanceof PsiParameter ) {
189-
targetType = ( (PsiParameter) resolved ).getType();
187+
else if ( resolved instanceof PsiParameter resolvedPsiParameter ) {
188+
targetType = resolvedPsiParameter.getType();
190189
}
191-
else if ( resolved instanceof PsiField) {
192-
targetType = ( (PsiField) resolved ).getType();
190+
else if ( resolved instanceof PsiField resolvedPsiField ) {
191+
targetType = resolvedPsiField.getType();
193192
}
194193
}
195194
}
@@ -259,12 +258,13 @@ else if ( resolved instanceof PsiField) {
259258
for ( PsiAnnotationMemberValue importValue : AnnotationUtil.arrayAttributeValues(
260259
attribute.getValue() ) ) {
261260

262-
if ( importValue instanceof PsiJavaCodeReferenceElement ) {
263-
imports.add( ( (PsiJavaCodeReferenceElement) importValue ).getQualifiedName() );
261+
if ( importValue instanceof PsiJavaCodeReferenceElement importJavaCodeReferenceElement ) {
262+
imports.add( importJavaCodeReferenceElement.getQualifiedName() );
264263
}
265-
else if ( importValue instanceof PsiClassObjectAccessExpression ) {
264+
else if ( importValue instanceof PsiClassObjectAccessExpression
265+
importClassObjectAccessExpression ) {
266266
PsiJavaCodeReferenceElement referenceElement =
267-
( (PsiClassObjectAccessExpression) importValue ).getOperand()
267+
importClassObjectAccessExpression.getOperand()
268268
.getInnermostComponentReferenceElement();
269269
if ( referenceElement != null ) {
270270
imports.add( referenceElement.getQualifiedName() );

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file,
133133
if (!super.isAvailable( project, file, startElement, endElement ) ) {
134134
return false;
135135
}
136-
if (startElement instanceof PsiParameter) {
137-
PsiParameter parameter = (PsiParameter) startElement;
136+
if (startElement instanceof PsiParameter parameter) {
138137
PsiType[] parameters = getGenericTypes( parameter );
139138
return parameters != null && parameters.length == 0;
140139
}
@@ -179,8 +178,7 @@ public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file,
179178
if (!super.isAvailable( project, file, startElement, endElement ) ) {
180179
return false;
181180
}
182-
if (startElement instanceof PsiParameter) {
183-
PsiParameter parameter = (PsiParameter) startElement;
181+
if (startElement instanceof PsiParameter parameter) {
184182
PsiType[] parameters = getGenericTypes( parameter );
185183
if (parameters == null || parameters.length != 2) {
186184
return false;

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ 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) {
84-
PsiNameValuePair psiNameValuePair = (PsiNameValuePair) psiElement;
83+
if (psiElement instanceof PsiNameValuePair psiNameValuePair) {
8584
PsiAnnotationMemberValue value = psiNameValuePair.getValue();
8685
if (value != null) {
8786
String text = value.getText();
@@ -102,10 +101,10 @@ public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file, @Not
102101
if ( !super.isAvailable( project, file, startElement, endElement ) ) {
103102
return false;
104103
}
105-
if ( !(startElement instanceof PsiNameValuePair ) ) {
104+
if ( !(startElement instanceof PsiNameValuePair startPsiNameValuePair ) ) {
106105
return false;
107106
}
108-
return ((PsiNameValuePair) startElement).getValue() != null;
107+
return startPsiNameValuePair.getValue() != null;
109108
}
110109
}
111110

@@ -126,8 +125,7 @@ private RemoveWhitespacesAfter(@NotNull PsiNameValuePair element) {
126125
@Override
127126
public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @NotNull PsiElement psiElement,
128127
@NotNull PsiElement psiElement1) {
129-
if (psiElement instanceof PsiNameValuePair) {
130-
PsiNameValuePair psiNameValuePair = (PsiNameValuePair) psiElement;
128+
if (psiElement instanceof PsiNameValuePair psiNameValuePair) {
131129
PsiAnnotationMemberValue value = psiNameValuePair.getValue();
132130
if (value != null) {
133131
String text = value.getText();
@@ -148,10 +146,10 @@ public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file, @Not
148146
if ( !super.isAvailable( project, file, startElement, endElement ) ) {
149147
return false;
150148
}
151-
if ( !(startElement instanceof PsiNameValuePair ) ) {
149+
if ( !(startElement instanceof PsiNameValuePair startPsiNameValuePair ) ) {
152150
return false;
153151
}
154-
return ((PsiNameValuePair) startElement).getValue() != null;
152+
return startPsiNameValuePair.getValue() != null;
155153
}
156154
}
157155
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ public void visitAnnotation(@NotNull PsiAnnotation annotation ) {
4444
MappingAnnotation mappingAnnotation = new MappingAnnotation();
4545
for (JvmAnnotationAttribute annotationAttribute : annotation.getAttributes()) {
4646
// exclude not written attributes. They result in a syntax error
47-
if (annotationAttribute instanceof PsiNameValuePair
47+
if (annotationAttribute instanceof PsiNameValuePair nameValuePair
4848
&& annotationAttribute.getAttributeValue() != null) {
49-
PsiNameValuePair nameValuePair = (PsiNameValuePair) annotationAttribute;
5049
switch (nameValuePair.getAttributeName()) {
5150
case "target" :
5251
mappingAnnotation.setTargetProperty( nameValuePair );
@@ -285,8 +284,7 @@ public boolean isAvailable( @NotNull Project project, @NotNull PsiFile file, @No
285284
@Override
286285
public void invoke( @NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement,
287286
@NotNull PsiElement endElement ) {
288-
if (endElement instanceof PsiNameValuePair) {
289-
PsiNameValuePair end = (PsiNameValuePair) endElement;
287+
if (endElement instanceof PsiNameValuePair end) {
290288
PsiAnnotationParamListImpl parent = (PsiAnnotationParamListImpl) end.getParent();
291289
PsiElement parent1 = parent.getParent();
292290

0 commit comments

Comments
 (0)