Extract static functions to CodegenTestUtil
Add Nullable/NotNull annotations
This commit is contained in:
committed by
Alexander Udalov
parent
63aacc416f
commit
9bf73cf4b3
@@ -25,6 +25,8 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.findDeclaredMethodByName;
|
||||
|
||||
public class ClassGenTest extends CodegenTestCase {
|
||||
|
||||
@Override
|
||||
@@ -161,7 +163,7 @@ public class ClassGenTest extends CodegenTestCase {
|
||||
loadText("abstract class Foo { abstract fun x(): String; fun y(): Int = 0 }");
|
||||
final Class aClass = generateClass("Foo");
|
||||
assertNotNull(aClass.getMethod("x"));
|
||||
assertNotNull(findMethodByName(aClass, "y"));
|
||||
assertNotNull(findDeclaredMethodByName(aClass, "y"));
|
||||
}
|
||||
|
||||
public void testInheritedMethod() {
|
||||
|
||||
@@ -16,9 +16,12 @@
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ClassPathInTheSameClassLoaderTest extends CodegenTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected GeneratedClassLoader createClassLoader(ClassFileFactory factory) {
|
||||
protected GeneratedClassLoader createClassLoader(@NotNull ClassFileFactory factory) {
|
||||
initializedClassLoader = new GeneratedClassLoader(factory, CodegenTestCase.class.getClassLoader(), getClassPathURLs());
|
||||
return initializedClassLoader;
|
||||
}
|
||||
|
||||
@@ -16,48 +16,38 @@
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.TestJdkKind;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.codegen.state.Progress;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.*;
|
||||
|
||||
public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
|
||||
// for environment and classloader
|
||||
protected JetCoreEnvironment myEnvironment;
|
||||
protected CodegenTestFiles myFiles;
|
||||
|
||||
private GenerationState alreadyGenerated;
|
||||
private ClassFileFactory classFileFactory;
|
||||
protected GeneratedClassLoader initializedClassLoader;
|
||||
|
||||
protected void createEnvironmentWithMockJdkAndIdeaAnnotations(@NotNull ConfigurationKind configurationKind) {
|
||||
@@ -67,22 +57,11 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
myEnvironment = JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable(), configurationKind);
|
||||
}
|
||||
|
||||
protected static void assertThrows(Method foo, Class<? extends Throwable> exceptionClass, Object instance, Object... args) throws IllegalAccessException {
|
||||
boolean caught = false;
|
||||
try {
|
||||
foo.invoke(instance, args);
|
||||
}
|
||||
catch(InvocationTargetException ex) {
|
||||
caught = exceptionClass.isInstance(ex.getTargetException());
|
||||
}
|
||||
assertTrue(caught);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
myFiles = null;
|
||||
myEnvironment = null;
|
||||
alreadyGenerated = null;
|
||||
classFileFactory = null;
|
||||
|
||||
if (initializedClassLoader != null) {
|
||||
initializedClassLoader.dispose();
|
||||
@@ -92,15 +71,17 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected void loadText(final String text) {
|
||||
protected void loadText(@NotNull String text) {
|
||||
myFiles = CodegenTestFiles.create("a.kt", text, myEnvironment.getProject());
|
||||
}
|
||||
|
||||
protected String loadFile(final String name) {
|
||||
@NotNull
|
||||
protected String loadFile(@NotNull String name) {
|
||||
return loadFileByFullPath(JetParsingTest.getTestDataDir() + "/codegen/" + name);
|
||||
}
|
||||
|
||||
protected String loadFileByFullPath(final String fullPath) {
|
||||
@NotNull
|
||||
protected String loadFileByFullPath(@NotNull String fullPath) {
|
||||
try {
|
||||
File file = new File(fullPath);
|
||||
final String content = FileUtil.loadFile(file, true);
|
||||
@@ -111,7 +92,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadFiles(final String... names) {
|
||||
protected void loadFiles(@NotNull String... names) {
|
||||
myFiles = CodegenTestFiles.create(myEnvironment.getProject(), names);
|
||||
}
|
||||
|
||||
@@ -119,20 +100,21 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
loadFile(getPrefix() + "/" + getTestName(true) + ".kt");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String getPrefix() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
protected void blackBoxFile(String filename) {
|
||||
protected void blackBoxFile(@NotNull String filename) {
|
||||
blackBoxMultiFile(filename);
|
||||
}
|
||||
|
||||
protected void blackBoxFileByFullPath(String filename) {
|
||||
protected void blackBoxFileByFullPath(@NotNull String filename) {
|
||||
loadFileByFullPath(filename);
|
||||
blackBox();
|
||||
}
|
||||
|
||||
protected void blackBoxMultiFile(String... filenames) {
|
||||
protected void blackBoxMultiFile(@NotNull String... filenames) {
|
||||
loadFiles(filenames);
|
||||
blackBox();
|
||||
}
|
||||
@@ -161,7 +143,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
}
|
||||
|
||||
protected void blackBoxFileWithJava(@NotNull String ktFile) {
|
||||
File javaClassesTempDirectory = compileJava(ktFile.replaceFirst("\\.kt$", ".java"));
|
||||
File javaClassesTempDirectory = CodegenTestUtil.compileJava(ktFile.replaceFirst("\\.kt$", ".java"));
|
||||
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory));
|
||||
@@ -169,27 +151,8 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
blackBoxFile(ktFile);
|
||||
}
|
||||
|
||||
protected File compileJava(@NotNull String filename) {
|
||||
try {
|
||||
File javaClassesTempDirectory = new File(FileUtil.getTempDirectory(), "java-classes");
|
||||
JetTestUtils.mkdirs(javaClassesTempDirectory);
|
||||
String classPath = "out/production/runtime" + File.pathSeparator + JetTestUtils.getAnnotationsJar().getPath();
|
||||
List<String> options = Arrays.asList(
|
||||
"-classpath", classPath,
|
||||
"-d", javaClassesTempDirectory.getPath()
|
||||
);
|
||||
|
||||
File javaFile = new File("compiler/testData/codegen/" + filename);
|
||||
JetTestUtils.compileJavaFiles(Collections.singleton(javaFile), options);
|
||||
|
||||
return javaClassesTempDirectory;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected GeneratedClassLoader createClassLoader(ClassFileFactory factory) {
|
||||
@NotNull
|
||||
protected GeneratedClassLoader createClassLoader(@NotNull ClassFileFactory factory) {
|
||||
if (initializedClassLoader != null) {
|
||||
fail("Double initialization of class loader in same test");
|
||||
}
|
||||
@@ -199,6 +162,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
return initializedClassLoader;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected URL[] getClassPathURLs() {
|
||||
List<URL> urls = Lists.newArrayList();
|
||||
for (File file : myEnvironment.getConfiguration().getList(JVMConfigurationKeys.CLASSPATH_KEY)) {
|
||||
@@ -212,40 +176,22 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
return urls.toArray(new URL[urls.size()]);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String generateToText() {
|
||||
if (alreadyGenerated == null) {
|
||||
alreadyGenerated = generateCommon(myEnvironment, myFiles);
|
||||
if (classFileFactory == null) {
|
||||
classFileFactory = generateFiles(myEnvironment, myFiles);
|
||||
}
|
||||
return alreadyGenerated.getFactory().createText();
|
||||
return classFileFactory.createText();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static GenerationState generateCommon(@NotNull JetCoreEnvironment environment, @NotNull CodegenTestFiles files) {
|
||||
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
||||
environment.getProject(),
|
||||
files.getPsiFiles(),
|
||||
files.getScriptParameterTypes(),
|
||||
Predicates.<PsiFile>alwaysTrue());
|
||||
analyzeExhaust.throwIfError();
|
||||
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
|
||||
CompilerConfiguration configuration = environment.getConfiguration();
|
||||
GenerationState state = new GenerationState(
|
||||
environment.getProject(), ClassBuilderFactories.TEST, Progress.DEAF, analyzeExhaust.getBindingContext(), files.getPsiFiles(),
|
||||
configuration.get(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY, BuiltinToJavaTypesMapping.ENABLED),
|
||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, true),
|
||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true),
|
||||
/*generateDeclaredClasses = */true
|
||||
);
|
||||
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
||||
return state;
|
||||
protected Class<?> generateNamespaceClass() {
|
||||
JvmClassName name = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFiles.getPsiFile()));
|
||||
return generateClass(name.getFqName().getFqName());
|
||||
}
|
||||
|
||||
protected Class generateNamespaceClass() {
|
||||
String name = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFiles.getPsiFile())).getFqName().getFqName();
|
||||
return generateClass(name);
|
||||
}
|
||||
|
||||
protected Class generateClass(String name) {
|
||||
@NotNull
|
||||
protected Class generateClass(@NotNull String name) {
|
||||
try {
|
||||
return createClassLoader(generateClassesInFile()).loadClass(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
@@ -256,70 +202,39 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
|
||||
@NotNull
|
||||
protected ClassFileFactory generateClassesInFile() {
|
||||
if (alreadyGenerated == null) {
|
||||
if (classFileFactory == null) {
|
||||
try {
|
||||
alreadyGenerated = generateCommon(myEnvironment, myFiles);
|
||||
classFileFactory = generateFiles(myEnvironment, myFiles);
|
||||
|
||||
if (DxChecker.RUN_DX_CHECKER) {
|
||||
DxChecker.check(alreadyGenerated.getFactory());
|
||||
DxChecker.check(classFileFactory);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
System.out.println(generateToText());
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
}
|
||||
}
|
||||
return alreadyGenerated.getFactory();
|
||||
return classFileFactory;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Method generateFunction() {
|
||||
Class aClass = generateNamespaceClass();
|
||||
Class<?> aClass = generateNamespaceClass();
|
||||
try {
|
||||
Method r = null;
|
||||
for (Method method : aClass.getMethods()) {
|
||||
if (method.getDeclaringClass().equals(Object.class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (r != null) {
|
||||
throw new AssertionError("more then one public method in class " + aClass);
|
||||
}
|
||||
|
||||
r = method;
|
||||
}
|
||||
if (r == null) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
return r;
|
||||
return findTheOnlyMethod(aClass);
|
||||
} catch (Error e) {
|
||||
System.out.println(generateToText());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
protected Method generateFunction(String name) {
|
||||
Class aClass = generateNamespaceClass();
|
||||
final Method method = findMethodByName(aClass, name);
|
||||
@NotNull
|
||||
protected Method generateFunction(@NotNull String name) {
|
||||
Class<?> aClass = generateNamespaceClass();
|
||||
Method method = findDeclaredMethodByName(aClass, name);
|
||||
if (method == null) {
|
||||
throw new IllegalArgumentException("couldn't find method " + name);
|
||||
throw new IllegalArgumentException("Couldn't find method " + name + " in class " + aClass);
|
||||
}
|
||||
return method;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected static Method findMethodByName(Class aClass, String name) {
|
||||
for (Method method : aClass.getDeclaredMethods()) {
|
||||
if (method.getName().equals(name)) {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static void assertIsCurrentTime(long returnValue) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long diff = Math.abs(returnValue - currentTime);
|
||||
long toleratedDifference = SystemInfo.isWindows ? 15 : 1;
|
||||
assertTrue("Difference with current time: " + diff + " (this test is a bad one: it may fail even if the generated code is correct)",
|
||||
diff <= toleratedDifference);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.codegen.state.Progress;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
public class CodegenTestUtil {
|
||||
private CodegenTestUtil() {}
|
||||
|
||||
@NotNull
|
||||
public static ClassFileFactory generateFiles(@NotNull JetCoreEnvironment environment, @NotNull CodegenTestFiles files) {
|
||||
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
||||
environment.getProject(),
|
||||
files.getPsiFiles(),
|
||||
files.getScriptParameterTypes(),
|
||||
Predicates.<PsiFile>alwaysTrue());
|
||||
analyzeExhaust.throwIfError();
|
||||
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
|
||||
CompilerConfiguration configuration = environment.getConfiguration();
|
||||
GenerationState state = new GenerationState(
|
||||
environment.getProject(), ClassBuilderFactories.TEST, Progress.DEAF, analyzeExhaust.getBindingContext(), files.getPsiFiles(),
|
||||
configuration.get(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY, BuiltinToJavaTypesMapping.ENABLED),
|
||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, true),
|
||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true),
|
||||
/*generateDeclaredClasses = */true
|
||||
);
|
||||
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
||||
return state.getFactory();
|
||||
}
|
||||
|
||||
public static void assertThrows(@NotNull Method foo, @NotNull Class<? extends Throwable> exceptionClass,
|
||||
@Nullable Object instance, @NotNull Object... args) throws IllegalAccessException {
|
||||
boolean caught = false;
|
||||
try {
|
||||
foo.invoke(instance, args);
|
||||
}
|
||||
catch (InvocationTargetException ex) {
|
||||
caught = exceptionClass.isInstance(ex.getTargetException());
|
||||
}
|
||||
assertTrue(caught);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Method findDeclaredMethodByName(@NotNull Class<?> aClass, @NotNull String name) {
|
||||
for (Method method : aClass.getDeclaredMethods()) {
|
||||
if (method.getName().equals(name)) {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void assertIsCurrentTime(long returnValue) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long diff = Math.abs(returnValue - currentTime);
|
||||
long toleratedDifference = SystemInfo.isWindows ? 15 : 1;
|
||||
assertTrue("Difference with current time: " + diff + " (this test is a bad one: it may fail even if the generated code is correct)",
|
||||
diff <= toleratedDifference);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File compileJava(@NotNull String filename) {
|
||||
try {
|
||||
File javaClassesTempDirectory = new File(FileUtil.getTempDirectory(), "java-classes");
|
||||
JetTestUtils.mkdirs(javaClassesTempDirectory);
|
||||
String classPath = "out/production/runtime" + File.pathSeparator + JetTestUtils.getAnnotationsJar().getPath();
|
||||
List<String> options = Arrays.asList(
|
||||
"-classpath", classPath,
|
||||
"-d", javaClassesTempDirectory.getPath()
|
||||
);
|
||||
|
||||
File javaFile = new File("compiler/testData/codegen/" + filename);
|
||||
JetTestUtils.compileJavaFiles(Collections.singleton(javaFile), options);
|
||||
|
||||
return javaClassesTempDirectory;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Method findTheOnlyMethod(@NotNull Class<?> aClass) {
|
||||
Method r = null;
|
||||
for (Method method : aClass.getMethods()) {
|
||||
if (method.getDeclaringClass().equals(Object.class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (r != null) {
|
||||
throw new AssertionError("More than one public method in class " + aClass);
|
||||
}
|
||||
|
||||
r = method;
|
||||
}
|
||||
if (r == null) {
|
||||
throw new AssertionError("No public methods in class " + aClass);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,15 @@
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.assertThrows;
|
||||
|
||||
public class ControlStructuresTest extends CodegenTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@@ -29,6 +32,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getPrefix() {
|
||||
return "controlStructures";
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.assertThrows;
|
||||
|
||||
public class ExtensionFunctionsTest extends CodegenTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@@ -27,6 +30,7 @@ public class ExtensionFunctionsTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getPrefix() {
|
||||
return "extensionFunctions";
|
||||
|
||||
@@ -27,13 +27,15 @@ import org.jetbrains.jet.TestJdkKind;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentUtil;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.compileJava;
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.generateFiles;
|
||||
|
||||
public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@@ -78,10 +80,10 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
||||
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK);
|
||||
JetCoreEnvironment tmpEnvironment = new JetCoreEnvironment(getTestRootDisposable(), configuration);
|
||||
GenerationState state = generateCommon(tmpEnvironment,
|
||||
ClassFileFactory factory = generateFiles(tmpEnvironment,
|
||||
CodegenTestFiles.create(tmpEnvironment.getProject(), new String[] {"notNullAssertions/noAssertionsForKotlin.kt"}));
|
||||
File compiledDirectory = new File(FileUtil.getTempDirectory(), "kotlin-classes");
|
||||
CompileEnvironmentUtil.writeToOutputDirectory(state.getFactory(), compiledDirectory);
|
||||
CompileEnvironmentUtil.writeToOutputDirectory(factory, compiledDirectory);
|
||||
|
||||
setUpEnvironment(true, false, compiledDirectory);
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.assertIsCurrentTime;
|
||||
|
||||
public class NamespaceGenTest extends CodegenTestCase {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.assertThrows;
|
||||
|
||||
public class PatternMatchingTest extends CodegenTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@@ -27,6 +30,7 @@ public class PatternMatchingTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getPrefix() {
|
||||
return "patternMatching";
|
||||
|
||||
@@ -16,11 +16,15 @@
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.asm4.Opcodes;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.assertIsCurrentTime;
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.findDeclaredMethodByName;
|
||||
|
||||
public class PropertyGenTest extends CodegenTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@@ -28,6 +32,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getPrefix() {
|
||||
return "properties";
|
||||
@@ -46,9 +51,9 @@ public class PropertyGenTest extends CodegenTestCase {
|
||||
loadFile();
|
||||
final Class aClass = generateClass("PrivateVar");
|
||||
final Object instance = aClass.newInstance();
|
||||
Method setter = findMethodByName(aClass, "setValueOfX");
|
||||
Method setter = findDeclaredMethodByName(aClass, "setValueOfX");
|
||||
setter.invoke(instance, 239);
|
||||
Method getter = findMethodByName(aClass, "getValueOfX");
|
||||
Method getter = findDeclaredMethodByName(aClass, "getValueOfX");
|
||||
assertEquals(239, ((Integer) getter.invoke(instance)).intValue());
|
||||
}
|
||||
|
||||
@@ -56,17 +61,17 @@ public class PropertyGenTest extends CodegenTestCase {
|
||||
loadText("class PublicVar() { public var foo : Int = 0; }");
|
||||
final Class aClass = generateClass("PublicVar");
|
||||
final Object instance = aClass.newInstance();
|
||||
Method setter = findMethodByName(aClass, "setFoo");
|
||||
Method setter = findDeclaredMethodByName(aClass, "setFoo");
|
||||
setter.invoke(instance, 239);
|
||||
Method getter = findMethodByName(aClass, "getFoo");
|
||||
Method getter = findDeclaredMethodByName(aClass, "getFoo");
|
||||
assertEquals(239, ((Integer) getter.invoke(instance)).intValue());
|
||||
}
|
||||
|
||||
public void testAccessorsInInterface() {
|
||||
loadText("class AccessorsInInterface() { public var foo : Int = 0; }");
|
||||
final Class aClass = generateClass("AccessorsInInterface");
|
||||
assertNotNull(findMethodByName(aClass, "getFoo"));
|
||||
assertNotNull(findMethodByName(aClass, "setFoo"));
|
||||
assertNotNull(findDeclaredMethodByName(aClass, "getFoo"));
|
||||
assertNotNull(findDeclaredMethodByName(aClass, "setFoo"));
|
||||
}
|
||||
|
||||
public void testPrivatePropertyInNamespace() throws Exception {
|
||||
@@ -118,14 +123,14 @@ public class PropertyGenTest extends CodegenTestCase {
|
||||
loadText("class AccessorsWithoutBody() { protected var foo: Int = 349\n get\n private set\n fun setter() { foo = 610; } } ");
|
||||
final Class aClass = generateClass("AccessorsWithoutBody");
|
||||
final Object instance = aClass.newInstance();
|
||||
final Method getFoo = findMethodByName(aClass, "getFoo");
|
||||
final Method getFoo = findDeclaredMethodByName(aClass, "getFoo");
|
||||
getFoo.setAccessible(true);
|
||||
assertTrue((getFoo.getModifiers() & Modifier.PROTECTED) != 0);
|
||||
assertEquals(349, getFoo.invoke(instance));
|
||||
final Method setFoo = findMethodByName(aClass, "setFoo");
|
||||
final Method setFoo = findDeclaredMethodByName(aClass, "setFoo");
|
||||
setFoo.setAccessible(true);
|
||||
assertTrue((setFoo.getModifiers() & Modifier.PRIVATE) != 0);
|
||||
final Method setter = findMethodByName(aClass, "setter");
|
||||
final Method setter = findDeclaredMethodByName(aClass, "setter");
|
||||
setter.invoke(instance);
|
||||
assertEquals(610, getFoo.invoke(instance));
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.TestJdkKind;
|
||||
@@ -49,8 +50,9 @@ public class StdlibTest extends CodegenTestCase {
|
||||
ConfigurationKind.ALL, TestJdkKind.FULL_JDK, JetTestUtils.getAnnotationsJar(), junitJar));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected GeneratedClassLoader createClassLoader(ClassFileFactory codegens) {
|
||||
protected GeneratedClassLoader createClassLoader(@NotNull ClassFileFactory codegens) {
|
||||
try {
|
||||
return new GeneratedClassLoader(
|
||||
codegens,
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
|
||||
public class TraitsTest extends CodegenTestCase {
|
||||
@@ -26,6 +27,7 @@ public class TraitsTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getPrefix() {
|
||||
return "traits";
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.assertThrows;
|
||||
|
||||
public class TypeInfoTest extends CodegenTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@@ -27,6 +30,7 @@ public class TypeInfoTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getPrefix() {
|
||||
return "typeInfo";
|
||||
|
||||
Reference in New Issue
Block a user