cast() method in DiagnosticFactory

This commit is contained in:
Andrey Breslav
2014-05-28 13:07:46 +04:00
parent d6cc62e12c
commit df413c0b47
32 changed files with 113 additions and 103 deletions
@@ -347,16 +347,16 @@ public class CheckerTestUtil {
public static class AbstractDiagnosticForTests implements Diagnostic { public static class AbstractDiagnosticForTests implements Diagnostic {
private final PsiElement element; private final PsiElement element;
private final DiagnosticFactory factory; private final DiagnosticFactory<?> factory;
public AbstractDiagnosticForTests(@NotNull PsiElement element, @NotNull DiagnosticFactory factory) { public AbstractDiagnosticForTests(@NotNull PsiElement element, @NotNull DiagnosticFactory<?> factory) {
this.element = element; this.element = element;
this.factory = factory; this.factory = factory;
} }
@NotNull @NotNull
@Override @Override
public DiagnosticFactory getFactory() { public DiagnosticFactory<?> getFactory() {
return factory; return factory;
} }
@@ -390,7 +390,7 @@ public class CheckerTestUtil {
} }
} }
public static class SyntaxErrorDiagnosticFactory extends DiagnosticFactory { public static class SyntaxErrorDiagnosticFactory extends DiagnosticFactory<SyntaxErrorDiagnostic> {
public static final SyntaxErrorDiagnosticFactory INSTANCE = new SyntaxErrorDiagnosticFactory(); public static final SyntaxErrorDiagnosticFactory INSTANCE = new SyntaxErrorDiagnosticFactory();
private SyntaxErrorDiagnosticFactory() { private SyntaxErrorDiagnosticFactory() {
@@ -410,7 +410,7 @@ public class CheckerTestUtil {
} }
} }
public static class DebugInfoDiagnosticFactory extends DiagnosticFactory { public static class DebugInfoDiagnosticFactory extends DiagnosticFactory<DebugInfoDiagnostic> {
public static final DebugInfoDiagnosticFactory AUTOCAST = new DebugInfoDiagnosticFactory("AUTOCAST"); public static final DebugInfoDiagnosticFactory AUTOCAST = new DebugInfoDiagnosticFactory("AUTOCAST");
public static final DebugInfoDiagnosticFactory ELEMENT_WITH_ERROR_TYPE = new DebugInfoDiagnosticFactory("ELEMENT_WITH_ERROR_TYPE"); public static final DebugInfoDiagnosticFactory ELEMENT_WITH_ERROR_TYPE = new DebugInfoDiagnosticFactory("ELEMENT_WITH_ERROR_TYPE");
public static final DebugInfoDiagnosticFactory UNRESOLVED_WITH_TARGET = new DebugInfoDiagnosticFactory("UNRESOLVED_WITH_TARGET"); public static final DebugInfoDiagnosticFactory UNRESOLVED_WITH_TARGET = new DebugInfoDiagnosticFactory("UNRESOLVED_WITH_TARGET");
@@ -58,9 +58,9 @@ public class DebugInfoUtil {
@NotNull final BindingContext bindingContext, @NotNull final BindingContext bindingContext,
@NotNull final DebugInfoReporter debugInfoReporter @NotNull final DebugInfoReporter debugInfoReporter
) { ) {
final Map<JetReferenceExpression, DiagnosticFactory> markedWithErrorElements = Maps.newHashMap(); final Map<JetReferenceExpression, DiagnosticFactory<?>> markedWithErrorElements = Maps.newHashMap();
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) { for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
DiagnosticFactory factory = diagnostic.getFactory(); DiagnosticFactory<?> factory = diagnostic.getFactory();
if (Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS.contains(diagnostic.getFactory())) { if (Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS.contains(diagnostic.getFactory())) {
markedWithErrorElements.put((JetReferenceExpression) diagnostic.getPsiElement(), factory); markedWithErrorElements.put((JetReferenceExpression) diagnostic.getPsiElement(), factory);
} }
@@ -136,7 +136,7 @@ public class DebugInfoUtil {
markedWithError = true; markedWithError = true;
} }
JetType expressionType = bindingContext.get(EXPRESSION_TYPE, expression); JetType expressionType = bindingContext.get(EXPRESSION_TYPE, expression);
DiagnosticFactory factory = markedWithErrorElements.get(expression); DiagnosticFactory<?> factory = markedWithErrorElements.get(expression);
if (declarationDescriptor != null && if (declarationDescriptor != null &&
(ErrorUtils.isError(declarationDescriptor) || ErrorUtils.containsErrorType(expressionType))) { (ErrorUtils.isError(declarationDescriptor) || ErrorUtils.containsErrorType(expressionType))) {
if (factory != Errors.EXPRESSION_EXPECTED_PACKAGE_FOUND) { if (factory != Errors.EXPRESSION_EXPECTED_PACKAGE_FOUND) {
@@ -274,7 +274,7 @@ public class JetFlowInformationProvider {
final Set<VariableDescriptor> declaredVariables = pseudocodeVariablesData.getDeclaredVariables(pseudocode, true); final Set<VariableDescriptor> declaredVariables = pseudocodeVariablesData.getDeclaredVariables(pseudocode, true);
final LexicalScopeVariableInfo lexicalScopeVariableInfo = pseudocodeVariablesData.getLexicalScopeVariableInfo(); final LexicalScopeVariableInfo lexicalScopeVariableInfo = pseudocodeVariablesData.getLexicalScopeVariableInfo();
final Map<Instruction, DiagnosticFactory> reportedDiagnosticMap = Maps.newHashMap(); final Map<Instruction, DiagnosticFactory<?>> reportedDiagnosticMap = Maps.newHashMap();
PseudocodeTraverserPackage.traverse( PseudocodeTraverserPackage.traverse(
pseudocode, FORWARD, initializers, pseudocode, FORWARD, initializers,
@@ -548,7 +548,7 @@ public class JetFlowInformationProvider {
final PseudocodeVariablesData pseudocodeVariablesData = getPseudocodeVariablesData(); final PseudocodeVariablesData pseudocodeVariablesData = getPseudocodeVariablesData();
Map<Instruction, Edges<Map<VariableDescriptor, VariableUseState>>> variableStatusData = Map<Instruction, Edges<Map<VariableDescriptor, VariableUseState>>> variableStatusData =
pseudocodeVariablesData.getVariableUseStatusData(); pseudocodeVariablesData.getVariableUseStatusData();
final Map<Instruction, DiagnosticFactory> reportedDiagnosticMap = Maps.newHashMap(); final Map<Instruction, DiagnosticFactory<?>> reportedDiagnosticMap = Maps.newHashMap();
InstructionDataAnalyzeStrategy<Map<VariableDescriptor, VariableUseState>> variableStatusAnalyzeStrategy = InstructionDataAnalyzeStrategy<Map<VariableDescriptor, VariableUseState>> variableStatusAnalyzeStrategy =
new InstructionDataAnalyzeStrategy<Map<VariableDescriptor, VariableUseState>>() { new InstructionDataAnalyzeStrategy<Map<VariableDescriptor, VariableUseState>>() {
@Override @Override
@@ -638,7 +638,7 @@ public class JetFlowInformationProvider {
// "Unused literals" in block // "Unused literals" in block
public void markUnusedLiteralsInBlock() { public void markUnusedLiteralsInBlock() {
final Map<Instruction, DiagnosticFactory> reportedDiagnosticMap = Maps.newHashMap(); final Map<Instruction, DiagnosticFactory<?>> reportedDiagnosticMap = Maps.newHashMap();
PseudocodeTraverserPackage.traverse( PseudocodeTraverserPackage.traverse(
pseudocode, FORWARD, new FunctionVoid1<Instruction>() { pseudocode, FORWARD, new FunctionVoid1<Instruction>() {
@Override @Override
@@ -828,13 +828,13 @@ public class JetFlowInformationProvider {
trace.report(diagnostic); trace.report(diagnostic);
return; return;
} }
Map<Instruction, DiagnosticFactory> previouslyReported = ctxt.reportedDiagnosticMap; Map<Instruction, DiagnosticFactory<?>> previouslyReported = ctxt.reportedDiagnosticMap;
previouslyReported.put(instruction, diagnostic.getFactory()); previouslyReported.put(instruction, diagnostic.getFactory());
boolean alreadyReported = false; boolean alreadyReported = false;
boolean sameErrorForAllCopies = true; boolean sameErrorForAllCopies = true;
for (Instruction copy : instruction.getCopies()) { for (Instruction copy : instruction.getCopies()) {
DiagnosticFactory previouslyReportedErrorFactory = previouslyReported.get(copy); DiagnosticFactory<?> previouslyReportedErrorFactory = previouslyReported.get(copy);
if (previouslyReportedErrorFactory != null) { if (previouslyReportedErrorFactory != null) {
alreadyReported = true; alreadyReported = true;
} }
@@ -857,7 +857,7 @@ public class JetFlowInformationProvider {
} }
} }
private static boolean mustBeReportedOnAllCopies(@NotNull DiagnosticFactory diagnosticFactory) { private static boolean mustBeReportedOnAllCopies(@NotNull DiagnosticFactory<?> diagnosticFactory) {
return diagnosticFactory == UNUSED_VARIABLE return diagnosticFactory == UNUSED_VARIABLE
|| diagnosticFactory == UNUSED_PARAMETER || diagnosticFactory == UNUSED_PARAMETER
|| diagnosticFactory == UNUSED_CHANGED_VALUE; || diagnosticFactory == UNUSED_CHANGED_VALUE;
@@ -865,13 +865,13 @@ public class JetFlowInformationProvider {
private class VariableContext { private class VariableContext {
final Map<Instruction, DiagnosticFactory> reportedDiagnosticMap; final Map<Instruction, DiagnosticFactory<?>> reportedDiagnosticMap;
final Instruction instruction; final Instruction instruction;
final VariableDescriptor variableDescriptor; final VariableDescriptor variableDescriptor;
private VariableContext( private VariableContext(
@NotNull Instruction instruction, @NotNull Instruction instruction,
@NotNull Map<Instruction, DiagnosticFactory> map @NotNull Map<Instruction, DiagnosticFactory<?>> map
) { ) {
this.instruction = instruction; this.instruction = instruction;
reportedDiagnosticMap = map; reportedDiagnosticMap = map;
@@ -885,7 +885,7 @@ public class JetFlowInformationProvider {
private VariableInitContext( private VariableInitContext(
@NotNull Instruction instruction, @NotNull Instruction instruction,
@NotNull Map<Instruction, DiagnosticFactory> map, @NotNull Map<Instruction, DiagnosticFactory<?>> map,
@NotNull Map<VariableDescriptor, VariableInitState> in, @NotNull Map<VariableDescriptor, VariableInitState> in,
@NotNull Map<VariableDescriptor, VariableInitState> out, @NotNull Map<VariableDescriptor, VariableInitState> out,
@NotNull LexicalScopeVariableInfo lexicalScopeVariableInfo @NotNull LexicalScopeVariableInfo lexicalScopeVariableInfo
@@ -914,7 +914,7 @@ public class JetFlowInformationProvider {
private VariableUseContext( private VariableUseContext(
@NotNull Instruction instruction, @NotNull Instruction instruction,
@NotNull Map<Instruction, DiagnosticFactory> map, @NotNull Map<Instruction, DiagnosticFactory<?>> map,
@NotNull Map<VariableDescriptor, VariableUseState> in, @NotNull Map<VariableDescriptor, VariableUseState> in,
@NotNull Map<VariableDescriptor, VariableUseState> out @NotNull Map<VariableDescriptor, VariableUseState> out
) { ) {
@@ -18,20 +18,18 @@ package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiErrorElement;
import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetNodeTypes;
import java.util.List; import java.util.List;
public abstract class AbstractDiagnostic<E extends PsiElement> implements ParametrizedDiagnostic<E> { public abstract class AbstractDiagnostic<E extends PsiElement> implements ParametrizedDiagnostic<E> {
private final E psiElement; private final E psiElement;
private final DiagnosticFactoryWithPsiElement<E> factory; private final DiagnosticFactoryWithPsiElement<E, ?> factory;
private final Severity severity; private final Severity severity;
public AbstractDiagnostic(@NotNull E psiElement, public AbstractDiagnostic(@NotNull E psiElement,
@NotNull DiagnosticFactoryWithPsiElement<E> factory, @NotNull DiagnosticFactoryWithPsiElement<E, ?> factory,
@NotNull Severity severity) { @NotNull Severity severity) {
this.psiElement = psiElement; this.psiElement = psiElement;
this.factory = factory; this.factory = factory;
@@ -40,7 +38,7 @@ public abstract class AbstractDiagnostic<E extends PsiElement> implements Parame
@NotNull @NotNull
@Override @Override
public DiagnosticFactoryWithPsiElement<E> getFactory() { public DiagnosticFactoryWithPsiElement<E, ?> getFactory() {
return factory; return factory;
} }
@@ -26,7 +26,7 @@ import java.util.List;
public interface Diagnostic { public interface Diagnostic {
@NotNull @NotNull
DiagnosticFactory getFactory(); DiagnosticFactory<?> getFactory();
@NotNull @NotNull
Severity getSeverity(); Severity getSeverity();
@@ -18,7 +18,10 @@ package org.jetbrains.jet.lang.diagnostics;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public abstract class DiagnosticFactory { import java.util.Arrays;
import java.util.Collection;
public abstract class DiagnosticFactory<D extends Diagnostic> {
private String name = null; private String name = null;
private final Severity severity; private final Severity severity;
@@ -41,6 +44,30 @@ public abstract class DiagnosticFactory {
return severity; return severity;
} }
@NotNull
public D cast(@NotNull Diagnostic diagnostic) {
if (diagnostic.getFactory() != this) {
throw new IllegalArgumentException("Factory mismatch: expected " + this + " but was " + diagnostic.getFactory());
}
//noinspection unchecked
return (D) diagnostic;
}
@NotNull
public static <D extends Diagnostic> D cast(@NotNull Diagnostic diagnostic, @NotNull DiagnosticFactory<? extends D>... factories) {
return cast(diagnostic, Arrays.asList(factories));
}
@NotNull
public static <D extends Diagnostic> D cast(@NotNull Diagnostic diagnostic, @NotNull Collection<? extends DiagnosticFactory<? extends D>> factories) {
for (DiagnosticFactory<? extends D> factory : factories) {
if (diagnostic.getFactory() == factory) return factory.cast(diagnostic);
}
throw new IllegalArgumentException("Factory mismatch: expected one of " + factories + " but was " + diagnostic.getFactory());
}
@Override @Override
public String toString() { public String toString() {
return getName(); return getName();
@@ -19,7 +19,7 @@ package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class DiagnosticFactory0<E extends PsiElement> extends DiagnosticFactoryWithPsiElement<E> { public class DiagnosticFactory0<E extends PsiElement> extends DiagnosticFactoryWithPsiElement<E, SimpleDiagnostic<E>> {
protected DiagnosticFactory0(Severity severity, PositioningStrategy<? super E> positioningStrategy) { protected DiagnosticFactory0(Severity severity, PositioningStrategy<? super E> positioningStrategy) {
super(severity, positioningStrategy); super(severity, positioningStrategy);
@@ -19,7 +19,7 @@ package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class DiagnosticFactory1<E extends PsiElement, A> extends DiagnosticFactoryWithPsiElement<E> { public class DiagnosticFactory1<E extends PsiElement, A> extends DiagnosticFactoryWithPsiElement<E, DiagnosticWithParameters1<E, A>> {
@NotNull @NotNull
public ParametrizedDiagnostic<E> on(@NotNull E element, @NotNull A argument) { public ParametrizedDiagnostic<E> on(@NotNull E element, @NotNull A argument) {
return new DiagnosticWithParameters1<E, A>(element, argument, this, getSeverity()); return new DiagnosticWithParameters1<E, A>(element, argument, this, getSeverity());
@@ -19,7 +19,7 @@ package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class DiagnosticFactory2<E extends PsiElement, A, B> extends DiagnosticFactoryWithPsiElement<E> { public class DiagnosticFactory2<E extends PsiElement, A, B> extends DiagnosticFactoryWithPsiElement<E, DiagnosticWithParameters2<E, A, B>> {
@NotNull @NotNull
public ParametrizedDiagnostic<E> on(@NotNull E element, @NotNull A a, @NotNull B b) { public ParametrizedDiagnostic<E> on(@NotNull E element, @NotNull A a, @NotNull B b) {
@@ -19,7 +19,7 @@ package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class DiagnosticFactory3<E extends PsiElement, A, B, C> extends DiagnosticFactoryWithPsiElement<E> { public class DiagnosticFactory3<E extends PsiElement, A, B, C> extends DiagnosticFactoryWithPsiElement<E, DiagnosticWithParameters3<E, A, B, C>> {
protected DiagnosticFactory3(Severity severity, PositioningStrategy<? super E> positioningStrategy) { protected DiagnosticFactory3(Severity severity, PositioningStrategy<? super E> positioningStrategy) {
super(severity, positioningStrategy); super(severity, positioningStrategy);
@@ -21,7 +21,7 @@ import com.intellij.psi.PsiElement;
import java.util.List; import java.util.List;
public abstract class DiagnosticFactoryWithPsiElement<E extends PsiElement> extends DiagnosticFactory { public abstract class DiagnosticFactoryWithPsiElement<E extends PsiElement, D extends Diagnostic> extends DiagnosticFactory<D> {
protected final PositioningStrategy<? super E> positioningStrategy; protected final PositioningStrategy<? super E> positioningStrategy;
public DiagnosticFactoryWithPsiElement(Severity severity, PositioningStrategy<? super E> positioningStrategy) { public DiagnosticFactoryWithPsiElement(Severity severity, PositioningStrategy<? super E> positioningStrategy) {
@@ -589,11 +589,11 @@ public interface Errors {
DiagnosticFactory0<JetElement> DECLARATION_CANT_BE_INLINED = DiagnosticFactory0.create(ERROR); DiagnosticFactory0<JetElement> DECLARATION_CANT_BE_INLINED = DiagnosticFactory0.create(ERROR);
// Error sets // Error sets
ImmutableSet<? extends DiagnosticFactory> UNRESOLVED_REFERENCE_DIAGNOSTICS = ImmutableSet.of( ImmutableSet<? extends DiagnosticFactory<?>> UNRESOLVED_REFERENCE_DIAGNOSTICS = ImmutableSet.of(
UNRESOLVED_REFERENCE, NAMED_PARAMETER_NOT_FOUND, UNRESOLVED_REFERENCE_WRONG_RECEIVER); UNRESOLVED_REFERENCE, NAMED_PARAMETER_NOT_FOUND, UNRESOLVED_REFERENCE_WRONG_RECEIVER);
ImmutableSet<? extends DiagnosticFactory> UNUSED_ELEMENT_DIAGNOSTICS = ImmutableSet.of( ImmutableSet<? extends DiagnosticFactory<?>> UNUSED_ELEMENT_DIAGNOSTICS = ImmutableSet.of(
UNUSED_VARIABLE, UNUSED_PARAMETER, ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE); UNUSED_VARIABLE, UNUSED_PARAMETER, ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE);
ImmutableSet<? extends DiagnosticFactory> TYPE_INFERENCE_ERRORS = ImmutableSet.of( ImmutableSet<? extends DiagnosticFactory<?>> TYPE_INFERENCE_ERRORS = ImmutableSet.of(
TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER, TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS, TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH, TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER, TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS, TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH,
TYPE_INFERENCE_UPPER_BOUND_VIOLATED, TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH); TYPE_INFERENCE_UPPER_BOUND_VIOLATED, TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH);
@@ -612,7 +612,7 @@ public interface Errors {
try { try {
Object value = field.get(null); Object value = field.get(null);
if (value instanceof DiagnosticFactory) { if (value instanceof DiagnosticFactory) {
DiagnosticFactory factory = (DiagnosticFactory)value; DiagnosticFactory<?> factory = (DiagnosticFactory<?>)value;
factory.setName(field.getName()); factory.setName(field.getName());
} }
} }
@@ -493,8 +493,8 @@ public class DefaultErrorMessages {
try { try {
Object fieldValue = field.get(null); Object fieldValue = field.get(null);
if (fieldValue instanceof DiagnosticFactory) { if (fieldValue instanceof DiagnosticFactory) {
if (MAP.get((DiagnosticFactory) fieldValue) == null) { if (MAP.get((DiagnosticFactory<?>) fieldValue) == null) {
throw new IllegalStateException("No default diagnostic renderer is provided for " + ((DiagnosticFactory)fieldValue).getName()); throw new IllegalStateException("No default diagnostic renderer is provided for " + ((DiagnosticFactory<?>)fieldValue).getName());
} }
} }
} }
@@ -26,8 +26,8 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public final class DiagnosticFactoryToRendererMap { public final class DiagnosticFactoryToRendererMap {
private final Map<DiagnosticFactory, DiagnosticRenderer<?>> map = private final Map<DiagnosticFactory<?>, DiagnosticRenderer<?>> map =
new HashMap<DiagnosticFactory, DiagnosticRenderer<?>>(); new HashMap<DiagnosticFactory<?>, DiagnosticRenderer<?>>();
private boolean immutable = false; private boolean immutable = false;
private void checkMutability() { private void checkMutability() {
@@ -64,7 +64,7 @@ public final class DiagnosticFactoryToRendererMap {
} }
@Nullable @Nullable
public DiagnosticRenderer<?> get(@NotNull DiagnosticFactory factory) { public DiagnosticRenderer<?> get(@NotNull DiagnosticFactory<?> factory) {
return map.get(factory); return map.get(factory);
} }
@@ -111,7 +111,7 @@ public class DiagnosticsWithSuppression implements Diagnostics {
private static boolean isSuppressedForDebugger(@NotNull Diagnostic diagnostic, @NotNull PsiElement element) { private static boolean isSuppressedForDebugger(@NotNull Diagnostic diagnostic, @NotNull PsiElement element) {
PsiFile containingFile = element.getContainingFile(); PsiFile containingFile = element.getContainingFile();
if (containingFile instanceof JetFile && CodeFragmentUtilPackage.skipVisibilityCheck((JetFile) containingFile)) { if (containingFile instanceof JetFile && CodeFragmentUtilPackage.skipVisibilityCheck((JetFile) containingFile)) {
DiagnosticFactory diagnosticFactory = diagnostic.getFactory(); DiagnosticFactory<?> diagnosticFactory = diagnostic.getFactory();
return diagnosticFactory == Errors.INVISIBLE_MEMBER || return diagnosticFactory == Errors.INVISIBLE_MEMBER ||
diagnosticFactory == Errors.INVISIBLE_REFERENCE || diagnosticFactory == Errors.INVISIBLE_REFERENCE ||
diagnosticFactory == Errors.INVISIBLE_SETTER; diagnosticFactory == Errors.INVISIBLE_SETTER;
@@ -36,8 +36,8 @@ import java.util.Set;
import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.diagnostics.Errors.*;
public class CompileTimeConstantChecker { public class CompileTimeConstantChecker {
private static final Set<DiagnosticFactory> errorsThatDependOnExpectedType = private static final Set<DiagnosticFactory<?>> errorsThatDependOnExpectedType =
Sets.<DiagnosticFactory>newHashSet(CONSTANT_EXPECTED_TYPE_MISMATCH, NULL_FOR_NONNULL_TYPE); Sets.<DiagnosticFactory<?>>newHashSet(CONSTANT_EXPECTED_TYPE_MISMATCH, NULL_FOR_NONNULL_TYPE);
private final KotlinBuiltIns builtIns; private final KotlinBuiltIns builtIns;
private final BindingTrace trace; private final BindingTrace trace;
@@ -451,7 +451,7 @@ public class ExpressionTypingUtils {
@Override @Override
public void report(@NotNull Diagnostic diagnostic) { public void report(@NotNull Diagnostic diagnostic) {
DiagnosticFactory factory = diagnostic.getFactory(); DiagnosticFactory<?> factory = diagnostic.getFactory();
if ((factory == TYPE_MISMATCH || factory == CONSTANT_EXPECTED_TYPE_MISMATCH || factory == NULL_FOR_NONNULL_TYPE) if ((factory == TYPE_MISMATCH || factory == CONSTANT_EXPECTED_TYPE_MISMATCH || factory == NULL_FOR_NONNULL_TYPE)
&& diagnostic.getPsiElement() == expressionToWatch) { && diagnostic.getPsiElement() == expressionToWatch) {
mismatchFound[0] = true; mismatchFound[0] = true;
@@ -31,6 +31,7 @@ import org.jetbrains.jet.lang.descriptors.DependencyKind;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptorImpl; import org.jetbrains.jet.lang.descriptors.ModuleDescriptorImpl;
import org.jetbrains.jet.lang.diagnostics.*; import org.jetbrains.jet.lang.diagnostics.*;
import org.jetbrains.jet.lang.psi.JetElement; import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.psi.JetExpression;
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.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -146,23 +147,26 @@ public abstract class AbstractJetDiagnosticsTest extends BaseDiagnosticsTest {
@SuppressWarnings({"unchecked", "ConstantConditions"}) @SuppressWarnings({"unchecked", "ConstantConditions"})
private static void checkResolvedCallsInDiagnostics(BindingContext bindingContext) { private static void checkResolvedCallsInDiagnostics(BindingContext bindingContext) {
Set<DiagnosticFactory> diagnosticsStoringResolvedCalls1 = Sets.<DiagnosticFactory>newHashSet( Set<DiagnosticFactory1<PsiElement, Collection<? extends ResolvedCall<?>>>> diagnosticsStoringResolvedCalls1 = Sets.newHashSet(
OVERLOAD_RESOLUTION_AMBIGUITY, NONE_APPLICABLE, CANNOT_COMPLETE_RESOLVE, UNRESOLVED_REFERENCE_WRONG_RECEIVER, OVERLOAD_RESOLUTION_AMBIGUITY, NONE_APPLICABLE, CANNOT_COMPLETE_RESOLVE, UNRESOLVED_REFERENCE_WRONG_RECEIVER,
ASSIGN_OPERATOR_AMBIGUITY, ITERATOR_AMBIGUITY); ASSIGN_OPERATOR_AMBIGUITY, ITERATOR_AMBIGUITY);
Set<DiagnosticFactory> diagnosticsStoringResolvedCalls2 = Sets.<DiagnosticFactory>newHashSet( Set<DiagnosticFactory2<JetExpression, ? extends Comparable<? extends Comparable<?>>, Collection<? extends ResolvedCall<?>>>>
diagnosticsStoringResolvedCalls2 = Sets.newHashSet(
COMPONENT_FUNCTION_AMBIGUITY, DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE); COMPONENT_FUNCTION_AMBIGUITY, DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE);
Diagnostics diagnostics = bindingContext.getDiagnostics(); Diagnostics diagnostics = bindingContext.getDiagnostics();
for (Diagnostic diagnostic : diagnostics) { for (Diagnostic diagnostic : diagnostics) {
DiagnosticFactory factory = diagnostic.getFactory(); DiagnosticFactory<?> factory = diagnostic.getFactory();
//noinspection SuspiciousMethodCalls
if (diagnosticsStoringResolvedCalls1.contains(factory)) { if (diagnosticsStoringResolvedCalls1.contains(factory)) {
assertResolvedCallsAreCompleted( assertResolvedCallsAreCompleted(
diagnostic, ((DiagnosticWithParameters1<PsiElement, Collection<? extends ResolvedCall<?>>>) diagnostic).getA()); diagnostic, DiagnosticFactory.cast(diagnostic, diagnosticsStoringResolvedCalls1).getA());
} }
//noinspection SuspiciousMethodCalls
if (diagnosticsStoringResolvedCalls2.contains(factory)) { if (diagnosticsStoringResolvedCalls2.contains(factory)) {
assertResolvedCallsAreCompleted( assertResolvedCallsAreCompleted(
diagnostic, diagnostic,
((DiagnosticWithParameters2<PsiElement, Object, Collection<? extends ResolvedCall<?>>>)diagnostic).getB()); DiagnosticFactory.cast(diagnostic, diagnosticsStoringResolvedCalls2).getB());
} }
} }
} }
@@ -55,7 +55,7 @@ public abstract class BaseDiagnosticsTest extends JetLiteFixture {
public static final String DIAGNOSTICS_DIRECTIVE = "DIAGNOSTICS"; public static final String DIAGNOSTICS_DIRECTIVE = "DIAGNOSTICS";
public static final Pattern DIAGNOSTICS_PATTERN = Pattern.compile("([\\+\\-!])(\\w+)\\s*"); public static final Pattern DIAGNOSTICS_PATTERN = Pattern.compile("([\\+\\-!])(\\w+)\\s*");
public static final ImmutableSet<DiagnosticFactory> DIAGNOSTICS_TO_INCLUDE_ANYWAY = public static final ImmutableSet<DiagnosticFactory<?>> DIAGNOSTICS_TO_INCLUDE_ANYWAY =
ImmutableSet.of( ImmutableSet.of(
Errors.UNRESOLVED_REFERENCE, Errors.UNRESOLVED_REFERENCE,
Errors.UNRESOLVED_REFERENCE_WRONG_RECEIVER, Errors.UNRESOLVED_REFERENCE_WRONG_RECEIVER,
@@ -28,7 +28,7 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory
import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiTreeUtil
class KotlinSuppressableWarningProblemGroup( class KotlinSuppressableWarningProblemGroup(
private val diagnosticFactory: DiagnosticFactory private val diagnosticFactory: DiagnosticFactory<*>
) : SuppressableProblemGroup { ) : SuppressableProblemGroup {
{ {
@@ -46,7 +46,7 @@ class KotlinSuppressableWarningProblemGroup(
} }
fun createSuppressWarningActions(element: PsiElement, diagnosticFactory: DiagnosticFactory): List<SuppressIntentionAction> { fun createSuppressWarningActions(element: PsiElement, diagnosticFactory: DiagnosticFactory<*>): List<SuppressIntentionAction> {
if (diagnosticFactory.getSeverity() != Severity.WARNING) if (diagnosticFactory.getSeverity() != Severity.WARNING)
return Collections.emptyList() return Collections.emptyList()
@@ -72,10 +72,8 @@ public abstract class AddStarProjectionsFix extends JetIntentionAction<JetUserTy
return new JetSingleIntentionActionFactory() { return new JetSingleIntentionActionFactory() {
@Override @Override
public IntentionAction createAction(Diagnostic diagnostic) { public IntentionAction createAction(Diagnostic diagnostic) {
assert diagnostic.getFactory() == Errors.NO_TYPE_ARGUMENTS_ON_RHS;
@SuppressWarnings("unchecked")
DiagnosticWithParameters2<JetTypeReference, Integer, String> diagnosticWithParameters = DiagnosticWithParameters2<JetTypeReference, Integer, String> diagnosticWithParameters =
(DiagnosticWithParameters2<JetTypeReference, Integer, String>) diagnostic; Errors.NO_TYPE_ARGUMENTS_ON_RHS.cast(diagnostic);
JetTypeElement typeElement = diagnosticWithParameters.getPsiElement().getTypeElement(); JetTypeElement typeElement = diagnosticWithParameters.getPsiElement().getTypeElement();
while (typeElement instanceof JetNullableType) { while (typeElement instanceof JetNullableType) {
typeElement = ((JetNullableType) typeElement).getInnerType(); typeElement = ((JetNullableType) typeElement).getInnerType();
@@ -91,9 +89,7 @@ public abstract class AddStarProjectionsFix extends JetIntentionAction<JetUserTy
return new JetSingleIntentionActionFactory() { return new JetSingleIntentionActionFactory() {
@Override @Override
public IntentionAction createAction(Diagnostic diagnostic) { public IntentionAction createAction(Diagnostic diagnostic) {
assert diagnostic.getFactory() == Errors.WRONG_NUMBER_OF_TYPE_ARGUMENTS; DiagnosticWithParameters1<JetElement, Integer> diagnosticWithParameters = Errors.WRONG_NUMBER_OF_TYPE_ARGUMENTS.cast(diagnostic);
@SuppressWarnings("unchecked")
DiagnosticWithParameters1<JetElement, Integer> diagnosticWithParameters = (DiagnosticWithParameters1) diagnostic;
Integer size = diagnosticWithParameters.getA(); Integer size = diagnosticWithParameters.getA();
@@ -86,10 +86,8 @@ public class CastExpressionFix extends JetIntentionAction<JetExpression> {
@Nullable @Nullable
@Override @Override
public IntentionAction createAction(Diagnostic diagnostic) { public IntentionAction createAction(Diagnostic diagnostic) {
assert diagnostic.getFactory() == Errors.AUTOCAST_IMPOSSIBLE;
@SuppressWarnings("unchecked")
DiagnosticWithParameters2<JetExpression, JetType, String> diagnosticWithParameters = DiagnosticWithParameters2<JetExpression, JetType, String> diagnosticWithParameters =
(DiagnosticWithParameters2<JetExpression, JetType, String>) diagnostic; Errors.AUTOCAST_IMPOSSIBLE.cast(diagnostic);
return new CastExpressionFix(diagnosticWithParameters.getPsiElement(), diagnosticWithParameters.getA()); return new CastExpressionFix(diagnosticWithParameters.getPsiElement(), diagnosticWithParameters.getA());
} }
}; };
@@ -29,14 +29,12 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor; import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters3;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.DescriptorResolver; import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
@@ -49,6 +47,8 @@ import org.jetbrains.jet.renderer.DescriptorRenderer;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import static org.jetbrains.jet.lang.diagnostics.Errors.COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH;
public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction> { public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction> {
private final JetType type; private final JetType type;
private final String renderedType; private final String renderedType;
@@ -127,8 +127,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
@NotNull @NotNull
public static JetMultiDeclarationEntry getMultiDeclarationEntryThatTypeMismatchComponentFunction(Diagnostic diagnostic) { public static JetMultiDeclarationEntry getMultiDeclarationEntryThatTypeMismatchComponentFunction(Diagnostic diagnostic) {
@SuppressWarnings("unchecked") String componentName = COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH.cast(diagnostic).getA().asString();
String componentName = ((DiagnosticWithParameters3<JetExpression, Name, JetType, JetType>) diagnostic).getA().asString();
int componentIndex = Integer.valueOf(componentName.substring(DescriptorResolver.COMPONENT_FUNCTION_NAME_PREFIX.length())); int componentIndex = Integer.valueOf(componentName.substring(DescriptorResolver.COMPONENT_FUNCTION_NAME_PREFIX.length()));
JetMultiDeclaration multiDeclaration = QuickFixUtil.getParentElementOfType(diagnostic, JetMultiDeclaration.class); JetMultiDeclaration multiDeclaration = QuickFixUtil.getParentElementOfType(diagnostic, JetMultiDeclaration.class);
assert multiDeclaration != null : "COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH reported on expression that is not within any multi declaration"; assert multiDeclaration != null : "COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH reported on expression that is not within any multi declaration";
@@ -20,7 +20,6 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiNameIdentifierOwner;
import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -29,8 +28,9 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters1; import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters2; import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters2;
import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.BindingContextUtils;
@@ -46,6 +46,8 @@ import org.jetbrains.jet.plugin.refactoring.changeSignature.JetParameterInfo;
import java.util.List; import java.util.List;
import static org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED; import static org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED;
import static org.jetbrains.jet.lang.diagnostics.Errors.EXPECTED_PARAMETERS_NUMBER_MISMATCH;
import static org.jetbrains.jet.lang.diagnostics.Errors.UNUSED_PARAMETER;
public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiElement> { public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiElement> {
protected final PsiElement context; protected final PsiElement context;
@@ -143,8 +145,8 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
@Override @Override
public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) { public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) {
JetCallElement callElement = PsiTreeUtil.getParentOfType(diagnostic.getPsiElement(), JetCallElement.class); JetCallElement callElement = PsiTreeUtil.getParentOfType(diagnostic.getPsiElement(), JetCallElement.class);
@SuppressWarnings("unchecked") //noinspection unchecked
CallableDescriptor descriptor = ((DiagnosticWithParameters1<PsiElement, CallableDescriptor>) diagnostic).getA(); CallableDescriptor descriptor = DiagnosticFactory.cast(diagnostic, Errors.TOO_MANY_ARGUMENTS, Errors.NO_VALUE_FOR_PARAMETER).getA();
if (callElement != null) { if (callElement != null) {
return createFix(callElement, callElement, descriptor); return createFix(callElement, callElement, descriptor);
@@ -159,9 +161,8 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
return new JetSingleIntentionActionFactory() { return new JetSingleIntentionActionFactory() {
@Override @Override
public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) { public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) {
@SuppressWarnings("unchecked")
DiagnosticWithParameters2<JetFunctionLiteral, Integer, List<JetType>> diagnosticWithParameters = DiagnosticWithParameters2<JetFunctionLiteral, Integer, List<JetType>> diagnosticWithParameters =
(DiagnosticWithParameters2<JetFunctionLiteral, Integer, List<JetType>>) diagnostic; EXPECTED_PARAMETERS_NUMBER_MISMATCH.cast(diagnostic);
JetFunctionLiteral functionLiteral = diagnosticWithParameters.getPsiElement(); JetFunctionLiteral functionLiteral = diagnosticWithParameters.getPsiElement();
BindingContext bindingContext = BindingContext bindingContext =
ResolvePackage.getBindingContext(functionLiteral.getContainingJetFile()); ResolvePackage.getBindingContext(functionLiteral.getContainingJetFile());
@@ -183,7 +184,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
@Override @Override
public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) { public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Object descriptor = ((DiagnosticWithParameters1<PsiNameIdentifierOwner, Object>) diagnostic).getA(); Object descriptor = UNUSED_PARAMETER.cast(diagnostic).getA();
if (descriptor instanceof ValueParameterDescriptor) { if (descriptor instanceof ValueParameterDescriptor) {
return createFix(null, diagnostic.getPsiElement(), (CallableDescriptor) descriptor); return createFix(null, diagnostic.getPsiElement(), (CallableDescriptor) descriptor);
@@ -64,9 +64,7 @@ public class ChangeTypeFix extends JetIntentionAction<JetTypeReference> {
@Nullable @Nullable
@Override @Override
public IntentionAction createAction(Diagnostic diagnostic) { public IntentionAction createAction(Diagnostic diagnostic) {
assert diagnostic.getFactory() == Errors.EXPECTED_PARAMETER_TYPE_MISMATCH; DiagnosticWithParameters1<JetParameter, JetType> diagnosticWithParameters = Errors.EXPECTED_PARAMETER_TYPE_MISMATCH.cast(diagnostic);
@SuppressWarnings("unchecked")
DiagnosticWithParameters1<JetParameter, JetType> diagnosticWithParameters = (DiagnosticWithParameters1<JetParameter, JetType>) diagnostic;
JetTypeReference typeReference = diagnosticWithParameters.getPsiElement().getTypeReference(); JetTypeReference typeReference = diagnosticWithParameters.getPsiElement().getTypeReference();
assert typeReference != null : "EXPECTED_PARAMETER_TYPE_MISMATCH reported on parameter without explicitly declared type"; assert typeReference != null : "EXPECTED_PARAMETER_TYPE_MISMATCH reported on parameter without explicitly declared type";
return new ChangeTypeFix(typeReference, diagnosticWithParameters.getA()); return new ChangeTypeFix(typeReference, diagnosticWithParameters.getA());
@@ -80,9 +78,7 @@ public class ChangeTypeFix extends JetIntentionAction<JetTypeReference> {
@Nullable @Nullable
@Override @Override
public IntentionAction createAction(Diagnostic diagnostic) { public IntentionAction createAction(Diagnostic diagnostic) {
assert diagnostic.getFactory() == Errors.EXPECTED_RETURN_TYPE_MISMATCH; DiagnosticWithParameters1<JetTypeReference, JetType> diagnosticWithParameters = Errors.EXPECTED_RETURN_TYPE_MISMATCH.cast(diagnostic);
@SuppressWarnings("unchecked")
DiagnosticWithParameters1<JetTypeReference, JetType> diagnosticWithParameters = (DiagnosticWithParameters1<JetTypeReference, JetType>) diagnostic;
return new ChangeTypeFix(diagnosticWithParameters.getPsiElement(), diagnosticWithParameters.getA()); return new ChangeTypeFix(diagnosticWithParameters.getPsiElement(), diagnosticWithParameters.getA());
} }
}; };
@@ -71,6 +71,8 @@ import java.util.ArrayList
import java.util.Properties import java.util.Properties
import org.jetbrains.jet.plugin.caches.resolve.getAnalysisResults import org.jetbrains.jet.plugin.caches.resolve.getAnalysisResults
import org.jetbrains.jet.plugin.caches.resolve.getBindingContext import org.jetbrains.jet.plugin.caches.resolve.getBindingContext
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory
import org.jetbrains.jet.lang.diagnostics
private val TYPE_PARAMETER_LIST_VARIABLE_NAME = "typeParameterList" private val TYPE_PARAMETER_LIST_VARIABLE_NAME = "typeParameterList"
private val TEMPLATE_FROM_USAGE_FUNCTION_BODY = "New Kotlin Function Body.kt" private val TEMPLATE_FROM_USAGE_FUNCTION_BODY = "New Kotlin Function Body.kt"
@@ -917,9 +919,7 @@ public class CreateFunctionFromUsageFix internal (
public fun createCreateHasNextFunctionFromUsageFactory(): JetSingleIntentionActionFactory { public fun createCreateHasNextFunctionFromUsageFactory(): JetSingleIntentionActionFactory {
return object : JetSingleIntentionActionFactory() { return object : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic?): IntentionAction? { override fun createAction(diagnostic: Diagnostic?): IntentionAction? {
assert(diagnostic!!.getFactory() == Errors.HAS_NEXT_MISSING || diagnostic.getFactory() == Errors.HAS_NEXT_FUNCTION_NONE_APPLICABLE) val diagnosticWithParameters = DiagnosticFactory.cast(diagnostic!!, Errors.HAS_NEXT_MISSING, Errors.HAS_NEXT_FUNCTION_NONE_APPLICABLE)
[suppress("UNCHECKED_CAST")]
val diagnosticWithParameters = diagnostic as DiagnosticWithParameters1<JetExpression, JetType>
val ownerType = TypeOrExpressionThereof(diagnosticWithParameters.getA(), Variance.IN_VARIANCE) val ownerType = TypeOrExpressionThereof(diagnosticWithParameters.getA(), Variance.IN_VARIANCE)
val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetForExpression>()) ?: return null val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetForExpression>()) ?: return null
@@ -932,9 +932,7 @@ public class CreateFunctionFromUsageFix internal (
public fun createCreateNextFunctionFromUsageFactory(): JetSingleIntentionActionFactory { public fun createCreateNextFunctionFromUsageFactory(): JetSingleIntentionActionFactory {
return object : JetSingleIntentionActionFactory() { return object : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic?): IntentionAction? { override fun createAction(diagnostic: Diagnostic?): IntentionAction? {
assert(diagnostic!!.getFactory() == Errors.NEXT_MISSING || diagnostic.getFactory() == Errors.NEXT_NONE_APPLICABLE) val diagnosticWithParameters = DiagnosticFactory.cast(diagnostic!!, Errors.NEXT_MISSING, Errors.NEXT_NONE_APPLICABLE)
[suppress("UNCHECKED_CAST")]
val diagnosticWithParameters = diagnostic as DiagnosticWithParameters1<JetExpression, JetType>
val ownerType = TypeOrExpressionThereof(diagnosticWithParameters.getA(), Variance.IN_VARIANCE) val ownerType = TypeOrExpressionThereof(diagnosticWithParameters.getA(), Variance.IN_VARIANCE)
val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetForExpression>()) ?: return null val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetForExpression>()) ?: return null
@@ -971,9 +969,7 @@ public class CreateFunctionFromUsageFix internal (
public fun createCreateComponentFunctionFromUsageFactory(): JetSingleIntentionActionFactory { public fun createCreateComponentFunctionFromUsageFactory(): JetSingleIntentionActionFactory {
return object : JetSingleIntentionActionFactory() { return object : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic?): IntentionAction? { override fun createAction(diagnostic: Diagnostic?): IntentionAction? {
assert(diagnostic!!.getFactory() == Errors.COMPONENT_FUNCTION_MISSING) val diagnosticWithParameters = Errors.COMPONENT_FUNCTION_MISSING.cast(diagnostic!!)
[suppress("UNCHECKED_CAST")]
val diagnosticWithParameters = (diagnostic as DiagnosticWithParameters2<JetExpression, Name, JetType>)
val name = diagnosticWithParameters.getA() val name = diagnosticWithParameters.getA()
val componentNumberMatcher = COMPONENT_FUNCTION_PATTERN.matcher(name.getIdentifier()) val componentNumberMatcher = COMPONENT_FUNCTION_PATTERN.matcher(name.getIdentifier())
if (!componentNumberMatcher.matches()) return null if (!componentNumberMatcher.matches()) return null
@@ -30,7 +30,7 @@ import org.jetbrains.jet.plugin.util.JetPsiPrecedences
public class KotlinSuppressIntentionAction( public class KotlinSuppressIntentionAction(
private val suppressAt: JetExpression, private val suppressAt: JetExpression,
private val diagnosticFactory: DiagnosticFactory, private val diagnosticFactory: DiagnosticFactory<*>,
private val kind: AnnotationHostKind private val kind: AnnotationHostKind
) : SuppressIntentionAction() { ) : SuppressIntentionAction() {
@@ -198,10 +198,8 @@ public class MapPlatformClassToKotlinFix extends JetIntentionAction<JetReference
ClassDescriptor platformClass = resolveToClass(typeExpr, context); ClassDescriptor platformClass = resolveToClass(typeExpr, context);
if (platformClass == null) return null; if (platformClass == null) return null;
assert diagnostic.getFactory() == Errors.PLATFORM_CLASS_MAPPED_TO_KOTLIN;
@SuppressWarnings("unchecked")
DiagnosticWithParameters1<JetElement, Collection<ClassDescriptor>> parametrizedDiagnostic = DiagnosticWithParameters1<JetElement, Collection<ClassDescriptor>> parametrizedDiagnostic =
(DiagnosticWithParameters1<JetElement, Collection<ClassDescriptor>>) diagnostic; Errors.PLATFORM_CLASS_MAPPED_TO_KOTLIN.cast(diagnostic);
return new MapPlatformClassToKotlinFix(typeExpr, platformClass, parametrizedDiagnostic.getA()); return new MapPlatformClassToKotlinFix(typeExpr, platformClass, parametrizedDiagnostic.getA());
} }
@@ -39,10 +39,7 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
public List<IntentionAction> createActions(Diagnostic diagnostic) { public List<IntentionAction> createActions(Diagnostic diagnostic) {
List<IntentionAction> actions = new LinkedList<IntentionAction>(); List<IntentionAction> actions = new LinkedList<IntentionAction>();
assert diagnostic.getFactory() == Errors.TYPE_MISMATCH; DiagnosticWithParameters2<JetExpression, JetType, JetType> diagnosticWithParameters = Errors.TYPE_MISMATCH.cast(diagnostic);
@SuppressWarnings("unchecked")
DiagnosticWithParameters2<JetExpression, JetType, JetType> diagnosticWithParameters =
(DiagnosticWithParameters2<JetExpression, JetType, JetType>) diagnostic;
JetExpression expression = diagnosticWithParameters.getPsiElement(); JetExpression expression = diagnosticWithParameters.getPsiElement();
JetType expectedType = diagnosticWithParameters.getA(); JetType expectedType = diagnosticWithParameters.getA();
JetType expressionType = diagnosticWithParameters.getB(); JetType expressionType = diagnosticWithParameters.getB();
@@ -30,14 +30,14 @@ import static org.jetbrains.jet.lexer.JetTokens.*;
public class QuickFixes { public class QuickFixes {
private static final Multimap<DiagnosticFactory, JetIntentionActionsFactory> factories = HashMultimap.create(); private static final Multimap<DiagnosticFactory<?>, JetIntentionActionsFactory> factories = HashMultimap.create();
private static final Multimap<DiagnosticFactory, IntentionAction> actions = HashMultimap.create(); private static final Multimap<DiagnosticFactory<?>, IntentionAction> actions = HashMultimap.create();
public static Collection<JetIntentionActionsFactory> getActionsFactories(DiagnosticFactory diagnosticFactory) { public static Collection<JetIntentionActionsFactory> getActionsFactories(DiagnosticFactory<?> diagnosticFactory) {
return factories.get(diagnosticFactory); return factories.get(diagnosticFactory);
} }
public static Collection<IntentionAction> getActions(DiagnosticFactory diagnosticFactory) { public static Collection<IntentionAction> getActions(DiagnosticFactory<?> diagnosticFactory) {
return actions.get(diagnosticFactory); return actions.get(diagnosticFactory);
} }
@@ -302,7 +302,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
JetFunctionLiteral functionLiteral = functionLiteralExpression.getFunctionLiteral(); JetFunctionLiteral functionLiteral = functionLiteralExpression.getFunctionLiteral();
BindingContext context = resolveSessionForBodies.resolveToElement(functionLiteralExpression); BindingContext context = resolveSessionForBodies.resolveToElement(functionLiteralExpression);
for (Diagnostic diagnostic : context.getDiagnostics()) { for (Diagnostic diagnostic : context.getDiagnostics()) {
DiagnosticFactory factory = diagnostic.getFactory(); DiagnosticFactory<?> factory = diagnostic.getFactory();
PsiElement element = diagnostic.getPsiElement(); PsiElement element = diagnostic.getPsiElement();
boolean hasCantInferParameter = factory == Errors.CANNOT_INFER_PARAMETER_TYPE && element.getParent().getParent() == functionLiteral; boolean hasCantInferParameter = factory == Errors.CANNOT_INFER_PARAMETER_TYPE && element.getParent().getParent() == functionLiteral;
boolean hasUnresolvedItOrThis = factory == Errors.UNRESOLVED_REFERENCE && element.getText().equals("it") && boolean hasUnresolvedItOrThis = factory == Errors.UNRESOLVED_REFERENCE && element.getText().equals("it") &&
@@ -78,7 +78,7 @@ public abstract class AbstractDiagnosticMessageTest extends JetLiteFixture {
String fileData = JetTestUtils.doLoadFile(file); String fileData = JetTestUtils.doLoadFile(file);
Map<String,String> directives = JetTestUtils.parseDirectives(fileData); Map<String,String> directives = JetTestUtils.parseDirectives(fileData);
int diagnosticNumber = getDiagnosticNumber(directives); int diagnosticNumber = getDiagnosticNumber(directives);
final Set<DiagnosticFactory> diagnosticFactories = getDiagnosticFactories(directives); final Set<DiagnosticFactory<?>> diagnosticFactories = getDiagnosticFactories(directives);
MessageType messageType = getMessageTypeDirective(directives); MessageType messageType = getMessageTypeDirective(directives);
JetFile psiFile = createPsiFile(null, fileName, loadFile(fileName)); JetFile psiFile = createPsiFile(null, fileName, loadFile(fileName));
@@ -128,10 +128,10 @@ public abstract class AbstractDiagnosticMessageTest extends JetLiteFixture {
} }
@NotNull @NotNull
private static Set<DiagnosticFactory> getDiagnosticFactories(Map<String, String> directives) { private static Set<DiagnosticFactory<?>> getDiagnosticFactories(Map<String, String> directives) {
String diagnosticsData = directives.get(DIAGNOSTICS_DIRECTIVE); String diagnosticsData = directives.get(DIAGNOSTICS_DIRECTIVE);
assert diagnosticsData != null : DIAGNOSTICS_DIRECTIVE + " should be present."; assert diagnosticsData != null : DIAGNOSTICS_DIRECTIVE + " should be present.";
Set<DiagnosticFactory> diagnosticFactories = Sets.newHashSet(); Set<DiagnosticFactory<?>> diagnosticFactories = Sets.newHashSet();
String[] diagnostics = diagnosticsData.split(" "); String[] diagnostics = diagnosticsData.split(" ");
for (String diagnosticName : diagnostics) { for (String diagnosticName : diagnostics) {
String errorMessage = "Can't load diagnostic factory for " + diagnosticName; String errorMessage = "Can't load diagnostic factory for " + diagnosticName;
@@ -139,7 +139,7 @@ public abstract class AbstractDiagnosticMessageTest extends JetLiteFixture {
Field field = Errors.class.getField(diagnosticName); Field field = Errors.class.getField(diagnosticName);
Object value = field.get(null); Object value = field.get(null);
if (value instanceof DiagnosticFactory) { if (value instanceof DiagnosticFactory) {
diagnosticFactories.add((DiagnosticFactory)value); diagnosticFactories.add((DiagnosticFactory<?>)value);
} }
else { else {
throw new AssertionError(errorMessage); throw new AssertionError(errorMessage);