Unused infrastructure of MutableClassDescriptor removed
This commit is contained in:
-65
@@ -314,71 +314,6 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
getWritableScopeForInitializers().changeLockLevel(WritableScope.LockLevel.READING);
|
||||
}
|
||||
|
||||
private PackageLikeBuilder builder = null;
|
||||
|
||||
@NotNull
|
||||
public PackageLikeBuilder getBuilder() {
|
||||
if (builder == null) {
|
||||
builder = new PackageLikeBuilder() {
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOwnerForChildren() {
|
||||
return MutableClassDescriptor.this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor) {
|
||||
getScopeForMemberLookupAsWritableScope().addClassifierDescriptor(classDescriptor);
|
||||
scopeForMemberResolution.addClassifierDescriptor(classDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
||||
getScopeForMemberLookupAsWritableScope().addFunctionDescriptor(functionDescriptor);
|
||||
functions.add(functionDescriptor);
|
||||
if (functionDescriptor.getKind().isReal()) {
|
||||
declaredCallableMembers.add(functionDescriptor);
|
||||
}
|
||||
allCallableMembers.add(functionDescriptor);
|
||||
scopeForMemberResolution.addFunctionDescriptor(functionDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||
if (getKind() == ClassKind.CLASS_OBJECT || isInner()) {
|
||||
return ClassObjectStatus.NOT_ALLOWED;
|
||||
}
|
||||
|
||||
if (MutableClassDescriptor.this.classObjectDescriptor != null) {
|
||||
return ClassObjectStatus.DUPLICATE;
|
||||
}
|
||||
|
||||
assert classObjectDescriptor.getKind() == ClassKind.CLASS_OBJECT;
|
||||
MutableClassDescriptor.this.classObjectDescriptor = classObjectDescriptor;
|
||||
|
||||
// Members of the class object are accessible from the class
|
||||
// The scope must be lazy, because classObjectDescriptor may not by fully built yet
|
||||
scopeForMemberResolution.importScope(new ClassObjectMixinScope(classObjectDescriptor));
|
||||
|
||||
return ClassObjectStatus.OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
getScopeForMemberLookupAsWritableScope().addPropertyDescriptor(propertyDescriptor);
|
||||
properties.add(propertyDescriptor);
|
||||
if (propertyDescriptor.getKind().isReal()) {
|
||||
declaredCallableMembers.add(propertyDescriptor);
|
||||
}
|
||||
allCallableMembers.add(propertyDescriptor);
|
||||
scopeForMemberResolution.addPropertyDescriptor(propertyDescriptor);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return DeclarationDescriptorImpl.toString(this);
|
||||
|
||||
-7
@@ -26,14 +26,12 @@ import org.jetbrains.kotlin.resolve.scopes.WritableScopeImpl;
|
||||
|
||||
public class MutablePackageFragmentDescriptor extends PackageFragmentDescriptorImpl {
|
||||
private final WritableScope scope;
|
||||
private final PackageLikeBuilder builder;
|
||||
|
||||
public MutablePackageFragmentDescriptor(@NotNull ModuleDescriptor module, @NotNull FqName fqName) {
|
||||
super(module, fqName);
|
||||
|
||||
scope = new WritableScopeImpl(JetScope.Empty.INSTANCE$, this, RedeclarationHandler.DO_NOTHING, "Members of " + fqName + " in " + module);
|
||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
builder = new ScopeBasedPackageLikeBuilder(this, scope);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -41,9 +39,4 @@ public class MutablePackageFragmentDescriptor extends PackageFragmentDescriptorI
|
||||
public WritableScope getMemberScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PackageLikeBuilder getBuilder() {
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
|
||||
|
||||
public interface PackageLikeBuilder {
|
||||
@NotNull
|
||||
DeclarationDescriptor getOwnerForChildren();
|
||||
|
||||
void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor);
|
||||
|
||||
void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor);
|
||||
|
||||
void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor);
|
||||
|
||||
enum ClassObjectStatus {
|
||||
OK,
|
||||
DUPLICATE,
|
||||
NOT_ALLOWED
|
||||
}
|
||||
|
||||
ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor);
|
||||
}
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
|
||||
|
||||
public class PackageLikeBuilderDummy implements PackageLikeBuilder {
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOwnerForChildren() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.scopes.WritableScope;
|
||||
|
||||
public class ScopeBasedPackageLikeBuilder implements PackageLikeBuilder {
|
||||
private final DeclarationDescriptor containingDeclaration;
|
||||
private final WritableScope scope;
|
||||
|
||||
ScopeBasedPackageLikeBuilder(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull WritableScope scope
|
||||
) {
|
||||
this.containingDeclaration = containingDeclaration;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOwnerForChildren() {
|
||||
return containingDeclaration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor) {
|
||||
scope.addClassifierDescriptor(classDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
||||
scope.addFunctionDescriptor(functionDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
scope.addPropertyDescriptor(propertyDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||
throw new IllegalStateException("Must be guaranteed not to happen by the parser");
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,10 @@
|
||||
package org.jetbrains.kotlin.resolve;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.MutableClassDescriptor;
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject;
|
||||
import org.jetbrains.kotlin.psi.JetDelegationSpecifier;
|
||||
import org.jetbrains.kotlin.psi.JetDelegatorByExpressionSpecifier;
|
||||
@@ -30,7 +28,10 @@ import org.jetbrains.kotlin.psi.JetTypeReference;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.DELEGATION;
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.MANY_IMPL_MEMBER_NOT_IMPLEMENTED;
|
||||
@@ -38,43 +39,6 @@ import static org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityI
|
||||
|
||||
public final class DelegationResolver<T extends CallableMemberDescriptor> {
|
||||
|
||||
public static void generateDelegatesInAClass(
|
||||
@NotNull MutableClassDescriptor classDescriptor,
|
||||
@NotNull final BindingTrace trace,
|
||||
@NotNull JetClassOrObject jetClassOrObject
|
||||
) {
|
||||
TypeResolver eagerTypeResolver = new TypeResolver() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JetType resolve(@NotNull JetTypeReference reference) {
|
||||
return trace.get(BindingContext.TYPE, reference);
|
||||
}
|
||||
};
|
||||
MemberExtractor<CallableMemberDescriptor> eagerExtractor = new MemberExtractor<CallableMemberDescriptor>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<CallableMemberDescriptor> getMembersByType(@NotNull JetType type) {
|
||||
//noinspection unchecked
|
||||
return (Collection) Collections2.filter(type.getMemberScope().getAllDescriptors(),
|
||||
Predicates.instanceOf(CallableMemberDescriptor.class));
|
||||
}
|
||||
};
|
||||
Set<CallableMemberDescriptor> existingMembers = classDescriptor.getAllCallableMembers();
|
||||
Collection<CallableMemberDescriptor> delegatedMembers =
|
||||
generateDelegatedMembers(jetClassOrObject, classDescriptor, existingMembers, trace, eagerExtractor, eagerTypeResolver);
|
||||
for (CallableMemberDescriptor descriptor : delegatedMembers) {
|
||||
if (descriptor instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
classDescriptor.getBuilder().addPropertyDescriptor(propertyDescriptor);
|
||||
}
|
||||
else if (descriptor instanceof SimpleFunctionDescriptor) {
|
||||
SimpleFunctionDescriptor functionDescriptor = (SimpleFunctionDescriptor) descriptor;
|
||||
classDescriptor.getBuilder().addFunctionDescriptor(functionDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static <T extends CallableMemberDescriptor> Collection<T> generateDelegatedMembers(
|
||||
@NotNull JetClassOrObject classOrObject,
|
||||
|
||||
Reference in New Issue
Block a user