KT-2524: Standalone compiler prints diagnostics in random order.
#KT-2524 Fixed
This commit is contained in:
+30
-1
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.cli.common.messages;
|
package org.jetbrains.jet.cli.common.messages;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.intellij.openapi.util.TextRange;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
@@ -34,6 +36,9 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
|||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pavel Talanov
|
* @author Pavel Talanov
|
||||||
@@ -111,12 +116,36 @@ public final class AnalyzerWithCompilerReport {
|
|||||||
|
|
||||||
public static boolean reportDiagnostics(@NotNull BindingContext bindingContext, @NotNull MessageCollector messageCollector) {
|
public static boolean reportDiagnostics(@NotNull BindingContext bindingContext, @NotNull MessageCollector messageCollector) {
|
||||||
boolean hasErrors = false;
|
boolean hasErrors = false;
|
||||||
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
List<Diagnostic> diagnostics = Lists.newArrayList(bindingContext.getDiagnostics());
|
||||||
|
sortDiagnostics(diagnostics);
|
||||||
|
for (Diagnostic diagnostic : diagnostics) {
|
||||||
hasErrors |= reportDiagnostic(diagnostic, messageCollector);
|
hasErrors |= reportDiagnostic(diagnostic, messageCollector);
|
||||||
}
|
}
|
||||||
return hasErrors;
|
return hasErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void sortDiagnostics(@NotNull List<Diagnostic> diagnostics) {
|
||||||
|
Comparator<Diagnostic> diagnosticComparator = new Comparator<Diagnostic>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Diagnostic d1, Diagnostic d2) {
|
||||||
|
String path1 = d1.getPsiFile().getViewProvider().getVirtualFile().getPath();
|
||||||
|
String path2 = d2.getPsiFile().getViewProvider().getVirtualFile().getPath();
|
||||||
|
if (!path1.equals(path2)) return path1.compareTo(path2);
|
||||||
|
|
||||||
|
TextRange range1 = d1.getTextRanges().iterator().next();
|
||||||
|
TextRange range2 = d2.getTextRanges().iterator().next();
|
||||||
|
int startOffsetDiff = range1.getStartOffset() - range2.getStartOffset();
|
||||||
|
if (startOffsetDiff != 0) return startOffsetDiff;
|
||||||
|
|
||||||
|
int endOffsetDiff = range1.getEndOffset() - range2.getEndOffset();
|
||||||
|
if (endOffsetDiff != 0) return endOffsetDiff;
|
||||||
|
|
||||||
|
return d1.getFactory().getName().compareTo(d2.getFactory().getName());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Collections.sort(diagnostics, diagnosticComparator);
|
||||||
|
}
|
||||||
|
|
||||||
private void reportSyntaxErrors(@NotNull Collection<JetFile> files) {
|
private void reportSyntaxErrors(@NotNull Collection<JetFile> files) {
|
||||||
for (JetFile file : files) {
|
for (JetFile file : files) {
|
||||||
reportSyntaxErrors(file, messageCollectorWrapper);
|
reportSyntaxErrors(file, messageCollectorWrapper);
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
ERROR: $TESTDATA_DIR$/diagnosticsOrder1.kt: (1, 5) Redeclaration: x
|
||||||
|
ERROR: $TESTDATA_DIR$/diagnosticsOrder1.kt: (2, 5) Redeclaration: x
|
||||||
|
ERROR: $TESTDATA_DIR$/diagnosticsOrder1.kt: (3, 5) Redeclaration: x
|
||||||
|
ERROR: $TESTDATA_DIR$/diagnosticsOrder1.kt: (4, 5) Redeclaration: x
|
||||||
|
ERROR: $TESTDATA_DIR$/diagnosticsOrder1.kt: (5, 5) Redeclaration: x
|
||||||
|
ERROR: $TESTDATA_DIR$/diagnosticsOrder1.kt: (6, 5) Redeclaration: x
|
||||||
|
ERROR: $TESTDATA_DIR$/diagnosticsOrder1.kt: (7, 5) Redeclaration: x
|
||||||
|
ERROR: $TESTDATA_DIR$/diagnosticsOrder2.kt: (1, 5) Redeclaration: y
|
||||||
|
ERROR: $TESTDATA_DIR$/diagnosticsOrder2.kt: (2, 5) Redeclaration: y
|
||||||
|
COMPILATION_ERROR
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
val x = 5
|
||||||
|
val x = 5
|
||||||
|
val x = 5
|
||||||
|
val x = 5
|
||||||
|
val x = 5
|
||||||
|
val x = 5
|
||||||
|
val x = 5
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
val y = 5
|
||||||
|
val y = 5
|
||||||
@@ -32,11 +32,7 @@ import org.junit.Rule;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.TestName;
|
import org.junit.rules.TestName;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
@@ -110,6 +106,16 @@ public class CliTest {
|
|||||||
Assert.assertTrue(new File(tmpdir.getTmpDir(), "namespace.class").isFile());
|
Assert.assertTrue(new File(tmpdir.getTmpDir(), "namespace.class").isFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void diagnosticsOrder() throws Exception {
|
||||||
|
String[] args = {
|
||||||
|
"-src", "compiler/testData/cli/diagnosticsOrder1.kt"
|
||||||
|
+ File.pathSeparator
|
||||||
|
+ "compiler/testData/cli/diagnosticsOrder2.kt",
|
||||||
|
"-output", tmpdir.getTmpDir().getPath()};
|
||||||
|
executeCompilerCompareOutput(args);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void help() throws Exception {
|
public void help() throws Exception {
|
||||||
executeCompilerCompareOutput(new String[] {"-help"});
|
executeCompilerCompareOutput(new String[] {"-help"});
|
||||||
@@ -175,22 +181,6 @@ public class CliTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testScriptWithoutScriptDefinition() {
|
|
||||||
LinkedList<AnalyzerScriptParameter> scriptParameters = new LinkedList<AnalyzerScriptParameter>();
|
|
||||||
AnalyzerScriptParameter parameter = new AnalyzerScriptParameter(Name.identifier("num"), JetTypeName.parse("jet.Int"));
|
|
||||||
scriptParameters.add(parameter);
|
|
||||||
Class aClass = KotlinToJVMBytecodeCompiler
|
|
||||||
.compileScript(getClass().getClassLoader(), "compiler/testData/cli/fib.fib.kt", scriptParameters, null);
|
|
||||||
Assert.assertNotNull(aClass);
|
|
||||||
|
|
||||||
try {
|
|
||||||
aClass.getConstructor(int.class).newInstance(4);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScriptWithScriptDefinition() {
|
public void testScriptWithScriptDefinition() {
|
||||||
|
|||||||
Reference in New Issue
Block a user