Check for syntax/diagnostic errors in some tests

This commit is contained in:
Alexander Udalov
2014-05-28 22:20:13 +04:00
parent 2b5bc6b63d
commit ea31f372aa
11 changed files with 40 additions and 60 deletions
@@ -6,7 +6,8 @@ public class BadClass {
fun foo() { fun foo() {
val x: () -> Int = { val x: () -> Int = {
bar(ArrayList<Int>()) bar(ArrayList<Int>())
baz<Double, ArrayList<ArrayList>>(ArrayList()) baz<Double, ArrayList<Double>>(ArrayList())
0
} }
} }
@@ -4,5 +4,5 @@ trait B {
fun foo(kotlinName: Int) fun foo(kotlinName: Int)
} }
class ZAB : A, B abstract class ZAB : A, B
class ZBA : B, A abstract class ZBA : B, A
@@ -10,12 +10,12 @@ internal trait B {
internal abstract fun foo(/*0*/ kotlinName: kotlin.Int): kotlin.Unit internal abstract fun foo(/*0*/ kotlinName: kotlin.Int): kotlin.Unit
} }
internal final class ZAB : test.A, test.B { internal abstract class ZAB : test.A, test.B {
public constructor ZAB() public constructor ZAB()
public abstract override /*2*/ /*fake_override*/ fun foo(/*0*/ kotlinName: kotlin.Int): kotlin.Unit public abstract override /*2*/ /*fake_override*/ fun foo(/*0*/ kotlinName: kotlin.Int): kotlin.Unit
} }
internal final class ZBA : test.B, test.A { internal abstract class ZBA : test.B, test.A {
public constructor ZBA() public constructor ZBA()
public abstract override /*2*/ /*fake_override*/ fun foo(/*0*/ kotlinName: kotlin.Int): kotlin.Unit public abstract override /*2*/ /*fake_override*/ fun foo(/*0*/ kotlinName: kotlin.Int): kotlin.Unit
} }
@@ -1,5 +1,5 @@
package test package test
class K1 : J() { class K1 : J() {
override fun foo(l: MutableList<String>): String override fun foo(l: MutableList<String>): String = ""
} }
@@ -193,7 +193,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
); );
JetFile jetFile = JetTestUtils.createFile(kotlinSrc.getPath(), FileUtil.loadFile(kotlinSrc, true), environment.getProject()); JetFile jetFile = JetTestUtils.createFile(kotlinSrc.getPath(), FileUtil.loadFile(kotlinSrc, true), environment.getProject());
AnalyzeExhaust exhaust = JvmResolveUtil.analyzeFilesWithJavaIntegration( AnalyzeExhaust exhaust = JvmResolveUtil.analyzeFilesWithJavaIntegrationAndCheckForErrors(
environment.getProject(), Collections.singleton(jetFile), Predicates.<PsiFile>alwaysTrue() environment.getProject(), Collections.singleton(jetFile), Predicates.<PsiFile>alwaysTrue()
); );
PackageViewDescriptor packageView = exhaust.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME); PackageViewDescriptor packageView = exhaust.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
@@ -82,7 +82,7 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
private PackageViewDescriptor analyzeFileToPackageView(@NotNull File... extraClassPath) throws IOException { private PackageViewDescriptor analyzeFileToPackageView(@NotNull File... extraClassPath) throws IOException {
Project project = createEnvironment(Arrays.asList(extraClassPath)).getProject(); Project project = createEnvironment(Arrays.asList(extraClassPath)).getProject();
AnalyzeExhaust exhaust = JvmResolveUtil.analyzeOneFileWithJavaIntegration( AnalyzeExhaust exhaust = JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(
JetTestUtils.loadJetFile(project, getTestDataFileWithExtension("kt")) JetTestUtils.loadJetFile(project, getTestDataFileWithExtension("kt"))
); );
@@ -26,7 +26,6 @@ import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.ConfigurationKind; import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.OutputFileCollection;
import org.jetbrains.jet.TestJdkKind; import org.jetbrains.jet.TestJdkKind;
import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.cli.common.output.outputUtils.OutputUtilsPackage; import org.jetbrains.jet.cli.common.output.outputUtils.OutputUtilsPackage;
@@ -68,12 +67,13 @@ public final class LoadDescriptorUtil {
@NotNull File outDir, @NotNull File outDir,
@NotNull Disposable disposable, @NotNull Disposable disposable,
@NotNull ConfigurationKind configurationKind @NotNull ConfigurationKind configurationKind
) throws IOException { ) {
JetFilesAndExhaust fileAndExhaust = JetFilesAndExhaust.createJetFilesAndAnalyze(kotlinFiles, disposable, configurationKind); JetFilesAndExhaust fileAndExhaust = JetFilesAndExhaust.createJetFilesAndAnalyze(kotlinFiles, disposable, configurationKind);
GenerationState state = GenerationUtils.compileFilesGetGenerationState(fileAndExhaust.getJetFiles().get(0).getProject(), fileAndExhaust.getExhaust(), fileAndExhaust.getJetFiles()); AnalyzeExhaust exhaust = fileAndExhaust.getExhaust();
OutputFileCollection outputFiles = state.getFactory(); List<JetFile> files = fileAndExhaust.getJetFiles();
OutputUtilsPackage.writeAllTo(outputFiles, outDir); GenerationState state = GenerationUtils.compileFilesGetGenerationState(files.get(0).getProject(), exhaust, files);
return fileAndExhaust.getExhaust(); OutputUtilsPackage.writeAllTo(state.getFactory(), outDir);
return exhaust;
} }
@NotNull @NotNull
@@ -124,23 +124,20 @@ public final class LoadDescriptorUtil {
@NotNull File ktFile, @NotNull File ktFile,
@NotNull Disposable disposable, @NotNull Disposable disposable,
@NotNull ConfigurationKind configurationKind @NotNull ConfigurationKind configurationKind
) throws Exception { ) {
JetFilesAndExhaust fileAndExhaust = JetFilesAndExhaust.createJetFilesAndAnalyze(Collections.singletonList(ktFile), disposable, configurationKind); JetFilesAndExhaust fileAndExhaust = JetFilesAndExhaust.createJetFilesAndAnalyze(Collections.singletonList(ktFile), disposable, configurationKind);
PackageViewDescriptor packageView = PackageViewDescriptor packageView = fileAndExhaust.getExhaust().getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
fileAndExhaust.getExhaust().getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
assert packageView != null: TEST_PACKAGE_FQNAME + " package not found in " + ktFile.getName(); assert packageView != null: TEST_PACKAGE_FQNAME + " package not found in " + ktFile.getName();
return packageView; return packageView;
} }
private static class JetFilesAndExhaust { private static class JetFilesAndExhaust {
@NotNull @NotNull
public static JetFilesAndExhaust createJetFilesAndAnalyze( public static JetFilesAndExhaust createJetFilesAndAnalyze(
@NotNull List<File> kotlinFiles, @NotNull List<File> kotlinFiles,
@NotNull Disposable disposable, @NotNull Disposable disposable,
@NotNull ConfigurationKind configurationKind @NotNull ConfigurationKind configurationKind
) ) {
throws IOException {
final JetCoreEnvironment jetCoreEnvironment = createEnvironmentWithMockJdkAndIdeaAnnotations(disposable, configurationKind); final JetCoreEnvironment jetCoreEnvironment = createEnvironmentWithMockJdkAndIdeaAnnotations(disposable, configurationKind);
List<JetFile> jetFiles = ContainerUtil.map(kotlinFiles, new Function<File, JetFile>() { List<JetFile> jetFiles = ContainerUtil.map(kotlinFiles, new Function<File, JetFile>() {
@Override @Override
@@ -154,18 +151,16 @@ public final class LoadDescriptorUtil {
} }
} }
}); });
AnalyzeExhaust exhaust = JvmResolveUtil.analyzeFilesWithJavaIntegration( AnalyzeExhaust exhaust = JvmResolveUtil.analyzeFilesWithJavaIntegrationAndCheckForErrors(
jetCoreEnvironment.getProject(), jetFiles, Predicates.<PsiFile>alwaysTrue()); jetCoreEnvironment.getProject(), jetFiles, Predicates.<PsiFile>alwaysTrue());
return new JetFilesAndExhaust(jetFiles, exhaust); return new JetFilesAndExhaust(jetFiles, exhaust);
} }
@NotNull
private final List<JetFile> jetFiles; private final List<JetFile> jetFiles;
@NotNull
private final AnalyzeExhaust exhaust; private final AnalyzeExhaust exhaust;
private JetFilesAndExhaust(@NotNull List<JetFile> files, @NotNull AnalyzeExhaust exhaust) { private JetFilesAndExhaust(@NotNull List<JetFile> jetFiles, @NotNull AnalyzeExhaust exhaust) {
jetFiles = files; this.jetFiles = jetFiles;
this.exhaust = exhaust; this.exhaust = exhaust;
} }
@@ -25,7 +25,6 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.descriptors.serialization.descriptors.MemberFilter; import org.jetbrains.jet.descriptors.serialization.descriptors.MemberFilter;
import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.BindingTraceContext; import org.jetbrains.jet.lang.resolve.BindingTraceContext;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
@@ -34,7 +33,7 @@ import java.util.Collections;
public class JvmResolveUtil { public class JvmResolveUtil {
@NotNull @NotNull
public static AnalyzeExhaust analyzeOneFileWithJavaIntegrationAndCheckForErrors(JetFile file) { public static AnalyzeExhaust analyzeOneFileWithJavaIntegrationAndCheckForErrors(@NotNull JetFile file) {
AnalyzingUtils.checkForSyntacticErrors(file); AnalyzingUtils.checkForSyntacticErrors(file);
AnalyzeExhaust analyzeExhaust = analyzeOneFileWithJavaIntegration(file); AnalyzeExhaust analyzeExhaust = analyzeOneFileWithJavaIntegration(file);
@@ -45,23 +44,22 @@ public class JvmResolveUtil {
} }
@NotNull @NotNull
public static AnalyzeExhaust analyzeOneFileWithJavaIntegration(JetFile file) { public static AnalyzeExhaust analyzeOneFileWithJavaIntegration(@NotNull JetFile file) {
return analyzeFilesWithJavaIntegration(file.getProject(), Collections.singleton(file), return analyzeFilesWithJavaIntegration(file.getProject(), Collections.singleton(file),
Predicates.<PsiFile>alwaysTrue()); Predicates.<PsiFile>alwaysTrue());
} }
@NotNull @NotNull
public static AnalyzeExhaust analyzeFilesWithJavaIntegrationAndCheckForErrors( public static AnalyzeExhaust analyzeFilesWithJavaIntegrationAndCheckForErrors(
Project project, @NotNull Project project,
Collection<JetFile> files, @NotNull Collection<JetFile> files,
Predicate<PsiFile> filesToAnalyzeCompletely @NotNull Predicate<PsiFile> filesToAnalyzeCompletely
) { ) {
for (JetFile file : files) { for (JetFile file : files) {
AnalyzingUtils.checkForSyntacticErrors(file); AnalyzingUtils.checkForSyntacticErrors(file);
} }
AnalyzeExhaust analyzeExhaust = analyzeFilesWithJavaIntegration( AnalyzeExhaust analyzeExhaust = analyzeFilesWithJavaIntegration(project, files, filesToAnalyzeCompletely);
project, files, filesToAnalyzeCompletely);
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext()); AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
@@ -70,24 +68,13 @@ public class JvmResolveUtil {
@NotNull @NotNull
public static AnalyzeExhaust analyzeFilesWithJavaIntegration( public static AnalyzeExhaust analyzeFilesWithJavaIntegration(
Project project, @NotNull Project project,
Collection<JetFile> files, @NotNull Collection<JetFile> files,
Predicate<PsiFile> filesToAnalyzeCompletely @NotNull Predicate<PsiFile> filesToAnalyzeCompletely
) { ) {
BindingTraceContext bindingTraceContext = new BindingTraceContext(); BindingTraceContext bindingTraceContext = new BindingTraceContext();
return analyzeFilesWithJavaIntegration(project, files, bindingTraceContext, filesToAnalyzeCompletely return AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files, bindingTraceContext, filesToAnalyzeCompletely,
);
}
@NotNull
public static AnalyzeExhaust analyzeFilesWithJavaIntegration(
Project project,
Collection<JetFile> files,
BindingTrace trace,
Predicate<PsiFile> filesToAnalyzeCompletely
) {
return AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files, trace, filesToAnalyzeCompletely,
AnalyzerFacadeForJVM.createJavaModule("<module>"), AnalyzerFacadeForJVM.createJavaModule("<module>"),
MemberFilter.ALWAYS_TRUE); MemberFilter.ALWAYS_TRUE);
} }
@@ -49,8 +49,8 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
val explicitReceiverKind = directives.getExplicitReceiverKind() val explicitReceiverKind = directives.getExplicitReceiverKind()
fun analyzeFileAndGetResolvedCallEntries(): Map<JetElement, ResolvedCall<*>> { fun analyzeFileAndGetResolvedCallEntries(): Map<JetElement, ResolvedCall<*>> {
val psiFile = JetTestUtils.loadJetFile(getProject(), file) val psiFile = JetTestUtils.loadJetFile(getProject(), file)!!
val analyzeExhaust = JvmResolveUtil.analyzeOneFileWithJavaIntegration(psiFile) val analyzeExhaust = JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(psiFile)
val bindingContext = analyzeExhaust.getBindingContext() val bindingContext = analyzeExhaust.getBindingContext()
return bindingContext.getSliceContents(BindingContext.RESOLVED_CALL) return bindingContext.getSliceContents(BindingContext.RESOLVED_CALL)
} }
@@ -33,7 +33,6 @@ import org.jetbrains.jet.resolve.constraintSystem.AbstractConstraintSystemTest.M
import org.jetbrains.jet.resolve.constraintSystem.AbstractConstraintSystemTest.MyConstraint import org.jetbrains.jet.resolve.constraintSystem.AbstractConstraintSystemTest.MyConstraint
import java.util.ArrayList import java.util.ArrayList
import java.util.LinkedHashMap import java.util.LinkedHashMap
import kotlin.properties.Delegates
import org.jetbrains.jet.lang.resolve.lazy.JvmResolveUtil import org.jetbrains.jet.lang.resolve.lazy.JvmResolveUtil
abstract public class AbstractConstraintSystemTest() : JetLiteFixture() { abstract public class AbstractConstraintSystemTest() : JetLiteFixture() {
@@ -74,8 +73,8 @@ abstract public class AbstractConstraintSystemTest() : JetLiteFixture() {
private fun analyzeDeclarations(): MyDeclarations { private fun analyzeDeclarations(): MyDeclarations {
val fileName = "declarations/declarations.kt" val fileName = "declarations/declarations.kt"
val psiFile = createPsiFile(null, fileName, loadFile(fileName)) val psiFile = createPsiFile(null, fileName, loadFile(fileName))!!
val analyzeExhaust = JvmResolveUtil.analyzeOneFileWithJavaIntegration(psiFile) val analyzeExhaust = JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(psiFile)
val bindingContext = analyzeExhaust.getBindingContext() val bindingContext = analyzeExhaust.getBindingContext()
return MyDeclarations(bindingContext, getProject(), typeResolver) return MyDeclarations(bindingContext, getProject(), typeResolver)
} }
@@ -32,7 +32,6 @@ import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters; import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.lazy.JvmResolveUtil; import org.jetbrains.jet.lang.resolve.lazy.JvmResolveUtil;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler; import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
@@ -44,7 +43,7 @@ import org.jetbrains.jet.storage.LockBasedStorageManager;
import java.util.List; import java.util.List;
public class JetDefaultModalityModifiersTest extends JetLiteFixture { public class JetDefaultModalityModifiersTest extends JetLiteFixture {
private JetDefaultModalityModifiersTestCase tc = new JetDefaultModalityModifiersTestCase(); private final JetDefaultModalityModifiersTestCase tc = new JetDefaultModalityModifiersTestCase();
@Override @Override
protected JetCoreEnvironment createEnvironment() { protected JetCoreEnvironment createEnvironment() {
@@ -64,7 +63,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
} }
public class JetDefaultModalityModifiersTestCase { public class JetDefaultModalityModifiersTestCase {
private ModuleDescriptorImpl root = JetTestUtils.createEmptyModule("<test_root>"); private final ModuleDescriptorImpl root = JetTestUtils.createEmptyModule("<test_root>");
private DescriptorResolver descriptorResolver; private DescriptorResolver descriptorResolver;
private JetScope scope; private JetScope scope;
@@ -84,8 +83,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
List<JetDeclaration> declarations = file.getDeclarations(); List<JetDeclaration> declarations = file.getDeclarations();
JetDeclaration aClass = declarations.get(0); JetDeclaration aClass = declarations.get(0);
assert aClass instanceof JetClass; assert aClass instanceof JetClass;
AnalyzeExhaust bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegration(file AnalyzeExhaust bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(file);
);
DeclarationDescriptor classDescriptor = bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass); DeclarationDescriptor classDescriptor = bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
WritableScopeImpl scope = new WritableScopeImpl( WritableScopeImpl scope = new WritableScopeImpl(
libraryScope, root, RedeclarationHandler.DO_NOTHING, "JetDefaultModalityModifiersTest"); libraryScope, root, RedeclarationHandler.DO_NOTHING, "JetDefaultModalityModifiersTest");
@@ -96,7 +94,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
} }
private ClassDescriptorWithResolutionScopes createClassDescriptor(ClassKind kind, JetClass aClass) { private ClassDescriptorWithResolutionScopes createClassDescriptor(ClassKind kind, JetClass aClass) {
MutableClassDescriptor classDescriptor = new MutableClassDescriptor(root, scope, kind, false, Name.identifier(aClass.getName())); MutableClassDescriptor classDescriptor = new MutableClassDescriptor(root, scope, kind, false, aClass.getNameAsSafeName());
TopDownAnalysisParameters parameters = TopDownAnalysisParameters.create( TopDownAnalysisParameters parameters = TopDownAnalysisParameters.create(
LockBasedStorageManager.NO_LOCKS, new ExceptionTracker(), Predicates.<PsiFile>alwaysTrue(), false, false LockBasedStorageManager.NO_LOCKS, new ExceptionTracker(), Predicates.<PsiFile>alwaysTrue(), false, false
); );