Introduce VariableDescriptorForObject interface
Add implementations Use this interface instead of CLASS_OBJECT_DECLARATION key in BindingContext
This commit is contained in:
committed by
Alexander Udalov
parent
dc5bc1488c
commit
a57f74c278
+3
-3
@@ -295,9 +295,9 @@ public class DeserializedClassDescriptor extends ClassDescriptorBase implements
|
||||
}
|
||||
|
||||
private void createEnumEntry(@NotNull MutableClassDescriptor enumClassObject, @NotNull Name name) {
|
||||
PropertyDescriptorImpl property = new PropertyDescriptorImpl(enumClassObject, Collections.<AnnotationDescriptor>emptyList(),
|
||||
Modality.FINAL, Visibilities.PUBLIC, false, name,
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
PropertyDescriptorImpl property = new PropertyDescriptorForObjectImpl(enumClassObject,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
Visibilities.PUBLIC, name, this);
|
||||
property.setType(getDefaultType(), Collections.<TypeParameterDescriptor>emptyList(),
|
||||
enumClassObject.getThisAsReceiverParameter(), NO_RECEIVER_PARAMETER);
|
||||
|
||||
|
||||
@@ -18,10 +18,7 @@ package org.jetbrains.jet.lang.cfg;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
@@ -90,11 +87,11 @@ public final class WhenChecker {
|
||||
if (reference == null) return false;
|
||||
|
||||
DeclarationDescriptor target = trace.get(BindingContext.REFERENCE_TARGET, reference);
|
||||
if (!(target instanceof VariableDescriptor)) {
|
||||
if (!(target instanceof VariableDescriptorForObject)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ClassDescriptor classDescriptor = trace.get(BindingContext.OBJECT_DECLARATION_CLASS, (VariableDescriptor) target);
|
||||
ClassDescriptor classDescriptor = ((VariableDescriptorForObject) target).getObjectClass();
|
||||
return classDescriptor == enumEntry;
|
||||
}
|
||||
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface VariableDescriptorForObject extends VariableDescriptor {
|
||||
@NotNull
|
||||
ClassDescriptor getObjectClass();
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptorForObject;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LocalVariableDescriptorForObject extends LocalVariableDescriptor implements VariableDescriptorForObject {
|
||||
|
||||
private final ClassDescriptor objectClass;
|
||||
|
||||
public LocalVariableDescriptorForObject(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Name name,
|
||||
@NotNull ClassDescriptor objectClass
|
||||
) {
|
||||
super(containingDeclaration, annotations, name, objectClass.getDefaultType(), false);
|
||||
this.objectClass = objectClass;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassDescriptor getObjectClass() {
|
||||
return objectClass;
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PropertyDescriptorForObjectImpl extends PropertyDescriptorImpl implements VariableDescriptorForObject {
|
||||
|
||||
private final ClassDescriptor objectClass;
|
||||
|
||||
public PropertyDescriptorForObjectImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Visibility visibility,
|
||||
@NotNull Name name,
|
||||
@NotNull ClassDescriptor objectClass
|
||||
) {
|
||||
super(containingDeclaration, annotations, Modality.FINAL, visibility, false, name, Kind.DECLARATION);
|
||||
this.objectClass = objectClass;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassDescriptor getObjectClass() {
|
||||
return objectClass;
|
||||
}
|
||||
}
|
||||
@@ -142,8 +142,6 @@ public interface BindingContext {
|
||||
|
||||
WritableSlice<Box<DeferredType>, Boolean> DEFERRED_TYPE = Slices.createCollectiveSetSlice();
|
||||
|
||||
WritableSlice<VariableDescriptor, ClassDescriptor> OBJECT_DECLARATION_CLASS = Slices.createSimpleSlice();
|
||||
|
||||
WritableSlice<PropertyDescriptor, Boolean> BACKING_FIELD_REQUIRED = new Slices.SetSlice<PropertyDescriptor>(DO_NOTHING) {
|
||||
@Override
|
||||
public Boolean computeValue(
|
||||
|
||||
@@ -840,19 +840,16 @@ public class DescriptorResolver {
|
||||
@NotNull ClassDescriptor classDescriptor, BindingTrace trace
|
||||
) {
|
||||
JetModifierList modifierList = objectDeclaration.getModifierList();
|
||||
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorImpl(
|
||||
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorForObjectImpl(
|
||||
containingDeclaration,
|
||||
annotationResolver.getResolvedAnnotations(modifierList, trace),
|
||||
Modality.FINAL,
|
||||
resolveVisibilityFromModifiers(objectDeclaration, getDefaultVisibilityForObjectPropertyDescriptor(classDescriptor)),
|
||||
false,
|
||||
JetPsiUtil.safeName(objectDeclaration.getName()),
|
||||
CallableMemberDescriptor.Kind.DECLARATION
|
||||
classDescriptor
|
||||
);
|
||||
propertyDescriptor.setType(getTypeForObjectDeclaration(classDescriptor), Collections.<TypeParameterDescriptor>emptyList(),
|
||||
getExpectedThisObjectIfNeeded(containingDeclaration), NO_RECEIVER_PARAMETER);
|
||||
propertyDescriptor.initialize(null, null);
|
||||
trace.record(BindingContext.OBJECT_DECLARATION_CLASS, propertyDescriptor, classDescriptor);
|
||||
JetObjectDeclarationName nameAsDeclaration = objectDeclaration.getNameAsDeclaration();
|
||||
if (nameAsDeclaration != null) {
|
||||
trace.record(BindingContext.OBJECT_DECLARATION, nameAsDeclaration, propertyDescriptor);
|
||||
@@ -878,13 +875,11 @@ public class DescriptorResolver {
|
||||
@NotNull JetClassOrObject objectDeclaration,
|
||||
@NotNull ClassDescriptor classDescriptor, BindingTrace trace
|
||||
) {
|
||||
VariableDescriptorImpl variableDescriptor = new LocalVariableDescriptor(
|
||||
VariableDescriptorImpl variableDescriptor = new LocalVariableDescriptorForObject(
|
||||
containingDeclaration,
|
||||
annotationResolver.getResolvedAnnotations(objectDeclaration.getModifierList(), trace),
|
||||
JetPsiUtil.safeName(objectDeclaration.getName()),
|
||||
classDescriptor.getDefaultType(),
|
||||
/*isVar =*/ false);
|
||||
trace.record(BindingContext.OBJECT_DECLARATION_CLASS, variableDescriptor, classDescriptor);
|
||||
classDescriptor);
|
||||
JetObjectDeclarationName nameAsDeclaration = objectDeclaration.getNameAsDeclaration();
|
||||
if (nameAsDeclaration != null) {
|
||||
trace.record(BindingContext.VARIABLE, nameAsDeclaration, variableDescriptor);
|
||||
|
||||
+1
-2
@@ -325,8 +325,7 @@ public class QualifiedExpressionResolver {
|
||||
public boolean apply(@Nullable DeclarationDescriptor descriptor) {
|
||||
return (descriptor instanceof NamespaceDescriptor) ||
|
||||
(descriptor instanceof ClassifierDescriptor) ||
|
||||
((descriptor instanceof PropertyDescriptor) &&
|
||||
(trace.get(BindingContext.OBJECT_DECLARATION_CLASS, ((PropertyDescriptor) descriptor)) != null));
|
||||
(descriptor instanceof VariableDescriptorForObject);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user