Base class for tests introduced
This commit is contained in:
@@ -37,6 +37,7 @@ import org.jetbrains.jet.cli.jvm.compiler.CliLightClassGenerationSupport;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
||||
import org.jetbrains.jet.codegen.forTestCompile.ForTestPackJdkAnnotations;
|
||||
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||
@@ -48,6 +49,7 @@ import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LazyResolveTestUtil;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
@@ -339,6 +341,16 @@ public class JetTestUtils {
|
||||
CliLightClassGenerationSupport.getInstanceForCli(environment.getProject()).newBindingTrace();
|
||||
}
|
||||
|
||||
public static void resolveAllKotlinFiles(JetCoreEnvironment environment) throws IOException {
|
||||
List<String> paths = environment.getConfiguration().get(CommonConfigurationKeys.SOURCE_ROOTS_KEY);
|
||||
assert paths != null;
|
||||
List<JetFile> jetFiles = Lists.newArrayList();
|
||||
for (String path : paths) {
|
||||
jetFiles.add(loadJetFile(environment.getProject(), new File(path)));
|
||||
}
|
||||
LazyResolveTestUtil.resolveEagerly(jetFiles, environment);
|
||||
}
|
||||
|
||||
public interface TestFileFactory<F> {
|
||||
F create(String fileName, String text);
|
||||
}
|
||||
|
||||
@@ -16,49 +16,20 @@
|
||||
|
||||
package org.jetbrains.jet.asJava;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LazyResolveTestUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class JavaElementFinderTest extends JetLiteFixture {
|
||||
private JavaElementFinder finder;
|
||||
|
||||
public JavaElementFinderTest() {
|
||||
super("asJava/findClasses");
|
||||
}
|
||||
public class JavaElementFinderTest extends KotlinAsJavaTestBase {
|
||||
|
||||
@Override
|
||||
protected JetCoreEnvironment createEnvironment() {
|
||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||
|
||||
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, getTestDataPath() + "/asJava/findClasses/" + getTestName(false) + ".kt");
|
||||
|
||||
return new JetCoreEnvironment(getTestRootDisposable(), configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
// We need to resolve all the files in order too fill in the trace that sits inside LightClassGenerationSupport
|
||||
List<String> paths = getEnvironment().getConfiguration().get(CommonConfigurationKeys.SOURCE_ROOTS_KEY);
|
||||
assert paths != null;
|
||||
List<JetFile> jetFiles = Lists.newArrayList();
|
||||
for (String path : paths) {
|
||||
jetFiles.add(JetTestUtils.loadJetFile(getProject(), new File(path)));
|
||||
}
|
||||
LazyResolveTestUtil.resolveEagerly(jetFiles, getEnvironment());
|
||||
finder = new JavaElementFinder(getProject(), LightClassGenerationSupport.getInstance(getProject()));
|
||||
protected List<File> getKotlinSourceRoots() {
|
||||
return Collections.singletonList(
|
||||
new File("compiler/testData/asJava/findClasses/" + getTestName(false) + ".kt")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.asJava;
|
||||
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinTestWithEnvironment;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class KotlinAsJavaTestBase extends KotlinTestWithEnvironment {
|
||||
protected JavaElementFinder finder;
|
||||
|
||||
@Override
|
||||
protected JetCoreEnvironment createEnvironment() {
|
||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||
|
||||
for (File root : getKotlinSourceRoots()) {
|
||||
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, root.getPath());
|
||||
}
|
||||
|
||||
return new JetCoreEnvironment(getTestRootDisposable(), configuration);
|
||||
}
|
||||
|
||||
protected abstract List<File> getKotlinSourceRoots();
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
// We need to resolve all the files in order too fill in the trace that sits inside LightClassGenerationSupport
|
||||
JetTestUtils.resolveAllKotlinFiles(getEnvironment());
|
||||
|
||||
finder = JavaElementFinder.getInstance(getProject());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
finder = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.jet.asJava;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiClassType;
|
||||
@@ -27,28 +26,26 @@ import com.intellij.psi.PsiTypeParameter;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinTestWithEnvironment;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LazyResolveTestUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.asJava.KotlinLightClassTest.ClassProperty.*;
|
||||
|
||||
public abstract class KotlinLightClassTest extends KotlinTestWithEnvironment {
|
||||
public abstract class KotlinLightClassTest extends KotlinAsJavaTestBase {
|
||||
|
||||
public static class Declared extends KotlinLightClassTest {
|
||||
public Declared() {
|
||||
super(new File("compiler/testData/asJava/lightClasses/Declared.kt"));
|
||||
|
||||
@Override
|
||||
protected List<File> getKotlinSourceRoots() {
|
||||
return Collections.singletonList(
|
||||
new File("compiler/testData/asJava/lightClasses/Declared.kt")
|
||||
);
|
||||
}
|
||||
|
||||
public void testNoModifiers() {
|
||||
@@ -97,8 +94,11 @@ public abstract class KotlinLightClassTest extends KotlinTestWithEnvironment {
|
||||
|
||||
public static class DeclaredWithGenerics extends KotlinLightClassTest {
|
||||
|
||||
public DeclaredWithGenerics() {
|
||||
super(new File("compiler/testData/asJava/lightClasses/DeclaredWithGenerics.kt"));
|
||||
@Override
|
||||
protected List<File> getKotlinSourceRoots() {
|
||||
return Collections.singletonList(
|
||||
new File("compiler/testData/asJava/lightClasses/DeclaredWithGenerics.kt")
|
||||
);
|
||||
}
|
||||
|
||||
public void testGeneric1() throws Exception {
|
||||
@@ -122,8 +122,11 @@ public abstract class KotlinLightClassTest extends KotlinTestWithEnvironment {
|
||||
|
||||
public static class Package extends KotlinLightClassTest {
|
||||
|
||||
public Package() {
|
||||
super(new File("compiler/testData/asJava/lightClasses/Package.kt"));
|
||||
@Override
|
||||
protected List<File> getKotlinSourceRoots() {
|
||||
return Collections.singletonList(
|
||||
new File("compiler/testData/asJava/lightClasses/Package.kt")
|
||||
);
|
||||
}
|
||||
|
||||
public void testPackage() throws Exception {
|
||||
@@ -131,45 +134,6 @@ public abstract class KotlinLightClassTest extends KotlinTestWithEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
private File path;
|
||||
private JavaElementFinder finder;
|
||||
|
||||
protected KotlinLightClassTest(File path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JetCoreEnvironment createEnvironment() {
|
||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||
|
||||
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, path.getPath());
|
||||
|
||||
return new JetCoreEnvironment(getTestRootDisposable(), configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
finder = JavaElementFinder.getInstance(getProject());
|
||||
|
||||
// We need to resolve all the files in order to fill in the trace that sits inside LightClassGenerationSupport
|
||||
List<String> paths = getEnvironment().getConfiguration().get(CommonConfigurationKeys.SOURCE_ROOTS_KEY);
|
||||
assert paths != null;
|
||||
List<JetFile> jetFiles = Lists.newArrayList();
|
||||
for (String path : paths) {
|
||||
jetFiles.add(JetTestUtils.loadJetFile(getProject(), new File(path)));
|
||||
}
|
||||
LazyResolveTestUtil.resolveEagerly(jetFiles, getEnvironment());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
finder = null;
|
||||
path = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected PsiClass findClass(String qualifiedName) {
|
||||
PsiClass psiClass = finder.findClass(qualifiedName, GlobalSearchScope.allScope(getProject()));
|
||||
|
||||
Reference in New Issue
Block a user