Drop InnerTestClasses annotation, use Java reflection
This commit is contained in:
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 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.kotlin.test;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target(ElementType.TYPE)
|
|
||||||
public @interface InnerTestClasses {
|
|
||||||
Class<? extends TestCase>[] value() default {};
|
|
||||||
}
|
|
||||||
@@ -34,7 +34,6 @@ import com.intellij.psi.impl.PsiFileFactoryImpl;
|
|||||||
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||||
import com.intellij.testFramework.LightVirtualFile;
|
import com.intellij.testFramework.LightVirtualFile;
|
||||||
import com.intellij.testFramework.TestDataFile;
|
import com.intellij.testFramework.TestDataFile;
|
||||||
import com.intellij.util.ArrayUtil;
|
|
||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
import com.intellij.util.Processor;
|
import com.intellij.util.Processor;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
@@ -87,9 +86,7 @@ import java.util.*;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.cli.jvm.config.ConfigPackage.addJavaSourceRoots;
|
import static org.jetbrains.kotlin.cli.jvm.config.ConfigPackage.*;
|
||||||
import static org.jetbrains.kotlin.cli.jvm.config.ConfigPackage.addJvmClasspathRoot;
|
|
||||||
import static org.jetbrains.kotlin.cli.jvm.config.ConfigPackage.addJvmClasspathRoots;
|
|
||||||
import static org.jetbrains.kotlin.cli.jvm.config.JVMConfigurationKeys.ANNOTATIONS_PATH_KEY;
|
import static org.jetbrains.kotlin.cli.jvm.config.JVMConfigurationKeys.ANNOTATIONS_PATH_KEY;
|
||||||
import static org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil.compileKotlinToDirAndGetAnalysisResult;
|
import static org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil.compileKotlinToDirAndGetAnalysisResult;
|
||||||
import static org.jetbrains.kotlin.psi.PsiPackage.JetPsiFactory;
|
import static org.jetbrains.kotlin.psi.PsiPackage.JetPsiFactory;
|
||||||
@@ -236,9 +233,6 @@ public class JetTestUtils {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static final Class<? extends TestCase>[] NO_INNER_CLASSES = ArrayUtil.EMPTY_CLASS_ARRAY;
|
|
||||||
|
|
||||||
// We suspect sequences of eight consecutive hexadecimal digits to be a package part hash code
|
// We suspect sequences of eight consecutive hexadecimal digits to be a package part hash code
|
||||||
private static final Pattern STRIP_PACKAGE_PART_HASH_PATTERN = Pattern.compile("\\$([0-9a-f]{8})");
|
private static final Pattern STRIP_PACKAGE_PART_HASH_PATTERN = Pattern.compile("\\$([0-9a-f]{8})");
|
||||||
|
|
||||||
@@ -849,14 +843,9 @@ public class JetTestUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertTestClassPresentByMetadata(
|
private static void assertTestClassPresentByMetadata(@NotNull Class<?> outerClass, @NotNull File testDataDir) {
|
||||||
@NotNull Class<?> outerClass,
|
for (Class<?> nestedClass : outerClass.getDeclaredClasses()) {
|
||||||
@NotNull File testDataDir
|
TestMetadata testMetadata = nestedClass.getAnnotation(TestMetadata.class);
|
||||||
) {
|
|
||||||
InnerTestClasses innerClassesAnnotation = outerClass.getAnnotation(InnerTestClasses.class);
|
|
||||||
Class<? extends TestCase>[] innerClasses = innerClassesAnnotation == null ? NO_INNER_CLASSES : innerClassesAnnotation.value();
|
|
||||||
for (Class<?> innerClass : innerClasses) {
|
|
||||||
TestMetadata testMetadata = innerClass.getAnnotation(TestMetadata.class);
|
|
||||||
if (testMetadata != null && testMetadata.value().equals(getFilePath(testDataDir))) {
|
if (testMetadata != null && testMetadata.value().equals(getFilePath(testDataDir))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import junit.framework.TestCase;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.generators.di.GeneratorsFileUtil;
|
import org.jetbrains.kotlin.generators.di.GeneratorsFileUtil;
|
||||||
import org.jetbrains.kotlin.test.InnerTestClasses;
|
|
||||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||||
import org.jetbrains.kotlin.test.TestMetadata;
|
import org.jetbrains.kotlin.test.TestMetadata;
|
||||||
@@ -37,6 +36,8 @@ import java.util.Collections;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static kotlin.KotlinPackage.single;
|
||||||
|
|
||||||
public class TestGenerator {
|
public class TestGenerator {
|
||||||
|
|
||||||
public static enum TargetBackend {
|
public static enum TargetBackend {
|
||||||
@@ -83,7 +84,6 @@ public class TestGenerator {
|
|||||||
p.println("package ", suiteClassPackage, ";");
|
p.println("package ", suiteClassPackage, ";");
|
||||||
p.println();
|
p.println();
|
||||||
p.println("import com.intellij.testFramework.TestDataPath;");
|
p.println("import com.intellij.testFramework.TestDataPath;");
|
||||||
p.println("import " + InnerTestClasses.class.getCanonicalName() + ";");
|
|
||||||
p.println("import ", RUNNER.getCanonicalName(), ";");
|
p.println("import ", RUNNER.getCanonicalName(), ";");
|
||||||
p.println("import " + JetTestUtils.class.getCanonicalName() + ";");
|
p.println("import " + JetTestUtils.class.getCanonicalName() + ";");
|
||||||
if (!suiteClassPackage.equals(baseTestClassPackage)) {
|
if (!suiteClassPackage.equals(baseTestClassPackage)) {
|
||||||
@@ -98,17 +98,18 @@ public class TestGenerator {
|
|||||||
p.println("/** This class is generated by {@link ", JetTestUtils.TEST_GENERATOR_NAME, "}. DO NOT MODIFY MANUALLY */");
|
p.println("/** This class is generated by {@link ", JetTestUtils.TEST_GENERATOR_NAME, "}. DO NOT MODIFY MANUALLY */");
|
||||||
|
|
||||||
generateSuppressAllWarnings(p);
|
generateSuppressAllWarnings(p);
|
||||||
|
|
||||||
|
TestClassModel model;
|
||||||
if (testClassModels.size() == 1) {
|
if (testClassModels.size() == 1) {
|
||||||
TestClassModel theOnlyTestClass = testClassModels.iterator().next();
|
model = new DelegatingTestClassModel(single(testClassModels)) {
|
||||||
generateTestClass(p, new DelegatingTestClassModel(theOnlyTestClass) {
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return suiteClassName;
|
return suiteClassName;
|
||||||
}
|
}
|
||||||
}, false);
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
generateTestClass(p, new TestClassModel() {
|
model = new TestClassModel() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<TestClassModel> getInnerTestClasses() {
|
public Collection<TestClassModel> getInnerTestClasses() {
|
||||||
@@ -141,9 +142,11 @@ public class TestGenerator {
|
|||||||
public String getDataPathRoot() {
|
public String getDataPathRoot() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}, false);
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generateTestClass(p, model, false);
|
||||||
|
|
||||||
File testSourceFile = new File(testSourceFilePath);
|
File testSourceFile = new File(testSourceFilePath);
|
||||||
GeneratorsFileUtil.writeFileIfContentChanged(testSourceFile, out.toString(), false);
|
GeneratorsFileUtil.writeFileIfContentChanged(testSourceFile, out.toString(), false);
|
||||||
}
|
}
|
||||||
@@ -153,7 +156,6 @@ public class TestGenerator {
|
|||||||
|
|
||||||
generateMetadata(p, testClassModel);
|
generateMetadata(p, testClassModel);
|
||||||
generateTestDataPath(p, testClassModel);
|
generateTestDataPath(p, testClassModel);
|
||||||
generateInnerClassesAnnotation(p, testClassModel);
|
|
||||||
p.println("@RunWith(", RUNNER.getSimpleName(), ".class)");
|
p.println("@RunWith(", RUNNER.getSimpleName(), ".class)");
|
||||||
|
|
||||||
p.println("public " + staticModifier + "class ", testClassModel.getName(), " extends ", baseTestClassName, " {");
|
p.println("public " + staticModifier + "class ", testClassModel.getName(), " extends ", baseTestClassName, " {");
|
||||||
@@ -209,26 +211,6 @@ public class TestGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void generateInnerClassesAnnotation(Printer p, TestClassModel testClassModel) {
|
|
||||||
Collection<TestClassModel> innerTestClasses = testClassModel.getInnerTestClasses();
|
|
||||||
if (innerTestClasses.isEmpty()) return;
|
|
||||||
p.println("@InnerTestClasses({");
|
|
||||||
|
|
||||||
p.pushIndent();
|
|
||||||
p.pushIndent();
|
|
||||||
|
|
||||||
for (TestClassModel innerTestClass : innerTestClasses) {
|
|
||||||
if (!innerTestClass.isEmpty()) {
|
|
||||||
p.println(testClassModel.getName(), ".", innerTestClass.getName(), ".class,");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
p.popIndent();
|
|
||||||
p.popIndent();
|
|
||||||
p.println("})");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void generateSuppressAllWarnings(Printer p) {
|
private static void generateSuppressAllWarnings(Printer p) {
|
||||||
p.println("@SuppressWarnings(\"all\")");
|
p.println("@SuppressWarnings(\"all\")");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user