Added checking for unresolved templates in CLI. Added test.
This commit is contained in:
+25
-11
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetIdeTemplate;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
@@ -54,6 +55,9 @@ public final class AnalyzerWithCompilerReport {
|
||||
|
||||
@NotNull
|
||||
private static final SimpleDiagnosticFactory<PsiErrorElement> SYNTAX_ERROR_FACTORY = SimpleDiagnosticFactory.create(Severity.ERROR);
|
||||
@NotNull
|
||||
private static final SimpleDiagnosticFactory<JetIdeTemplate> UNRESOLVED_IDE_TEMPLATE_ERROR_FACTORY
|
||||
= SimpleDiagnosticFactory.create(Severity.ERROR);
|
||||
|
||||
private boolean hasErrors = false;
|
||||
@NotNull
|
||||
@@ -81,8 +85,8 @@ public final class AnalyzerWithCompilerReport {
|
||||
VirtualFile virtualFile = diagnostic.getPsiFile().getVirtualFile();
|
||||
String path = virtualFile == null ? null : virtualFile.getPath();
|
||||
String render;
|
||||
if (diagnostic.getFactory() == SYNTAX_ERROR_FACTORY) {
|
||||
render = ((SyntaxErrorDiagnostic)diagnostic).message;
|
||||
if (diagnostic instanceof MyDiagnostic) {
|
||||
render = ((MyDiagnostic)diagnostic).message;
|
||||
}
|
||||
else {
|
||||
render = DefaultErrorMessages.RENDERER.render(diagnostic);
|
||||
@@ -114,8 +118,8 @@ public final class AnalyzerWithCompilerReport {
|
||||
}
|
||||
|
||||
private void reportSyntaxErrors(@NotNull Collection<JetFile> files) {
|
||||
for (PsiElement file : files) {
|
||||
reportSyntaxErrors(file, AnalyzerWithCompilerReport.this.messageCollectorWrapper);
|
||||
for (JetFile file : files) {
|
||||
reportSyntaxErrors(file, messageCollectorWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,13 +127,23 @@ public final class AnalyzerWithCompilerReport {
|
||||
class ErrorReportingVisitor extends AnalyzingUtils.PsiErrorElementVisitor {
|
||||
boolean hasErrors = false;
|
||||
|
||||
private <E extends PsiElement> void reportDiagnostic(E element, SimpleDiagnosticFactory<E> factory, String message) {
|
||||
MyDiagnostic<?> diagnostic = new MyDiagnostic<E>(element, factory, message);
|
||||
AnalyzerWithCompilerReport.reportDiagnostic(diagnostic, messageCollector);
|
||||
hasErrors = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitIdeTemplate(JetIdeTemplate expression) {
|
||||
String placeholderText = expression.getPlaceholderText();
|
||||
reportDiagnostic(expression, UNRESOLVED_IDE_TEMPLATE_ERROR_FACTORY,
|
||||
"Unresolved IDE template" + (StringUtil.isEmpty(placeholderText) ? "" : ": " + placeholderText));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitErrorElement(PsiErrorElement element) {
|
||||
String description = element.getErrorDescription();
|
||||
String message = StringUtil.isEmpty(description) ? "Syntax error" : description;
|
||||
Diagnostic diagnostic = new SyntaxErrorDiagnostic(element, Severity.ERROR, message);
|
||||
reportDiagnostic(diagnostic, messageCollector);
|
||||
hasErrors = true;
|
||||
reportDiagnostic(element, SYNTAX_ERROR_FACTORY, StringUtil.isEmpty(description) ? "Syntax error" : description);
|
||||
}
|
||||
}
|
||||
ErrorReportingVisitor visitor = new ErrorReportingVisitor();
|
||||
@@ -156,11 +170,11 @@ public final class AnalyzerWithCompilerReport {
|
||||
}
|
||||
|
||||
|
||||
public static class SyntaxErrorDiagnostic extends SimpleDiagnostic<PsiErrorElement> {
|
||||
private static class MyDiagnostic<E extends PsiElement> extends SimpleDiagnostic<E> {
|
||||
private String message;
|
||||
|
||||
public SyntaxErrorDiagnostic(@NotNull PsiErrorElement psiElement, @NotNull Severity severity, String message) {
|
||||
super(psiElement, SYNTAX_ERROR_FACTORY, severity);
|
||||
public MyDiagnostic(@NotNull E psiElement, @NotNull SimpleDiagnosticFactory<E> factory, String message) {
|
||||
super(psiElement, factory, Severity.ERROR);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||
import org.jetbrains.jet.lang.psi.JetIdeTemplate;
|
||||
import org.jetbrains.jet.lang.psi.JetVisitorVoid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -32,7 +34,7 @@ import java.util.List;
|
||||
*/
|
||||
public class AnalyzingUtils {
|
||||
|
||||
public abstract static class PsiErrorElementVisitor extends PsiElementVisitor {
|
||||
public abstract static class PsiErrorElementVisitor extends JetVisitorVoid {
|
||||
@Override
|
||||
public void visitElement(PsiElement element) {
|
||||
element.acceptChildren(this);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
fun main(args : Array<String>) {
|
||||
if (<#<condition>#>) {
|
||||
<#<block>#>
|
||||
} else {
|
||||
<#<block>#>
|
||||
}
|
||||
|
||||
fun <#<name>#>(<#<params>#>) : <#<returnType>#> {
|
||||
<#<body>#>
|
||||
}
|
||||
|
||||
for (<#<i>#> in <#<elements>#>) {
|
||||
<#<body>#>
|
||||
}
|
||||
|
||||
when (<#<expression>#>) {
|
||||
<#<condition>#> -> <#<value>#>
|
||||
else -> <#<elseValue>#>
|
||||
}
|
||||
|
||||
var <#<name>#> = <#<value>#>
|
||||
|
||||
class <#<name>#> {
|
||||
<#<body>#>
|
||||
}
|
||||
|
||||
class <#<name>#> {
|
||||
var <#<name>#> : <#<varType>#>
|
||||
get() {
|
||||
<#<body>#>
|
||||
}
|
||||
set(value) {
|
||||
<#<body>#>
|
||||
}
|
||||
|
||||
val <#<name>#> : <#<valType>#>
|
||||
get() {
|
||||
<#<body>#>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (2, 9) Unresolved IDE template: condition
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (3, 9) Unresolved IDE template: block
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (5, 9) Unresolved IDE template: block
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (8, 9) Unresolved IDE template: name
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (8, 20) Unresolved IDE template: params
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (8, 36) Unresolved IDE template: returnType
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (9, 9) Unresolved IDE template: body
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (12, 10) Unresolved IDE template: i
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (12, 21) Unresolved IDE template: elements
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (13, 9) Unresolved IDE template: body
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (16, 11) Unresolved IDE template: expression
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (17, 9) Unresolved IDE template: condition
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (17, 28) Unresolved IDE template: value
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (18, 17) Unresolved IDE template: elseValue
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (21, 9) Unresolved IDE template: name
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (21, 22) Unresolved IDE template: value
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (23, 11) Unresolved IDE template: name
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (24, 9) Unresolved IDE template: body
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (27, 11) Unresolved IDE template: name
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (28, 13) Unresolved IDE template: name
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (28, 26) Unresolved IDE template: varType
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (30, 13) Unresolved IDE template: body
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (33, 13) Unresolved IDE template: body
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (36, 13) Unresolved IDE template: name
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (36, 26) Unresolved IDE template: valType
|
||||
ERROR: $TESTDATA_DIR$/ideTemplates.kt: (38, 13) Unresolved IDE template: body
|
||||
COMPILATION_ERROR
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.cli.jvm;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.ExitCode;
|
||||
@@ -62,7 +63,8 @@ public class CliTest {
|
||||
|
||||
private void executeCompilerCompareOutput(@NotNull String[] args) {
|
||||
try {
|
||||
String actual = normalize(executeCompilerGrabOutput(args));
|
||||
String actual = normalize(executeCompilerGrabOutput(args))
|
||||
.replace(FileUtil.toSystemIndependentName(new File("compiler/testData/cli/").getAbsolutePath()), "$TESTDATA_DIR$");
|
||||
|
||||
String expected = normalize(FileUtil.loadFile(new File("compiler/testData/cli/" + testName.getMethodName() + ".out")));
|
||||
|
||||
@@ -103,7 +105,7 @@ public class CliTest {
|
||||
|
||||
@Test
|
||||
public void help() throws Exception {
|
||||
executeCompilerCompareOutput(new String[]{ "--help" });
|
||||
executeCompilerCompareOutput(new String[] {"--help"});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,4 +113,9 @@ public class CliTest {
|
||||
executeCompilerCompareOutput(new String[]{ "-script", "compiler/testData/cli/script.ktscript", "hi", "there" });
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ideTemplates() {
|
||||
executeCompilerCompareOutput(new String[]{ "-src", "compiler/testData/cli/ideTemplates.kt", "-output", tmpdir.getTmpDir().getPath()});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user