Remove traces of class object constraints feature from parser, frontend, tests and psi

This commit is contained in:
Pavel V. Talanov
2015-04-01 16:29:21 +03:00
parent 5fe8bb4a92
commit a986d913c3
34 changed files with 35 additions and 731 deletions
@@ -220,7 +220,6 @@ public interface Errors {
// Type parameter declarations
DiagnosticFactory1<JetTypeReference, JetType> FINAL_UPPER_BOUND = DiagnosticFactory1.create(WARNING);
DiagnosticFactory1<JetTypeReference, JetType> FINAL_COMPANION_OBJECT_UPPER_BOUND = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<JetTypeReference> DYNAMIC_UPPER_BOUND = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<JetNamedDeclaration, TypeParameterDescriptor> CONFLICTING_UPPER_BOUNDS =
@@ -356,7 +356,6 @@ public class DefaultErrorMessages {
});
MAP.put(UPPER_BOUND_VIOLATED, "Type argument is not within its bounds: should be subtype of ''{0}''", RENDER_TYPE, RENDER_TYPE);
MAP.put(FINAL_COMPANION_OBJECT_UPPER_BOUND, "''{0}'' is a final type, and thus a companion object cannot extend it", RENDER_TYPE);
MAP.put(FINAL_UPPER_BOUND, "''{0}'' is a final type, and thus a value of the type parameter is predetermined", RENDER_TYPE);
MAP.put(DYNAMIC_UPPER_BOUND, "Dynamic type can not be used as an upper bound");
MAP.put(USELESS_ELVIS, "Elvis operator (?:) always returns the left operand of non-nullable type {0}", RENDER_TYPE);
@@ -1550,7 +1550,6 @@ public class JetParsing extends AbstractJetParsing {
/*
* typeConstraint
* : annotations SimpleName ":" type
* : annotations "class" "object" SimpleName ":" type
* ;
*/
private void parseTypeConstraint() {
@@ -1558,13 +1557,6 @@ public class JetParsing extends AbstractJetParsing {
parseAnnotations(REGULAR_ANNOTATIONS_ONLY_WITH_BRACKETS);
if (at(CLASS_KEYWORD)) {
advance(); // CLASS_KEYWORD
expect(OBJECT_KEYWORD, "Expecting 'object'", TYPE_REF_FIRST);
}
PsiBuilder.Marker reference = mark();
if (expect(IDENTIFIER, "Expecting type parameter name", TokenSet.orSet(TokenSet.create(COLON, COMMA), TYPE_REF_FIRST))) {
reference.done(REFERENCE_EXPRESSION);
@@ -19,16 +19,15 @@ package org.jetbrains.kotlin.psi;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.lexer.JetTokens;
import org.jetbrains.kotlin.psi.stubs.KotlinTypeConstraintStub;
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub;
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes;
public class JetTypeConstraint extends JetElementImplStub<KotlinTypeConstraintStub> {
public class JetTypeConstraint extends JetElementImplStub<KotlinPlaceHolderStub<JetTypeConstraint>> {
public JetTypeConstraint(@NotNull ASTNode node) {
super(node);
}
public JetTypeConstraint(@NotNull KotlinTypeConstraintStub stub) {
public JetTypeConstraint(@NotNull KotlinPlaceHolderStub<JetTypeConstraint> stub) {
super(stub, JetStubElementTypes.TYPE_CONSTRAINT);
}
@@ -37,15 +36,6 @@ public class JetTypeConstraint extends JetElementImplStub<KotlinTypeConstraintSt
return visitor.visitTypeConstraint(this, data);
}
public boolean isCompanionObjectConstraint() {
KotlinTypeConstraintStub stub = getStub();
if (stub != null) {
return stub.isCompanionObjectConstraint();
}
return findChildByType(JetTokens.CLASS_KEYWORD) != null &&
findChildByType(JetTokens.OBJECT_KEYWORD) != null;
}
@Nullable @IfNotParsed
public JetSimpleNameExpression getSubjectTypeParameterName() {
return getStubOrPsiChild(JetStubElementTypes.REFERENCE_EXPRESSION);
@@ -103,10 +103,6 @@ public trait KotlinPropertyStub : KotlinStubWithFqName<JetProperty> {
public fun isProbablyNothingType(): Boolean
}
public trait KotlinTypeConstraintStub : StubElement<JetTypeConstraint> {
public fun isCompanionObjectConstraint(): Boolean
}
public trait KotlinTypeParameterStub : KotlinStubWithFqName<JetTypeParameter> {
public fun isInVariance(): Boolean
public fun isOutVariance(): Boolean
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.psi.stubs.impl.KotlinFileStubImpl;
import java.io.IOException;
public class JetFileElementType extends IStubFileElementType<KotlinFileStub> {
public static final int STUB_VERSION = 41;
public static final int STUB_VERSION = 42;
private static final String NAME = "kotlin.FILE";
@@ -70,7 +70,8 @@ public interface JetStubElementTypes {
JetPlaceHolderStubElementType<JetTypeConstraintList> TYPE_CONSTRAINT_LIST =
new JetPlaceHolderStubElementType<JetTypeConstraintList>("TYPE_CONSTRAINT_LIST", JetTypeConstraintList.class);
JetTypeConstraintElementType TYPE_CONSTRAINT = new JetTypeConstraintElementType("TYPE_CONSTRAINT");
JetPlaceHolderStubElementType<JetTypeConstraint> TYPE_CONSTRAINT =
new JetPlaceHolderStubElementType<JetTypeConstraint>("TYPE_CONSTRAINT", JetTypeConstraint.class);
JetPlaceHolderStubElementType<JetNullableType> NULLABLE_TYPE =
new JetPlaceHolderStubElementType<JetNullableType>("NULLABLE_TYPE", JetNullableType.class);
@@ -1,51 +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.stubs.elements;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubInputStream;
import com.intellij.psi.stubs.StubOutputStream;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.psi.JetTypeConstraint;
import org.jetbrains.kotlin.psi.stubs.KotlinTypeConstraintStub;
import org.jetbrains.kotlin.psi.stubs.impl.KotlinTypeConstraintStubImpl;
import java.io.IOException;
public class JetTypeConstraintElementType extends JetStubElementType<KotlinTypeConstraintStub, JetTypeConstraint> {
public JetTypeConstraintElementType(@NotNull @NonNls String debugName) {
super(debugName, JetTypeConstraint.class, KotlinTypeConstraintStub.class);
}
@Override
public KotlinTypeConstraintStub createStub(@NotNull JetTypeConstraint psi, StubElement parentStub) {
return new KotlinTypeConstraintStubImpl(parentStub, psi.isCompanionObjectConstraint());
}
@Override
public void serialize(@NotNull KotlinTypeConstraintStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeBoolean(stub.isCompanionObjectConstraint());
}
@NotNull
@Override
public KotlinTypeConstraintStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
boolean isCompanionObjectConstraint = dataStream.readBoolean();
return new KotlinTypeConstraintStubImpl(parentStub, isCompanionObjectConstraint);
}
}
@@ -1,31 +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.stubs.impl
import com.intellij.psi.stubs.StubElement
import org.jetbrains.kotlin.psi.JetTypeConstraint
import org.jetbrains.kotlin.psi.stubs.KotlinTypeConstraintStub
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes
import com.intellij.psi.PsiElement
public class KotlinTypeConstraintStubImpl(
parent: StubElement<out PsiElement>?,
private val isCompanionObjectConstraint: Boolean
) : KotlinStubBaseImpl<JetTypeConstraint>(parent, JetStubElementTypes.TYPE_CONSTRAINT), KotlinTypeConstraintStub {
override fun isCompanionObjectConstraint() = isCompanionObjectConstraint
}
@@ -158,12 +158,12 @@ public class DeclarationsChecker {
for (JetTypeParameter jetTypeParameter : jetClass.getTypeParameters()) {
checkBoundsForTypeInClassHeader(jetTypeParameter.getExtendsBound());
checkFinalUpperBounds(jetTypeParameter.getExtendsBound(), false);
checkFinalUpperBounds(jetTypeParameter.getExtendsBound());
}
for (JetTypeConstraint constraint : jetClass.getTypeConstraints()) {
checkBoundsForTypeInClassHeader(constraint.getBoundTypeReference());
checkFinalUpperBounds(constraint.getBoundTypeReference(), constraint.isCompanionObjectConstraint());
checkFinalUpperBounds(constraint.getBoundTypeReference());
}
}
@@ -176,11 +176,11 @@ public class DeclarationsChecker {
}
}
private void checkFinalUpperBounds(@Nullable JetTypeReference typeReference, boolean isCompanionObjectConstraint) {
private void checkFinalUpperBounds(@Nullable JetTypeReference typeReference) {
if (typeReference != null) {
JetType type = trace.getBindingContext().get(TYPE, typeReference);
if (type != null) {
DescriptorResolver.checkUpperBoundType(typeReference, type, isCompanionObjectConstraint, trace);
DescriptorResolver.checkUpperBoundType(typeReference, type, trace);
}
}
}
@@ -456,12 +456,10 @@ public class DescriptorResolver {
static final class UpperBoundCheckerTask {
JetTypeReference upperBound;
JetType upperBoundType;
boolean isCompanionObjectConstraint;
private UpperBoundCheckerTask(JetTypeReference upperBound, JetType upperBoundType, boolean companionObjectConstraint) {
private UpperBoundCheckerTask(JetTypeReference upperBound, JetType upperBoundType) {
this.upperBound = upperBound;
this.upperBoundType = upperBoundType;
isCompanionObjectConstraint = companionObjectConstraint;
}
}
@@ -486,12 +484,10 @@ public class DescriptorResolver {
if (extendsBound != null) {
JetType type = typeResolver.resolveType(scope, extendsBound, trace, false);
typeParameterDescriptor.addUpperBound(type);
deferredUpperBoundCheckerTasks.add(new UpperBoundCheckerTask(extendsBound, type, false));
deferredUpperBoundCheckerTasks.add(new UpperBoundCheckerTask(extendsBound, type));
}
}
for (JetTypeConstraint constraint : declaration.getTypeConstraints()) {
reportUnsupportedCompanionObjectConstraint(trace, constraint);
JetSimpleNameExpression subjectTypeParameterName = constraint.getSubjectTypeParameterName();
if (subjectTypeParameterName == null) {
continue;
@@ -502,19 +498,13 @@ public class DescriptorResolver {
JetType bound = null;
if (boundTypeReference != null) {
bound = typeResolver.resolveType(scope, boundTypeReference, trace, false);
deferredUpperBoundCheckerTasks
.add(new UpperBoundCheckerTask(boundTypeReference, bound, constraint.isCompanionObjectConstraint()));
deferredUpperBoundCheckerTasks.add(new UpperBoundCheckerTask(boundTypeReference, bound));
}
if (typeParameterDescriptor != null) {
trace.record(BindingContext.REFERENCE_TARGET, subjectTypeParameterName, typeParameterDescriptor);
if (bound != null) {
if (constraint.isCompanionObjectConstraint()) {
// Companion object bounds are not supported
}
else {
typeParameterDescriptor.addUpperBound(bound);
}
typeParameterDescriptor.addUpperBound(bound);
}
}
}
@@ -529,7 +519,7 @@ public class DescriptorResolver {
if (!(declaration instanceof JetClass)) {
for (UpperBoundCheckerTask checkerTask : deferredUpperBoundCheckerTasks) {
checkUpperBoundType(checkerTask.upperBound, checkerTask.upperBoundType, checkerTask.isCompanionObjectConstraint, trace);
checkUpperBoundType(checkerTask.upperBound, checkerTask.upperBoundType, trace);
}
checkNamesInConstraints(declaration, descriptor, scope, trace);
@@ -577,25 +567,13 @@ public class DescriptorResolver {
}
}
public static void reportUnsupportedCompanionObjectConstraint(BindingTrace trace, JetTypeConstraint constraint) {
if (constraint.isCompanionObjectConstraint()) {
trace.report(UNSUPPORTED.on(constraint, "Companion objects constraints are not supported yet"));
}
}
public static void checkUpperBoundType(
JetTypeReference upperBound,
@NotNull JetType upperBoundType,
boolean isCompanionObjectConstraint,
BindingTrace trace
) {
if (!TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, upperBoundType)) {
if (isCompanionObjectConstraint) {
trace.report(FINAL_COMPANION_OBJECT_UPPER_BOUND.on(upperBound, upperBoundType));
}
else {
trace.report(FINAL_UPPER_BOUND.on(upperBound, upperBoundType));
}
trace.report(FINAL_UPPER_BOUND.on(upperBound, upperBoundType));
}
if (TypesPackage.isDynamic(upperBoundType)) {
trace.report(DYNAMIC_UPPER_BOUND.on(upperBound));
@@ -83,8 +83,6 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
if (classOrObject instanceof JetClass) {
JetClass jetClass = (JetClass) classOrObject;
for (JetTypeConstraint jetTypeConstraint : jetClass.getTypeConstraints()) {
DescriptorResolver.reportUnsupportedCompanionObjectConstraint(c.getTrace(), jetTypeConstraint);
JetSimpleNameExpression constrainedParameterName = jetTypeConstraint.getSubjectTypeParameterName();
if (constrainedParameterName != null) {
if (getName().equals(constrainedParameterName.getReferencedNameAsName())) {
@@ -93,9 +91,7 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
JetTypeReference boundTypeReference = jetTypeConstraint.getBoundTypeReference();
if (boundTypeReference != null) {
JetType boundType = resolveBoundType(boundTypeReference);
if (!jetTypeConstraint.isCompanionObjectConstraint()) {
upperBounds.add(boundType);
}
upperBounds.add(boundType);
}
}
}