Use Java 8 lambdas instead of anonymous classes in compiler modules
This commit is contained in:
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.asJava;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.asJava.finder.JavaElementFinder;
|
||||
import org.jetbrains.kotlin.checkers.KotlinMultiFileTestWithJava;
|
||||
@@ -54,22 +52,14 @@ public abstract class AbstractCompilerLightClassTest extends KotlinMultiFileTest
|
||||
|
||||
@Override
|
||||
protected void doMultiFileTest(File file, Map<String, ModuleAndDependencies> modules, List<Void> files) throws IOException {
|
||||
LightClassTestCommon.INSTANCE.testLightClass(file, new Function1<String, PsiClass>() {
|
||||
@Override
|
||||
public PsiClass invoke(String s) {
|
||||
try {
|
||||
return createFinder(getEnvironment()).findClass(s, GlobalSearchScope.allScope(getEnvironment().getProject()));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
LightClassTestCommon.INSTANCE.testLightClass(file, s -> {
|
||||
try {
|
||||
return createFinder(getEnvironment()).findClass(s, GlobalSearchScope.allScope(getEnvironment().getProject()));
|
||||
}
|
||||
}, new Function1<String, String>() {
|
||||
@Override
|
||||
public String invoke(String s) {
|
||||
return LightClassTestCommon.INSTANCE.removeEmptyDefaultImpls(s);
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
});
|
||||
}, LightClassTestCommon.INSTANCE::removeEmptyDefaultImpls);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,11 +16,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.asJava;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import kotlin.collections.ArraysKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cli.jvm.config.JvmContentRootsKt;
|
||||
@@ -29,7 +28,6 @@ import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.name.SpecialNames;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -237,15 +235,7 @@ public abstract class KotlinLightClassStructureTest extends KotlinAsJavaTestBase
|
||||
assertEquals(name, typeParameter.getName());
|
||||
assertEquals(index, typeParameter.getIndex());
|
||||
Set<String> expectedBounds = Sets.newHashSet(bounds);
|
||||
Set<String> actualBounds = Sets.newHashSet(Collections2.transform(
|
||||
Arrays.asList(typeParameter.getExtendsListTypes()),
|
||||
new Function<PsiClassType, String>() {
|
||||
@Override
|
||||
public String apply(PsiClassType input) {
|
||||
return input.getCanonicalText();
|
||||
}
|
||||
}
|
||||
));
|
||||
Set<String> actualBounds = Sets.newHashSet(ArraysKt.map(typeParameter.getExtendsListTypes(), PsiType::getCanonicalText));
|
||||
|
||||
assertEquals(expectedBounds, actualBounds);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.cfg;
|
||||
|
||||
import kotlin.jvm.functions.Function3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeImpl;
|
||||
@@ -36,22 +35,19 @@ public abstract class AbstractControlFlowTest extends AbstractPseudocodeTest {
|
||||
) {
|
||||
int nextInstructionsColumnWidth = countNextInstructionsColumnWidth(pseudocode.getInstructionsIncludingDeadCode());
|
||||
|
||||
dumpInstructions(pseudocode, out, new Function3<Instruction, Instruction, Instruction, String>() {
|
||||
@Override
|
||||
public String invoke(Instruction instruction, Instruction next, Instruction prev) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
Collection<Instruction> nextInstructions = instruction.getNextInstructions();
|
||||
dumpInstructions(pseudocode, out, (instruction, next, prev) -> {
|
||||
StringBuilder result = new StringBuilder();
|
||||
Collection<Instruction> nextInstructions = instruction.getNextInstructions();
|
||||
|
||||
if (!sameContents(next, nextInstructions)) {
|
||||
result.append(" NEXT:").append(
|
||||
String.format("%1$-" + nextInstructionsColumnWidth + "s", formatInstructionList(nextInstructions)));
|
||||
}
|
||||
Collection<Instruction> previousInstructions = instruction.getPreviousInstructions();
|
||||
if (!sameContents(prev, previousInstructions)) {
|
||||
result.append(" PREV:").append(formatInstructionList(previousInstructions));
|
||||
}
|
||||
return result.toString();
|
||||
if (!sameContents(next, nextInstructions)) {
|
||||
result.append(" NEXT:").append(
|
||||
String.format("%1$-" + nextInstructionsColumnWidth + "s", formatInstructionList(nextInstructions)));
|
||||
}
|
||||
Collection<Instruction> previousInstructions = instruction.getPreviousInstructions();
|
||||
if (!sameContents(prev, previousInstructions)) {
|
||||
result.append(" PREV:").append(formatInstructionList(previousInstructions));
|
||||
}
|
||||
return result.toString();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.cfg;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import kotlin.jvm.functions.Function3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeImpl;
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction;
|
||||
@@ -47,25 +46,22 @@ public abstract class AbstractDataFlowTest extends AbstractPseudocodeTest {
|
||||
String usePrefix = " USE:";
|
||||
int initializersColumnWidth = countDataColumnWidth(initPrefix, pseudocode.getInstructionsIncludingDeadCode(), variableInitializers);
|
||||
|
||||
dumpInstructions(pseudocode, out, new Function3<Instruction, Instruction, Instruction, String>() {
|
||||
@Override
|
||||
public String invoke(Instruction instruction, Instruction next, Instruction prev) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
Edges<InitControlFlowInfo> initializersEdges = variableInitializers.get(instruction);
|
||||
Edges<InitControlFlowInfo> previousInitializersEdges = variableInitializers.get(prev);
|
||||
String initializersData = "";
|
||||
if (initializersEdges != null && !initializersEdges.equals(previousInitializersEdges)) {
|
||||
initializersData = dumpEdgesData(initPrefix, initializersEdges);
|
||||
}
|
||||
result.append(String.format("%1$-" + initializersColumnWidth + "s", initializersData));
|
||||
|
||||
Edges<UseControlFlowInfo> useStatusEdges = useStatusData.get(instruction);
|
||||
Edges<UseControlFlowInfo> nextUseStatusEdges = useStatusData.get(next);
|
||||
if (useStatusEdges != null && !useStatusEdges.equals(nextUseStatusEdges)) {
|
||||
result.append(dumpEdgesData(usePrefix, useStatusEdges));
|
||||
}
|
||||
return result.toString();
|
||||
dumpInstructions(pseudocode, out, (instruction, next, prev) -> {
|
||||
StringBuilder result = new StringBuilder();
|
||||
Edges<InitControlFlowInfo> initializersEdges = variableInitializers.get(instruction);
|
||||
Edges<InitControlFlowInfo> previousInitializersEdges = variableInitializers.get(prev);
|
||||
String initializersData = "";
|
||||
if (initializersEdges != null && !initializersEdges.equals(previousInitializersEdges)) {
|
||||
initializersData = dumpEdgesData(initPrefix, initializersEdges);
|
||||
}
|
||||
result.append(String.format("%1$-" + initializersColumnWidth + "s", initializersData));
|
||||
|
||||
Edges<UseControlFlowInfo> useStatusEdges = useStatusData.get(instruction);
|
||||
Edges<UseControlFlowInfo> nextUseStatusEdges = useStatusData.get(next);
|
||||
if (useStatusEdges != null && !useStatusEdges.equals(nextUseStatusEdges)) {
|
||||
result.append(dumpEdgesData(usePrefix, useStatusEdges));
|
||||
}
|
||||
return result.toString();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.intellij.util.ArrayUtil;
|
||||
import kotlin.Pair;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.io.FilesKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import kotlin.text.Charsets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler;
|
||||
@@ -130,23 +129,20 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
||||
static List<String> readArgs(@NotNull String argsFilePath, @NotNull String tempDir) throws IOException {
|
||||
List<String> lines = FilesKt.readLines(new File(argsFilePath), Charsets.UTF_8);
|
||||
|
||||
return CollectionsKt.mapNotNull(lines, new Function1<String, String>() {
|
||||
@Override
|
||||
public String invoke(String arg) {
|
||||
if (arg.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Do not replace ':' after '\' (used in compiler plugin tests)
|
||||
String argsWithColonsReplaced = arg
|
||||
.replace("\\:", "$COLON$")
|
||||
.replace(":", File.pathSeparator)
|
||||
.replace("$COLON$", ":");
|
||||
|
||||
return argsWithColonsReplaced
|
||||
.replace("$TEMP_DIR$", tempDir)
|
||||
.replace("$TESTDATA_DIR$", new File(argsFilePath).getParent());
|
||||
return CollectionsKt.mapNotNull(lines, arg -> {
|
||||
if (arg.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Do not replace ':' after '\' (used in compiler plugin tests)
|
||||
String argsWithColonsReplaced = arg
|
||||
.replace("\\:", "$COLON$")
|
||||
.replace(":", File.pathSeparator)
|
||||
.replace("$COLON$", ":");
|
||||
|
||||
return argsWithColonsReplaced
|
||||
.replace("$TEMP_DIR$", tempDir)
|
||||
.replace("$TESTDATA_DIR$", new File(argsFilePath).getParent());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
||||
@@ -121,14 +120,7 @@ public class InnerClassInfoGenTest extends CodegenTestCase {
|
||||
|
||||
private void checkAccess(@NotNull String outerName, @NotNull String innerName, int accessFlags) {
|
||||
String name = outerName + "$" + innerName;
|
||||
InnerClassAttribute attribute = CollectionsKt.single(extractInnerClasses(name),
|
||||
new Function1<InnerClassAttribute, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(InnerClassAttribute attribute) {
|
||||
return innerName.equals(attribute.innerName);
|
||||
}
|
||||
}
|
||||
);
|
||||
InnerClassAttribute attribute = CollectionsKt.single(extractInnerClasses(name), value -> innerName.equals(value.innerName));
|
||||
|
||||
InnerClassAttribute expectedAttribute = new InnerClassAttribute(name, outerName, innerName, accessFlags);
|
||||
|
||||
|
||||
+12
-13
@@ -17,13 +17,15 @@
|
||||
package org.jetbrains.kotlin.jvm.compiler;
|
||||
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.renderer.*;
|
||||
import org.jetbrains.kotlin.renderer.AnnotationArgumentsRenderingPolicy;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier;
|
||||
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir;
|
||||
@@ -46,17 +48,14 @@ public abstract class AbstractCompileJavaAgainstKotlinTest extends TestCaseWithT
|
||||
private static final RecursiveDescriptorComparator.Configuration CONFIGURATION =
|
||||
AbstractLoadJavaTest.COMPARATOR_CONFIGURATION.withRenderer(
|
||||
DescriptorRenderer.Companion.withOptions(
|
||||
new Function1<DescriptorRendererOptions, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(DescriptorRendererOptions options) {
|
||||
options.setWithDefinedIn(false);
|
||||
options.setParameterNameRenderingPolicy(ParameterNameRenderingPolicy.NONE);
|
||||
options.setVerbose(true);
|
||||
options.setAnnotationArgumentsRenderingPolicy(AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY);
|
||||
options.setExcludedAnnotationClasses(Collections.singleton(new FqName(Retention.class.getName())));
|
||||
options.setModifiers(DescriptorRendererModifier.ALL);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
options -> {
|
||||
options.setWithDefinedIn(false);
|
||||
options.setParameterNameRenderingPolicy(ParameterNameRenderingPolicy.NONE);
|
||||
options.setVerbose(true);
|
||||
options.setAnnotationArgumentsRenderingPolicy(AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY);
|
||||
options.setExcludedAnnotationClasses(Collections.singleton(new FqName(Retention.class.getName())));
|
||||
options.setModifiers(DescriptorRendererModifier.ALL);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
+30
-50
@@ -20,7 +20,6 @@ import com.google.common.collect.Iterables;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import kotlin.Pair;
|
||||
import kotlin.collections.SetsKt;
|
||||
import kotlin.io.FilesKt;
|
||||
@@ -152,12 +151,7 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
|
||||
@NotNull
|
||||
private static File copyJarFileWithoutEntry(@NotNull File jarPath, @NotNull String... entriesToDelete) {
|
||||
return transformJar(jarPath, new Function2<String, byte[], byte[]>() {
|
||||
@Override
|
||||
public byte[] invoke(String s, byte[] bytes) {
|
||||
return bytes;
|
||||
}
|
||||
}, entriesToDelete);
|
||||
return transformJar(jarPath, (s, bytes) -> bytes, entriesToDelete);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -292,21 +286,16 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
@NotNull String... additionalOptions
|
||||
) throws Exception {
|
||||
int[] version = new JvmMetadataVersion(42, 0, 0).toArray();
|
||||
File library = transformJar(compileLibrary(libraryName), new Function2<String, byte[], byte[]>() {
|
||||
@Override
|
||||
public byte[] invoke(String name, byte[] bytes) {
|
||||
return WrongBytecodeVersionTest.Companion.transformMetadataInClassFile(bytes, new Function2<String, Object, Object>() {
|
||||
@Override
|
||||
public Object invoke(String name, Object value) {
|
||||
if (additionalTransformation != null) {
|
||||
Object result = additionalTransformation.invoke(name, value);
|
||||
if (result != null) return result;
|
||||
}
|
||||
return JvmAnnotationNames.METADATA_VERSION_FIELD_NAME.equals(name) ? version : null;
|
||||
File library = transformJar(
|
||||
compileLibrary(libraryName),
|
||||
(entryName, bytes) -> WrongBytecodeVersionTest.Companion.transformMetadataInClassFile(bytes, (fieldName, value) -> {
|
||||
if (additionalTransformation != null) {
|
||||
Object result = additionalTransformation.invoke(fieldName, value);
|
||||
if (result != null) return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return JvmAnnotationNames.METADATA_VERSION_FIELD_NAME.equals(fieldName) ? version : null;
|
||||
})
|
||||
);
|
||||
Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, Arrays.asList(additionalOptions), library);
|
||||
KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output));
|
||||
}
|
||||
@@ -509,20 +498,17 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
public void testWrongMetadataVersionBadMetadata() throws Exception {
|
||||
doTestKotlinLibraryWithWrongMetadataVersion(
|
||||
"library",
|
||||
new Function2<String, Object, Object>() {
|
||||
@Override
|
||||
public Object invoke(String name, Object value) {
|
||||
if (JvmAnnotationNames.METADATA_DATA_FIELD_NAME.equals(name)) {
|
||||
String[] strings = (String[]) value;
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
byte[] bytes = strings[i].getBytes();
|
||||
for (int j = 0; j < bytes.length; j++) bytes[j] ^= 42;
|
||||
strings[i] = new String(bytes);
|
||||
}
|
||||
return strings;
|
||||
(name, value) -> {
|
||||
if (JvmAnnotationNames.METADATA_DATA_FIELD_NAME.equals(name)) {
|
||||
String[] strings = (String[]) value;
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
byte[] bytes = strings[i].getBytes();
|
||||
for (int j = 0; j < bytes.length; j++) bytes[j] ^= 42;
|
||||
strings[i] = new String(bytes);
|
||||
}
|
||||
return null;
|
||||
return strings;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -530,14 +516,11 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
public void testWrongMetadataVersionBadMetadata2() throws Exception {
|
||||
doTestKotlinLibraryWithWrongMetadataVersion(
|
||||
"library",
|
||||
new Function2<String, Object, Object>() {
|
||||
@Override
|
||||
public Object invoke(String name, Object value) {
|
||||
if (JvmAnnotationNames.METADATA_STRINGS_FIELD_NAME.equals(name)) {
|
||||
return ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
return null;
|
||||
(name, value) -> {
|
||||
if (JvmAnnotationNames.METADATA_STRINGS_FIELD_NAME.equals(name)) {
|
||||
return ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -648,18 +631,15 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
File library2 = compileJava("library2");
|
||||
|
||||
// Copy everything from library2 to library1
|
||||
FileUtil.visitFiles(library2, new Processor<File>() {
|
||||
@Override
|
||||
public boolean process(File file) {
|
||||
if (!file.isDirectory()) {
|
||||
File newFile = new File(library1, FilesKt.relativeTo(file, library2).getPath());
|
||||
if (!newFile.getParentFile().exists()) {
|
||||
assert newFile.getParentFile().mkdirs();
|
||||
}
|
||||
assert file.renameTo(newFile);
|
||||
FileUtil.visitFiles(library2, file -> {
|
||||
if (!file.isDirectory()) {
|
||||
File newFile = new File(library1, FilesKt.relativeTo(file, library2).getPath());
|
||||
if (!newFile.getParentFile().exists()) {
|
||||
assert newFile.getParentFile().mkdirs();
|
||||
}
|
||||
return true;
|
||||
assert file.renameTo(newFile);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, library1);
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import kotlin.Unit;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
@@ -33,7 +32,10 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentProvider;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.renderer.*;
|
||||
import org.jetbrains.kotlin.renderer.AnnotationArgumentsRenderingPolicy;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier;
|
||||
import org.jetbrains.kotlin.renderer.OverrideRenderingPolicy;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.AdditionalClassPartsProvider;
|
||||
@@ -46,7 +48,6 @@ import org.jetbrains.kotlin.test.TestJdkKind;
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -64,16 +65,13 @@ public class LoadBuiltinsTest extends KotlinTestWithEnvironment {
|
||||
RecursiveDescriptorComparator.Configuration configuration =
|
||||
RecursiveDescriptorComparator.RECURSIVE_ALL.includeMethodsOfKotlinAny(false).withRenderer(
|
||||
DescriptorRenderer.Companion.withOptions(
|
||||
new Function1<DescriptorRendererOptions, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(DescriptorRendererOptions options) {
|
||||
options.setWithDefinedIn(false);
|
||||
options.setOverrideRenderingPolicy(OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE);
|
||||
options.setVerbose(true);
|
||||
options.setAnnotationArgumentsRenderingPolicy(AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY);
|
||||
options.setModifiers(DescriptorRendererModifier.ALL);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
options -> {
|
||||
options.setWithDefinedIn(false);
|
||||
options.setOverrideRenderingPolicy(OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE);
|
||||
options.setVerbose(true);
|
||||
options.setAnnotationArgumentsRenderingPolicy(AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY);
|
||||
options.setModifiers(DescriptorRendererModifier.ALL);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -113,12 +111,7 @@ public class LoadBuiltinsTest extends KotlinTestWithEnvironment {
|
||||
Collections.singletonList(new BuiltInFictitiousFunctionClassFactory(storageManager, builtInsModule)),
|
||||
PlatformDependentDeclarationFilter.All.INSTANCE,
|
||||
AdditionalClassPartsProvider.None.INSTANCE,
|
||||
new Function1<String, InputStream>() {
|
||||
@Override
|
||||
public InputStream invoke(String path) {
|
||||
return ForTestCompileRuntime.runtimeJarClassLoader().getResourceAsStream(path);
|
||||
}
|
||||
}
|
||||
ForTestCompileRuntime.runtimeJarClassLoader()::getResourceAsStream
|
||||
);
|
||||
|
||||
builtInsModule.initialize(packageFragmentProvider);
|
||||
|
||||
@@ -20,8 +20,6 @@ import junit.framework.TestCase;
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.util.ReenteringLazyValueComputationException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -278,12 +276,7 @@ public class StorageManagerTest extends TestCase {
|
||||
}
|
||||
},
|
||||
null,
|
||||
new Function1<String, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(String s) {
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
}
|
||||
s -> Unit.INSTANCE
|
||||
);
|
||||
}
|
||||
|
||||
@@ -306,19 +299,11 @@ public class StorageManagerTest extends TestCase {
|
||||
return rec.invoke();
|
||||
}
|
||||
},
|
||||
new Function1<Boolean, String>() {
|
||||
@Override
|
||||
public String invoke(Boolean aBoolean) {
|
||||
return "tolerant";
|
||||
}
|
||||
},
|
||||
new Function1<String, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(String s) {
|
||||
counter.inc();
|
||||
assertEquals("tolerant", s);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
aBoolean -> "tolerant",
|
||||
s -> {
|
||||
counter.inc();
|
||||
assertEquals("tolerant", s);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -332,22 +317,16 @@ public class StorageManagerTest extends TestCase {
|
||||
public void testPostComputeNoRecursion() throws Exception {
|
||||
CounterImpl counter = new CounterImpl();
|
||||
NotNullLazyValue<Collection<String>> v = m.createLazyValueWithPostCompute(
|
||||
new Function0<Collection<String>>() {
|
||||
@Override
|
||||
public Collection<String> invoke() {
|
||||
List<String> strings = new ArrayList<String>();
|
||||
strings.add("first");
|
||||
return strings;
|
||||
}
|
||||
() -> {
|
||||
List<String> strings = new ArrayList<String>();
|
||||
strings.add("first");
|
||||
return strings;
|
||||
},
|
||||
null,
|
||||
new Function1<Collection<String>, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(Collection<String> strings) {
|
||||
counter.inc();
|
||||
strings.add("postComputed");
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
strings -> {
|
||||
counter.inc();
|
||||
strings.add("postComputed");
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -359,21 +338,15 @@ public class StorageManagerTest extends TestCase {
|
||||
public void testNullablePostComputeNoRecursion() throws Exception {
|
||||
CounterImpl counter = new CounterImpl();
|
||||
NullableLazyValue<Collection<String>> v = m.createNullableLazyValueWithPostCompute(
|
||||
new Function0<Collection<String>>() {
|
||||
@Override
|
||||
public Collection<String> invoke() {
|
||||
ArrayList<String> strings = new ArrayList<String>();
|
||||
strings.add("first");
|
||||
return strings;
|
||||
}
|
||||
() -> {
|
||||
ArrayList<String> strings = new ArrayList<String>();
|
||||
strings.add("first");
|
||||
return strings;
|
||||
},
|
||||
new Function1<Collection<String>, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(Collection<String> strings) {
|
||||
counter.inc();
|
||||
strings.add("postComputed");
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
strings -> {
|
||||
counter.inc();
|
||||
strings.add("postComputed");
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -392,21 +365,15 @@ public class StorageManagerTest extends TestCase {
|
||||
return rec.invoke();
|
||||
}
|
||||
},
|
||||
new Function1<Boolean, String>() {
|
||||
@Override
|
||||
public String invoke(Boolean firstTime) {
|
||||
if (firstTime) {
|
||||
throw new ReenteringLazyValueComputationException();
|
||||
}
|
||||
return "second";
|
||||
firstTime -> {
|
||||
if (firstTime) {
|
||||
throw new ReenteringLazyValueComputationException();
|
||||
}
|
||||
return "second";
|
||||
},
|
||||
new Function1<String, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(String s) {
|
||||
fail("Recursion-tolerating value should not be post computed");
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
s -> {
|
||||
fail("Recursion-tolerating value should not be post computed");
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -449,23 +416,13 @@ public class StorageManagerTest extends TestCase {
|
||||
public void testExceptionHandlingStrategyForLazyValues() throws Exception {
|
||||
class RethrownException extends RuntimeException {}
|
||||
|
||||
LockBasedStorageManager m = LockBasedStorageManager.createWithExceptionHandling(new LockBasedStorageManager.ExceptionHandlingStrategy() {
|
||||
@NotNull
|
||||
@Override
|
||||
public RuntimeException handleException(@NotNull Throwable throwable) {
|
||||
throw new RethrownException();
|
||||
}
|
||||
LockBasedStorageManager m = LockBasedStorageManager.createWithExceptionHandling(throwable -> {
|
||||
throw new RethrownException();
|
||||
});
|
||||
try {
|
||||
m.createLazyValue(
|
||||
new Function0<Object>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Object invoke() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
).invoke();
|
||||
m.createLazyValue(() -> {
|
||||
throw new RuntimeException();
|
||||
}).invoke();
|
||||
fail("Exception should have occurred");
|
||||
}
|
||||
catch (RethrownException ignored) {
|
||||
@@ -475,23 +432,13 @@ public class StorageManagerTest extends TestCase {
|
||||
public void testExceptionHandlingStrategyForMemoizedFunctions() throws Exception {
|
||||
class RethrownException extends RuntimeException {}
|
||||
|
||||
LockBasedStorageManager m = LockBasedStorageManager.createWithExceptionHandling(new LockBasedStorageManager.ExceptionHandlingStrategy() {
|
||||
@NotNull
|
||||
@Override
|
||||
public RuntimeException handleException(@NotNull Throwable throwable) {
|
||||
throw new RethrownException();
|
||||
}
|
||||
LockBasedStorageManager m = LockBasedStorageManager.createWithExceptionHandling(throwable -> {
|
||||
throw new RethrownException();
|
||||
});
|
||||
try {
|
||||
m.createMemoizedFunction(
|
||||
new Function1<Object, Object>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Object invoke(@Nullable Object o) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
).invoke("");
|
||||
m.createMemoizedFunction(o -> {
|
||||
throw new RuntimeException();
|
||||
}).invoke("");
|
||||
fail("Exception should have occurred");
|
||||
}
|
||||
catch (RethrownException ignored) {
|
||||
@@ -501,12 +448,7 @@ public class StorageManagerTest extends TestCase {
|
||||
// Utilities
|
||||
|
||||
private static <K, V> Function0<V> apply(Function1<K, V> f, K x) {
|
||||
return new Function0<V>() {
|
||||
@Override
|
||||
public V invoke() {
|
||||
return f.invoke(x);
|
||||
}
|
||||
};
|
||||
return () -> f.invoke(x);
|
||||
}
|
||||
|
||||
private interface Counter {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.types;
|
||||
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
@@ -90,16 +89,16 @@ public class DefaultModalityModifiersTest extends KotlinTestWithEnvironment {
|
||||
KtDeclaration aClass = file.getDeclarations().get(0);
|
||||
assert aClass instanceof KtClass;
|
||||
AnalysisResult bindingContext = JvmResolveUtil.analyzeAndCheckForErrors(file, getEnvironment());
|
||||
DeclarationDescriptor classDescriptor = bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
|
||||
return new LexicalScopeImpl(ScopeUtilsKt.memberScopeAsImportingScope(libraryScope), root, false, null,
|
||||
LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
handler.addClassifierDescriptor((ClassifierDescriptor) classDescriptor);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
});
|
||||
DeclarationDescriptor classDescriptor =
|
||||
bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
|
||||
return new LexicalScopeImpl(
|
||||
ScopeUtilsKt.memberScopeAsImportingScope(libraryScope), root, false, null,
|
||||
LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||
handler -> {
|
||||
handler.addClassifierDescriptor((ClassifierDescriptor) classDescriptor);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private ClassDescriptorWithResolutionScopes createClassDescriptor(ClassKind kind, KtClass aClass) {
|
||||
|
||||
@@ -20,9 +20,7 @@ import com.google.common.collect.Maps;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
@@ -31,7 +29,6 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages;
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
@@ -96,14 +93,11 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
||||
LexicalScope typeParameters = new LexicalScopeImpl(
|
||||
topLevelScope, module, false, null, LexicalScopeKind.SYNTHETIC,
|
||||
redeclarationChecker,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
for (TypeParameterDescriptor parameterDescriptor : contextClass.getTypeConstructor().getParameters()) {
|
||||
handler.addClassifierDescriptor(parameterDescriptor);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
handler -> {
|
||||
for (TypeParameterDescriptor parameterDescriptor : contextClass.getTypeConstructor().getParameters()) {
|
||||
handler.addClassifierDescriptor(parameterDescriptor);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
return new LexicalChainedScope(
|
||||
@@ -157,15 +151,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
||||
BindingTrace trace = new BindingTraceContext();
|
||||
KotlinType type = container.getTypeResolver().resolveType(scope, jetTypeReference, trace, true);
|
||||
if (!trace.getBindingContext().getDiagnostics().isEmpty()) {
|
||||
fail("Errors:\n" + StringUtil.join(
|
||||
trace.getBindingContext().getDiagnostics(),
|
||||
new Function<Diagnostic, String>() {
|
||||
@Override
|
||||
public String fun(Diagnostic diagnostic) {
|
||||
return DefaultErrorMessages.render(diagnostic);
|
||||
}
|
||||
},
|
||||
"\n"));
|
||||
fail("Errors:\n" + StringUtil.join(trace.getBindingContext().getDiagnostics(), DefaultErrorMessages::render, "\n"));
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import kotlin.Unit;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
@@ -31,7 +30,6 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactoryKt;
|
||||
import org.jetbrains.kotlin.psi.KtTypeProjection;
|
||||
@@ -69,12 +67,8 @@ public class TypeUnifierTest extends KotlinTestWithEnvironment {
|
||||
module = DslKt.getService(container, ModuleDescriptor.class);
|
||||
|
||||
builtinsImportingScope = ScopeUtilsKt.chainImportingScopes(
|
||||
CollectionsKt.map(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAMES, new Function1<FqName, ImportingScope>() {
|
||||
@Override
|
||||
public ImportingScope invoke(FqName fqName) {
|
||||
return ScopeUtilsKt.memberScopeAsImportingScope(module.getPackage(fqName).getMemberScope());
|
||||
}
|
||||
}), null);
|
||||
CollectionsKt.map(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAMES,
|
||||
fqName -> ScopeUtilsKt.memberScopeAsImportingScope(module.getPackage(fqName).getMemberScope())), null);
|
||||
typeResolver = DslKt.getService(container, TypeResolver.class);
|
||||
x = createTypeVariable("X");
|
||||
y = createTypeVariable("Y");
|
||||
@@ -202,13 +196,10 @@ public class TypeUnifierTest extends KotlinTestWithEnvironment {
|
||||
LexicalScope withX = new LexicalScopeImpl(
|
||||
builtinsImportingScope, module,
|
||||
false, null, LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
handler.addClassifierDescriptor(x);
|
||||
handler.addClassifierDescriptor(y);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
handler -> {
|
||||
handler.addClassifierDescriptor(x);
|
||||
handler.addClassifierDescriptor(y);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user