Skip to content

Commit

Permalink
#157 Use 2023.3 and remove MockJDK downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphr committed Oct 20, 2024
1 parent 3978833 commit 012cbf2
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 141 deletions.
40 changes: 0 additions & 40 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,46 +126,6 @@ task libs(type: Sync) {
rename 'mapstruct-1.5.3.Final.jar', 'mapstruct.jar'
}

def mockJdkLocation = "https://github.com/JetBrains/intellij-community/raw/212.5712/java/mock"
def mockJdkDest = layout.buildDirectory.dir("mock").get().asFile.toString()
def downloadMockJdk(mockJdkLocation, mockJdkDest, mockJdkVersion) {
def location = mockJdkLocation + mockJdkVersion
def destination = mockJdkDest + mockJdkVersion
download.run {
src([
"$location/jre/lib/annotations.jar",
"$location/jre/lib/rt.jar"
])
dest "$destination/jre/lib/"
overwrite false
quiet false
}
}

task downloadMockJdk7() {
def jdkVersion = "JDK-1.7"
def mockJdk7Location = mockJdkLocation + jdkVersion
def mockJdk7Dest = mockJdkDest + jdkVersion
downloadMockJdk(mockJdkLocation, mockJdkDest, jdkVersion)
download.run {
src([
"$mockJdk7Location/src.zip"
])
dest "$mockJdk7Dest"
overwrite false
quiet false
}
}

task downloadMockJdk8() {
downloadMockJdk(mockJdkLocation, mockJdkDest, "JDK-1.8")
}

task downloadMockJdk11() {
downloadMockJdk(mockJdkLocation, mockJdkDest, "JDK-11")
}

test.dependsOn( libs, downloadMockJdk7, downloadMockJdk8, downloadMockJdk11 )
prepareSandbox.dependsOn( libs )
composedJar.dependsOn( libs )

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.3
ideaVersion = 2023.3
ideaType = IC
sources = true
runGenerators = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.intellij.psi.PsiParameter;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiType;
import com.intellij.psi.PsiTypes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mapstruct.intellij.util.MapstructUtil;
Expand Down Expand Up @@ -97,7 +98,7 @@ Object[] getVariantsInternal(@NotNull PsiMethod mappingMethod) {
}

private boolean methodHasReturnType(@NotNull PsiMethod psiMethod) {
return !PsiType.VOID.equals( psiMethod.getReturnType() );
return !PsiTypes.voidType().equals( psiMethod.getReturnType() );
}

@NotNull
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/mapstruct/intellij/util/SourceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.intellij.psi.PsiRecordComponent;
import com.intellij.psi.PsiSubstitutor;
import com.intellij.psi.PsiType;
import com.intellij.psi.PsiTypes;
import com.intellij.psi.impl.source.PsiClassReferenceType;
import com.intellij.psi.util.PsiUtil;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -187,7 +188,7 @@ private static String extractPublicGetterPropertyName(PsiMethod method) {
// This logic is aligned with the DefaultAccessorNamingStrategy

PsiType returnType = method.getReturnType();
if ( returnType == null || PsiType.VOID.equals( returnType ) ) {
if ( returnType == null || PsiTypes.voidType().equals( returnType ) ) {
return null;
}

Expand All @@ -201,7 +202,7 @@ private static String extractPublicGetterPropertyName(PsiMethod method) {
}
}
else if ( methodName.startsWith( "is" ) && (
PsiType.BOOLEAN.equals( returnType ) ||
PsiTypes.booleanType().equals( returnType ) ||
returnType.equalsToText( CommonClassNames.JAVA_LANG_BOOLEAN ) )
) {
// boolean getter
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/mapstruct/intellij/util/TargetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.intellij.psi.PsiParameter;
import com.intellij.psi.PsiSubstitutor;
import com.intellij.psi.PsiType;
import com.intellij.psi.PsiTypes;
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
import com.intellij.psi.util.PsiUtil;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -77,7 +78,7 @@ public static PsiType getRelevantType(@NotNull PsiMethod mappingMethod) {
return null;
}
PsiType psiType = mappingMethod.getReturnType();
if ( psiType == null || PsiType.VOID.equalsToText( psiType.getCanonicalText() ) ) {
if ( psiType == null || PsiTypes.voidType().equalsToText( psiType.getCanonicalText() ) ) {
psiType = Stream.of( mappingMethod.getParameterList().getParameters() )
.filter( MapstructUtil::isMappingTarget )
.findAny()
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<vendor url="https://www.mapstruct.org">MapStruct</vendor>

<!-- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
<idea-version since-build="223"/>
<idea-version since-build="233"/>

<!-- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
on how to target different products -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,11 @@
import java.io.File;

import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.projectRoots.JavaSdk;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.LanguageLevelModuleExtension;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
import com.intellij.util.PathUtil;
import com.intellij.util.lang.JavaVersion;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -32,7 +23,6 @@
public abstract class MapstructBaseCompletionTestCase extends LightFixtureCompletionTestCase {

private static final String BUILD_LIBS_DIRECTORY = "build/libs";
private static final String BUILD_MOCK_JDK_DIRECTORY = "build/mockJDK-";

@Override
protected void setUp() throws Exception {
Expand All @@ -56,33 +46,6 @@ protected void addDirectoryToProject(@NotNull String directory) {
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
LanguageLevel languageLevel = getLanguageLevel();
return new DefaultLightProjectDescriptor() {
@Override
public Sdk getSdk() {
JavaVersion version = languageLevel.toJavaVersion();
int mockJdk;
if ( version.feature >= 11 ) {
mockJdk = 11;
}
else {
mockJdk = version.feature;
}
String compilerOption = ( mockJdk < 11 ? "1." : "" ) + mockJdk;
return JavaSdk.getInstance()
.createJdk( "java " + compilerOption, BUILD_MOCK_JDK_DIRECTORY + compilerOption, false );
}

@Override
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model,
@NotNull ContentEntry contentEntry) {
model.getModuleExtension( LanguageLevelModuleExtension.class )
.setLanguageLevel( languageLevel );
}
};
}

protected LanguageLevel getLanguageLevel() {
return LanguageLevel.JDK_1_8;
return JAVA_17;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementPresentation;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiRecordComponent;

Expand All @@ -32,11 +31,6 @@ protected void setUp() throws Exception {
addDirectoryToProject( "dto" );
}

@Override
protected LanguageLevel getLanguageLevel() {
return LanguageLevel.JDK_17;
}

private void assertCarDtoRecordAutoComplete() {
assertThat( myItems )
.extracting( LookupElement::getLookupString )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.pom.java.LanguageLevel;
import org.jetbrains.annotations.NotNull;

import java.util.List;
Expand Down Expand Up @@ -63,9 +62,4 @@ public void testJavaExpressionUnnecessaryWhitespacesTextBlock() {
List<IntentionAction> allQuickFixes = myFixture.getAllQuickFixes();
assertThat( allQuickFixes ).isEmpty();
}

@Override
protected LanguageLevel getLanguageLevel() {
return LanguageLevel.JDK_15;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.List;

import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.pom.java.LanguageLevel;
import org.jetbrains.annotations.NotNull;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -29,11 +28,6 @@ protected void setUp() throws Exception {
super.setUp();
}

@Override
protected LanguageLevel getLanguageLevel() {
return LanguageLevel.JDK_17;
}

public void testUnmappedRecordTargetProperties() {
doTest();
String testName = getTestName( false );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.List;

import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.pom.java.LanguageLevel;
import org.jetbrains.annotations.NotNull;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -18,11 +17,6 @@
*/
public class UnmappedTargetPropertiesInspectionTest extends BaseInspectionTest {

@Override
protected LanguageLevel getLanguageLevel() {
return LanguageLevel.JDK_1_7;
}

@NotNull
@Override
protected Class<UnmappedTargetPropertiesInspection> getInspection() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.mapstruct.intellij.rename;

import com.intellij.pom.java.LanguageLevel;
import org.mapstruct.intellij.MapstructBaseCompletionTestCase;

/**
Expand All @@ -18,11 +17,6 @@ protected String getTestDataPath() {
return "testData/rename";
}

@Override
protected LanguageLevel getLanguageLevel() {
return LanguageLevel.JDK_17;
}

public void testRenameRecordSourceParameter() {
myFixture.configureByFile( "RenameRecordSourceParameter.java" );
myFixture.renameElementAtCaret( "anotherName" );
Expand Down
44 changes: 17 additions & 27 deletions testData/inspection/UnmappedTargetProperties_after.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ interface NotMapStructMapper {
@Mapper
interface SingleMappingMapper {

@Mappings({
@Mapping(target = "testName", source = "name"),
@Mapping(target = "moreTarget", ignore = true),
@Mapping(target = "moreTarget", source = "")
})
@Mapping(target = "moreTarget", source = "")
@Mapping(target = "moreTarget", ignore = true)
@Mapping(target = "testName", source = "name")
Target map(Source source);
}

Expand Down Expand Up @@ -53,14 +51,12 @@ interface SingleMappingsNoBracesMapper {
@Mapper
interface NoMappingMapper {

@Mappings({
@Mapping(target = "moreTarget", ignore = true),
@Mapping(target = "moreTarget", source = ""),
@Mapping(target = "testName", ignore = true),
@Mapping(target = "testName", source = ""),
@Mapping(target = "moreTarget", ignore = true),
@Mapping(target = "testName", ignore = true)
})
@Mapping(target = "testName", ignore = true)
@Mapping(target = "moreTarget", ignore = true)
@Mapping(target = "testName", source = "")
@Mapping(target = "testName", ignore = true)
@Mapping(target = "moreTarget", source = "")
@Mapping(target = "moreTarget", ignore = true)
Target map(Source source);

@org.mapstruct.InheritInverseConfiguration
Expand Down Expand Up @@ -94,21 +90,17 @@ interface AllMappingsMapperConfig {
@Mapper
interface UpdateMapper {

@Mappings({
@Mapping(target = "moreTarget", source = "moreSource"),
@Mapping(target = "testName", ignore = true),
@Mapping(target = "testName", source = "")
})
@Mapping(target = "testName", source = "")
@Mapping(target = "testName", ignore = true)
@Mapping(target = "moreTarget", source = "moreSource")
void update(@MappingTarget Target target, Source source);
}

@Mapper
interface MultiSourceUpdateMapper {

@Mappings({
@Mapping(target = "moreTarget", ignore = true),
@Mapping(target = "moreTarget", source = "")
})
@Mapping(target = "moreTarget", source = "")
@Mapping(target = "moreTarget", ignore = true)
void update(@MappingTarget Target moreTarget, Source source, String testName, @org.mapstruct.Context String matching);
}

Expand All @@ -117,10 +109,8 @@ interface SingleMappingConstantReferenceMapper {

String TEST_NAME = "testName";

@Mappings({
@Mapping(target = TEST_NAME, source = "name"),
@Mapping(target = "moreTarget", ignore = true),
@Mapping(target = "moreTarget", source = "")
})
@Mapping(target = "moreTarget", source = "")
@Mapping(target = "moreTarget", ignore = true)
@Mapping(target = TEST_NAME, source = "name")
Target map(Source source);
}

0 comments on commit 012cbf2

Please sign in to comment.