default -> companion: replace all mentions of default and default object
This commit is contained in:
@@ -1379,7 +1379,7 @@ public class JetControlFlowProcessor {
|
||||
|
||||
@Override
|
||||
public void visitTypeProjection(@NotNull JetTypeProjection typeProjection) {
|
||||
// TODO : Support Type Arguments. Default object may be initialized at this point");
|
||||
// TODO : Support Type Arguments. Companion object may be initialized at this point");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public interface ClassDescriptorWithResolutionScopes extends ClassDescriptor {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
ClassDescriptorWithResolutionScopes getDefaultObjectDescriptor();
|
||||
ClassDescriptorWithResolutionScopes getCompanionObjectDescriptor();
|
||||
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
|
||||
+10
-10
@@ -44,7 +44,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private Collection<JetType> supertypes = new ArrayList<JetType>();
|
||||
|
||||
private MutableClassDescriptor defaultObjectDescriptor;
|
||||
private MutableClassDescriptor companionObjectDescriptor;
|
||||
|
||||
private final Set<ConstructorDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
private ConstructorDescriptor primaryConstructor;
|
||||
@@ -71,7 +71,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
@NotNull SourceElement source
|
||||
) {
|
||||
super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name, source);
|
||||
assert kind != ClassKind.OBJECT : "Fix isDefaultObject()";
|
||||
assert kind != ClassKind.OBJECT : "Fix isCompanionObject()";
|
||||
|
||||
this.kind = kind;
|
||||
this.isInner = isInner;
|
||||
@@ -98,13 +98,13 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public MutableClassDescriptor getDefaultObjectDescriptor() {
|
||||
return defaultObjectDescriptor;
|
||||
public MutableClassDescriptor getCompanionObjectDescriptor() {
|
||||
return companionObjectDescriptor;
|
||||
}
|
||||
|
||||
public void setDefaultObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||
assert this.defaultObjectDescriptor == null : "classObjectDescriptor already assigned in " + this;
|
||||
this.defaultObjectDescriptor = classObjectDescriptor;
|
||||
public void setCompanionObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||
assert this.companionObjectDescriptor == null : "classObjectDescriptor already assigned in " + this;
|
||||
this.companionObjectDescriptor = classObjectDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -155,7 +155,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefaultObject() {
|
||||
public boolean isCompanionObject() {
|
||||
//TODO:
|
||||
return false;
|
||||
}
|
||||
@@ -329,8 +329,8 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
|
||||
public void lockScopes() {
|
||||
getScopeForMemberLookupAsWritableScope().changeLockLevel(WritableScope.LockLevel.READING);
|
||||
if (defaultObjectDescriptor != null) {
|
||||
defaultObjectDescriptor.lockScopes();
|
||||
if (companionObjectDescriptor != null) {
|
||||
companionObjectDescriptor.lockScopes();
|
||||
}
|
||||
scopeForSupertypeResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
scopeForMemberResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
@@ -203,10 +203,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);
|
||||
|
||||
// Default objects
|
||||
// Companion objects
|
||||
|
||||
DiagnosticFactory0<JetObjectDeclaration> MANY_DEFAULT_OBJECTS = DiagnosticFactory0.create(ERROR, DEFAULT_OBJECT);
|
||||
DiagnosticFactory0<JetObjectDeclaration> DEFAULT_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR, DEFAULT_OBJECT);
|
||||
DiagnosticFactory0<JetObjectDeclaration> MANY_COMPANION_OBJECTS = DiagnosticFactory0.create(ERROR, COMPANION_OBJECT);
|
||||
DiagnosticFactory0<JetObjectDeclaration> COMPANION_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR, COMPANION_OBJECT);
|
||||
|
||||
DiagnosticFactory0<JetObjectDeclaration> DEPRECATED_CLASS_OBJECT_SYNTAX = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
@@ -217,12 +217,12 @@ public interface Errors {
|
||||
// Type parameter declarations
|
||||
|
||||
DiagnosticFactory1<JetTypeReference, JetType> FINAL_UPPER_BOUND = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory1<JetTypeReference, JetType> FINAL_DEFAULT_OBJECT_UPPER_BOUND = DiagnosticFactory1.create(ERROR);
|
||||
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 =
|
||||
DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
|
||||
DiagnosticFactory1<JetNamedDeclaration, TypeParameterDescriptor> CONFLICTING_DEFAULT_OBJECT_UPPER_BOUNDS
|
||||
DiagnosticFactory1<JetNamedDeclaration, TypeParameterDescriptor> CONFLICTING_COMPANION_OBJECT_UPPER_BOUNDS
|
||||
= DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
|
||||
|
||||
DiagnosticFactory2<JetSimpleNameExpression, JetTypeConstraint, JetTypeParameterListOwner> NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER =
|
||||
@@ -636,7 +636,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_DEFAULT_OBJECT = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<JetSimpleNameExpression, ClassifierDescriptor> NO_COMPANION_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);
|
||||
|
||||
@@ -391,10 +391,10 @@ public object PositioningStrategies {
|
||||
}
|
||||
}
|
||||
|
||||
public val DEFAULT_OBJECT: PositioningStrategy<JetObjectDeclaration> = object : PositioningStrategy<JetObjectDeclaration>() {
|
||||
public val COMPANION_OBJECT: PositioningStrategy<JetObjectDeclaration> = object : PositioningStrategy<JetObjectDeclaration>() {
|
||||
override fun mark(element: JetObjectDeclaration): List<TextRange> {
|
||||
if (element.hasModifier(JetTokens.DEFAULT_KEYWORD)) {
|
||||
return modifierSetPosition(JetTokens.DEFAULT_KEYWORD).mark(element)
|
||||
if (element.hasModifier(JetTokens.COMPANION_KEYWORD)) {
|
||||
return modifierSetPosition(JetTokens.COMPANION_KEYWORD).mark(element)
|
||||
}
|
||||
return DEFAULT.mark(element)
|
||||
}
|
||||
|
||||
+7
-7
@@ -273,10 +273,10 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(UNREACHABLE_CODE, "Unreachable code", TO_STRING);
|
||||
|
||||
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(MANY_COMPANION_OBJECTS, "Only one companion object is allowed per class");
|
||||
MAP.put(COMPANION_OBJECT_NOT_ALLOWED, "A companion object is not allowed here");
|
||||
|
||||
MAP.put(DEPRECATED_CLASS_OBJECT_SYNTAX, "'class object' syntax for default objects was deprecated. Use 'default' modifier instead");
|
||||
MAP.put(DEPRECATED_CLASS_OBJECT_SYNTAX, "'class object' syntax for companion objects was deprecated. Use 'default' modifier instead");
|
||||
|
||||
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);
|
||||
@@ -321,9 +321,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_DEFAULT_OBJECT, "Please specify constructor invocation; classifier ''{0}'' does not have a default object", NAME);
|
||||
MAP.put(NO_COMPANION_OBJECT, "Please specify constructor invocation; classifier ''{0}'' does not have a companion 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 default 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 companion 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);
|
||||
@@ -381,12 +381,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_DEFAULT_OBJECT_UPPER_BOUND, "''{0}'' is a final type, and thus a default object cannot extend it", 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);
|
||||
MAP.put(CONFLICTING_UPPER_BOUNDS, "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(CONFLICTING_COMPANION_OBJECT_UPPER_BOUNDS, "Companion object upper bounds of {0} have empty intersection", NAME);
|
||||
|
||||
MAP.put(TOO_MANY_ARGUMENTS, "Too many arguments for {0}", FQ_NAMES_IN_TYPES);
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ public interface JetTokens {
|
||||
JetModifierKeywordToken VARARG_KEYWORD = JetModifierKeywordToken.softKeywordModifier("vararg");
|
||||
JetModifierKeywordToken REIFIED_KEYWORD = JetModifierKeywordToken.softKeywordModifier("reified");
|
||||
JetModifierKeywordToken DYNAMIC_KEYWORD = JetModifierKeywordToken.softKeywordModifier("dynamic");
|
||||
JetModifierKeywordToken DEFAULT_KEYWORD = JetModifierKeywordToken.softKeywordModifier("default");
|
||||
JetModifierKeywordToken COMPANION_KEYWORD = JetModifierKeywordToken.softKeywordModifier("companion");
|
||||
|
||||
JetKeywordToken FINALLY_KEYWORD = JetKeywordToken.softKeyword("finally");
|
||||
JetModifierKeywordToken FINAL_KEYWORD = JetModifierKeywordToken.softKeywordModifier("final");
|
||||
@@ -173,7 +173,7 @@ public interface JetTokens {
|
||||
SET_KEYWORD, ABSTRACT_KEYWORD, ENUM_KEYWORD, OPEN_KEYWORD, INNER_KEYWORD, ANNOTATION_KEYWORD,
|
||||
OVERRIDE_KEYWORD, PRIVATE_KEYWORD, PUBLIC_KEYWORD, INTERNAL_KEYWORD, PROTECTED_KEYWORD,
|
||||
CATCH_KEYWORD, FINALLY_KEYWORD, OUT_KEYWORD, FINAL_KEYWORD, VARARG_KEYWORD, REIFIED_KEYWORD,
|
||||
DYNAMIC_KEYWORD, DEFAULT_KEYWORD, CONSTRUCTOR_KEYWORD, INIT_KEYWORD
|
||||
DYNAMIC_KEYWORD, COMPANION_KEYWORD, CONSTRUCTOR_KEYWORD, INIT_KEYWORD
|
||||
);
|
||||
|
||||
/*
|
||||
@@ -185,7 +185,7 @@ public interface JetTokens {
|
||||
new JetModifierKeywordToken[] {
|
||||
ABSTRACT_KEYWORD, ENUM_KEYWORD, OPEN_KEYWORD, INNER_KEYWORD, ANNOTATION_KEYWORD, OVERRIDE_KEYWORD, PRIVATE_KEYWORD,
|
||||
PUBLIC_KEYWORD, INTERNAL_KEYWORD, PROTECTED_KEYWORD, OUT_KEYWORD, IN_KEYWORD, FINAL_KEYWORD, VARARG_KEYWORD,
|
||||
REIFIED_KEYWORD, DEFAULT_KEYWORD
|
||||
REIFIED_KEYWORD, COMPANION_KEYWORD
|
||||
};
|
||||
|
||||
TokenSet MODIFIER_KEYWORDS = TokenSet.create(MODIFIER_KEYWORDS_ARRAY);
|
||||
|
||||
@@ -785,7 +785,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
* ;
|
||||
*
|
||||
* memberDeclaration'
|
||||
* : defaultObject
|
||||
* : companionObject
|
||||
* : secondaryConstructor
|
||||
* : function
|
||||
* : property
|
||||
@@ -957,7 +957,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
}
|
||||
|
||||
/*
|
||||
* defaultObject
|
||||
* companionObject
|
||||
* : modifiers "class" object
|
||||
* ;
|
||||
*/
|
||||
@@ -2083,7 +2083,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
if (item == JetTokens.ENUM_KEYWORD) {
|
||||
enumDetected = true;
|
||||
}
|
||||
else if (item == JetTokens.DEFAULT_KEYWORD) {
|
||||
else if (item == JetTokens.COMPANION_KEYWORD) {
|
||||
defaultDetected = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,12 +220,12 @@ public class JetClass extends JetTypeParameterListOwnerStub<KotlinClassStub> imp
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetObjectDeclaration> getDefaultObjects() {
|
||||
public List<JetObjectDeclaration> getCompanionObjects() {
|
||||
JetClassBody body = getBody();
|
||||
if (body == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return body.getAllDefaultObjects();
|
||||
return body.getAllCompanionObjects();
|
||||
}
|
||||
|
||||
public boolean hasPrimaryConstructor() {
|
||||
|
||||
@@ -72,10 +72,10 @@ public class JetClassBody extends JetElementImplStub<KotlinPlaceHolderStub<JetCl
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetObjectDeclaration> getAllDefaultObjects() {
|
||||
public List<JetObjectDeclaration> getAllCompanionObjects() {
|
||||
List<JetObjectDeclaration> result = Lists.newArrayList();
|
||||
for (JetObjectDeclaration declaration : getStubOrPsiChildrenAsList(JetStubElementTypes.OBJECT_DECLARATION)) {
|
||||
if (declaration.isDefault()) {
|
||||
if (declaration.isCompanion()) {
|
||||
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).isDefault()) {
|
||||
JetElement defaultObjectClass = PsiTreeUtil.getParentOfType(containingClass, JetClassOrObject.class);
|
||||
if (defaultObjectClass != null) {
|
||||
containingClass = defaultObjectClass;
|
||||
if (containingClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) containingClass).isCompanion()) {
|
||||
JetElement companionObjectClass = PsiTreeUtil.getParentOfType(containingClass, JetClassOrObject.class);
|
||||
if (companionObjectClass != null) {
|
||||
containingClass = companionObjectClass;
|
||||
}
|
||||
}
|
||||
if (containingClass != null) {
|
||||
|
||||
@@ -51,9 +51,9 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<KotlinObjectSt
|
||||
}
|
||||
|
||||
JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration();
|
||||
if (nameAsDeclaration == null && isDefault()) {
|
||||
if (nameAsDeclaration == null && isCompanion()) {
|
||||
//NOTE: a hack in PSI that simplifies writing frontend code
|
||||
return SpecialNames.DEFAULT_NAME_FOR_DEFAULT_OBJECT.toString();
|
||||
return SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT.toString();
|
||||
}
|
||||
return nameAsDeclaration == null ? null : nameAsDeclaration.getName();
|
||||
}
|
||||
@@ -94,12 +94,12 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<KotlinObjectSt
|
||||
return (JetObjectDeclarationName) findChildByType(JetNodeTypes.OBJECT_DECLARATION_NAME);
|
||||
}
|
||||
|
||||
public boolean isDefault() {
|
||||
public boolean isCompanion() {
|
||||
KotlinObjectStub stub = getStub();
|
||||
if (stub != null) {
|
||||
return stub.isDefault();
|
||||
}
|
||||
return getClassKeyword() != null || hasModifier(JetTokens.DEFAULT_KEYWORD);
|
||||
return getClassKeyword() != null || hasModifier(JetTokens.COMPANION_KEYWORD);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,10 +37,10 @@ public class JetTypeConstraint extends JetElementImplStub<KotlinTypeConstraintSt
|
||||
return visitor.visitTypeConstraint(this, data);
|
||||
}
|
||||
|
||||
public boolean isDefaultObjectConstraint() {
|
||||
public boolean isCompanionObjectConstraint() {
|
||||
KotlinTypeConstraintStub stub = getStub();
|
||||
if (stub != null) {
|
||||
return stub.isDefaultObjectConstraint();
|
||||
return stub.isCompanionObjectConstraint();
|
||||
}
|
||||
return findChildByType(JetTokens.CLASS_KEYWORD) != null &&
|
||||
findChildByType(JetTokens.OBJECT_KEYWORD) != null;
|
||||
|
||||
@@ -95,4 +95,4 @@ private val MODIFIERS_ORDER = listOf(PUBLIC_KEYWORD, PROTECTED_KEYWORD, PRIVATE_
|
||||
FINAL_KEYWORD, OPEN_KEYWORD, ABSTRACT_KEYWORD,
|
||||
OVERRIDE_KEYWORD,
|
||||
INNER_KEYWORD,
|
||||
ANNOTATION_KEYWORD, ENUM_KEYWORD, DEFAULT_KEYWORD)
|
||||
ANNOTATION_KEYWORD, ENUM_KEYWORD, COMPANION_KEYWORD)
|
||||
|
||||
@@ -104,7 +104,7 @@ public trait KotlinPropertyStub : KotlinStubWithFqName<JetProperty> {
|
||||
}
|
||||
|
||||
public trait KotlinTypeConstraintStub : StubElement<JetTypeConstraint> {
|
||||
public fun isDefaultObjectConstraint(): Boolean
|
||||
public fun isCompanionObjectConstraint(): Boolean
|
||||
}
|
||||
|
||||
public trait KotlinTypeParameterStub : KotlinStubWithFqName<JetTypeParameter> {
|
||||
|
||||
+1
-1
@@ -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.isDefault(), psi.isLocal(), psi.isObjectLiteral());
|
||||
psi.isTopLevel(), psi.isCompanion(), psi.isLocal(), psi.isObjectLiteral());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-4
@@ -34,18 +34,18 @@ public class JetTypeConstraintElementType extends JetStubElementType<KotlinTypeC
|
||||
|
||||
@Override
|
||||
public KotlinTypeConstraintStub createStub(@NotNull JetTypeConstraint psi, StubElement parentStub) {
|
||||
return new KotlinTypeConstraintStubImpl(parentStub, psi.isDefaultObjectConstraint());
|
||||
return new KotlinTypeConstraintStubImpl(parentStub, psi.isCompanionObjectConstraint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(@NotNull KotlinTypeConstraintStub stub, @NotNull StubOutputStream dataStream) throws IOException {
|
||||
dataStream.writeBoolean(stub.isDefaultObjectConstraint());
|
||||
dataStream.writeBoolean(stub.isCompanionObjectConstraint());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public KotlinTypeConstraintStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
|
||||
boolean isDefaultObjectConstraint = dataStream.readBoolean();
|
||||
return new KotlinTypeConstraintStubImpl(parentStub, isDefaultObjectConstraint);
|
||||
boolean isCompanionObjectConstraint = dataStream.readBoolean();
|
||||
return new KotlinTypeConstraintStubImpl(parentStub, isCompanionObjectConstraint);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,8 +24,8 @@ import com.intellij.psi.PsiElement
|
||||
|
||||
public class KotlinTypeConstraintStubImpl(
|
||||
parent: StubElement<out PsiElement>?,
|
||||
private val isDefaultObjectConstraint: Boolean
|
||||
private val isCompanionObjectConstraint: Boolean
|
||||
) : KotlinStubBaseImpl<JetTypeConstraint>(parent, JetStubElementTypes.TYPE_CONSTRAINT), KotlinTypeConstraintStub {
|
||||
|
||||
override fun isDefaultObjectConstraint() = isDefaultObjectConstraint
|
||||
override fun isCompanionObjectConstraint() = isCompanionObjectConstraint
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ public fun DeclarationDescriptor.hasIntrinsicAnnotation(): Boolean {
|
||||
}
|
||||
|
||||
public fun CallableDescriptor.isPlatformStaticInObjectOrClass(): Boolean =
|
||||
isPlatformStaticIn { DescriptorUtils.isNonDefaultObject(it) || DescriptorUtils.isClass(it) }
|
||||
isPlatformStaticIn { DescriptorUtils.isNonCompanionObject(it) || DescriptorUtils.isClass(it) }
|
||||
|
||||
public fun CallableDescriptor.isPlatformStaticInDefaultObject(): Boolean =
|
||||
isPlatformStaticIn { DescriptorUtils.isDefaultObject(it) }
|
||||
public fun CallableDescriptor.isPlatformStaticInCompanionObject(): Boolean =
|
||||
isPlatformStaticIn { DescriptorUtils.isCompanionObject(it) }
|
||||
|
||||
private fun CallableDescriptor.isPlatformStaticIn(predicate: (DeclarationDescriptor) -> Boolean): Boolean =
|
||||
when (this) {
|
||||
|
||||
@@ -96,8 +96,8 @@ public interface BindingContext {
|
||||
|
||||
WritableSlice<JetReferenceExpression, DeclarationDescriptor> REFERENCE_TARGET =
|
||||
new BasicWritableSlice<JetReferenceExpression, DeclarationDescriptor>(DO_NOTHING);
|
||||
// if 'A' really means 'A.Default' then this slice stores class descriptor for A, REFERENCE_TARGET stores descriptor Default in this case
|
||||
WritableSlice<JetReferenceExpression, ClassDescriptor> SHORT_REFERENCE_TO_DEFAULT_OBJECT =
|
||||
// if 'A' really means 'A.Companion' then this slice stores class descriptor for A, REFERENCE_TARGET stores descriptor Companion in this case
|
||||
WritableSlice<JetReferenceExpression, ClassDescriptor> SHORT_REFERENCE_TO_COMPANION_OBJECT =
|
||||
new BasicWritableSlice<JetReferenceExpression, ClassDescriptor>(DO_NOTHING);
|
||||
|
||||
@KotlinSignature("val RESOLVED_CALL: WritableSlice<Call, ResolvedCall<out CallableDescriptor>>")
|
||||
|
||||
@@ -151,7 +151,7 @@ public class DeclarationsChecker {
|
||||
|
||||
for (JetTypeConstraint constraint : jetClass.getTypeConstraints()) {
|
||||
checkBoundsForTypeInClassHeader(constraint.getBoundTypeReference());
|
||||
checkFinalUpperBounds(constraint.getBoundTypeReference(), constraint.isDefaultObjectConstraint());
|
||||
checkFinalUpperBounds(constraint.getBoundTypeReference(), constraint.isCompanionObjectConstraint());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,11 +164,11 @@ public class DeclarationsChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkFinalUpperBounds(@Nullable JetTypeReference typeReference, boolean isDefaultObjectConstraint) {
|
||||
private void checkFinalUpperBounds(@Nullable JetTypeReference typeReference, boolean isCompanionObjectConstraint) {
|
||||
if (typeReference != null) {
|
||||
JetType type = trace.getBindingContext().get(TYPE, typeReference);
|
||||
if (type != null) {
|
||||
DescriptorResolver.checkUpperBoundType(typeReference, type, isDefaultObjectConstraint, trace);
|
||||
DescriptorResolver.checkUpperBoundType(typeReference, type, isCompanionObjectConstraint, trace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -258,7 +258,7 @@ public class DeclarationsChecker {
|
||||
private void checkObject(JetObjectDeclaration declaration, ClassDescriptor classDescriptor) {
|
||||
checkDeprecatedClassObjectSyntax(declaration);
|
||||
reportErrorIfHasIllegalModifier(declaration);
|
||||
if (declaration.isLocal() && !declaration.isDefault() && !declaration.isObjectLiteral()) {
|
||||
if (declaration.isLocal() && !declaration.isCompanion() && !declaration.isObjectLiteral()) {
|
||||
trace.report(LOCAL_OBJECT_NOT_ALLOWED.on(declaration, classDescriptor));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,12 +455,12 @@ public class DescriptorResolver {
|
||||
static final class UpperBoundCheckerTask {
|
||||
JetTypeReference upperBound;
|
||||
JetType upperBoundType;
|
||||
boolean isDefaultObjectConstraint;
|
||||
boolean isCompanionObjectConstraint;
|
||||
|
||||
private UpperBoundCheckerTask(JetTypeReference upperBound, JetType upperBoundType, boolean defaultObjectConstraint) {
|
||||
private UpperBoundCheckerTask(JetTypeReference upperBound, JetType upperBoundType, boolean companionObjectConstraint) {
|
||||
this.upperBound = upperBound;
|
||||
this.upperBoundType = upperBoundType;
|
||||
isDefaultObjectConstraint = defaultObjectConstraint;
|
||||
isCompanionObjectConstraint = companionObjectConstraint;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,7 +489,7 @@ public class DescriptorResolver {
|
||||
}
|
||||
}
|
||||
for (JetTypeConstraint constraint : declaration.getTypeConstraints()) {
|
||||
reportUnsupportedDefaultObjectConstraint(trace, constraint);
|
||||
reportUnsupportedCompanionObjectConstraint(trace, constraint);
|
||||
|
||||
JetSimpleNameExpression subjectTypeParameterName = constraint.getSubjectTypeParameterName();
|
||||
if (subjectTypeParameterName == null) {
|
||||
@@ -502,14 +502,14 @@ public class DescriptorResolver {
|
||||
if (boundTypeReference != null) {
|
||||
bound = typeResolver.resolveType(scope, boundTypeReference, trace, false);
|
||||
deferredUpperBoundCheckerTasks
|
||||
.add(new UpperBoundCheckerTask(boundTypeReference, bound, constraint.isDefaultObjectConstraint()));
|
||||
.add(new UpperBoundCheckerTask(boundTypeReference, bound, constraint.isCompanionObjectConstraint()));
|
||||
}
|
||||
|
||||
if (typeParameterDescriptor != null) {
|
||||
trace.record(BindingContext.REFERENCE_TARGET, subjectTypeParameterName, typeParameterDescriptor);
|
||||
if (bound != null) {
|
||||
if (constraint.isDefaultObjectConstraint()) {
|
||||
// Default object bounds are not supported
|
||||
if (constraint.isCompanionObjectConstraint()) {
|
||||
// Companion object bounds are not supported
|
||||
}
|
||||
else {
|
||||
typeParameterDescriptor.addUpperBound(bound);
|
||||
@@ -528,7 +528,7 @@ public class DescriptorResolver {
|
||||
|
||||
if (!(declaration instanceof JetClass)) {
|
||||
for (UpperBoundCheckerTask checkerTask : deferredUpperBoundCheckerTasks) {
|
||||
checkUpperBoundType(checkerTask.upperBound, checkerTask.upperBoundType, checkerTask.isDefaultObjectConstraint, trace);
|
||||
checkUpperBoundType(checkerTask.upperBound, checkerTask.upperBoundType, checkerTask.isCompanionObjectConstraint, trace);
|
||||
}
|
||||
|
||||
checkNamesInConstraints(declaration, descriptor, scope, trace);
|
||||
@@ -546,7 +546,7 @@ public class DescriptorResolver {
|
||||
|
||||
JetType classObjectType = parameter.getClassObjectType();
|
||||
if (classObjectType != null && KotlinBuiltIns.isNothing(classObjectType)) {
|
||||
trace.report(CONFLICTING_DEFAULT_OBJECT_UPPER_BOUNDS.on(typeParameter, parameter));
|
||||
trace.report(CONFLICTING_COMPANION_OBJECT_UPPER_BOUNDS.on(typeParameter, parameter));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,21 +581,21 @@ public class DescriptorResolver {
|
||||
}
|
||||
}
|
||||
|
||||
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 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 isDefaultObjectConstraint,
|
||||
boolean isCompanionObjectConstraint,
|
||||
BindingTrace trace
|
||||
) {
|
||||
if (!TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, upperBoundType)) {
|
||||
if (isDefaultObjectConstraint) {
|
||||
trace.report(FINAL_DEFAULT_OBJECT_UPPER_BOUND.on(upperBound, upperBoundType));
|
||||
if (isCompanionObjectConstraint) {
|
||||
trace.report(FINAL_COMPANION_OBJECT_UPPER_BOUND.on(upperBound, upperBoundType));
|
||||
}
|
||||
else {
|
||||
trace.report(FINAL_UPPER_BOUND.on(upperBound, upperBoundType));
|
||||
|
||||
@@ -192,13 +192,13 @@ public class LazyTopDownAnalyzer {
|
||||
}
|
||||
|
||||
private void checkClassOrObjectDeclarations(JetClassOrObject classOrObject, ClassDescriptor classDescriptor) {
|
||||
boolean defaultObjectAlreadyFound = false;
|
||||
boolean companionObjectAlreadyFound = false;
|
||||
for (JetDeclaration jetDeclaration : classOrObject.getDeclarations()) {
|
||||
if (jetDeclaration instanceof JetObjectDeclaration && ((JetObjectDeclaration) jetDeclaration).isDefault()) {
|
||||
if (defaultObjectAlreadyFound) {
|
||||
trace.report(MANY_DEFAULT_OBJECTS.on((JetObjectDeclaration) jetDeclaration));
|
||||
if (jetDeclaration instanceof JetObjectDeclaration && ((JetObjectDeclaration) jetDeclaration).isCompanion()) {
|
||||
if (companionObjectAlreadyFound) {
|
||||
trace.report(MANY_COMPANION_OBJECTS.on((JetObjectDeclaration) jetDeclaration));
|
||||
}
|
||||
defaultObjectAlreadyFound = true;
|
||||
companionObjectAlreadyFound = true;
|
||||
}
|
||||
else if (jetDeclaration instanceof JetSecondaryConstructor) {
|
||||
if (DescriptorUtils.isSingletonOrAnonymousObject(classDescriptor)) {
|
||||
|
||||
@@ -40,7 +40,7 @@ import java.util.*;
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
||||
import static org.jetbrains.kotlin.lexer.JetTokens.*;
|
||||
import static org.jetbrains.kotlin.psi.JetStubbedPsiUtil.getContainingDeclaration;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isDefaultObject;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isCompanionObject;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry;
|
||||
|
||||
public class ModifiersChecker {
|
||||
@@ -235,13 +235,13 @@ public class ModifiersChecker {
|
||||
}
|
||||
|
||||
private void checkDefaultModifier(@NotNull JetDeclaration declaration) {
|
||||
if (declaration.hasModifier(DEFAULT_KEYWORD) && !isDefaultModifierAllowed(declaration)) {
|
||||
reportIllegalModifiers(declaration, Collections.singletonList(DEFAULT_KEYWORD));
|
||||
if (declaration.hasModifier(COMPANION_KEYWORD) && !isDefaultModifierAllowed(declaration)) {
|
||||
reportIllegalModifiers(declaration, Collections.singletonList(COMPANION_KEYWORD));
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: just checks if this is legal context for default modifier (Default object descriptor can be created)
|
||||
// DEFAULT_OBJECT_NOT_ALLOWED can be reported later
|
||||
// NOTE: just checks if this is legal context for companion modifier (Companion object descriptor can be created)
|
||||
// COMPANION_OBJECT_NOT_ALLOWED can be reported later
|
||||
public static boolean isDefaultModifierAllowed(@NotNull JetDeclaration declaration) {
|
||||
if (declaration instanceof JetObjectDeclaration) {
|
||||
JetDeclaration containingDeclaration = getContainingDeclaration(declaration);
|
||||
@@ -388,7 +388,7 @@ public class ModifiersChecker {
|
||||
if (isEnumEntry(descriptor)) {
|
||||
return Visibilities.PUBLIC;
|
||||
}
|
||||
if (isDefaultObject(descriptor)) {
|
||||
if (isCompanionObject(descriptor)) {
|
||||
return ((ClassDescriptor) descriptor.getContainingDeclaration()).getVisibility();
|
||||
}
|
||||
return Visibilities.INTERNAL;
|
||||
|
||||
@@ -121,9 +121,9 @@ public class OverloadResolver {
|
||||
return name;
|
||||
}
|
||||
if (jetClass instanceof JetObjectDeclaration) {
|
||||
// must be default object
|
||||
// must be companion object
|
||||
name = classDescriptor.getContainingDeclaration().getName().asString();
|
||||
return "default object " + name;
|
||||
return "companion object " + name;
|
||||
}
|
||||
// safe
|
||||
return "<unknown>";
|
||||
|
||||
@@ -92,8 +92,8 @@ public class TaskPrioritizer(private val storageManager: StorageManager) {
|
||||
val classifierDescriptor = qualifierReceiver.classifier
|
||||
doComputeTasks(classObjectReceiver, taskPrioritizerContext.filterCollectors {
|
||||
when {
|
||||
classifierDescriptor is ClassDescriptor && classifierDescriptor.getDefaultObjectDescriptor() != null -> {
|
||||
// nested classes and objects should not be accessible via short reference to default object
|
||||
classifierDescriptor is ClassDescriptor && classifierDescriptor.getCompanionObjectDescriptor() != null -> {
|
||||
// nested classes and objects should not be accessible via short reference to companion object
|
||||
it !is ConstructorDescriptor && it !is FakeCallableDescriptorForObject
|
||||
}
|
||||
classifierDescriptor != null && DescriptorUtils.isEnumEntry(classifierDescriptor) -> {
|
||||
|
||||
+2
-2
@@ -60,8 +60,8 @@ public class TracingStrategyImpl extends AbstractTracingStrategy {
|
||||
if (descriptor instanceof FakeCallableDescriptorForObject) {
|
||||
FakeCallableDescriptorForObject fakeCallableDescriptorForObject = (FakeCallableDescriptorForObject) descriptor;
|
||||
descriptor = fakeCallableDescriptorForObject.getReferencedDescriptor();
|
||||
if (fakeCallableDescriptorForObject.getClassDescriptor().getDefaultObjectDescriptor() != null) {
|
||||
trace.record(SHORT_REFERENCE_TO_DEFAULT_OBJECT, reference, fakeCallableDescriptorForObject.getClassDescriptor());
|
||||
if (fakeCallableDescriptorForObject.getClassDescriptor().getCompanionObjectDescriptor() != null) {
|
||||
trace.record(SHORT_REFERENCE_TO_COMPANION_OBJECT, reference, fakeCallableDescriptorForObject.getClassDescriptor());
|
||||
}
|
||||
}
|
||||
DeclarationDescriptor storedReference = trace.get(REFERENCE_TARGET, reference);
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public class FakeCallableDescriptorForObject(
|
||||
|
||||
{
|
||||
assert(classDescriptor.getClassObjectType() != null) {
|
||||
"FakeCallableDescriptorForObject can be created only for objects, classes with default object or enum entries: $classDescriptor"
|
||||
"FakeCallableDescriptorForObject can be created only for objects, classes with companion object or enum entries: $classDescriptor"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public interface JetClassLikeInfo extends JetDeclarationContainer {
|
||||
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
List<JetObjectDeclaration> getDefaultObjects();
|
||||
List<JetObjectDeclaration> getCompanionObjects();
|
||||
|
||||
// This element is used to identify resolution scope for the class
|
||||
@NotNull
|
||||
|
||||
+2
-2
@@ -58,12 +58,12 @@ public abstract class JetClassOrObjectInfo<E extends JetClassOrObject> implement
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetObjectDeclaration> getDefaultObjects() {
|
||||
public List<JetObjectDeclaration> getCompanionObjects() {
|
||||
JetClassBody body = element.getBody();
|
||||
if (body == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return body.getAllDefaultObjects();
|
||||
return body.getAllCompanionObjects();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -54,7 +54,7 @@ public class JetObjectInfo extends JetClassOrObjectInfo<JetObjectDeclaration> {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public boolean isDefaultObject() {
|
||||
return element.isDefault() && ModifiersChecker.isDefaultModifierAllowed(element);
|
||||
public boolean isCompanionObject() {
|
||||
return element.isCompanion() && ModifiersChecker.isDefaultModifierAllowed(element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class JetScriptInfo(
|
||||
public val fqName: FqName = ScriptNameUtil.classNameForScript(script)
|
||||
override fun getContainingPackageFqName() = fqName.parent()
|
||||
override fun getModifierList() = null
|
||||
override fun getDefaultObjects() = listOf<JetObjectDeclaration>()
|
||||
override fun getCompanionObjects() = listOf<JetObjectDeclaration>()
|
||||
override fun getScopeAnchor() = script
|
||||
override fun getCorrespondingClassOrObject() = null
|
||||
override fun getTypeParameterList() = null
|
||||
|
||||
+46
-46
@@ -83,8 +83,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
|
||||
private final Annotations annotations;
|
||||
private final Annotations danglingAnnotations;
|
||||
private final NullableLazyValue<LazyClassDescriptor> defaultObjectDescriptor;
|
||||
private final MemoizedFunctionToNotNull<JetObjectDeclaration, ClassDescriptor> extraDefaultObjectDescriptors;
|
||||
private final NullableLazyValue<LazyClassDescriptor> companionObjectDescriptor;
|
||||
private final MemoizedFunctionToNotNull<JetObjectDeclaration, ClassDescriptor> extraCompanionObjectDescriptors;
|
||||
|
||||
private final LazyClassMemberScope unsubstitutedMemberScope;
|
||||
private final JetScope staticScope = new StaticScopeForKotlinClass(this);
|
||||
@@ -95,7 +95,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
private final NotNullLazyValue<JetScope> scopeForSecondaryConstructorHeaderResolution;
|
||||
|
||||
private final NullableLazyValue<Void> forceResolveAllContents;
|
||||
private final boolean isDefaultObject;
|
||||
private final boolean isCompanionObject;
|
||||
|
||||
public LazyClassDescriptor(
|
||||
@NotNull LazyClassContext c,
|
||||
@@ -122,7 +122,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
this.typeConstructor = new LazyClassTypeConstructor();
|
||||
|
||||
this.kind = classLikeInfo.getClassKind();
|
||||
this.isDefaultObject = classLikeInfo instanceof JetObjectInfo && ((JetObjectInfo) classLikeInfo).isDefaultObject();
|
||||
this.isCompanionObject = classLikeInfo instanceof JetObjectInfo && ((JetObjectInfo) classLikeInfo).isCompanionObject();
|
||||
|
||||
JetModifierList modifierList = classLikeInfo.getModifierList();
|
||||
if (kind.isSingleton()) {
|
||||
@@ -182,16 +182,16 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
);
|
||||
}
|
||||
|
||||
this.defaultObjectDescriptor = storageManager.createNullableLazyValue(new Function0<LazyClassDescriptor>() {
|
||||
this.companionObjectDescriptor = storageManager.createNullableLazyValue(new Function0<LazyClassDescriptor>() {
|
||||
@Override
|
||||
public LazyClassDescriptor invoke() {
|
||||
return computeDefaultObjectDescriptor(getDefaultObjectIfAllowed());
|
||||
return computeCompanionObjectDescriptor(getCompanionObjectIfAllowed());
|
||||
}
|
||||
});
|
||||
this.extraDefaultObjectDescriptors = storageManager.createMemoizedFunction(new Function1<JetObjectDeclaration, ClassDescriptor>() {
|
||||
this.extraCompanionObjectDescriptors = storageManager.createMemoizedFunction(new Function1<JetObjectDeclaration, ClassDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor invoke(JetObjectDeclaration defaultObject) {
|
||||
return computeDefaultObjectDescriptor(defaultObject);
|
||||
public ClassDescriptor invoke(JetObjectDeclaration companionObject) {
|
||||
return computeCompanionObjectDescriptor(companionObject);
|
||||
}
|
||||
});
|
||||
this.scopeForClassHeaderResolution = storageManager.createLazyValue(new Function0<JetScope>() {
|
||||
@@ -277,8 +277,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
thisScope.setImplicitReceiver(this.getThisAsReceiverParameter());
|
||||
thisScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
ClassDescriptor defaultObjectDescriptor = getDefaultObjectDescriptor();
|
||||
JetScope defaultObjectAdapterScope = (defaultObjectDescriptor != null) ? new DefaultObjectMixinScope(defaultObjectDescriptor) : JetScope.Empty.INSTANCE$;
|
||||
ClassDescriptor companionObjectDescriptor = getCompanionObjectDescriptor();
|
||||
JetScope companionObjectAdapterScope = (companionObjectDescriptor != null) ? new CompanionObjectMixinScope(companionObjectDescriptor) : JetScope.Empty.INSTANCE$;
|
||||
|
||||
return new ChainedScope(
|
||||
this,
|
||||
@@ -286,7 +286,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
thisScope,
|
||||
getScopeForMemberLookup(),
|
||||
getScopeForClassHeaderResolution(),
|
||||
defaultObjectAdapterScope,
|
||||
companionObjectAdapterScope,
|
||||
getStaticScope()
|
||||
);
|
||||
}
|
||||
@@ -374,47 +374,47 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
|
||||
@Override
|
||||
public LazyClassDescriptor getDefaultObjectDescriptor() {
|
||||
return defaultObjectDescriptor.invoke();
|
||||
public LazyClassDescriptor getCompanionObjectDescriptor() {
|
||||
return companionObjectDescriptor.invoke();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
public List<ClassDescriptor> getDescriptorsForExtraDefaultObjects() {
|
||||
final JetObjectDeclaration allowedDefaultObject = getDefaultObjectIfAllowed();
|
||||
public List<ClassDescriptor> getDescriptorsForExtraCompanionObjects() {
|
||||
final JetObjectDeclaration allowedCompanionObject = getCompanionObjectIfAllowed();
|
||||
|
||||
return KotlinPackage.map(
|
||||
KotlinPackage.filter(
|
||||
declarationProvider.getOwnerInfo().getDefaultObjects(),
|
||||
declarationProvider.getOwnerInfo().getCompanionObjects(),
|
||||
new Function1<JetObjectDeclaration, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(JetObjectDeclaration defaultObject) {
|
||||
return defaultObject != allowedDefaultObject;
|
||||
public Boolean invoke(JetObjectDeclaration companionObject) {
|
||||
return companionObject != allowedCompanionObject;
|
||||
}
|
||||
}
|
||||
),
|
||||
new Function1<JetObjectDeclaration, ClassDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor invoke(JetObjectDeclaration defaultObject) {
|
||||
return extraDefaultObjectDescriptors.invoke(defaultObject);
|
||||
public ClassDescriptor invoke(JetObjectDeclaration companionObject) {
|
||||
return extraCompanionObjectDescriptors.invoke(companionObject);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private LazyClassDescriptor computeDefaultObjectDescriptor(@Nullable JetObjectDeclaration defaultObject) {
|
||||
JetClassLikeInfo defaultObjectInfo = getDefaultObjectInfo(defaultObject);
|
||||
if (!(defaultObjectInfo instanceof JetClassOrObjectInfo)) {
|
||||
private LazyClassDescriptor computeCompanionObjectDescriptor(@Nullable JetObjectDeclaration companionObject) {
|
||||
JetClassLikeInfo companionObjectInfo = getCompanionObjectInfo(companionObject);
|
||||
if (!(companionObjectInfo instanceof JetClassOrObjectInfo)) {
|
||||
return null;
|
||||
}
|
||||
Name name = ((JetClassOrObjectInfo) defaultObjectInfo).getName();
|
||||
Name name = ((JetClassOrObjectInfo) companionObjectInfo).getName();
|
||||
assert name != null;
|
||||
getScopeForMemberLookup().getClassifier(name);
|
||||
ClassDescriptor defaultObjectDescriptor = c.getTrace().get(BindingContext.CLASS, defaultObject);
|
||||
if (defaultObjectDescriptor instanceof LazyClassDescriptor) {
|
||||
assert DescriptorUtils.isDefaultObject(defaultObjectDescriptor) : "Not a default object: " + defaultObjectDescriptor;
|
||||
return (LazyClassDescriptor) defaultObjectDescriptor;
|
||||
ClassDescriptor companionObjectDescriptor = c.getTrace().get(BindingContext.CLASS, companionObject);
|
||||
if (companionObjectDescriptor instanceof LazyClassDescriptor) {
|
||||
assert DescriptorUtils.isCompanionObject(companionObjectDescriptor) : "Not a companion object: " + companionObjectDescriptor;
|
||||
return (LazyClassDescriptor) companionObjectDescriptor;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
@@ -422,25 +422,25 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JetClassLikeInfo getDefaultObjectInfo(@Nullable JetObjectDeclaration defaultObject) {
|
||||
if (defaultObject != null) {
|
||||
if (!isDefaultObjectAllowed()) {
|
||||
c.getTrace().report(DEFAULT_OBJECT_NOT_ALLOWED.on(defaultObject));
|
||||
private JetClassLikeInfo getCompanionObjectInfo(@Nullable JetObjectDeclaration companionObject) {
|
||||
if (companionObject != null) {
|
||||
if (!isCompanionObjectAllowed()) {
|
||||
c.getTrace().report(COMPANION_OBJECT_NOT_ALLOWED.on(companionObject));
|
||||
}
|
||||
|
||||
return JetClassInfoUtil.createClassLikeInfo(defaultObject);
|
||||
return JetClassInfoUtil.createClassLikeInfo(companionObject);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JetObjectDeclaration getDefaultObjectIfAllowed() {
|
||||
JetObjectDeclaration defaultObject = firstOrNull(declarationProvider.getOwnerInfo().getDefaultObjects());
|
||||
return (defaultObject != null && isDefaultObjectAllowed()) ? defaultObject : null;
|
||||
private JetObjectDeclaration getCompanionObjectIfAllowed() {
|
||||
JetObjectDeclaration companionObject = firstOrNull(declarationProvider.getOwnerInfo().getCompanionObjects());
|
||||
return (companionObject != null && isCompanionObjectAllowed()) ? companionObject : null;
|
||||
}
|
||||
|
||||
private boolean isDefaultObjectAllowed() {
|
||||
private boolean isCompanionObjectAllowed() {
|
||||
return !(getKind().isSingleton() || isInner() || DescriptorUtils.isLocal(this));
|
||||
}
|
||||
|
||||
@@ -468,8 +468,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefaultObject() {
|
||||
return isDefaultObject;
|
||||
public boolean isCompanionObject() {
|
||||
return isCompanionObject;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -496,13 +496,13 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
|
||||
private void doForceResolveAllContents() {
|
||||
resolveMemberHeaders();
|
||||
ClassDescriptor defaultObjectDescriptor = getDefaultObjectDescriptor();
|
||||
if (defaultObjectDescriptor != null) {
|
||||
ForceResolveUtil.forceResolveAllContents(defaultObjectDescriptor);
|
||||
ClassDescriptor companionObjectDescriptor = getCompanionObjectDescriptor();
|
||||
if (companionObjectDescriptor != null) {
|
||||
ForceResolveUtil.forceResolveAllContents(companionObjectDescriptor);
|
||||
}
|
||||
|
||||
ForceResolveUtil.forceResolveAllContents(getConstructors());
|
||||
ForceResolveUtil.forceResolveAllContents(getDescriptorsForExtraDefaultObjects());
|
||||
ForceResolveUtil.forceResolveAllContents(getDescriptorsForExtraCompanionObjects());
|
||||
ForceResolveUtil.forceResolveAllContents(getScopeForMemberLookup());
|
||||
ForceResolveUtil.forceResolveAllContents(getTypeConstructor());
|
||||
}
|
||||
@@ -512,9 +512,9 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
ForceResolveUtil.forceResolveAllContents(getAnnotations());
|
||||
ForceResolveUtil.forceResolveAllContents(getDanglingAnnotations());
|
||||
|
||||
getDefaultObjectDescriptor();
|
||||
getCompanionObjectDescriptor();
|
||||
|
||||
getDescriptorsForExtraDefaultObjects();
|
||||
getDescriptorsForExtraCompanionObjects();
|
||||
|
||||
getClassObjectType();
|
||||
getConstructors();
|
||||
|
||||
+1
-1
@@ -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 default objects do not have delegated members
|
||||
?: return setOf()
|
||||
|
||||
val lazyTypeResolver = DelegationResolver.TypeResolver { reference ->
|
||||
c.typeResolver.resolveType(thisDescriptor.getScopeForClassHeaderResolution(), reference, trace, false)
|
||||
|
||||
+2
-2
@@ -83,7 +83,7 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
|
||||
if (classOrObject instanceof JetClass) {
|
||||
JetClass jetClass = (JetClass) classOrObject;
|
||||
for (JetTypeConstraint jetTypeConstraint : jetClass.getTypeConstraints()) {
|
||||
DescriptorResolver.reportUnsupportedDefaultObjectConstraint(c.getTrace(), jetTypeConstraint);
|
||||
DescriptorResolver.reportUnsupportedCompanionObjectConstraint(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.isDefaultObjectConstraint()) {
|
||||
if (!jetTypeConstraint.isCompanionObjectConstraint()) {
|
||||
upperBounds.add(boundType);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.resolve.scopes
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
|
||||
/**
|
||||
* Members of the default object are accessible from the class.
|
||||
* Scope lazily delegates requests to default object scope.
|
||||
* Members of the companion object are accessible from the class.
|
||||
* Scope lazily delegates requests to companion object scope.
|
||||
*/
|
||||
public class DefaultObjectMixinScope(private val defaultObjectDescriptor: ClassDescriptor) : AbstractScopeAdapter() {
|
||||
public class CompanionObjectMixinScope(private val companionObjectDescriptor: ClassDescriptor) : AbstractScopeAdapter() {
|
||||
override val workerScope: JetScope
|
||||
get() = defaultObjectDescriptor.getDefaultType().getMemberScope()
|
||||
get() = companionObjectDescriptor.getDefaultType().getMemberScope()
|
||||
|
||||
override fun getImplicitReceiversHierarchy() = listOf(defaultObjectDescriptor.getThisAsReceiverParameter())
|
||||
override fun getImplicitReceiversHierarchy() = listOf(companionObjectDescriptor.getThisAsReceiverParameter())
|
||||
}
|
||||
|
||||
+2
-2
@@ -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 default object
|
||||
// members of the default object must be able to find it as an implicit receiver
|
||||
// Example: class member resolution scope imports a scope of it's companion object
|
||||
// members of the companion 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_DEFAULT_OBJECT.on(referenceExpression, classifier))
|
||||
context.trace.report(NO_COMPANION_OBJECT.on(referenceExpression, classifier))
|
||||
}
|
||||
else if (packageView != null) {
|
||||
context.trace.report(EXPRESSION_EXPECTED_PACKAGE_FOUND.on(referenceExpression))
|
||||
@@ -174,8 +174,8 @@ private fun QualifierReceiver.resolveReferenceTarget(
|
||||
(selector.getDispatchReceiverParameter() != null || selector.getExtensionReceiverParameter() != null)
|
||||
|
||||
if (classifier is ClassDescriptor && classifier.classObjectDescriptor != null && isCallableWithReceiver) {
|
||||
if (classifier.getDefaultObjectDescriptor() != null) {
|
||||
context.trace.record(SHORT_REFERENCE_TO_DEFAULT_OBJECT, referenceExpression, classifier)
|
||||
if (classifier.getCompanionObjectDescriptor() != null) {
|
||||
context.trace.record(SHORT_REFERENCE_TO_COMPANION_OBJECT, referenceExpression, classifier)
|
||||
}
|
||||
return classifier.getClassObjectReferenceTarget()
|
||||
}
|
||||
|
||||
+1
-1
@@ -180,7 +180,7 @@ class DeclarationScopeProviderForLocalClassifierAnalyzer(
|
||||
}
|
||||
|
||||
override fun getOuterDataFlowInfoForDeclaration(elementOfDeclaration: PsiElement): DataFlowInfo {
|
||||
// nested (non-inner) classes and default objects are forbidden in local classes, so it's enough to be simply inside the class
|
||||
// nested (non-inner) classes and companion objects are forbidden in local classes, so it's enough to be simply inside the class
|
||||
if (localClassDescriptorManager.insideMyClass(elementOfDeclaration)) {
|
||||
return localClassDescriptorManager.expressionTypingContext.dataFlowInfo
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user