Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
merged with backported changes from master
Browse files Browse the repository at this point in the history
  • Loading branch information
mplushnikov committed Oct 3, 2019
1 parent 5480679 commit 6643537
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 67 deletions.
57 changes: 0 additions & 57 deletions src/test/java/de/plushnikov/TestUtil.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void setUp() throws Exception {
}

protected void loadLombokLibrary() {
LombokTestUtil.loadLombokLibrary(myFixture.getProjectDisposable(), getModule());
LombokTestUtil.loadLombokLibrary(myFixture, getModule());
}

protected PsiFile loadToPsiFile(String fileName) {
Expand Down
42 changes: 39 additions & 3 deletions src/test/java/de/plushnikov/intellij/plugin/LombokTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture;
import com.intellij.util.PathUtil;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

public class LombokTestUtil {
private static final String LOMBOK_LIBRARY_DIRECTORY = "lib";
private static final String LOMBOK_JAR_NAME = "lombok-1.18.10.jar";

public static void loadLombokLibrary(@NotNull Disposable projectDisposable, @NotNull Module module) {
public static void loadLombokLibrary(@NotNull JavaCodeInsightTestFixture projectDisposable, @NotNull Module module) {
final String lombokLibPath = PathUtil.toSystemIndependentName(new File(LOMBOK_LIBRARY_DIRECTORY).getAbsolutePath());
VfsRootAccess.allowRootAccess(projectDisposable, lombokLibPath);
PsiTestUtil.addLibrary(projectDisposable, module, "Lombok Library", lombokLibPath, LOMBOK_JAR_NAME);
addLibrary(projectDisposable, module, "Lombok Library", lombokLibPath, LOMBOK_JAR_NAME);
}

public static LightProjectDescriptor getProjectDescriptor() {
Expand All @@ -40,4 +43,37 @@ public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel
}
};
}

/*
* For IntelliJ >= 2017.3 we need to call PsiTestUtil.addLibrary with Disposable parameter
* For IntelliJ <2017.3 we can use default PsiTestUtil.addLibrary version
*/
public static void addLibrary(@NotNull JavaCodeInsightTestFixture parent, Module module, String libName, String libPath, String jarArr) {
Disposable projectDisposable;
try {
final MethodHandle methodHandle = MethodHandles.lookup().findVirtual(JavaCodeInsightTestFixture.class, "getProjectDisposable", MethodType.methodType(Disposable.class));
projectDisposable = (Disposable) methodHandle.invoke(parent);
} catch (Throwable throwable) {
projectDisposable = null;
}

if (null == projectDisposable) {
VfsRootAccess.allowRootAccess(libPath);
PsiTestUtil.addLibrary(module, libName, libPath, jarArr);
} else {
VfsRootAccess.allowRootAccess(projectDisposable, libPath);
addLibrary(projectDisposable, module, libName, libPath, jarArr);
}
}

private static void addLibrary(@NotNull Disposable projectDisposable, Module module, String libName, String libPath, String jarArr) {
final MethodHandle methodHandle;
try {
methodHandle = MethodHandles.lookup().findStatic(PsiTestUtil.class, "addLibrary", MethodType.methodType(void.class,
Disposable.class, Module.class, String.class, String.class, String[].class));
methodHandle.invoke(projectDisposable, module, libName, libPath, new String[]{jarArr});
} catch (Throwable throwable) {
PsiTestUtil.addLibrary(module, libName, libPath, jarArr);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.intellij.testFramework.LightProjectDescriptor;
import com.siyeh.ig.LightInspectionTestCase;
import de.plushnikov.intellij.plugin.LombokTestUtil;
import de.plushnikov.TestUtil;
import org.jetbrains.annotations.NotNull;

import static com.intellij.testFramework.LightPlatformTestCase.getModule;
Expand All @@ -15,7 +14,7 @@ public abstract class LombokInspectionTest extends LightInspectionTestCase {
public void setUp() throws Exception {
super.setUp();

LombokTestUtil.loadLombokLibrary(myFixture.getProjectDisposable(), getModule());
LombokTestUtil.loadLombokLibrary(myFixture, getModule());
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.plushnikov.intellij.plugin.processor;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess;
import com.intellij.util.PathUtil;
Expand All @@ -21,10 +20,10 @@ public class FieldNameConstantsOldTest extends AbstractLombokParsingTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
final Disposable projectDisposable = myFixture.getProjectDisposable();

final String basePath = new File(getTestDataPath(), getBasePath()).getCanonicalPath();
VfsRootAccess.allowRootAccess(projectDisposable, basePath, new File(LOMBOK_SRC_PATH).getCanonicalPath());
VfsRootAccess.allowRootAccess(projectDisposable, basePath, new File(OLD_LOMBOK_SRC_PATH).getCanonicalPath());
VfsRootAccess.allowRootAccess(basePath, new File(LOMBOK_SRC_PATH).getCanonicalPath());
VfsRootAccess.allowRootAccess(basePath, new File(OLD_LOMBOK_SRC_PATH).getCanonicalPath());
}

public void testFieldnameconstants$FieldNameConstantsOldBasic() {
Expand Down

0 comments on commit 6643537

Please sign in to comment.