Refactor: process mentions of class object

Rename usages that refer to "default object" concept now
Test data file names are left as is
This commit is contained in:
Pavel V. Talanov
2015-03-03 17:28:24 +03:00
parent 27f5d71e4f
commit 48fbce9582
137 changed files with 471 additions and 479 deletions
@@ -1379,7 +1379,7 @@ public class JetControlFlowProcessor {
@Override
public void visitTypeProjection(@NotNull JetTypeProjection typeProjection) {
// TODO : Support Type Arguments. Class object may be initialized at this point");
// TODO : Support Type Arguments. Default object may be initialized at this point");
}
@Override
@@ -44,7 +44,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
private List<TypeParameterDescriptor> typeParameters;
private Collection<JetType> supertypes = new ArrayList<JetType>();
private MutableClassDescriptor classObjectDescriptor;
private MutableClassDescriptor defaultObjectDescriptor;
private final Set<ConstructorDescriptor> constructors = Sets.newLinkedHashSet();
private ConstructorDescriptor primaryConstructor;
@@ -93,7 +93,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
@Nullable
@Override
public MutableClassDescriptor getDefaultObjectDescriptor() {
return classObjectDescriptor;
return defaultObjectDescriptor;
}
@NotNull
@@ -306,8 +306,8 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
public void lockScopes() {
getScopeForMemberLookupAsWritableScope().changeLockLevel(WritableScope.LockLevel.READING);
if (classObjectDescriptor != null) {
classObjectDescriptor.lockScopes();
if (defaultObjectDescriptor != null) {
defaultObjectDescriptor.lockScopes();
}
scopeForSupertypeResolution.changeLockLevel(WritableScope.LockLevel.READING);
scopeForMemberResolution.changeLockLevel(WritableScope.LockLevel.READING);
@@ -186,10 +186,10 @@ public interface Errors {
DiagnosticFactory1<JetTypeReference, ClassDescriptor> ENUM_ENTRY_ILLEGAL_TYPE = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<JetClass, ClassDescriptor> LOCAL_ENUM_NOT_ALLOWED = DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
// Class objects
// Default objects
DiagnosticFactory0<JetObjectDeclaration> MANY_CLASS_OBJECTS = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetObjectDeclaration> CLASS_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetObjectDeclaration> MANY_DEFAULT_OBJECTS = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetObjectDeclaration> DEFAULT_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR);
// Objects
@@ -198,12 +198,12 @@ public interface Errors {
// Type parameter declarations
DiagnosticFactory1<JetTypeReference, JetType> FINAL_UPPER_BOUND = DiagnosticFactory1.create(WARNING);
DiagnosticFactory1<JetTypeReference, JetType> FINAL_CLASS_OBJECT_UPPER_BOUND = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<JetTypeReference, JetType> FINAL_DEFAULT_OBJECT_UPPER_BOUND = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<JetTypeReference> DYNAMIC_UPPER_BOUND = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<JetNamedDeclaration, TypeParameterDescriptor> CONFLICTING_UPPER_BOUNDS =
DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
DiagnosticFactory1<JetNamedDeclaration, TypeParameterDescriptor> CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS
DiagnosticFactory1<JetNamedDeclaration, TypeParameterDescriptor> CONFLICTING_DEFAULT_OBJECT_UPPER_BOUNDS
= DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
DiagnosticFactory2<JetSimpleNameExpression, JetTypeConstraint, JetTypeParameterListOwner> NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER =
@@ -605,7 +605,7 @@ public interface Errors {
DiagnosticFactory0<JetThisExpression> NO_THIS = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetRootPackageExpression> PACKAGE_IS_NOT_AN_EXPRESSION = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<JetSimpleNameExpression, ClassifierDescriptor> NO_CLASS_OBJECT = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<JetSimpleNameExpression, ClassifierDescriptor> NO_DEFAULT_OBJECT = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<JetSimpleNameExpression, TypeParameterDescriptor> TYPE_PARAMETER_IS_NOT_AN_EXPRESSION = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<JetSimpleNameExpression, TypeParameterDescriptor> TYPE_PARAMETER_ON_LHS_OF_DOT = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<JetExpression, ClassDescriptor> NESTED_CLASS_ACCESSED_VIA_INSTANCE_REFERENCE = DiagnosticFactory1.create(ERROR);
@@ -270,8 +270,8 @@ public class DefaultErrorMessages {
MAP.put(UNREACHABLE_CODE, "Unreachable code", TO_STRING);
MAP.put(MANY_CLASS_OBJECTS, "Only one class object is allowed per class");
MAP.put(CLASS_OBJECT_NOT_ALLOWED, "A class object is not allowed here");
MAP.put(MANY_DEFAULT_OBJECTS, "Only one default object is allowed per class");
MAP.put(DEFAULT_OBJECT_NOT_ALLOWED, "A default object is not allowed here");
MAP.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", NAME);
MAP.put(LOCAL_ENUM_NOT_ALLOWED, "Enum class ''{0}'' cannot be local", NAME);
MAP.put(DELEGATION_IN_TRAIT, "Traits cannot use delegation");
@@ -315,9 +315,9 @@ public class DefaultErrorMessages {
MAP.put(USELESS_NULLABLE_CHECK, "Non-null type is checked for instance of nullable type");
MAP.put(WRONG_SETTER_PARAMETER_TYPE, "Setter parameter type must be equal to the type of the property, i.e. ''{0}''", RENDER_TYPE, RENDER_TYPE);
MAP.put(WRONG_GETTER_RETURN_TYPE, "Getter return type must be equal to the type of the property, i.e. ''{0}''", RENDER_TYPE, RENDER_TYPE);
MAP.put(NO_CLASS_OBJECT, "Please specify constructor invocation; classifier ''{0}'' does not have a class object", NAME);
MAP.put(NO_DEFAULT_OBJECT, "Please specify constructor invocation; classifier ''{0}'' does not have a default object", NAME);
MAP.put(TYPE_PARAMETER_IS_NOT_AN_EXPRESSION, "Type parameter ''{0}'' is not an expression", NAME);
MAP.put(TYPE_PARAMETER_ON_LHS_OF_DOT, "Type parameter ''{0}'' cannot have or inherit a class object, so it cannot be on the left hand side of dot", NAME);
MAP.put(TYPE_PARAMETER_ON_LHS_OF_DOT, "Type parameter ''{0}'' cannot have or inherit a default object, so it cannot be on the left hand side of dot", NAME);
MAP.put(NO_GENERICS_IN_SUPERTYPE_SPECIFIER, "Generic arguments of the base type must be specified");
MAP.put(NESTED_CLASS_ACCESSED_VIA_INSTANCE_REFERENCE, "Nested {0} accessed via instance reference", RENDER_CLASS_OR_OBJECT_NAME);
MAP.put(NESTED_CLASS_SHOULD_BE_QUALIFIED, "Nested {0} should be qualified as ''{1}''", RENDER_CLASS_OR_OBJECT_NAME, TO_STRING);
@@ -375,12 +375,12 @@ 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_CLASS_OBJECT_UPPER_BOUND, "''{0}'' is a final type, and thus a class object cannot extend it", RENDER_TYPE);
MAP.put(FINAL_DEFAULT_OBJECT_UPPER_BOUND, "''{0}'' is a final type, and thus a default 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);
MAP.put(CONFLICTING_UPPER_BOUNDS, "Upper bounds of {0} have empty intersection", NAME);
MAP.put(CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS, "Class object upper bounds of {0} have empty intersection", NAME);
MAP.put(CONFLICTING_DEFAULT_OBJECT_UPPER_BOUNDS, "Default object upper bounds of {0} have empty intersection", NAME);
MAP.put(TOO_MANY_ARGUMENTS, "Too many arguments for {0}", FQ_NAMES_IN_TYPES);
@@ -765,7 +765,7 @@ public class JetParsing extends AbstractJetParsing {
* ;
*
* memberDeclaration'
* : classObject
* : defaultObject
* : constructor
* : function
* : property
@@ -798,7 +798,7 @@ public class JetParsing extends AbstractJetParsing {
IElementType declType = null;
if (keywordToken == CLASS_KEYWORD) {
if (lookahead(1) == OBJECT_KEYWORD) {
declType = parseClassObject();
declType = parseDefaultObject();
}
else {
declType = parseClass(isEnum);
@@ -876,11 +876,11 @@ public class JetParsing extends AbstractJetParsing {
}
/*
* classObject
* defaultObject
* : modifiers "class" object
* ;
*/
private IElementType parseClassObject() {
private IElementType parseDefaultObject() {
assert _at(CLASS_KEYWORD) && lookahead(1) == OBJECT_KEYWORD;
advance(); // CLASS_KEYWORD
parseObject(NameParsingMode.ALLOWED, true);
@@ -237,7 +237,7 @@ private object DebugTextBuildingVisitor : JetVisitor<String, Unit>() {
return buildText {
append("STUB: ")
appendInn(declaration.getModifierList(), suffix = " ")
if (declaration.isClassObject()) {
if (declaration.isDefault()) {
append("class ")
}
append("object ")
@@ -273,7 +273,7 @@ private object DebugTextBuildingVisitor : JetVisitor<String, Unit>() {
override fun visitTypeConstraint(constraint: JetTypeConstraint, data: Unit?): String? {
return buildText {
if (constraint.isClassObjectConstraint()) {
if (constraint.isDefaultObjectConstraint()) {
append("class object ")
}
appendInn(constraint.getSubjectTypeParameterName())
@@ -142,10 +142,10 @@ public class JetClass extends JetTypeParameterListOwnerStub<KotlinClassStub> imp
}
@Nullable
public JetObjectDeclaration getClassObject() {
public JetObjectDeclaration getDefaultObject() {
JetClassBody body = getBody();
if (body == null) return null;
return body.getClassObject();
return body.getDefaultObject();
}
public List<JetProperty> getProperties() {
@@ -67,15 +67,15 @@ public class JetClassBody extends JetElementImplStub<KotlinPlaceHolderStub<JetCl
}
@Nullable
public JetObjectDeclaration getClassObject() {
return firstOrNull(getAllClassObjects());
public JetObjectDeclaration getDefaultObject() {
return firstOrNull(getAllDefaultObjects());
}
@NotNull
public List<JetObjectDeclaration> getAllClassObjects() {
public List<JetObjectDeclaration> getAllDefaultObjects() {
List<JetObjectDeclaration> result = Lists.newArrayList();
for (JetObjectDeclaration declaration : getStubOrPsiChildrenAsList(JetStubElementTypes.OBJECT_DECLARATION)) {
if (declaration.isClassObject()) {
if (declaration.isDefault()) {
result.add(declaration);
}
}
@@ -95,10 +95,10 @@ abstract class JetNamedDeclarationStub<T extends KotlinStubWithFqName> extends J
if (hasModifier(JetTokens.PRIVATE_KEYWORD)) {
JetElement containingClass = PsiTreeUtil.getParentOfType(this, JetClassOrObject.class);
if (containingClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) containingClass).isClassObject()) {
JetElement classObjectClass = PsiTreeUtil.getParentOfType(containingClass, JetClassOrObject.class);
if (classObjectClass != null) {
containingClass = classObjectClass;
if (containingClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) containingClass).isDefault()) {
JetElement defaultObjectClass = PsiTreeUtil.getParentOfType(containingClass, JetClassOrObject.class);
if (defaultObjectClass != null) {
containingClass = defaultObjectClass;
}
}
if (containingClass != null) {
@@ -51,7 +51,7 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<KotlinObjectSt
}
JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration();
if (nameAsDeclaration == null && isClassObject()) {
if (nameAsDeclaration == null && isDefault()) {
//NOTE: a hack in PSI that simplifies writing frontend code
return SpecialNames.DEFAULT_NAME_FOR_DEFAULT_OBJECT.toString();
}
@@ -86,10 +86,10 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<KotlinObjectSt
return (JetObjectDeclarationName) findChildByType(JetNodeTypes.OBJECT_DECLARATION_NAME);
}
public boolean isClassObject() {
public boolean isDefault() {
KotlinObjectStub stub = getStub();
if (stub != null) {
return stub.isClassObject();
return stub.isDefault();
}
return getClassKeyword() != null;
}
@@ -37,10 +37,10 @@ public class JetTypeConstraint extends JetElementImplStub<KotlinTypeConstraintSt
return visitor.visitTypeConstraint(this, data);
}
public boolean isClassObjectConstraint() {
public boolean isDefaultObjectConstraint() {
KotlinTypeConstraintStub stub = getStub();
if (stub != null) {
return stub.isClassObjectConstraint();
return stub.isDefaultObjectConstraint();
}
return findChildByType(JetTokens.CLASS_KEYWORD) != null &&
findChildByType(JetTokens.OBJECT_KEYWORD) != null;
@@ -47,7 +47,7 @@ public trait KotlinClassStub : KotlinClassOrObjectStub<JetClass> {
}
public trait KotlinObjectStub : KotlinClassOrObjectStub<JetObjectDeclaration> {
public fun isClassObject(): Boolean
public fun isDefault(): Boolean
public fun isObjectLiteral(): Boolean
}
@@ -104,7 +104,7 @@ public trait KotlinPropertyStub : KotlinStubWithFqName<JetProperty> {
}
public trait KotlinTypeConstraintStub : StubElement<JetTypeConstraint> {
public fun isClassObjectConstraint(): Boolean
public fun isDefaultObjectConstraint(): Boolean
}
public trait KotlinTypeParameterStub : KotlinStubWithFqName<JetTypeParameter> {
@@ -45,7 +45,7 @@ public class JetObjectElementType extends JetStubElementType<KotlinObjectStub, J
FqName fqName = ResolveSessionUtils.safeFqNameForLazyResolve(psi);
List<String> superNames = PsiUtilPackage.getSuperNames(psi);
return new KotlinObjectStubImpl(parentStub, StringRef.fromString(name), fqName, Utils.INSTANCE$.wrapStrings(superNames),
psi.isTopLevel(), psi.isClassObject(), psi.isLocal(), psi.isObjectLiteral());
psi.isTopLevel(), psi.isDefault(), psi.isLocal(), psi.isObjectLiteral());
}
@Override
@@ -56,7 +56,7 @@ public class JetObjectElementType extends JetStubElementType<KotlinObjectStub, J
dataStream.writeName(fqName != null ? fqName.toString() : null);
dataStream.writeBoolean(stub.isTopLevel());
dataStream.writeBoolean(stub.isClassObject());
dataStream.writeBoolean(stub.isDefault());
dataStream.writeBoolean(stub.isLocal());
dataStream.writeBoolean(stub.isObjectLiteral());
@@ -75,7 +75,7 @@ public class JetObjectElementType extends JetStubElementType<KotlinObjectStub, J
FqName fqName = fqNameStr != null ? new FqName(fqNameStr.toString()) : null;
boolean isTopLevel = dataStream.readBoolean();
boolean isClassObject = dataStream.readBoolean();
boolean isDefault = dataStream.readBoolean();
boolean isLocal = dataStream.readBoolean();
boolean isObjectLiteral = dataStream.readBoolean();
@@ -85,7 +85,7 @@ public class JetObjectElementType extends JetStubElementType<KotlinObjectStub, J
superNames[i] = dataStream.readName();
}
return new KotlinObjectStubImpl(parentStub, name, fqName, superNames, isTopLevel, isClassObject, isLocal, isObjectLiteral);
return new KotlinObjectStubImpl(parentStub, name, fqName, superNames, isTopLevel, isDefault, isLocal, isObjectLiteral);
}
@Override
@@ -34,18 +34,18 @@ public class JetTypeConstraintElementType extends JetStubElementType<KotlinTypeC
@Override
public KotlinTypeConstraintStub createStub(@NotNull JetTypeConstraint psi, StubElement parentStub) {
return new KotlinTypeConstraintStubImpl(parentStub, psi.isClassObjectConstraint());
return new KotlinTypeConstraintStubImpl(parentStub, psi.isDefaultObjectConstraint());
}
@Override
public void serialize(@NotNull KotlinTypeConstraintStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeBoolean(stub.isClassObjectConstraint());
dataStream.writeBoolean(stub.isDefaultObjectConstraint());
}
@NotNull
@Override
public KotlinTypeConstraintStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
boolean isClassObjectConstraint = dataStream.readBoolean();
return new KotlinTypeConstraintStubImpl(parentStub, isClassObjectConstraint);
boolean isDefaultObjectConstraint = dataStream.readBoolean();
return new KotlinTypeConstraintStubImpl(parentStub, isDefaultObjectConstraint);
}
}
@@ -31,7 +31,7 @@ public class KotlinObjectStubImpl(
private val fqName: FqName?,
private val superNames: Array<StringRef>,
private val isTopLevel: Boolean,
private val isClassObject: Boolean,
private val isDefault: Boolean,
private val isLocal: Boolean,
private val isObjectLiteral: Boolean
) : KotlinStubBaseImpl<JetObjectDeclaration>(parent, JetStubElementTypes.OBJECT_DECLARATION), KotlinObjectStub {
@@ -39,7 +39,7 @@ public class KotlinObjectStubImpl(
override fun getName() = StringRef.toString(name)
override fun getSuperNames() = superNames map { it.toString() }
override fun isTopLevel() = isTopLevel
override fun isClassObject() = isClassObject
override fun isDefault() = isDefault
override fun isObjectLiteral() = isObjectLiteral
override fun isLocal() = isLocal
}
@@ -24,8 +24,8 @@ import com.intellij.psi.PsiElement
public class KotlinTypeConstraintStubImpl(
parent: StubElement<out PsiElement>?,
private val isClassObjectConstraint: Boolean
private val isDefaultObjectConstraint: Boolean
) : KotlinStubBaseImpl<JetTypeConstraint>(parent, JetStubElementTypes.TYPE_CONSTRAINT), KotlinTypeConstraintStub {
override fun isClassObjectConstraint() = isClassObjectConstraint
override fun isDefaultObjectConstraint() = isDefaultObjectConstraint
}
@@ -38,7 +38,7 @@ public fun DeclarationDescriptor.hasIntrinsicAnnotation(): Boolean {
public fun CallableDescriptor.isPlatformStaticInObjectOrClass(): Boolean =
isPlatformStaticIn(ClassKind.OBJECT, ClassKind.CLASS)
public fun CallableDescriptor.isPlatformStaticInClassObject(): Boolean =
public fun CallableDescriptor.isPlatformStaticInDefaultObject(): Boolean =
isPlatformStaticIn(ClassKind.CLASS_OBJECT)
private fun CallableDescriptor.isPlatformStaticIn(vararg kinds: ClassKind): Boolean =
@@ -61,16 +61,16 @@ public class DeclarationResolver {
public fun checkRedeclarationsInInnerClassNames(c: TopDownAnalysisContext) {
for (classDescriptor in c.getDeclaredClasses().values()) {
if (classDescriptor.getKind() == ClassKind.CLASS_OBJECT) {
// Class objects should be considered during analysing redeclarations in classes
// Default objects should be considered during analysing redeclarations in classes
continue
}
var allDescriptors = classDescriptor.getScopeForMemberLookup().getOwnDeclaredDescriptors()
val classObj = classDescriptor.getDefaultObjectDescriptor()
if (classObj != null) {
val classObjDescriptors = classObj.getScopeForMemberLookup().getOwnDeclaredDescriptors()
if (classObjDescriptors.isNotEmpty()) {
allDescriptors = allDescriptors + classObjDescriptors
val defaultObject = classDescriptor.getDefaultObjectDescriptor()
if (defaultObject != null) {
val descriptorsFromDefaultObject = defaultObject.getScopeForMemberLookup().getOwnDeclaredDescriptors()
if (descriptorsFromDefaultObject.isNotEmpty()) {
allDescriptors = allDescriptors + descriptorsFromDefaultObject
}
}
@@ -154,7 +154,7 @@ public class DeclarationsChecker {
for (JetTypeConstraint constraint : jetClass.getTypeConstraints()) {
checkBoundsForTypeInClassHeader(constraint.getBoundTypeReference());
checkFinalUpperBounds(constraint.getBoundTypeReference(), constraint.isClassObjectConstraint());
checkFinalUpperBounds(constraint.getBoundTypeReference(), constraint.isDefaultObjectConstraint());
}
}
@@ -167,11 +167,11 @@ public class DeclarationsChecker {
}
}
private void checkFinalUpperBounds(@Nullable JetTypeReference typeReference, boolean isClassObjectConstraint) {
private void checkFinalUpperBounds(@Nullable JetTypeReference typeReference, boolean isDefaultObjectConstraint) {
if (typeReference != null) {
JetType type = trace.getBindingContext().get(TYPE, typeReference);
if (type != null) {
DescriptorResolver.checkUpperBoundType(typeReference, type, isClassObjectConstraint, trace);
DescriptorResolver.checkUpperBoundType(typeReference, type, isDefaultObjectConstraint, trace);
}
}
}
@@ -260,7 +260,7 @@ public class DeclarationsChecker {
private void checkObject(JetObjectDeclaration declaration, ClassDescriptor classDescriptor) {
reportErrorIfHasIllegalModifier(declaration);
if (declaration.isLocal() && !declaration.isClassObject() && !declaration.isObjectLiteral()) {
if (declaration.isLocal() && !declaration.isDefault() && !declaration.isObjectLiteral()) {
trace.report(LOCAL_OBJECT_NOT_ALLOWED.on(declaration, classDescriptor));
}
}
@@ -651,12 +651,12 @@ public class DescriptorResolver {
static final class UpperBoundCheckerTask {
JetTypeReference upperBound;
JetType upperBoundType;
boolean isClassObjectConstraint;
boolean isDefaultObjectConstraint;
private UpperBoundCheckerTask(JetTypeReference upperBound, JetType upperBoundType, boolean classObjectConstraint) {
private UpperBoundCheckerTask(JetTypeReference upperBound, JetType upperBoundType, boolean defaultObjectConstraint) {
this.upperBound = upperBound;
this.upperBoundType = upperBoundType;
isClassObjectConstraint = classObjectConstraint;
isDefaultObjectConstraint = defaultObjectConstraint;
}
}
@@ -685,7 +685,7 @@ public class DescriptorResolver {
}
}
for (JetTypeConstraint constraint : declaration.getTypeConstraints()) {
reportUnsupportedClassObjectConstraint(trace, constraint);
reportUnsupportedDefaultObjectConstraint(trace, constraint);
JetSimpleNameExpression subjectTypeParameterName = constraint.getSubjectTypeParameterName();
if (subjectTypeParameterName == null) {
@@ -698,15 +698,14 @@ public class DescriptorResolver {
if (boundTypeReference != null) {
bound = typeResolver.resolveType(scope, boundTypeReference, trace, false);
deferredUpperBoundCheckerTasks
.add(new UpperBoundCheckerTask(boundTypeReference, bound, constraint.isClassObjectConstraint()));
.add(new UpperBoundCheckerTask(boundTypeReference, bound, constraint.isDefaultObjectConstraint()));
}
if (typeParameterDescriptor != null) {
trace.record(BindingContext.REFERENCE_TARGET, subjectTypeParameterName, typeParameterDescriptor);
if (bound != null) {
if (constraint.isClassObjectConstraint()) {
// Class object bounds are not supported
//typeParameterDescriptor.addClassObjectBound(bound);
if (constraint.isDefaultObjectConstraint()) {
// Default object bounds are not supported
}
else {
typeParameterDescriptor.addUpperBound(bound);
@@ -725,7 +724,7 @@ public class DescriptorResolver {
if (!(declaration instanceof JetClass)) {
for (UpperBoundCheckerTask checkerTask : deferredUpperBoundCheckerTasks) {
checkUpperBoundType(checkerTask.upperBound, checkerTask.upperBoundType, checkerTask.isClassObjectConstraint, trace);
checkUpperBoundType(checkerTask.upperBound, checkerTask.upperBoundType, checkerTask.isDefaultObjectConstraint, trace);
}
checkNamesInConstraints(declaration, descriptor, scope, trace);
@@ -743,7 +742,7 @@ public class DescriptorResolver {
JetType classObjectType = parameter.getClassObjectType();
if (classObjectType != null && KotlinBuiltIns.isNothing(classObjectType)) {
trace.report(CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS.on(typeParameter, parameter));
trace.report(CONFLICTING_DEFAULT_OBJECT_UPPER_BOUNDS.on(typeParameter, parameter));
}
}
@@ -778,21 +777,21 @@ public class DescriptorResolver {
}
}
public static void reportUnsupportedClassObjectConstraint(BindingTrace trace, JetTypeConstraint constraint) {
if (constraint.isClassObjectConstraint()) {
trace.report(UNSUPPORTED.on(constraint, "Class objects constraints are not supported yet"));
public static void reportUnsupportedDefaultObjectConstraint(BindingTrace trace, JetTypeConstraint constraint) {
if (constraint.isDefaultObjectConstraint()) {
trace.report(UNSUPPORTED.on(constraint, "Default objects constraints are not supported yet"));
}
}
public static void checkUpperBoundType(
JetTypeReference upperBound,
@NotNull JetType upperBoundType,
boolean isClassObjectConstraint,
boolean isDefaultObjectConstraint,
BindingTrace trace
) {
if (!TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, upperBoundType)) {
if (isClassObjectConstraint) {
trace.report(FINAL_CLASS_OBJECT_UPPER_BOUND.on(upperBound, upperBoundType));
if (isDefaultObjectConstraint) {
trace.report(FINAL_DEFAULT_OBJECT_UPPER_BOUND.on(upperBound, upperBoundType));
}
else {
trace.report(FINAL_UPPER_BOUND.on(upperBound, upperBoundType));
@@ -36,7 +36,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static org.jetbrains.kotlin.diagnostics.Errors.MANY_CLASS_OBJECTS;
import static org.jetbrains.kotlin.diagnostics.Errors.MANY_DEFAULT_OBJECTS;
import static org.jetbrains.kotlin.diagnostics.Errors.UNSUPPORTED;
public class LazyTopDownAnalyzer {
@@ -191,19 +191,19 @@ public class LazyTopDownAnalyzer {
registerDeclarations(classOrObject.getDeclarations());
registerTopLevelFqName(topLevelFqNames, classOrObject, descriptor);
checkManyClassObjects(classOrObject);
checkManyDefaultObjects(classOrObject);
}
private void checkManyClassObjects(JetClassOrObject classOrObject) {
boolean classObjectAlreadyFound = false;
private void checkManyDefaultObjects(JetClassOrObject classOrObject) {
boolean defaultObjectAlreadyFound = false;
for (JetDeclaration jetDeclaration : classOrObject.getDeclarations()) {
jetDeclaration.accept(this);
if (jetDeclaration instanceof JetObjectDeclaration && ((JetObjectDeclaration) jetDeclaration).isClassObject()) {
if (classObjectAlreadyFound) {
trace.report(MANY_CLASS_OBJECTS.on((JetObjectDeclaration) jetDeclaration));
if (jetDeclaration instanceof JetObjectDeclaration && ((JetObjectDeclaration) jetDeclaration).isDefault()) {
if (defaultObjectAlreadyFound) {
trace.report(MANY_DEFAULT_OBJECTS.on((JetObjectDeclaration) jetDeclaration));
}
classObjectAlreadyFound = true;
defaultObjectAlreadyFound = true;
}
}
}
@@ -243,7 +243,7 @@ public class ModifiersChecker {
if (DescriptorUtils.isTrait(containingDeclaration)) {
return InnerModifierCheckResult.IN_TRAIT;
}
else if (DescriptorUtils.isClassObject(containingDeclaration) || DescriptorUtils.isObject(containingDeclaration)) {
else if (DescriptorUtils.isDefaultObject(containingDeclaration) || DescriptorUtils.isObject(containingDeclaration)) {
return InnerModifierCheckResult.IN_OBJECT;
}
else {
@@ -121,7 +121,7 @@ public class OverloadResolver {
return name;
}
if (jetClass instanceof JetObjectDeclaration) {
// must be class object
// must be default object
name = classDescriptor.getContainingDeclaration().getName().asString();
return "class object " + name;
}
@@ -35,7 +35,7 @@ public class FakeCallableDescriptorForObject(
{
assert(classDescriptor.getClassObjectType() != null) {
"FakeCallableDescriptorForObject can be created only for objects, classes with class object or enum entries: $classDescriptor"
"FakeCallableDescriptorForObject can be created only for objects, classes with default object or enum entries: $classDescriptor"
}
}
@@ -49,7 +49,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
return false
}
if (DescriptorUtils.isObject(descriptor.getContainingDeclaration()) ||
DescriptorUtils.isClassObject(descriptor.getContainingDeclaration()) ||
DescriptorUtils.isDefaultObject(descriptor.getContainingDeclaration()) ||
DescriptorUtils.isStaticDeclaration(descriptor)) {
val returnType = descriptor.getType()
return KotlinBuiltIns.isPrimitiveType(returnType) || KotlinBuiltIns.isString(returnType)
@@ -46,8 +46,8 @@ public class JetClassInfo extends JetClassOrObjectInfo<JetClass> {
}
@Override
public JetObjectDeclaration getClassObject() {
return element.getClassObject();
public JetObjectDeclaration getDefaultObject() {
return element.getDefaultObject();
}
@Nullable
@@ -34,11 +34,11 @@ public interface JetClassLikeInfo extends JetDeclarationContainer {
JetModifierList getModifierList();
@Nullable
JetObjectDeclaration getClassObject();
JetObjectDeclaration getDefaultObject();
@NotNull
@ReadOnly
List<JetObjectDeclaration> getClassObjects();
List<JetObjectDeclaration> getDefaultObjects();
// This element is used to identify resolution scope for the class
@NotNull
@@ -58,12 +58,12 @@ public abstract class JetClassOrObjectInfo<E extends JetClassOrObject> implement
@NotNull
@Override
public List<JetObjectDeclaration> getClassObjects() {
public List<JetObjectDeclaration> getDefaultObjects() {
JetClassBody body = element.getBody();
if (body == null) {
return Collections.emptyList();
}
return body.getAllClassObjects();
return body.getAllDefaultObjects();
}
@NotNull
@@ -34,11 +34,11 @@ public class JetObjectInfo extends JetClassOrObjectInfo<JetObjectDeclaration> {
super(element);
this.kind = element.isObjectLiteral()
? ClassKind.CLASS
: (element.isClassObject() ? ClassKind.CLASS_OBJECT : ClassKind.OBJECT);
: (element.isDefault() ? ClassKind.CLASS_OBJECT : ClassKind.OBJECT);
}
@Override
public JetObjectDeclaration getClassObject() {
public JetObjectDeclaration getDefaultObject() {
return null;
}
@@ -27,8 +27,8 @@ public class JetScriptInfo(
public val fqName: FqName = ScriptNameUtil.classNameForScript(script)
override fun getContainingPackageFqName() = fqName.parent()
override fun getModifierList() = null
override fun getClassObject() = null
override fun getClassObjects() = listOf<JetObjectDeclaration>()
override fun getDefaultObject() = null
override fun getDefaultObjects() = listOf<JetObjectDeclaration>()
override fun getScopeAnchor() = script
override fun getCorrespondingClassOrObject() = null
override fun getTypeParameterList() = null
@@ -81,8 +81,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
private final Annotations annotations;
private final Annotations danglingAnnotations;
private final NullableLazyValue<LazyClassDescriptor> classObjectDescriptor;
private final MemoizedFunctionToNotNull<JetObjectDeclaration, ClassDescriptor> extraClassObjectDescriptors;
private final NullableLazyValue<LazyClassDescriptor> defaultObjectDescriptor;
private final MemoizedFunctionToNotNull<JetObjectDeclaration, ClassDescriptor> extraDefaultObjectDescriptors;
private final LazyClassMemberScope unsubstitutedMemberScope;
private final JetScope staticScope = new StaticScopeForKotlinClass(this);
@@ -177,16 +177,16 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
);
}
this.classObjectDescriptor = storageManager.createNullableLazyValue(new Function0<LazyClassDescriptor>() {
this.defaultObjectDescriptor = storageManager.createNullableLazyValue(new Function0<LazyClassDescriptor>() {
@Override
public LazyClassDescriptor invoke() {
return computeClassObjectDescriptor(getClassObjectIfAllowed());
return computeDefaultObjectDescriptor(getDefaultObjectIfAllowed());
}
});
this.extraClassObjectDescriptors = storageManager.createMemoizedFunction(new Function1<JetObjectDeclaration, ClassDescriptor>() {
this.extraDefaultObjectDescriptors = storageManager.createMemoizedFunction(new Function1<JetObjectDeclaration, ClassDescriptor>() {
@Override
public ClassDescriptor invoke(JetObjectDeclaration classObject) {
return computeClassObjectDescriptor(classObject);
public ClassDescriptor invoke(JetObjectDeclaration defaultObject) {
return computeDefaultObjectDescriptor(defaultObject);
}
});
this.scopeForClassHeaderResolution = storageManager.createLazyValue(new Function0<JetScope>() {
@@ -266,8 +266,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
thisScope.setImplicitReceiver(this.getThisAsReceiverParameter());
thisScope.changeLockLevel(WritableScope.LockLevel.READING);
ClassDescriptor classObject = getDefaultObjectDescriptor();
JetScope classObjectAdapterScope = (classObject != null) ? new ClassObjectMixinScope(classObject) : JetScope.Empty.INSTANCE$;
ClassDescriptor defaultObjectDescriptor = getDefaultObjectDescriptor();
JetScope defaultObjectAdapterScope = (defaultObjectDescriptor != null) ? new DefaultObjectMixinScope(defaultObjectDescriptor) : JetScope.Empty.INSTANCE$;
return new ChainedScope(
this,
@@ -275,7 +275,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
thisScope,
getScopeForMemberLookup(),
getScopeForClassHeaderResolution(),
classObjectAdapterScope,
defaultObjectAdapterScope,
getStaticScope()
);
}
@@ -347,46 +347,46 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
@Override
public LazyClassDescriptor getDefaultObjectDescriptor() {
return classObjectDescriptor.invoke();
return defaultObjectDescriptor.invoke();
}
@NotNull
@ReadOnly
public List<ClassDescriptor> getDescriptorsForExtraClassObjects() {
final JetObjectDeclaration allowedClassObject = getClassObjectIfAllowed();
public List<ClassDescriptor> getDescriptorsForExtraDefaultObjects() {
final JetObjectDeclaration allowedDefaultObject = getDefaultObjectIfAllowed();
return KotlinPackage.map(
KotlinPackage.filter(
declarationProvider.getOwnerInfo().getClassObjects(),
declarationProvider.getOwnerInfo().getDefaultObjects(),
new Function1<JetObjectDeclaration, Boolean>() {
@Override
public Boolean invoke(JetObjectDeclaration classObject) {
return classObject != allowedClassObject;
public Boolean invoke(JetObjectDeclaration defaultObject) {
return defaultObject != allowedDefaultObject;
}
}
),
new Function1<JetObjectDeclaration, ClassDescriptor>() {
@Override
public ClassDescriptor invoke(JetObjectDeclaration classObject) {
return extraClassObjectDescriptors.invoke(classObject);
public ClassDescriptor invoke(JetObjectDeclaration defaultObject) {
return extraDefaultObjectDescriptors.invoke(defaultObject);
}
}
);
}
@Nullable
private LazyClassDescriptor computeClassObjectDescriptor(@Nullable JetObjectDeclaration classObject) {
JetClassLikeInfo classObjectInfo = getClassObjectInfo(classObject);
if (!(classObjectInfo instanceof JetClassOrObjectInfo)) {
private LazyClassDescriptor computeDefaultObjectDescriptor(@Nullable JetObjectDeclaration defaultObject) {
JetClassLikeInfo defaultObjectInfo = getDefaultObjectInfo(defaultObject);
if (!(defaultObjectInfo instanceof JetClassOrObjectInfo)) {
return null;
}
Name name = ((JetClassOrObjectInfo) classObjectInfo).getName();
Name name = ((JetClassOrObjectInfo) defaultObjectInfo).getName();
assert name != null;
getScopeForMemberLookup().getClassifier(name);
ClassDescriptor classObjectDescriptor = c.getTrace().get(BindingContext.CLASS, classObject);
if (classObjectDescriptor instanceof LazyClassDescriptor) {
assert DescriptorUtils.isClassObject(classObjectDescriptor) : "Not a class object: " + classObjectDescriptor;
return (LazyClassDescriptor) classObjectDescriptor;
ClassDescriptor defaultObjectDescriptor = c.getTrace().get(BindingContext.CLASS, defaultObject);
if (defaultObjectDescriptor instanceof LazyClassDescriptor) {
assert DescriptorUtils.isDefaultObject(defaultObjectDescriptor) : "Not a default object: " + defaultObjectDescriptor;
return (LazyClassDescriptor) defaultObjectDescriptor;
}
else {
return null;
@@ -394,25 +394,25 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
}
@Nullable
private JetClassLikeInfo getClassObjectInfo(@Nullable JetObjectDeclaration classObject) {
if (classObject != null) {
if (!isClassObjectAllowed()) {
c.getTrace().report(CLASS_OBJECT_NOT_ALLOWED.on(classObject));
private JetClassLikeInfo getDefaultObjectInfo(@Nullable JetObjectDeclaration defaultObject) {
if (defaultObject != null) {
if (!isDefaultObjectAllowed()) {
c.getTrace().report(DEFAULT_OBJECT_NOT_ALLOWED.on(defaultObject));
}
return JetClassInfoUtil.createClassLikeInfo(classObject);
return JetClassInfoUtil.createClassLikeInfo(defaultObject);
}
return null;
}
@Nullable
private JetObjectDeclaration getClassObjectIfAllowed() {
JetObjectDeclaration classObject = declarationProvider.getOwnerInfo().getClassObject();
return (classObject != null && isClassObjectAllowed()) ? classObject : null;
private JetObjectDeclaration getDefaultObjectIfAllowed() {
JetObjectDeclaration defaultObject = declarationProvider.getOwnerInfo().getDefaultObject();
return (defaultObject != null && isDefaultObjectAllowed()) ? defaultObject : null;
}
private boolean isClassObjectAllowed() {
private boolean isDefaultObjectAllowed() {
return !(getKind().isSingleton() || isInner() || DescriptorUtils.isLocal(this));
}
@@ -463,13 +463,13 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
private void doForceResolveAllContents() {
resolveMemberHeaders();
ClassDescriptor classObjectDescriptor = getDefaultObjectDescriptor();
if (classObjectDescriptor != null) {
ForceResolveUtil.forceResolveAllContents(classObjectDescriptor);
ClassDescriptor defaultObjectDescriptor = getDefaultObjectDescriptor();
if (defaultObjectDescriptor != null) {
ForceResolveUtil.forceResolveAllContents(defaultObjectDescriptor);
}
ForceResolveUtil.forceResolveAllContents(getConstructors());
ForceResolveUtil.forceResolveAllContents(getDescriptorsForExtraClassObjects());
ForceResolveUtil.forceResolveAllContents(getDescriptorsForExtraDefaultObjects());
ForceResolveUtil.forceResolveAllContents(getScopeForMemberLookup());
ForceResolveUtil.forceResolveAllContents(getTypeConstructor());
}
@@ -481,7 +481,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
getDefaultObjectDescriptor();
getDescriptorsForExtraClassObjects();
getDescriptorsForExtraDefaultObjects();
getClassObjectType();
getConstructors();
@@ -230,7 +230,7 @@ public open class LazyClassMemberScope(
private fun <T : CallableMemberDescriptor> generateDelegatingDescriptors(name: Name, extractor: MemberExtractor<T>, existingDescriptors: Collection<CallableDescriptor>): Collection<T> {
val classOrObject = declarationProvider.getOwnerInfo().getCorrespondingClassOrObject()
?: return setOf() // Enum class objects do not have delegated members
?: return setOf() // Enum default objects do not have delegated members
val lazyTypeResolver = DelegationResolver.TypeResolver { reference ->
c.typeResolver.resolveType(thisDescriptor.getScopeForClassHeaderResolution(), reference, trace, false)
@@ -83,7 +83,7 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
if (classOrObject instanceof JetClass) {
JetClass jetClass = (JetClass) classOrObject;
for (JetTypeConstraint jetTypeConstraint : jetClass.getTypeConstraints()) {
DescriptorResolver.reportUnsupportedClassObjectConstraint(c.getTrace(), jetTypeConstraint);
DescriptorResolver.reportUnsupportedDefaultObjectConstraint(c.getTrace(), jetTypeConstraint);
JetSimpleNameExpression constrainedParameterName = jetTypeConstraint.getSubjectTypeParameterName();
if (constrainedParameterName != null) {
@@ -93,7 +93,7 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
JetTypeReference boundTypeReference = jetTypeConstraint.getBoundTypeReference();
if (boundTypeReference != null) {
JetType boundType = resolveBoundType(boundTypeReference);
if (!jetTypeConstraint.isClassObjectConstraint()) {
if (!jetTypeConstraint.isDefaultObjectConstraint()) {
upperBounds.add(boundType);
}
}
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.descriptors.ClassDescriptor
/**
* Members of the class object are accessible from the class.
* Scope lazily delegates requests to class object scope.
* Members of the default object are accessible from the class.
* Scope lazily delegates requests to default object scope.
*/
public class ClassObjectMixinScope(private val classObjectDescriptor: ClassDescriptor) : AbstractScopeAdapter() {
public class DefaultObjectMixinScope(private val defaultObjectDescriptor: ClassDescriptor) : AbstractScopeAdapter() {
override val workerScope: JetScope
get() = classObjectDescriptor.getDefaultType().getMemberScope()
get() = defaultObjectDescriptor.getDefaultType().getMemberScope()
override fun getImplicitReceiversHierarchy() = listOf(classObjectDescriptor.getThisAsReceiverParameter())
override fun getImplicitReceiversHierarchy() = listOf(defaultObjectDescriptor.getThisAsReceiverParameter())
}
@@ -91,8 +91,8 @@ public abstract class WritableScopeWithImports(override val workerScope: JetScop
protected open fun computeImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> {
val implicitReceiverHierarchy = Lists.newArrayList<ReceiverParameterDescriptor>()
// Imported scopes come with their receivers
// Example: class member resolution scope imports a scope of it's class object
// members of the class object must be able to find it as an implicit receiver
// Example: class member resolution scope imports a scope of it's default object
// members of the default object must be able to find it as an implicit receiver
for (scope in getImports()) {
implicitReceiverHierarchy.addAll(scope.getImplicitReceiversHierarchy())
}
@@ -129,7 +129,7 @@ private fun QualifierReceiver.resolveAsStandaloneExpression(context: ExpressionT
context.trace.report(TYPE_PARAMETER_IS_NOT_AN_EXPRESSION.on(referenceExpression, classifier))
}
else if (classifier is ClassDescriptor && classifier.getClassObjectType() == null) {
context.trace.report(NO_CLASS_OBJECT.on(referenceExpression, classifier))
context.trace.report(NO_DEFAULT_OBJECT.on(referenceExpression, classifier))
}
else if (packageView != null) {
context.trace.report(EXPRESSION_EXPECTED_PACKAGE_FOUND.on(referenceExpression))
@@ -185,7 +185,7 @@ class DeclarationScopeProviderForLocalClassifierAnalyzer(
}
override fun getOuterDataFlowInfoForDeclaration(elementOfDeclaration: PsiElement): DataFlowInfo {
// nested (non-inner) classes and class objects are forbidden in local classes, so it's enough to be simply inside the class
// nested (non-inner) classes and default objects are forbidden in local classes, so it's enough to be simply inside the class
if (localClassDescriptorManager.insideMyClass(elementOfDeclaration)) {
return localClassDescriptorManager.expressionTypingContext.dataFlowInfo
}