val / var are now forbidden on a loop multi declaration parameter #KT-6274 Fixed

VAL_OR_VAR_ON_LOOP_MULTI_PARAMETER error added
KtValVarKeywordOwner interface added for PSIs that have getValOrVarKeyword method
This commit is contained in:
Anton Sukhonosenko
2015-10-26 01:47:16 +03:00
committed by Mikhail Glukhikh
parent 54cb575819
commit 141ffa27dc
17 changed files with 119 additions and 20 deletions
@@ -667,6 +667,7 @@ public interface Errors {
DiagnosticFactory3<KtExpression, DeclarationDescriptor, Visibility, DeclarationDescriptor> INVISIBLE_SETTER = DiagnosticFactory3.create(ERROR);
DiagnosticFactory1<PsiElement, KtKeywordToken> VAL_OR_VAR_ON_LOOP_PARAMETER = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, KtKeywordToken> VAL_OR_VAR_ON_LOOP_MULTI_PARAMETER = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, KtKeywordToken> VAL_OR_VAR_ON_FUN_PARAMETER = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, KtKeywordToken> VAL_OR_VAR_ON_CATCH_PARAMETER = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, KtKeywordToken> VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER = DiagnosticFactory1.create(ERROR);
@@ -264,6 +264,7 @@ public class DefaultErrorMessages {
MAP.put(VARIABLE_EXPECTED, "Variable expected");
MAP.put(VAL_OR_VAR_ON_LOOP_PARAMETER, "''{0}'' on loop parameter is not allowed", TO_STRING);
MAP.put(VAL_OR_VAR_ON_LOOP_MULTI_PARAMETER, "''{0}'' on loop multi parameter is not allowed", TO_STRING);
MAP.put(VAL_OR_VAR_ON_FUN_PARAMETER, "''{0}'' on function parameter is not allowed", TO_STRING);
MAP.put(VAL_OR_VAR_ON_CATCH_PARAMETER, "''{0}'' on catch parameter is not allowed", TO_STRING);
MAP.put(VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER, "''{0}'' on secondary constructor parameter is not allowed", TO_STRING);
@@ -29,7 +29,7 @@ import java.util.List;
import static org.jetbrains.kotlin.lexer.KtTokens.*;
public class KtMultiDeclaration extends KtDeclarationImpl {
public class KtMultiDeclaration extends KtDeclarationImpl implements KtValVarKeywordOwner {
public KtMultiDeclaration(@NotNull ASTNode node) {
super(node);
}
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.psi.typeRefHelpers.TypeRefHelpersKt;
import java.util.Collections;
import java.util.List;
public class KtParameter extends KtNamedDeclarationStub<KotlinParameterStub> implements KtCallableDeclaration {
public class KtParameter extends KtNamedDeclarationStub<KotlinParameterStub> implements KtCallableDeclaration, KtValVarKeywordOwner {
public KtParameter(@NotNull ASTNode node) {
super(node);
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.psi;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.Nullable;
public interface KtValVarKeywordOwner extends PsiElement {
@Nullable
PsiElement getValOrVarKeyword();
}
@@ -16,12 +16,6 @@
package org.jetbrains.kotlin.psi;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.Nullable;
public interface KtVariableDeclaration extends KtCallableDeclaration, KtWithExpressionInitializer {
public interface KtVariableDeclaration extends KtCallableDeclaration, KtWithExpressionInitializer, KtValVarKeywordOwner {
boolean isVar();
@Nullable
PsiElement getValOrVarKeyword();
}
@@ -163,7 +163,7 @@ public class ModifiersChecker {
}
public void checkParameterHasNoValOrVar(
@NotNull KtParameter parameter,
@NotNull KtValVarKeywordOwner parameter,
@NotNull DiagnosticFactory1<PsiElement, KtKeywordToken> diagnosticFactory
) {
PsiElement valOrVar = parameter.getValOrVarKeyword();
@@ -407,6 +407,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
loopScope, multiParameter, iteratorNextAsReceiver, loopRange, context
);
components.modifiersChecker.withTrace(context.trace).checkModifiersForMultiDeclaration(multiParameter);
components.modifiersChecker.withTrace(context.trace).checkParameterHasNoValOrVar(multiParameter, VAL_OR_VAR_ON_LOOP_MULTI_PARAMETER);
components.identifierChecker.checkDeclaration(multiParameter, context.trace);
}
}