From 03d944d2b3182b8684f79ddaac72cb4c774e3d1a Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 20 Oct 2015 19:28:01 +0300 Subject: [PATCH] Backing field: four more errors dropped --- .../cfg/JetFlowInformationProvider.java | 67 +------------------ .../jetbrains/kotlin/diagnostics/Errors.java | 7 -- .../rendering/DefaultErrorMessages.java | 6 -- .../kotlin/idea/quickfix/QuickFixRegistrar.kt | 5 -- 4 files changed, 3 insertions(+), 82 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/JetFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/kotlin/cfg/JetFlowInformationProvider.java index 6c437059afc..59de928aac3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/JetFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/JetFlowInformationProvider.java @@ -325,9 +325,7 @@ public class JetFlowInformationProvider { if (instruction instanceof ReadValueInstruction) { ReadValueInstruction readValueInstruction = (ReadValueInstruction) instruction; KtElement element = readValueInstruction.getElement(); - boolean error = checkBackingField(ctxt, element); - if (!error && - PseudocodeUtil.isThisOrNoDispatchReceiver(readValueInstruction, trace.getBindingContext()) && + if (PseudocodeUtil.isThisOrNoDispatchReceiver(readValueInstruction, trace.getBindingContext()) && declaredVariables.contains(ctxt.variableDescriptor)) { checkIsInitialized(ctxt, element, varWithUninitializedErrorGenerated); } @@ -336,12 +334,9 @@ public class JetFlowInformationProvider { if (!(instruction instanceof WriteValueInstruction)) return; WriteValueInstruction writeValueInstruction = (WriteValueInstruction) instruction; KtElement element = writeValueInstruction.getLValue(); - boolean error = checkBackingField(ctxt, element); if (!(element instanceof KtExpression)) return; - if (!error) { - error = checkValReassignment(ctxt, (KtExpression) element, writeValueInstruction, - varWithValReassignErrorGenerated); - } + boolean error = checkValReassignment(ctxt, (KtExpression) element, writeValueInstruction, + varWithValReassignErrorGenerated); if (!error && processClassOrObject) { error = checkAssignmentBeforeDeclaration(ctxt, (KtExpression) element); } @@ -522,62 +517,6 @@ public class JetFlowInformationProvider { return false; } - private boolean checkBackingField(@NotNull VariableContext cxtx, @NotNull KtElement element) { - VariableDescriptor variableDescriptor = cxtx.variableDescriptor; - boolean[] error = new boolean[1]; - if (!isCorrectBackingFieldReference(element, cxtx, error, true)) return false; - if (error[0]) return true; - if (!(variableDescriptor instanceof PropertyDescriptor)) { - report(Errors.NOT_PROPERTY_BACKING_FIELD.on(element), cxtx); - return true; - } - PsiElement property = DescriptorToSourceUtils.descriptorToDeclaration(variableDescriptor); - boolean insideSelfAccessors = PsiTreeUtil.isAncestor(property, element, false); - if (!trace.get(BindingContext.BACKING_FIELD_REQUIRED, (PropertyDescriptor) variableDescriptor) && - // not to generate error in accessors of abstract properties, there is one: declared accessor of abstract property - !insideSelfAccessors) { - - if (((PropertyDescriptor) variableDescriptor).getModality() == Modality.ABSTRACT) { - report(NO_BACKING_FIELD_ABSTRACT_PROPERTY.on(element), cxtx); - } - else { - report(NO_BACKING_FIELD_CUSTOM_ACCESSORS.on(element), cxtx); - } - return true; - } - if (insideSelfAccessors) return false; - - DeclarationDescriptor declarationDescriptor = BindingContextUtils.getEnclosingDescriptor(trace.getBindingContext(), element); - - DeclarationDescriptor containingDeclaration = variableDescriptor.getContainingDeclaration(); - if ((containingDeclaration instanceof ClassDescriptor) - && DescriptorUtils.isAncestor(containingDeclaration, declarationDescriptor, false)) { - return false; - } - report(Errors.INACCESSIBLE_BACKING_FIELD.on(element), cxtx); - return true; - } - - private boolean isCorrectBackingFieldReference( - @Nullable KtElement element, - VariableContext ctxt, - boolean[] error, - boolean reportError - ) { - error[0] = false; - if (element instanceof KtDotQualifiedExpression && isCorrectBackingFieldReference( - ((KtDotQualifiedExpression) element).getSelectorExpression(), ctxt, error, false)) { - if (((KtDotQualifiedExpression) element).getReceiverExpression() instanceof KtThisExpression) { - return true; - } - error[0] = true; - if (reportError) { - report(Errors.INACCESSIBLE_BACKING_FIELD.on(element), ctxt); - } - } - return false; - } - private void recordInitializedVariables( @NotNull Pseudocode pseudocode, @NotNull Map>> initializersMap diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index b4376f030f8..e8ba441c271 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -669,13 +669,6 @@ public interface Errors { DiagnosticFactory1 VAL_OR_VAR_ON_CATCH_PARAMETER = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER = DiagnosticFactory1.create(ERROR); - // Backing fields - - DiagnosticFactory0 NO_BACKING_FIELD_ABSTRACT_PROPERTY = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 NO_BACKING_FIELD_CUSTOM_ACCESSORS = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 INACCESSIBLE_BACKING_FIELD = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 NOT_PROPERTY_BACKING_FIELD = DiagnosticFactory0.create(ERROR); - // When expressions DiagnosticFactory0 EXPECTED_CONDITION = DiagnosticFactory0.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index dc5cbe31ac9..6161a172f52 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -164,12 +164,6 @@ public class DefaultErrorMessages { MAP.put(CANNOT_INFER_PARAMETER_TYPE, "Cannot infer a type for this parameter. Please specify it explicitly."); - MAP.put(NO_BACKING_FIELD_ABSTRACT_PROPERTY, "This property doesn't have a backing field, because it's abstract"); - MAP.put(NO_BACKING_FIELD_CUSTOM_ACCESSORS, - "This property doesn't have a backing field, because it has custom accessors without reference to the backing field"); - MAP.put(INACCESSIBLE_BACKING_FIELD, "The backing field is not accessible here"); - MAP.put(NOT_PROPERTY_BACKING_FIELD, "The referenced variable is not a property and doesn't have backing field"); - MAP.put(MIXING_NAMED_AND_POSITIONED_ARGUMENTS, "Mixing named and positioned arguments is not allowed"); MAP.put(ARGUMENT_PASSED_TWICE, "An argument is already passed for this parameter"); MAP.put(NAMED_PARAMETER_NOT_FOUND, "Cannot find a parameter with this name: {0}", ELEMENT_TEXT); diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index 4bc55ecda14..7a3d4941f66 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -123,11 +123,6 @@ public class QuickFixRegistrar : QuickFixContributor { WRONG_MODIFIER_CONTAINING_DECLARATION.registerFactory(removeModifierFactory) REPEATED_MODIFIER.registerFactory(removeModifierFactory) - val changeToPropertyNameFactory = ChangeToPropertyNameFix.createFactory() - NO_BACKING_FIELD_ABSTRACT_PROPERTY.registerFactory(changeToPropertyNameFactory) - NO_BACKING_FIELD_CUSTOM_ACCESSORS.registerFactory(changeToPropertyNameFactory) - INACCESSIBLE_BACKING_FIELD.registerFactory(changeToPropertyNameFactory) - UNRESOLVED_REFERENCE.registerFactory(AutoImportFix) UNRESOLVED_REFERENCE_WRONG_RECEIVER.registerFactory(AutoImportFix)