Added compiler diagnostic for unresolved IDE templates.
This commit is contained in:
@@ -470,6 +470,7 @@ public interface Errors {
|
||||
}
|
||||
};
|
||||
|
||||
ParameterizedDiagnosticFactory1<String> UNRESOLVED_IDE_TEMPLATE = new ParameterizedDiagnosticFactory1<String>(ERROR, "Unresolved IDE template: {0}");
|
||||
|
||||
// This field is needed to make the Initializer class load (interfaces cannot have static initializers)
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
/**
|
||||
* @author Evgeny Gerashchenko
|
||||
@@ -21,4 +24,10 @@ public class JetIdeTemplateExpression extends JetExpression {
|
||||
public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitIdeTemplateExpression(this, data);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getText() {
|
||||
PsiElement idElement = findChildByType(JetTokens.IDENTIFIER);
|
||||
return idElement == null ? null : idElement.getText();
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -5,6 +5,7 @@ import com.google.common.collect.Multimap;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
@@ -734,6 +735,12 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType visitIdeTemplateExpression(JetIdeTemplateExpression expression, ExpressionTypingContext context) {
|
||||
context.trace.report(UNRESOLVED_IDE_TEMPLATE.on(expression, ObjectUtils.notNull(expression.getText(), "<no name>")));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType visitBinaryExpression(JetBinaryExpression expression, ExpressionTypingContext contextWithExpectedType) {
|
||||
ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE);
|
||||
|
||||
+5
@@ -20,6 +20,11 @@ import static org.jetbrains.jet.lang.diagnostics.Errors.TYPECHECKER_HAS_RUN_INTO
|
||||
*/
|
||||
public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetType, ExpressionTypingContext> implements ExpressionTypingInternals {
|
||||
|
||||
@Override
|
||||
public JetType visitIdeTemplateExpression(JetIdeTemplateExpression expression, ExpressionTypingContext data) {
|
||||
return basic.visitIdeTemplateExpression(expression, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ExpressionTypingFacade create() {
|
||||
return new ExpressionTypingVisitorDispatcher(null);
|
||||
|
||||
+7
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.types.expressions;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -282,4 +283,10 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
||||
public JetType visitUnaryExpression(JetUnaryExpression expression, ExpressionTypingContext context) {
|
||||
return basic.visitUnaryExpression(expression, context, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType visitIdeTemplateExpression(JetIdeTemplateExpression expression, ExpressionTypingContext context) {
|
||||
context.trace.report(UNRESOLVED_IDE_TEMPLATE.on(expression, ObjectUtils.notNull(expression.getText(), "<no name>")));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
fun main(args : Array<String>) {
|
||||
if (<!UNRESOLVED_IDE_TEMPLATE!><#<condition>#><!>) {
|
||||
<!UNRESOLVED_IDE_TEMPLATE!><#<block>#><!>
|
||||
} else {
|
||||
<!UNRESOLVED_IDE_TEMPLATE!><#<block>#><!>
|
||||
}
|
||||
|
||||
fun <!UNRESOLVED_IDE_TEMPLATE!><#<name>#><!>(<#<params>#>) : <#<returnType>#> {
|
||||
<#<body>#>
|
||||
}
|
||||
|
||||
for (<#<i>#> in <!UNRESOLVED_IDE_TEMPLATE!><#<elements>#><!>) {
|
||||
<!UNRESOLVED_IDE_TEMPLATE!><#<body>#><!>
|
||||
}
|
||||
|
||||
when (<!UNRESOLVED_IDE_TEMPLATE!><#<expression>#><!>) {
|
||||
<!UNRESOLVED_IDE_TEMPLATE!><#<condition>#><!> -> <#<value>#>
|
||||
else -> <!UNRESOLVED_IDE_TEMPLATE!><#<elseValue>#><!>
|
||||
}
|
||||
|
||||
var <#<name>#> = <!UNRESOLVED_IDE_TEMPLATE!><#<value>#><!>
|
||||
|
||||
class <#<name>#> {
|
||||
<#<body>#>
|
||||
}
|
||||
|
||||
class <#<name>#> {
|
||||
var <#<name>#> : <#<varType>#>
|
||||
get() {
|
||||
<#<body>#>
|
||||
}
|
||||
set(value) {
|
||||
<#<body>#>
|
||||
}
|
||||
|
||||
val <#<name>#> : <#<valType>#>
|
||||
get() {
|
||||
<#<body>#>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +144,9 @@ public class JetPsiChecker implements Annotator {
|
||||
) {
|
||||
List<TextRange> textRanges = diagnostic.getFactory().getTextRanges(diagnostic);
|
||||
if (diagnostic.getSeverity() == Severity.ERROR) {
|
||||
if (diagnostic.getFactory() == Errors.UNRESOLVED_IDE_TEMPLATE) {
|
||||
return;
|
||||
}
|
||||
if (diagnostic instanceof UnresolvedReferenceDiagnostic) {
|
||||
UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic) diagnostic;
|
||||
JetReferenceExpression referenceExpression = unresolvedReferenceDiagnostic.getPsiElement();
|
||||
|
||||
Reference in New Issue
Block a user