Skip to content

Commit

Permalink
Upgrade to Java 17 (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
hduelme authored Jul 21, 2024
1 parent e7a24b4 commit e0586d7
Show file tree
Hide file tree
Showing 19 changed files with 328 additions and 323 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ jobs:
fail-fast: false
matrix:
version:
- { jdk: 11, idea: 2022.1 }
- { jdk: 17, idea: 2022.2 }
- { jdk: 17, idea: 2022.3 }
- { jdk: 17, idea: 2023.1 }
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ apply plugin: 'license'
apply plugin: 'checkstyle'
apply plugin: 'jacoco'

sourceCompatibility = 11
targetCompatibility = 11
sourceCompatibility = 17
targetCompatibility = 17

repositories {
mavenLocal()
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://www.jetbrains.com/intellij-repository/releases
# https://www.jetbrains.com/intellij-repository/snapshots

ideaVersion = 2022.1
ideaVersion = 2022.2
ideaType = IC
sources = true
isEAP = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ static <T extends MapstructBaseReference> PsiReference[] create(PsiElement psiEl
ReferenceCreator<T> creator, boolean supportsNested) {
String targetValue;
Function<String, TextRange> rangeCreator;
if ( psiElement instanceof PsiReferenceExpression ) {
PsiElement resolvedPsiElement = ( (PsiReferenceExpression) psiElement ).resolve();
if ( psiElement instanceof PsiReferenceExpression psiReferenceExpression ) {
PsiElement resolvedPsiElement = psiReferenceExpression.resolve();

PsiLiteralExpression expression = PsiTreeUtil.findChildOfType(
resolvedPsiElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,17 @@ Object[] getVariantsInternal(@NotNull PsiMethod mappingMethod) {
PsiType resolvedType() {
PsiElement element = resolve();

if ( element instanceof PsiMethod ) {
return ( (PsiMethod) element ).getReturnType();
if ( element instanceof PsiMethod psiMethod ) {
return psiMethod.getReturnType();
}
else if ( element instanceof PsiParameter ) {
return ( (PsiParameter) element ).getType();
else if ( element instanceof PsiParameter psiParameter ) {
return psiParameter.getType();
}
else if ( element instanceof PsiRecordComponent ) {
return ( (PsiRecordComponent) element ).getType();
else if ( element instanceof PsiRecordComponent psiRecordComponent ) {
return psiRecordComponent.getType();
}
else if ( element instanceof PsiField ) {
return ( (PsiField) element ).getType();
else if ( element instanceof PsiField psiField ) {
return psiField.getType();
}

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

private static PsiType memberPsiType(PsiElement psiMember) {
if ( psiMember instanceof PsiMethod ) {
return ( (PsiMethod) psiMember ).getReturnType();
if ( psiMember instanceof PsiMethod psiMemberMethod ) {
return psiMemberMethod.getReturnType();
}
else if ( psiMember instanceof PsiVariable ) {
return ( (PsiVariable) psiMember ).getType();
else if ( psiMember instanceof PsiVariable psiMemberVariable ) {
return psiMemberVariable.getType();
}
else {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,17 @@ Object[] getVariantsInternal(@NotNull PsiMethod mappingMethod) {
PsiType resolvedType() {
PsiElement element = resolve();

if ( element instanceof PsiMethod ) {
return firstParameterPsiType( (PsiMethod) element );
if ( element instanceof PsiMethod psiMethod ) {
return firstParameterPsiType( psiMethod );
}
else if ( element instanceof PsiParameter ) {
return ( (PsiParameter) element ).getType();
else if ( element instanceof PsiParameter psiParameter ) {
return psiParameter.getType();
}
else if ( element instanceof PsiRecordComponent ) {
return ( (PsiRecordComponent) element ).getType();
else if ( element instanceof PsiRecordComponent psiRecordComponent ) {
return psiRecordComponent.getType();
}
else if ( element instanceof PsiField ) {
return ( (PsiField) element ).getType();
else if ( element instanceof PsiField psiField ) {
return psiField.getType();
}

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

private static PsiType memberPsiType(PsiElement psiMember) {
if ( psiMember instanceof PsiMethod ) {
return firstParameterPsiType( (PsiMethod) psiMember );
if ( psiMember instanceof PsiMethod psiMemberMethod ) {
return firstParameterPsiType( psiMemberMethod );
}
else if ( psiMember instanceof PsiVariable ) {
return ( (PsiVariable) psiMember ).getType();
else if ( psiMember instanceof PsiVariable psiMemberVariable ) {
return psiMemberVariable.getType();
}
else {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ private void importIfNecessary(PsiClass cls, @NotNull Set<String> imports) {

private void appendType(@NotNull StringBuilder sb, @NotNull Set<String> imports, @NotNull PsiType type) {
importIfNecessary( PsiUtil.resolveClassInType( type ), imports );
if ( !( type instanceof PsiClassType ) ) {
if ( !( type instanceof PsiClassType ct ) ) {
sb.append( type.getPresentableText() );
return;
}
PsiClassType ct = (PsiClassType) type;
sb.append( ct.getName() );
PsiType[] typeParameters = ct.getParameters();
if ( typeParameters.length == 0 ) {
Expand Down Expand Up @@ -178,18 +177,18 @@ public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull
attributeValue );
if ( references.length > 0 ) {
PsiElement resolved = references[0].resolve();
if ( resolved instanceof PsiMethod ) {
if ( resolved instanceof PsiMethod resolvedPsiMethod ) {
PsiParameter[] psiParameters =
((PsiMethod) resolved).getParameterList().getParameters();
resolvedPsiMethod.getParameterList().getParameters();
if ( psiParameters.length > 0) {
targetType = psiParameters[0].getType();
}
}
else if ( resolved instanceof PsiParameter ) {
targetType = ( (PsiParameter) resolved ).getType();
else if ( resolved instanceof PsiParameter resolvedPsiParameter ) {
targetType = resolvedPsiParameter.getType();
}
else if ( resolved instanceof PsiField) {
targetType = ( (PsiField) resolved ).getType();
else if ( resolved instanceof PsiField resolvedPsiField ) {
targetType = resolvedPsiField.getType();
}
}
}
Expand Down Expand Up @@ -259,12 +258,13 @@ else if ( resolved instanceof PsiField) {
for ( PsiAnnotationMemberValue importValue : AnnotationUtil.arrayAttributeValues(
attribute.getValue() ) ) {

if ( importValue instanceof PsiJavaCodeReferenceElement ) {
imports.add( ( (PsiJavaCodeReferenceElement) importValue ).getQualifiedName() );
if ( importValue instanceof PsiJavaCodeReferenceElement importJavaCodeReferenceElement ) {
imports.add( importJavaCodeReferenceElement.getQualifiedName() );
}
else if ( importValue instanceof PsiClassObjectAccessExpression ) {
else if ( importValue instanceof PsiClassObjectAccessExpression
importClassObjectAccessExpression ) {
PsiJavaCodeReferenceElement referenceElement =
( (PsiClassObjectAccessExpression) importValue ).getOperand()
importClassObjectAccessExpression.getOperand()
.getInnermostComponentReferenceElement();
if ( referenceElement != null ) {
imports.add( referenceElement.getQualifiedName() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file,
if (!super.isAvailable( project, file, startElement, endElement ) ) {
return false;
}
if (startElement instanceof PsiParameter) {
PsiParameter parameter = (PsiParameter) startElement;
if (startElement instanceof PsiParameter parameter) {
PsiType[] parameters = getGenericTypes( parameter );
return parameters != null && parameters.length == 0;
}
Expand Down Expand Up @@ -179,8 +178,7 @@ public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file,
if (!super.isAvailable( project, file, startElement, endElement ) ) {
return false;
}
if (startElement instanceof PsiParameter) {
PsiParameter parameter = (PsiParameter) startElement;
if (startElement instanceof PsiParameter parameter) {
PsiType[] parameters = getGenericTypes( parameter );
if (parameters == null || parameters.length != 2) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ private RemoveWhitespacesBefore(@NotNull PsiNameValuePair element) {
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @NotNull PsiElement psiElement,
@NotNull PsiElement psiElement1) {
if (psiElement instanceof PsiNameValuePair) {
PsiNameValuePair psiNameValuePair = (PsiNameValuePair) psiElement;
if (psiElement instanceof PsiNameValuePair psiNameValuePair) {
PsiAnnotationMemberValue value = psiNameValuePair.getValue();
if (value != null) {
String text = value.getText();
Expand All @@ -102,10 +101,10 @@ public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file, @Not
if ( !super.isAvailable( project, file, startElement, endElement ) ) {
return false;
}
if ( !(startElement instanceof PsiNameValuePair ) ) {
if ( !(startElement instanceof PsiNameValuePair startPsiNameValuePair ) ) {
return false;
}
return ((PsiNameValuePair) startElement).getValue() != null;
return startPsiNameValuePair.getValue() != null;
}
}

Expand All @@ -126,8 +125,7 @@ private RemoveWhitespacesAfter(@NotNull PsiNameValuePair element) {
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @NotNull PsiElement psiElement,
@NotNull PsiElement psiElement1) {
if (psiElement instanceof PsiNameValuePair) {
PsiNameValuePair psiNameValuePair = (PsiNameValuePair) psiElement;
if (psiElement instanceof PsiNameValuePair psiNameValuePair) {
PsiAnnotationMemberValue value = psiNameValuePair.getValue();
if (value != null) {
String text = value.getText();
Expand All @@ -148,10 +146,10 @@ public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file, @Not
if ( !super.isAvailable( project, file, startElement, endElement ) ) {
return false;
}
if ( !(startElement instanceof PsiNameValuePair ) ) {
if ( !(startElement instanceof PsiNameValuePair startPsiNameValuePair ) ) {
return false;
}
return ((PsiNameValuePair) startElement).getValue() != null;
return startPsiNameValuePair.getValue() != null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ public void visitAnnotation(@NotNull PsiAnnotation annotation ) {
MappingAnnotation mappingAnnotation = new MappingAnnotation();
for (JvmAnnotationAttribute annotationAttribute : annotation.getAttributes()) {
// exclude not written attributes. They result in a syntax error
if (annotationAttribute instanceof PsiNameValuePair
if (annotationAttribute instanceof PsiNameValuePair nameValuePair
&& annotationAttribute.getAttributeValue() != null) {
PsiNameValuePair nameValuePair = (PsiNameValuePair) annotationAttribute;
switch (nameValuePair.getAttributeName()) {
case "target" :
mappingAnnotation.setTargetProperty( nameValuePair );
Expand Down Expand Up @@ -285,8 +284,7 @@ public boolean isAvailable( @NotNull Project project, @NotNull PsiFile file, @No
@Override
public void invoke( @NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement,
@NotNull PsiElement endElement ) {
if (endElement instanceof PsiNameValuePair) {
PsiNameValuePair end = (PsiNameValuePair) endElement;
if (endElement instanceof PsiNameValuePair end) {
PsiAnnotationParamListImpl parent = (PsiAnnotationParamListImpl) end.getParent();
PsiElement parent1 = parent.getParent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ public void visitMethodCallExpression(PsiMethodCallExpression expression) {
if ( MAPPERS_FACTORY_CALL_MATCHER.test( expression ) ) {
PsiExpression argument = PsiUtil.skipParenthesizedExprDown( expression.getArgumentList()
.getExpressions()[0] );
if ( !( argument instanceof PsiClassObjectAccessExpression ) ) {
if ( !( argument instanceof PsiClassObjectAccessExpression classObjectAccessExpression ) ) {
return;
}
PsiClassObjectAccessExpression classObjectAccessExpression = (PsiClassObjectAccessExpression) argument;
PsiJavaCodeReferenceElement referenceElement = classObjectAccessExpression.getOperand()
.getInnermostComponentReferenceElement();

Expand All @@ -79,11 +78,10 @@ public void visitMethodCallExpression(PsiMethodCallExpression expression) {

PsiElement mapperElement = referenceElement.resolve();

if ( !( mapperElement instanceof PsiClass ) ) {
if ( !( mapperElement instanceof PsiClass mapperClass ) ) {
return;
}

PsiClass mapperClass = (PsiClass) mapperElement;
PsiAnnotation mapperAnnotation = mapperClass.getAnnotation( MapstructUtil.MAPPER_ANNOTATION_FQN );
if ( mapperAnnotation == null ) {
List<LocalQuickFix> fixes = new ArrayList<>(2);
Expand Down Expand Up @@ -165,9 +163,9 @@ public String getFamilyName() {

private static LocalQuickFix createRemoveMappersFix(@NotNull PsiMethodCallExpression methodCallExpression) {
PsiElement parent = methodCallExpression.getParent();
if ( parent instanceof PsiVariable ) {
if ( parent instanceof PsiVariable parentPsiVariable ) {

return new RemoveMappersFix( (PsiVariable) parent );
return new RemoveMappersFix( parentPsiVariable );
}

return null;
Expand Down
Loading

0 comments on commit e0586d7

Please sign in to comment.