Drop parsing of enum initializers using `this'
#KT-6626 Fixed
This commit is contained in:
@@ -76,8 +76,6 @@ public interface JetNodeTypes {
|
||||
// TODO: review
|
||||
IElementType PROPERTY_ACCESSOR = JetStubElementTypes.PROPERTY_ACCESSOR;
|
||||
IElementType INITIALIZER_LIST = JetStubElementTypes.INITIALIZER_LIST;
|
||||
IElementType THIS_CALL = JetStubElementTypes.THIS_CALL;
|
||||
JetNodeType THIS_CONSTRUCTOR_REFERENCE = new JetNodeType("THIS_CONSTRUCTOR_REFERENCE", JetThisReferenceExpression.class);
|
||||
IElementType TYPE_CONSTRAINT_LIST = JetStubElementTypes.TYPE_CONSTRAINT_LIST;
|
||||
IElementType TYPE_CONSTRAINT = JetStubElementTypes.TYPE_CONSTRAINT;
|
||||
|
||||
|
||||
@@ -859,7 +859,6 @@ public class JetParsing extends AbstractJetParsing {
|
||||
|
||||
/*
|
||||
* initializer
|
||||
* : annotations "this" valueArguments
|
||||
* : annotations constructorInvocation // type parameters may (must?) be omitted
|
||||
* ;
|
||||
*/
|
||||
@@ -868,20 +867,14 @@ public class JetParsing extends AbstractJetParsing {
|
||||
parseAnnotations(REGULAR_ANNOTATIONS_ONLY_WITH_BRACKETS);
|
||||
|
||||
IElementType type;
|
||||
if (at(THIS_KEYWORD)) {
|
||||
PsiBuilder.Marker mark = mark();
|
||||
advance(); // THIS_KEYWORD
|
||||
mark.done(THIS_CONSTRUCTOR_REFERENCE);
|
||||
type = THIS_CALL;
|
||||
}
|
||||
else if (atSet(TYPE_REF_FIRST)) {
|
||||
if (atSet(TYPE_REF_FIRST)) {
|
||||
PsiBuilder.Marker reference = mark();
|
||||
parseTypeRef();
|
||||
reference.done(CONSTRUCTOR_CALLEE);
|
||||
type = DELEGATOR_SUPER_CALL;
|
||||
}
|
||||
else {
|
||||
errorWithRecovery("Expecting constructor call (this(...)) or supertype initializer",
|
||||
errorWithRecovery("Expecting constructor call (<class-name>(...))",
|
||||
TokenSet.orSet(TOPLEVEL_OBJECT_FIRST, TokenSet.create(RBRACE, LBRACE, COMMA, SEMICOLON)));
|
||||
initializer.drop();
|
||||
return;
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* 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.lang.ASTNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.JetNodeTypes;
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub;
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class JetDelegatorToThisCall extends JetDelegationSpecifier implements JetCallElement {
|
||||
|
||||
public JetDelegatorToThisCall(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
public JetDelegatorToThisCall(@NotNull KotlinPlaceHolderStub<? extends JetDelegationSpecifier> stub) {
|
||||
super(stub, JetStubElementTypes.THIS_CALL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitDelegationToThisCall(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetExpression getCalleeExpression() {
|
||||
return getThisReference();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JetValueArgumentList getValueArgumentList() {
|
||||
return (JetValueArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<? extends ValueArgument> getValueArguments() {
|
||||
JetValueArgumentList list = getValueArgumentList();
|
||||
return list != null ? list.getArguments() : Collections.<JetValueArgument>emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetTypeProjection> getTypeArguments() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetTypeArgumentList getTypeArgumentList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public JetReferenceExpression getThisReference() {
|
||||
return findChildByClass(JetThisReferenceExpression.class);
|
||||
}
|
||||
}
|
||||
@@ -134,10 +134,6 @@ public class JetVisitor<R, D> extends PsiElementVisitor {
|
||||
return visitDelegationSpecifier(specifier, data);
|
||||
}
|
||||
|
||||
public R visitDelegationToThisCall(@NotNull JetDelegatorToThisCall thisCall, D data) {
|
||||
return visitDelegationSpecifier(thisCall, data);
|
||||
}
|
||||
|
||||
public R visitPropertyDelegate(@NotNull JetPropertyDelegate delegate, D data) {
|
||||
return visitJetElement(delegate, data);
|
||||
}
|
||||
|
||||
@@ -129,10 +129,6 @@ public class JetVisitorVoid extends JetVisitor<Void, Void> {
|
||||
super.visitDelegationToSuperClassSpecifier(specifier, null);
|
||||
}
|
||||
|
||||
public void visitDelegationToThisCall(@NotNull JetDelegatorToThisCall thisCall) {
|
||||
super.visitDelegationToThisCall(thisCall, null);
|
||||
}
|
||||
|
||||
public void visitPropertyDelegate(@NotNull JetPropertyDelegate delegate) {
|
||||
super.visitPropertyDelegate(delegate, null);
|
||||
}
|
||||
@@ -580,12 +576,6 @@ public class JetVisitorVoid extends JetVisitor<Void, Void> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Void visitDelegationToThisCall(@NotNull JetDelegatorToThisCall thisCall, Void data) {
|
||||
visitDelegationToThisCall(thisCall);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Void visitPropertyDelegate(@NotNull JetPropertyDelegate delegate, Void data) {
|
||||
visitPropertyDelegate(delegate);
|
||||
|
||||
@@ -130,10 +130,6 @@ public class JetVisitorVoidWithParameter<P> extends JetVisitor<Void, P> {
|
||||
super.visitDelegationToSuperClassSpecifier(specifier, data);
|
||||
}
|
||||
|
||||
public void visitDelegationToThisCallVoid(@NotNull JetDelegatorToThisCall thisCall, P data) {
|
||||
super.visitDelegationToThisCall(thisCall, data);
|
||||
}
|
||||
|
||||
public void visitPropertyDelegateVoid(@NotNull JetPropertyDelegate delegate, P data) {
|
||||
super.visitPropertyDelegate(delegate, data);
|
||||
}
|
||||
@@ -577,12 +573,6 @@ public class JetVisitorVoidWithParameter<P> extends JetVisitor<Void, P> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Void visitDelegationToThisCall(@NotNull JetDelegatorToThisCall thisCall, P data) {
|
||||
visitDelegationToThisCallVoid(thisCall, data);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Void visitPropertyDelegate(@NotNull JetPropertyDelegate delegate, P data) {
|
||||
visitPropertyDelegateVoid(delegate, data);
|
||||
|
||||
+1
-3
@@ -107,15 +107,13 @@ public interface JetStubElementTypes {
|
||||
new JetPlaceHolderStubElementType<JetDelegatorToSuperCall>("DELEGATOR_SUPER_CALL", JetDelegatorToSuperCall.class);
|
||||
JetPlaceHolderStubElementType<JetDelegatorToSuperClass> DELEGATOR_SUPER_CLASS =
|
||||
new JetPlaceHolderStubElementType<JetDelegatorToSuperClass>("DELEGATOR_SUPER_CLASS", JetDelegatorToSuperClass.class);
|
||||
JetPlaceHolderStubElementType<JetDelegatorToThisCall> THIS_CALL =
|
||||
new JetPlaceHolderStubElementType<JetDelegatorToThisCall>("THIS_CALL", JetDelegatorToThisCall.class);
|
||||
JetPlaceHolderStubElementType<JetConstructorCalleeExpression> CONSTRUCTOR_CALLEE =
|
||||
new JetPlaceHolderStubElementType<JetConstructorCalleeExpression>("CONSTRUCTOR_CALLEE", JetConstructorCalleeExpression.class);
|
||||
|
||||
TokenSet DECLARATION_TYPES =
|
||||
TokenSet.create(CLASS, OBJECT_DECLARATION, FUNCTION, PROPERTY, ANONYMOUS_INITIALIZER, ENUM_ENTRY);
|
||||
|
||||
TokenSet DELEGATION_SPECIFIER_TYPES = TokenSet.create(DELEGATOR_BY, DELEGATOR_SUPER_CALL, DELEGATOR_SUPER_CLASS, THIS_CALL);
|
||||
TokenSet DELEGATION_SPECIFIER_TYPES = TokenSet.create(DELEGATOR_BY, DELEGATOR_SUPER_CALL, DELEGATOR_SUPER_CLASS);
|
||||
|
||||
TokenSet TYPE_ELEMENT_TYPES = TokenSet.create(USER_TYPE, NULLABLE_TYPE, FUNCTION_TYPE, DYNAMIC_TYPE, SELF_TYPE);
|
||||
|
||||
|
||||
@@ -231,11 +231,6 @@ public class BodyResolver {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDelegationToThisCall(@NotNull JetDelegatorToThisCall thisCall) {
|
||||
throw new IllegalStateException("This-calls should be prohibited by the parser");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitJetElement(@NotNull JetElement element) {
|
||||
throw new UnsupportedOperationException(element.getText() + " : " + element);
|
||||
|
||||
@@ -18,7 +18,7 @@ JetFile: EnumEntryInitList.kt
|
||||
PsiElement(COLON)(':')
|
||||
PsiWhiteSpace('\n')
|
||||
INITIALIZER_LIST
|
||||
PsiErrorElement:Expecting constructor call (this(...)) or supertype initializer
|
||||
PsiErrorElement:Expecting constructor call (<class-name>(...))
|
||||
<empty list>
|
||||
PsiElement(RBRACE)('}')
|
||||
PsiWhiteSpace('\n\n')
|
||||
@@ -39,7 +39,7 @@ JetFile: EnumEntryInitList.kt
|
||||
PsiElement(COLON)(':')
|
||||
PsiWhiteSpace('\n\n ')
|
||||
INITIALIZER_LIST
|
||||
PsiErrorElement:Expecting constructor call (this(...)) or supertype initializer
|
||||
PsiErrorElement:Expecting constructor call (<class-name>(...))
|
||||
<empty list>
|
||||
FUN
|
||||
PsiElement(fun)('fun')
|
||||
@@ -72,7 +72,7 @@ JetFile: EnumEntryInitList.kt
|
||||
PsiElement(COLON)(':')
|
||||
PsiWhiteSpace('\n\n ')
|
||||
INITIALIZER_LIST
|
||||
PsiErrorElement:Expecting constructor call (this(...)) or supertype initializer
|
||||
PsiErrorElement:Expecting constructor call (<class-name>(...))
|
||||
<empty list>
|
||||
PROPERTY
|
||||
PsiElement(val)('val')
|
||||
@@ -103,7 +103,7 @@ JetFile: EnumEntryInitList.kt
|
||||
PsiElement(COLON)(':')
|
||||
PsiWhiteSpace('\n\n ')
|
||||
INITIALIZER_LIST
|
||||
PsiErrorElement:Expecting constructor call (this(...)) or supertype initializer
|
||||
PsiErrorElement:Expecting constructor call (<class-name>(...))
|
||||
<empty list>
|
||||
CLASS
|
||||
PsiElement(class)('class')
|
||||
@@ -139,7 +139,7 @@ JetFile: EnumEntryInitList.kt
|
||||
PsiElement(LPAR)('(')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiElement(COMMA)(',')
|
||||
PsiErrorElement:Expecting constructor call (this(...)) or supertype initializer
|
||||
PsiErrorElement:Expecting constructor call (<class-name>(...))
|
||||
<empty list>
|
||||
PsiWhiteSpace('\n\n ')
|
||||
CLASS
|
||||
@@ -176,7 +176,7 @@ JetFile: EnumEntryInitList.kt
|
||||
PsiElement(LPAR)('(')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiElement(COMMA)(',')
|
||||
PsiErrorElement:Expecting constructor call (this(...)) or supertype initializer
|
||||
PsiErrorElement:Expecting constructor call (<class-name>(...))
|
||||
<empty list>
|
||||
PsiElement(SEMICOLON)(';')
|
||||
PsiWhiteSpace('\n\n ')
|
||||
|
||||
@@ -53,7 +53,6 @@ functionParameter
|
||||
;
|
||||
|
||||
initializer
|
||||
: annotations "this" valueArguments
|
||||
: annotations constructorInvocation // type parameters may (must?) be omitted
|
||||
;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user