Extract VariableDescriptorWithInitializerImpl out of VariableDescriptorImpl
Because ValueParameterDescriptorImpl extends from VariableDescriptorImpl, but it never has a compile-time initializer, so it was always storing an extra null
This commit is contained in:
+2
-10
@@ -24,9 +24,7 @@ import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
||||
|
||||
public class LocalVariableDescriptor extends VariableDescriptorImpl {
|
||||
private final boolean isVar;
|
||||
|
||||
public class LocalVariableDescriptor extends VariableDescriptorWithInitializerImpl {
|
||||
public LocalVariableDescriptor(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull Annotations annotations,
|
||||
@@ -35,8 +33,7 @@ public class LocalVariableDescriptor extends VariableDescriptorImpl {
|
||||
boolean mutable,
|
||||
@NotNull SourceElement source
|
||||
) {
|
||||
super(containingDeclaration, annotations, name, type, source);
|
||||
isVar = mutable;
|
||||
super(containingDeclaration, annotations, name, type, mutable, source);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -51,11 +48,6 @@ public class LocalVariableDescriptor extends VariableDescriptorImpl {
|
||||
return visitor.visitVariableDescriptor(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVar() {
|
||||
return isVar;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
|
||||
@@ -629,7 +629,7 @@ public class DescriptorResolver {
|
||||
result = propertyDescriptor;
|
||||
}
|
||||
else {
|
||||
VariableDescriptorImpl variableDescriptor =
|
||||
LocalVariableDescriptor variableDescriptor =
|
||||
resolveLocalVariableDescriptorWithType(scope, variable, null, trace);
|
||||
// For a local variable the type must not be deferred
|
||||
type = getVariableType(variableDescriptor, scope, variable, dataFlowInfo, false, trace);
|
||||
@@ -656,13 +656,13 @@ public class DescriptorResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public VariableDescriptorImpl resolveLocalVariableDescriptorWithType(
|
||||
public LocalVariableDescriptor resolveLocalVariableDescriptorWithType(
|
||||
@NotNull JetScope scope,
|
||||
@NotNull JetVariableDeclaration variable,
|
||||
@Nullable JetType type,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
VariableDescriptorImpl variableDescriptor = new LocalVariableDescriptor(
|
||||
LocalVariableDescriptor variableDescriptor = new LocalVariableDescriptor(
|
||||
scope.getContainingDeclaration(),
|
||||
annotationResolver.resolveAnnotationsWithArguments(scope, variable.getModifierList(), trace),
|
||||
JetPsiUtil.safeName(variable.getName()),
|
||||
@@ -768,7 +768,7 @@ public class DescriptorResolver {
|
||||
|
||||
@NotNull
|
||||
private JetType getVariableType(
|
||||
@NotNull final VariableDescriptorImpl variableDescriptor,
|
||||
@NotNull final VariableDescriptorWithInitializerImpl variableDescriptor,
|
||||
@NotNull final JetScope scope,
|
||||
@NotNull final JetVariableDeclaration variable,
|
||||
@NotNull final DataFlowInfo dataFlowInfo,
|
||||
@@ -830,7 +830,7 @@ public class DescriptorResolver {
|
||||
}
|
||||
|
||||
private void setConstantForVariableIfNeeded(
|
||||
@NotNull VariableDescriptorImpl variableDescriptor,
|
||||
@NotNull VariableDescriptorWithInitializerImpl variableDescriptor,
|
||||
@NotNull final JetScope scope,
|
||||
@NotNull final JetVariableDeclaration variable,
|
||||
@NotNull final DataFlowInfo dataFlowInfo,
|
||||
|
||||
+2
-9
@@ -33,10 +33,9 @@ import java.util.*;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
|
||||
|
||||
public class PropertyDescriptorImpl extends VariableDescriptorImpl implements PropertyDescriptor {
|
||||
public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImpl implements PropertyDescriptor {
|
||||
private final Modality modality;
|
||||
private Visibility visibility;
|
||||
private final boolean isVar;
|
||||
private final Set<PropertyDescriptor> overriddenProperties = new LinkedHashSet<PropertyDescriptor>(); // LinkedHashSet is essential here
|
||||
private final PropertyDescriptor original;
|
||||
private final Kind kind;
|
||||
@@ -59,8 +58,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
|
||||
@NotNull Kind kind,
|
||||
@NotNull SourceElement source
|
||||
) {
|
||||
super(containingDeclaration, annotations, name, null, source);
|
||||
this.isVar = isVar;
|
||||
super(containingDeclaration, annotations, name, null, isVar, source);
|
||||
this.modality = modality;
|
||||
this.visibility = visibility;
|
||||
this.original = original == null ? this : original;
|
||||
@@ -142,11 +140,6 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
|
||||
return getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVar() {
|
||||
return isVar;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Modality getModality() {
|
||||
|
||||
+7
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
||||
|
||||
@@ -98,6 +99,12 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ConstantValue<?> getCompileTimeInitializer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ValueParameterDescriptor copy(@NotNull CallableDescriptor newOwner, @NotNull Name newName) {
|
||||
|
||||
+1
-24
@@ -21,18 +21,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||
import org.jetbrains.kotlin.storage.NullableLazyValue;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.LazyType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class VariableDescriptorImpl extends DeclarationDescriptorNonRootImpl implements VariableDescriptor {
|
||||
private JetType outType;
|
||||
protected NullableLazyValue<ConstantValue<?>> compileTimeInitializer;
|
||||
protected JetType outType;
|
||||
|
||||
public VariableDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@@ -57,25 +53,6 @@ public abstract class VariableDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
this.outType = outType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ConstantValue<?> getCompileTimeInitializer() {
|
||||
// Force computation and setting of compileTimeInitializer, if needed
|
||||
if (compileTimeInitializer == null && outType instanceof LazyType) {
|
||||
outType.getConstructor();
|
||||
}
|
||||
|
||||
if (compileTimeInitializer != null) {
|
||||
return compileTimeInitializer.invoke();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setCompileTimeInitializer(@NotNull NullableLazyValue<ConstantValue<?>> compileTimeInitializer) {
|
||||
assert !isVar() : "Compile-time value for property initializer should be recorded only for final variables " + getName();
|
||||
this.compileTimeInitializer = compileTimeInitializer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public VariableDescriptor getOriginal() {
|
||||
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||
import org.jetbrains.kotlin.storage.NullableLazyValue;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.LazyType;
|
||||
|
||||
public abstract class VariableDescriptorWithInitializerImpl extends VariableDescriptorImpl {
|
||||
private final boolean isVar;
|
||||
|
||||
protected NullableLazyValue<ConstantValue<?>> compileTimeInitializer;
|
||||
|
||||
public VariableDescriptorWithInitializerImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull Annotations annotations,
|
||||
@NotNull Name name,
|
||||
@Nullable JetType outType,
|
||||
boolean isVar,
|
||||
@NotNull SourceElement source
|
||||
) {
|
||||
super(containingDeclaration, annotations, name, outType, source);
|
||||
|
||||
this.isVar = isVar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVar() {
|
||||
return isVar;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ConstantValue<?> getCompileTimeInitializer() {
|
||||
// Force computation and setting of compileTimeInitializer, if needed
|
||||
if (compileTimeInitializer == null && outType instanceof LazyType) {
|
||||
outType.getConstructor();
|
||||
}
|
||||
|
||||
if (compileTimeInitializer != null) {
|
||||
return compileTimeInitializer.invoke();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setCompileTimeInitializer(@NotNull NullableLazyValue<ConstantValue<?>> compileTimeInitializer) {
|
||||
assert !isVar() : "Constant value for variable initializer should be recorded only for final variables: " + getName();
|
||||
this.compileTimeInitializer = compileTimeInitializer;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user