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 {
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.factory = factory;
}
@NotNull
@Override
public DiagnosticFactory getFactory() {
public DiagnosticFactory<?> getFactory() {
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();
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 ELEMENT_WITH_ERROR_TYPE = new DebugInfoDiagnosticFactory("ELEMENT_WITH_ERROR_TYPE");
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 DebugInfoReporter debugInfoReporter
) {
final Map<JetReferenceExpression, DiagnosticFactory> markedWithErrorElements = Maps.newHashMap();
final Map<JetReferenceExpression, DiagnosticFactory<?>> markedWithErrorElements = Maps.newHashMap();
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
DiagnosticFactory factory = diagnostic.getFactory();
DiagnosticFactory<?> factory = diagnostic.getFactory();
if (Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS.contains(diagnostic.getFactory())) {
markedWithErrorElements.put((JetReferenceExpression) diagnostic.getPsiElement(), factory);
}
@@ -136,7 +136,7 @@ public class DebugInfoUtil {
markedWithError = true;
}
JetType expressionType = bindingContext.get(EXPRESSION_TYPE, expression);
DiagnosticFactory factory = markedWithErrorElements.get(expression);
DiagnosticFactory<?> factory = markedWithErrorElements.get(expression);
if (declarationDescriptor != null &&
(ErrorUtils.isError(declarationDescriptor) || ErrorUtils.containsErrorType(expressionType))) {
if (factory != Errors.EXPRESSION_EXPECTED_PACKAGE_FOUND) {
@@ -274,7 +274,7 @@ public class JetFlowInformationProvider {
final Set<VariableDescriptor> declaredVariables = pseudocodeVariablesData.getDeclaredVariables(pseudocode, true);
final LexicalScopeVariableInfo lexicalScopeVariableInfo = pseudocodeVariablesData.getLexicalScopeVariableInfo();
final Map<Instruction, DiagnosticFactory> reportedDiagnosticMap = Maps.newHashMap();
final Map<Instruction, DiagnosticFactory<?>> reportedDiagnosticMap = Maps.newHashMap();
PseudocodeTraverserPackage.traverse(
pseudocode, FORWARD, initializers,
@@ -548,7 +548,7 @@ public class JetFlowInformationProvider {
final PseudocodeVariablesData pseudocodeVariablesData = getPseudocodeVariablesData();
Map<Instruction, Edges<Map<VariableDescriptor, VariableUseState>>> variableStatusData =
pseudocodeVariablesData.getVariableUseStatusData();
final Map<Instruction, DiagnosticFactory> reportedDiagnosticMap = Maps.newHashMap();
final Map<Instruction, DiagnosticFactory<?>> reportedDiagnosticMap = Maps.newHashMap();
InstructionDataAnalyzeStrategy<Map<VariableDescriptor, VariableUseState>> variableStatusAnalyzeStrategy =
new InstructionDataAnalyzeStrategy<Map<VariableDescriptor, VariableUseState>>() {
@Override
@@ -638,7 +638,7 @@ public class JetFlowInformationProvider {
// "Unused literals" in block
public void markUnusedLiteralsInBlock() {
final Map<Instruction, DiagnosticFactory> reportedDiagnosticMap = Maps.newHashMap();
final Map<Instruction, DiagnosticFactory<?>> reportedDiagnosticMap = Maps.newHashMap();
PseudocodeTraverserPackage.traverse(
pseudocode, FORWARD, new FunctionVoid1<Instruction>() {
@Override
@@ -828,13 +828,13 @@ public class JetFlowInformationProvider {
trace.report(diagnostic);
return;
}
Map<Instruction, DiagnosticFactory> previouslyReported = ctxt.reportedDiagnosticMap;
Map<Instruction, DiagnosticFactory<?>> previouslyReported = ctxt.reportedDiagnosticMap;
previouslyReported.put(instruction, diagnostic.getFactory());
boolean alreadyReported = false;
boolean sameErrorForAllCopies = true;
for (Instruction copy : instruction.getCopies()) {
DiagnosticFactory previouslyReportedErrorFactory = previouslyReported.get(copy);
DiagnosticFactory<?> previouslyReportedErrorFactory = previouslyReported.get(copy);
if (previouslyReportedErrorFactory != null) {
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
|| diagnosticFactory == UNUSED_PARAMETER
|| diagnosticFactory == UNUSED_CHANGED_VALUE;
@@ -865,13 +865,13 @@ public class JetFlowInformationProvider {
private class VariableContext {
final Map<Instruction, DiagnosticFactory> reportedDiagnosticMap;
final Map<Instruction, DiagnosticFactory<?>> reportedDiagnosticMap;
final Instruction instruction;
final VariableDescriptor variableDescriptor;
private VariableContext(
@NotNull Instruction instruction,
@NotNull Map<Instruction, DiagnosticFactory> map
@NotNull Map<Instruction, DiagnosticFactory<?>> map
) {
this.instruction = instruction;
reportedDiagnosticMap = map;
@@ -885,7 +885,7 @@ public class JetFlowInformationProvider {
private VariableInitContext(
@NotNull Instruction instruction,
@NotNull Map<Instruction, DiagnosticFactory> map,
@NotNull Map<Instruction, DiagnosticFactory<?>> map,
@NotNull Map<VariableDescriptor, VariableInitState> in,
@NotNull Map<VariableDescriptor, VariableInitState> out,
@NotNull LexicalScopeVariableInfo lexicalScopeVariableInfo
@@ -914,7 +914,7 @@ public class JetFlowInformationProvider {
private VariableUseContext(
@NotNull Instruction instruction,
@NotNull Map<Instruction, DiagnosticFactory> map,
@NotNull Map<Instruction, DiagnosticFactory<?>> map,
@NotNull Map<VariableDescriptor, VariableUseState> in,
@NotNull Map<VariableDescriptor, VariableUseState> out
) {
@@ -18,20 +18,18 @@ package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiErrorElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetNodeTypes;
import java.util.List;
public abstract class AbstractDiagnostic<E extends PsiElement> implements ParametrizedDiagnostic<E> {
private final E psiElement;
private final DiagnosticFactoryWithPsiElement<E> factory;
private final DiagnosticFactoryWithPsiElement<E, ?> factory;
private final Severity severity;
public AbstractDiagnostic(@NotNull E psiElement,
@NotNull DiagnosticFactoryWithPsiElement<E> factory,
@NotNull DiagnosticFactoryWithPsiElement<E, ?> factory,
@NotNull Severity severity) {
this.psiElement = psiElement;
this.factory = factory;
@@ -40,7 +38,7 @@ public abstract class AbstractDiagnostic<E extends PsiElement> implements Parame
@NotNull
@Override
public DiagnosticFactoryWithPsiElement<E> getFactory() {
public DiagnosticFactoryWithPsiElement<E, ?> getFactory() {
return factory;
}
@@ -26,7 +26,7 @@ import java.util.List;
public interface Diagnostic {
@NotNull
DiagnosticFactory getFactory();
DiagnosticFactory<?> getFactory();
@NotNull
Severity getSeverity();
@@ -18,7 +18,10 @@ package org.jetbrains.jet.lang.diagnostics;
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 final Severity severity;
@@ -41,6 +44,30 @@ public abstract class DiagnosticFactory {
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
public String toString() {
return getName();
@@ -19,7 +19,7 @@ package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
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) {
super(severity, positioningStrategy);
@@ -19,7 +19,7 @@ package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
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
public ParametrizedDiagnostic<E> on(@NotNull E element, @NotNull A argument) {
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 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
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 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) {
super(severity, positioningStrategy);
@@ -21,7 +21,7 @@ import com.intellij.psi.PsiElement;
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;
public DiagnosticFactoryWithPsiElement(Severity severity, PositioningStrategy<? super E> positioningStrategy) {
@@ -589,11 +589,11 @@ public interface Errors {
DiagnosticFactory0<JetElement> DECLARATION_CANT_BE_INLINED = DiagnosticFactory0.create(ERROR);
// 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);
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);
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_UPPER_BOUND_VIOLATED, TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH);
@@ -612,7 +612,7 @@ public interface Errors {
try {
Object value = field.get(null);
if (value instanceof DiagnosticFactory) {
DiagnosticFactory factory = (DiagnosticFactory)value;
DiagnosticFactory<?> factory = (DiagnosticFactory<?>)value;
factory.setName(field.getName());
}
}
@@ -493,8 +493,8 @@ public class DefaultErrorMessages {
try {
Object fieldValue = field.get(null);
if (fieldValue instanceof DiagnosticFactory) {
if (MAP.get((DiagnosticFactory) fieldValue) == null) {
throw new IllegalStateException("No default diagnostic renderer is provided for " + ((DiagnosticFactory)fieldValue).getName());
if (MAP.get((DiagnosticFactory<?>) fieldValue) == null) {
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;
public final class DiagnosticFactoryToRendererMap {
private final Map<DiagnosticFactory, DiagnosticRenderer<?>> map =
new HashMap<DiagnosticFactory, DiagnosticRenderer<?>>();
private final Map<DiagnosticFactory<?>, DiagnosticRenderer<?>> map =
new HashMap<DiagnosticFactory<?>, DiagnosticRenderer<?>>();
private boolean immutable = false;
private void checkMutability() {
@@ -64,7 +64,7 @@ public final class DiagnosticFactoryToRendererMap {
}
@Nullable
public DiagnosticRenderer<?> get(@NotNull DiagnosticFactory factory) {
public DiagnosticRenderer<?> get(@NotNull DiagnosticFactory<?> factory) {
return map.get(factory);
}
@@ -111,7 +111,7 @@ public class DiagnosticsWithSuppression implements Diagnostics {
private static boolean isSuppressedForDebugger(@NotNull Diagnostic diagnostic, @NotNull PsiElement element) {
PsiFile containingFile = element.getContainingFile();
if (containingFile instanceof JetFile && CodeFragmentUtilPackage.skipVisibilityCheck((JetFile) containingFile)) {
DiagnosticFactory diagnosticFactory = diagnostic.getFactory();
DiagnosticFactory<?> diagnosticFactory = diagnostic.getFactory();
return diagnosticFactory == Errors.INVISIBLE_MEMBER ||
diagnosticFactory == Errors.INVISIBLE_REFERENCE ||
diagnosticFactory == Errors.INVISIBLE_SETTER;
@@ -36,8 +36,8 @@ import java.util.Set;
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
public class CompileTimeConstantChecker {
private static final Set<DiagnosticFactory> errorsThatDependOnExpectedType =
Sets.<DiagnosticFactory>newHashSet(CONSTANT_EXPECTED_TYPE_MISMATCH, NULL_FOR_NONNULL_TYPE);
private static final Set<DiagnosticFactory<?>> errorsThatDependOnExpectedType =
Sets.<DiagnosticFactory<?>>newHashSet(CONSTANT_EXPECTED_TYPE_MISMATCH, NULL_FOR_NONNULL_TYPE);
private final KotlinBuiltIns builtIns;
private final BindingTrace trace;
@@ -451,7 +451,7 @@ public class ExpressionTypingUtils {
@Override
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)
&& diagnostic.getPsiElement() == expressionToWatch) {
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.diagnostics.*;
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.resolve.AnalyzingUtils;
import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -146,23 +147,26 @@ public abstract class AbstractJetDiagnosticsTest extends BaseDiagnosticsTest {
@SuppressWarnings({"unchecked", "ConstantConditions"})
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,
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);
Diagnostics diagnostics = bindingContext.getDiagnostics();
for (Diagnostic diagnostic : diagnostics) {
DiagnosticFactory factory = diagnostic.getFactory();
DiagnosticFactory<?> factory = diagnostic.getFactory();
//noinspection SuspiciousMethodCalls
if (diagnosticsStoringResolvedCalls1.contains(factory)) {
assertResolvedCallsAreCompleted(
diagnostic, ((DiagnosticWithParameters1<PsiElement, Collection<? extends ResolvedCall<?>>>) diagnostic).getA());
diagnostic, DiagnosticFactory.cast(diagnostic, diagnosticsStoringResolvedCalls1).getA());
}
//noinspection SuspiciousMethodCalls
if (diagnosticsStoringResolvedCalls2.contains(factory)) {
assertResolvedCallsAreCompleted(
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 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(
Errors.UNRESOLVED_REFERENCE,
Errors.UNRESOLVED_REFERENCE_WRONG_RECEIVER,
@@ -28,7 +28,7 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory
import com.intellij.psi.util.PsiTreeUtil
class KotlinSuppressableWarningProblemGroup(
private val diagnosticFactory: DiagnosticFactory
private val diagnosticFactory: DiagnosticFactory<*>
) : 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)
return Collections.emptyList()
@@ -72,10 +72,8 @@ public abstract class AddStarProjectionsFix extends JetIntentionAction<JetUserTy
return new JetSingleIntentionActionFactory() {
@Override
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>) diagnostic;
Errors.NO_TYPE_ARGUMENTS_ON_RHS.cast(diagnostic);
JetTypeElement typeElement = diagnosticWithParameters.getPsiElement().getTypeElement();
while (typeElement instanceof JetNullableType) {
typeElement = ((JetNullableType) typeElement).getInnerType();
@@ -91,9 +89,7 @@ public abstract class AddStarProjectionsFix extends JetIntentionAction<JetUserTy
return new JetSingleIntentionActionFactory() {
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
assert diagnostic.getFactory() == Errors.WRONG_NUMBER_OF_TYPE_ARGUMENTS;
@SuppressWarnings("unchecked")
DiagnosticWithParameters1<JetElement, Integer> diagnosticWithParameters = (DiagnosticWithParameters1) diagnostic;
DiagnosticWithParameters1<JetElement, Integer> diagnosticWithParameters = Errors.WRONG_NUMBER_OF_TYPE_ARGUMENTS.cast(diagnostic);
Integer size = diagnosticWithParameters.getA();
@@ -86,10 +86,8 @@ public class CastExpressionFix extends JetIntentionAction<JetExpression> {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
assert diagnostic.getFactory() == Errors.AUTOCAST_IMPOSSIBLE;
@SuppressWarnings("unchecked")
DiagnosticWithParameters2<JetExpression, JetType, String> diagnosticWithParameters =
(DiagnosticWithParameters2<JetExpression, JetType, String>) diagnostic;
Errors.AUTOCAST_IMPOSSIBLE.cast(diagnostic);
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.SimpleFunctionDescriptor;
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.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
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.JetType;
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.List;
import static org.jetbrains.jet.lang.diagnostics.Errors.COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH;
public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction> {
private final JetType type;
private final String renderedType;
@@ -127,8 +127,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
@NotNull
public static JetMultiDeclarationEntry getMultiDeclarationEntryThatTypeMismatchComponentFunction(Diagnostic diagnostic) {
@SuppressWarnings("unchecked")
String componentName = ((DiagnosticWithParameters3<JetExpression, Name, JetType, JetType>) diagnostic).getA().asString();
String componentName = COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH.cast(diagnostic).getA().asString();
int componentIndex = Integer.valueOf(componentName.substring(DescriptorResolver.COMPONENT_FUNCTION_NAME_PREFIX.length()));
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";
@@ -20,7 +20,6 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiNameIdentifierOwner;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
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.ValueParameterDescriptor;
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.Errors;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
@@ -46,6 +46,8 @@ import org.jetbrains.jet.plugin.refactoring.changeSignature.JetParameterInfo;
import java.util.List;
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> {
protected final PsiElement context;
@@ -143,8 +145,8 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
@Override
public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) {
JetCallElement callElement = PsiTreeUtil.getParentOfType(diagnostic.getPsiElement(), JetCallElement.class);
@SuppressWarnings("unchecked")
CallableDescriptor descriptor = ((DiagnosticWithParameters1<PsiElement, CallableDescriptor>) diagnostic).getA();
//noinspection unchecked
CallableDescriptor descriptor = DiagnosticFactory.cast(diagnostic, Errors.TOO_MANY_ARGUMENTS, Errors.NO_VALUE_FOR_PARAMETER).getA();
if (callElement != null) {
return createFix(callElement, callElement, descriptor);
@@ -159,9 +161,8 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
return new JetSingleIntentionActionFactory() {
@Override
public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) {
@SuppressWarnings("unchecked")
DiagnosticWithParameters2<JetFunctionLiteral, Integer, List<JetType>> diagnosticWithParameters =
(DiagnosticWithParameters2<JetFunctionLiteral, Integer, List<JetType>>) diagnostic;
EXPECTED_PARAMETERS_NUMBER_MISMATCH.cast(diagnostic);
JetFunctionLiteral functionLiteral = diagnosticWithParameters.getPsiElement();
BindingContext bindingContext =
ResolvePackage.getBindingContext(functionLiteral.getContainingJetFile());
@@ -183,7 +184,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
@Override
public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) {
@SuppressWarnings("unchecked")
Object descriptor = ((DiagnosticWithParameters1<PsiNameIdentifierOwner, Object>) diagnostic).getA();
Object descriptor = UNUSED_PARAMETER.cast(diagnostic).getA();
if (descriptor instanceof ValueParameterDescriptor) {
return createFix(null, diagnostic.getPsiElement(), (CallableDescriptor) descriptor);
@@ -64,9 +64,7 @@ public class ChangeTypeFix extends JetIntentionAction<JetTypeReference> {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
assert diagnostic.getFactory() == Errors.EXPECTED_PARAMETER_TYPE_MISMATCH;
@SuppressWarnings("unchecked")
DiagnosticWithParameters1<JetParameter, JetType> diagnosticWithParameters = (DiagnosticWithParameters1<JetParameter, JetType>) diagnostic;
DiagnosticWithParameters1<JetParameter, JetType> diagnosticWithParameters = Errors.EXPECTED_PARAMETER_TYPE_MISMATCH.cast(diagnostic);
JetTypeReference typeReference = diagnosticWithParameters.getPsiElement().getTypeReference();
assert typeReference != null : "EXPECTED_PARAMETER_TYPE_MISMATCH reported on parameter without explicitly declared type";
return new ChangeTypeFix(typeReference, diagnosticWithParameters.getA());
@@ -80,9 +78,7 @@ public class ChangeTypeFix extends JetIntentionAction<JetTypeReference> {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
assert diagnostic.getFactory() == Errors.EXPECTED_RETURN_TYPE_MISMATCH;
@SuppressWarnings("unchecked")
DiagnosticWithParameters1<JetTypeReference, JetType> diagnosticWithParameters = (DiagnosticWithParameters1<JetTypeReference, JetType>) diagnostic;
DiagnosticWithParameters1<JetTypeReference, JetType> diagnosticWithParameters = Errors.EXPECTED_RETURN_TYPE_MISMATCH.cast(diagnostic);
return new ChangeTypeFix(diagnosticWithParameters.getPsiElement(), diagnosticWithParameters.getA());
}
};
@@ -71,6 +71,8 @@ import java.util.ArrayList
import java.util.Properties
import org.jetbrains.jet.plugin.caches.resolve.getAnalysisResults
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 TEMPLATE_FROM_USAGE_FUNCTION_BODY = "New Kotlin Function Body.kt"
@@ -917,9 +919,7 @@ public class CreateFunctionFromUsageFix internal (
public fun createCreateHasNextFunctionFromUsageFactory(): JetSingleIntentionActionFactory {
return object : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic?): IntentionAction? {
assert(diagnostic!!.getFactory() == Errors.HAS_NEXT_MISSING || diagnostic.getFactory() == Errors.HAS_NEXT_FUNCTION_NONE_APPLICABLE)
[suppress("UNCHECKED_CAST")]
val diagnosticWithParameters = diagnostic as DiagnosticWithParameters1<JetExpression, JetType>
val diagnosticWithParameters = DiagnosticFactory.cast(diagnostic!!, Errors.HAS_NEXT_MISSING, Errors.HAS_NEXT_FUNCTION_NONE_APPLICABLE)
val ownerType = TypeOrExpressionThereof(diagnosticWithParameters.getA(), Variance.IN_VARIANCE)
val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetForExpression>()) ?: return null
@@ -932,9 +932,7 @@ public class CreateFunctionFromUsageFix internal (
public fun createCreateNextFunctionFromUsageFactory(): JetSingleIntentionActionFactory {
return object : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic?): IntentionAction? {
assert(diagnostic!!.getFactory() == Errors.NEXT_MISSING || diagnostic.getFactory() == Errors.NEXT_NONE_APPLICABLE)
[suppress("UNCHECKED_CAST")]
val diagnosticWithParameters = diagnostic as DiagnosticWithParameters1<JetExpression, JetType>
val diagnosticWithParameters = DiagnosticFactory.cast(diagnostic!!, Errors.NEXT_MISSING, Errors.NEXT_NONE_APPLICABLE)
val ownerType = TypeOrExpressionThereof(diagnosticWithParameters.getA(), Variance.IN_VARIANCE)
val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetForExpression>()) ?: return null
@@ -971,9 +969,7 @@ public class CreateFunctionFromUsageFix internal (
public fun createCreateComponentFunctionFromUsageFactory(): JetSingleIntentionActionFactory {
return object : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic?): IntentionAction? {
assert(diagnostic!!.getFactory() == Errors.COMPONENT_FUNCTION_MISSING)
[suppress("UNCHECKED_CAST")]
val diagnosticWithParameters = (diagnostic as DiagnosticWithParameters2<JetExpression, Name, JetType>)
val diagnosticWithParameters = Errors.COMPONENT_FUNCTION_MISSING.cast(diagnostic!!)
val name = diagnosticWithParameters.getA()
val componentNumberMatcher = COMPONENT_FUNCTION_PATTERN.matcher(name.getIdentifier())
if (!componentNumberMatcher.matches()) return null
@@ -30,7 +30,7 @@ import org.jetbrains.jet.plugin.util.JetPsiPrecedences
public class KotlinSuppressIntentionAction(
private val suppressAt: JetExpression,
private val diagnosticFactory: DiagnosticFactory,
private val diagnosticFactory: DiagnosticFactory<*>,
private val kind: AnnotationHostKind
) : SuppressIntentionAction() {
@@ -198,10 +198,8 @@ public class MapPlatformClassToKotlinFix extends JetIntentionAction<JetReference
ClassDescriptor platformClass = resolveToClass(typeExpr, context);
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>>) diagnostic;
Errors.PLATFORM_CLASS_MAPPED_TO_KOTLIN.cast(diagnostic);
return new MapPlatformClassToKotlinFix(typeExpr, platformClass, parametrizedDiagnostic.getA());
}
@@ -39,10 +39,7 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
public List<IntentionAction> createActions(Diagnostic diagnostic) {
List<IntentionAction> actions = new LinkedList<IntentionAction>();
assert diagnostic.getFactory() == Errors.TYPE_MISMATCH;
@SuppressWarnings("unchecked")
DiagnosticWithParameters2<JetExpression, JetType, JetType> diagnosticWithParameters =
(DiagnosticWithParameters2<JetExpression, JetType, JetType>) diagnostic;
DiagnosticWithParameters2<JetExpression, JetType, JetType> diagnosticWithParameters = Errors.TYPE_MISMATCH.cast(diagnostic);
JetExpression expression = diagnosticWithParameters.getPsiElement();
JetType expectedType = diagnosticWithParameters.getA();
JetType expressionType = diagnosticWithParameters.getB();
@@ -30,14 +30,14 @@ import static org.jetbrains.jet.lexer.JetTokens.*;
public class QuickFixes {
private static final Multimap<DiagnosticFactory, JetIntentionActionsFactory> factories = HashMultimap.create();
private static final Multimap<DiagnosticFactory, IntentionAction> actions = HashMultimap.create();
private static final Multimap<DiagnosticFactory<?>, JetIntentionActionsFactory> factories = 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);
}
public static Collection<IntentionAction> getActions(DiagnosticFactory diagnosticFactory) {
public static Collection<IntentionAction> getActions(DiagnosticFactory<?> diagnosticFactory) {
return actions.get(diagnosticFactory);
}
@@ -302,7 +302,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
JetFunctionLiteral functionLiteral = functionLiteralExpression.getFunctionLiteral();
BindingContext context = resolveSessionForBodies.resolveToElement(functionLiteralExpression);
for (Diagnostic diagnostic : context.getDiagnostics()) {
DiagnosticFactory factory = diagnostic.getFactory();
DiagnosticFactory<?> factory = diagnostic.getFactory();
PsiElement element = diagnostic.getPsiElement();
boolean hasCantInferParameter = factory == Errors.CANNOT_INFER_PARAMETER_TYPE && element.getParent().getParent() == functionLiteral;
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);
Map<String,String> directives = JetTestUtils.parseDirectives(fileData);
int diagnosticNumber = getDiagnosticNumber(directives);
final Set<DiagnosticFactory> diagnosticFactories = getDiagnosticFactories(directives);
final Set<DiagnosticFactory<?>> diagnosticFactories = getDiagnosticFactories(directives);
MessageType messageType = getMessageTypeDirective(directives);
JetFile psiFile = createPsiFile(null, fileName, loadFile(fileName));
@@ -128,10 +128,10 @@ public abstract class AbstractDiagnosticMessageTest extends JetLiteFixture {
}
@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);
assert diagnosticsData != null : DIAGNOSTICS_DIRECTIVE + " should be present.";
Set<DiagnosticFactory> diagnosticFactories = Sets.newHashSet();
Set<DiagnosticFactory<?>> diagnosticFactories = Sets.newHashSet();
String[] diagnostics = diagnosticsData.split(" ");
for (String diagnosticName : diagnostics) {
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);
Object value = field.get(null);
if (value instanceof DiagnosticFactory) {
diagnosticFactories.add((DiagnosticFactory)value);
diagnosticFactories.add((DiagnosticFactory<?>)value);
}
else {
throw new AssertionError(errorMessage);