Remove NumberValueTypeConstructor
This commit is contained in:
+1
-1
@@ -51,5 +51,5 @@ public interface AnnotationArgumentVisitor<R, D> {
|
||||
|
||||
R visitJavaClassValue(JavaClassValue value, D data);
|
||||
|
||||
R visitNumberTypeValue(NumberValueTypeConstant value, D data);
|
||||
R visitNumberTypeValue(IntegerValueTypeConstant value, D data);
|
||||
}
|
||||
|
||||
+16
-2
@@ -27,7 +27,13 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public abstract class NumberValueTypeConstant<T extends Number> implements CompileTimeConstant<NumberValueTypeConstructor<T>> {
|
||||
public class IntegerValueTypeConstant implements CompileTimeConstant<IntegerValueTypeConstructor> {
|
||||
|
||||
private final IntegerValueTypeConstructor value;
|
||||
|
||||
public IntegerValueTypeConstant(long value) {
|
||||
this.value = new IntegerValueTypeConstructor(value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -43,6 +49,14 @@ public abstract class NumberValueTypeConstant<T extends Number> implements Compi
|
||||
return visitor.visitNumberTypeValue(this, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public abstract NumberValueTypeConstructor<T> getValue();
|
||||
public IntegerValueTypeConstructor getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.resolve.constants;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class IntegerValueTypeConstructor implements TypeConstructor {
|
||||
private final long value;
|
||||
private final Collection<JetType> supertypes = Lists.newArrayList();
|
||||
|
||||
public IntegerValueTypeConstructor(long value) {
|
||||
// order of types matters
|
||||
// 'getPrimitiveNumberType' returns first of supertypes that is a subtype of expected type
|
||||
// for expected type 'Any' result type 'Int' should be returned
|
||||
this.value = value;
|
||||
checkBoundsAndAddSuperType(value, (long) Integer.MIN_VALUE, (long) Integer.MAX_VALUE, KotlinBuiltIns.getInstance().getIntType());
|
||||
checkBoundsAndAddSuperType(value, (long) Byte.MIN_VALUE, (long) Byte.MAX_VALUE, KotlinBuiltIns.getInstance().getByteType());
|
||||
checkBoundsAndAddSuperType(value, (long) Short.MIN_VALUE, (long) Short.MAX_VALUE, KotlinBuiltIns.getInstance().getShortType());
|
||||
supertypes.add(KotlinBuiltIns.getInstance().getLongType());
|
||||
}
|
||||
|
||||
private void checkBoundsAndAddSuperType(long value, long minValue, long maxValue, JetType kotlinType) {
|
||||
if (value >= minValue && value <= maxValue) {
|
||||
supertypes.add(kotlinType);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetType> getSupertypes() {
|
||||
return supertypes;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getParameters() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFinal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDenotable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ClassifierDescriptor getDeclarationDescriptor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<AnnotationDescriptor> getAnnotations() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public Long getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "IntegerValueType(" + value + ")";
|
||||
}
|
||||
}
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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.resolve.constants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class NumberValueTypeConstructor<T extends Number> implements TypeConstructor {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getParameters() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFinal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDenotable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ClassifierDescriptor getDeclarationDescriptor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<AnnotationDescriptor> getAnnotations() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public abstract T getValue();
|
||||
}
|
||||
@@ -33,7 +33,7 @@ import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl;
|
||||
import org.jetbrains.jet.lang.resolve.constants.NumberValueTypeConstructor;
|
||||
import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstructor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.ChainedScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
@@ -594,7 +594,7 @@ public class TypeUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType getDefaultPrimitiveNumberType(@NotNull NumberValueTypeConstructor numberValueTypeConstructor) {
|
||||
public static JetType getDefaultPrimitiveNumberType(@NotNull IntegerValueTypeConstructor numberValueTypeConstructor) {
|
||||
JetType type = getDefaultPrimitiveNumberType(numberValueTypeConstructor.getSupertypes());
|
||||
assert type != null : "Strange number value type constructor: " + numberValueTypeConstructor + ". " +
|
||||
"Super types doesn't contain double, int or long: " + numberValueTypeConstructor.getSupertypes();
|
||||
@@ -620,7 +620,7 @@ public class TypeUtils {
|
||||
|
||||
@NotNull
|
||||
public static JetType getPrimitiveNumberType(
|
||||
@NotNull NumberValueTypeConstructor numberValueTypeConstructor,
|
||||
@NotNull IntegerValueTypeConstructor numberValueTypeConstructor,
|
||||
@NotNull JetType expectedType
|
||||
) {
|
||||
if (noExpectedType(expectedType) || expectedType.isError()) {
|
||||
@@ -639,7 +639,7 @@ public class TypeUtils {
|
||||
Collection<JetType> numberTypes = Sets.newLinkedHashSet();
|
||||
Collection<JetType> otherTypes = Sets.newLinkedHashSet();
|
||||
for (JetType type : types) {
|
||||
if (type.getConstructor() instanceof NumberValueTypeConstructor) {
|
||||
if (type.getConstructor() instanceof IntegerValueTypeConstructor) {
|
||||
numberTypes.add(type);
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user