Use one method to create compile-time value
This commit is contained in:
+1
-2
@@ -48,7 +48,6 @@ import org.jetbrains.jet.lang.resolve.java.lazy.types.toAttributes
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer
|
||||
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap
|
||||
import org.jetbrains.jet.lang.types.TypeUtils
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.resolveCompileTimeConstantValue
|
||||
|
||||
private object DEPRECATED_IN_JAVA : JavaLiteralAnnotationArgument {
|
||||
override fun getName(): Name? = null
|
||||
@@ -109,7 +108,7 @@ class LazyJavaAnnotationDescriptor(
|
||||
|
||||
private fun resolveAnnotationArgument(argument: JavaAnnotationArgument?): CompileTimeConstant<*>? {
|
||||
return when (argument) {
|
||||
is JavaLiteralAnnotationArgument -> ConstantUtils.createCompileTimeConstant(argument.getValue(), true, false, null)
|
||||
is JavaLiteralAnnotationArgument -> createCompileTimeConstant(argument.getValue(), true, false, null)
|
||||
is JavaReferenceAnnotationArgument -> resolveFromReference(argument.resolve())
|
||||
is JavaArrayAnnotationArgument -> resolveFromArray(argument.getName() ?: DEFAULT_ANNOTATION_MEMBER_NAME, argument.getElements())
|
||||
is JavaAnnotationAsAnnotationArgument -> resolveFromAnnotation(argument.getAnnotation())
|
||||
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.java.resolver
|
||||
|
||||
import org.jetbrains.jet.lang.resolve.constants.*
|
||||
import org.jetbrains.jet.lang.types.JetType
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
|
||||
fun resolveCompileTimeConstantValue(value: Any?, canBeUsedInAnnotations: Boolean, expectedType: JetType?): CompileTimeConstant<*>? {
|
||||
return when (value) {
|
||||
is String -> StringValue(value, canBeUsedInAnnotations)
|
||||
is Byte -> ByteValue(value, canBeUsedInAnnotations, false)
|
||||
is Short -> ShortValue(value, canBeUsedInAnnotations, false)
|
||||
is Char -> CharValue(value, canBeUsedInAnnotations, false)
|
||||
is Int -> {
|
||||
val builtIns = KotlinBuiltIns.getInstance()
|
||||
when (expectedType) {
|
||||
builtIns.getShortType() -> ShortValue(value.toShort(), canBeUsedInAnnotations, false)
|
||||
builtIns.getByteType() -> ByteValue(value.toByte(), canBeUsedInAnnotations, false)
|
||||
builtIns.getCharType() -> CharValue(value.toChar(), canBeUsedInAnnotations, false)
|
||||
else -> IntValue(value, canBeUsedInAnnotations, false)
|
||||
}
|
||||
}
|
||||
is Long -> LongValue(value, canBeUsedInAnnotations, false)
|
||||
is Float -> FloatValue(value, canBeUsedInAnnotations)
|
||||
is Double -> DoubleValue(value, canBeUsedInAnnotations)
|
||||
is Boolean -> BooleanValue(value, canBeUsedInAnnotations)
|
||||
null -> NullValue.NULL
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
+2
-6
@@ -27,15 +27,11 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationsImpl;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.constants.ConstantUtils;
|
||||
import org.jetbrains.jet.lang.resolve.constants.EnumValue;
|
||||
import org.jetbrains.jet.lang.resolve.constants.ErrorValue;
|
||||
import org.jetbrains.jet.lang.resolve.constants.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.ErrorReporter;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.ResolverPackage;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.DependencyClassByQualifiedNameResolver;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
@@ -135,7 +131,7 @@ public class AnnotationDescriptorDeserializer extends BaseDescriptorDeserializer
|
||||
@Override
|
||||
public void visit(@Nullable Name name, @Nullable Object value) {
|
||||
if (name != null) {
|
||||
CompileTimeConstant<?> argument = ConstantUtils.createCompileTimeConstant(value, true, false, null);
|
||||
CompileTimeConstant<?> argument = ConstantsPackage.createCompileTimeConstant(value, true, false, null);
|
||||
setArgumentValueByName(name, argument != null ? argument : ErrorValue.create("Unsupported annotation argument: " + name));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ public class DescriptorDeserializersStorage {
|
||||
public KotlinJvmBinaryClass.AnnotationVisitor visitField(@NotNull Name name, @NotNull String desc, @Nullable Object initializer) {
|
||||
MemberSignature signature = MemberSignature.fromFieldNameAndDesc(name, desc);
|
||||
if (initializer != null) {
|
||||
propertyConstants.put(signature, ConstantUtils.createCompileTimeConstant(
|
||||
propertyConstants.put(signature, ConstantsPackage.createCompileTimeConstant(
|
||||
initializer, /* canBeUsedInAnnotation */ true, /* isPureIntConstant */ true, /* expectedType */ null));
|
||||
}
|
||||
return new MemberAnnotationVisitor(signature);
|
||||
|
||||
Reference in New Issue
Block a user