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

Commit

Permalink
merged adapted changes from master
Browse files Browse the repository at this point in the history
  • Loading branch information
mplushnikov committed Jan 2, 2021
1 parent 5a8eb33 commit 8589797
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@
package de.plushnikov.intellij.plugin.jps;

import com.intellij.compiler.server.BuildProcessParametersProvider;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.OrderEntry;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiPackage;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import de.plushnikov.intellij.plugin.Version;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.List;

/**
Expand All @@ -38,36 +27,36 @@ public LombokBuildProcessParametersProvider(Project project) {
// }
return super.getVMArguments();
}

private boolean isVersionLessThan1_18_16(Project project) {
return CachedValuesManager.getManager(project).getCachedValue(project, () -> {
Boolean isVersionLessThan;
try {
isVersionLessThan = ReadAction.nonBlocking(
() -> isVersionLessThanInternal(project, Version.LAST_LOMBOK_VERSION_WITH_JPS_FIX))
.executeSynchronously();
} catch (ProcessCanceledException e) {
throw e;
} catch (Throwable e) {
isVersionLessThan = false;
LOG.error(e);
}
return new CachedValueProvider.Result<>(isVersionLessThan, ProjectRootManager.getInstance(project));
});
}

private boolean isVersionLessThanInternal(@NotNull Project project, @NotNull String version) {
PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage("lombok.experimental");
if (aPackage != null) {
PsiDirectory[] directories = aPackage.getDirectories();
if (directories.length > 0) {
List<OrderEntry> entries =
ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(directories[0].getVirtualFile());
if (!entries.isEmpty()) {
return Version.isLessThan(entries.get(0), version);
}
}
}
return false;
}
//
// private boolean isVersionLessThan1_18_16(Project project) {
// return CachedValuesManager.getManager(project).getCachedValue(project, () -> {
// Boolean isVersionLessThan;
// try {
// isVersionLessThan = ReadAction.nonBlocking(
// () -> isVersionLessThanInternal(project, Version.LAST_LOMBOK_VERSION_WITH_JPS_FIX))
// .executeSynchronously();
// } catch (ProcessCanceledException e) {
// throw e;
// } catch (Throwable e) {
// isVersionLessThan = false;
// LOG.error(e);
// }
// return new CachedValueProvider.Result<>(isVersionLessThan, ProjectRootManager.getInstance(project));
// });
// }
//
// private boolean isVersionLessThanInternal(@NotNull Project project, @NotNull String version) {
// PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage("lombok.experimental");
// if (aPackage != null) {
// PsiDirectory[] directories = aPackage.getDirectories();
// if (directories.length > 0) {
// List<OrderEntry> entries =
// ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(directories[0].getVirtualFile());
// if (!entries.isEmpty()) {
// return Version.isLessThan(entries.get(0), version);
// }
// }
// }
// return false;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -76,33 +75,6 @@ private static LombokLightClassBuilder createEnum(@NotNull String name, @NotNull
.withImplicitModifier(PsiModifier.STATIC)
.withImplicitModifier(PsiModifier.FINAL);

lazyClassBuilder.withMethodSupplier(()-> {
//add enum methods like here: ClassInnerStuffCache.calcMethods
final PsiManager psiManager = containingClass.getManager();
final PsiClassType enumClassType = PsiClassUtil.getTypeWithGenerics(lazyClassBuilder);
// "public static " + myClass.getName() + "[] values() { }"
final LombokLightMethodBuilder valuesEnumMethod = new LombokLightMethodBuilder(psiManager, "values")
.withModifier(PsiModifier.PUBLIC)
.withModifier(PsiModifier.STATIC)
.withContainingClass(containingClass)
.withNavigationElement(navigationElement)
.withMethodReturnType(new PsiArrayType(enumClassType));
valuesEnumMethod.withBody(PsiMethodUtil.createCodeBlockFromText("", valuesEnumMethod));

// "public static " + myClass.getName() + " valueOf(java.lang.String name) throws java.lang.IllegalArgumentException { }"
final LombokLightMethodBuilder valueOfEnumMethod = new LombokLightMethodBuilder(psiManager, "valueOf")
.withModifier(PsiModifier.PUBLIC)
.withModifier(PsiModifier.STATIC)
.withContainingClass(containingClass)
.withNavigationElement(navigationElement)
.withParameter("name", PsiType.getJavaLangString(psiManager, containingClass.getResolveScope()))
.withException(PsiType.getTypeByName("java.lang.IllegalArgumentException", containingClass.getProject(), containingClass.getResolveScope()))
.withMethodReturnType(enumClassType);
valueOfEnumMethod.withBody(PsiMethodUtil.createCodeBlockFromText("", valueOfEnumMethod));

return Arrays.asList(valuesEnumMethod, valueOfEnumMethod);
});

return lazyClassBuilder;
}

Expand Down

0 comments on commit 8589797

Please sign in to comment.