Annotation parameter processing util
This commit is contained in:
+1
-1
@@ -65,7 +65,7 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
||||
) {
|
||||
super.initialize(receiverParameterType, expectedThisObject, typeParameters, unsubstitutedValueParameters, unsubstitutedReturnType,
|
||||
modality, visibility);
|
||||
this.inlineStrategy = InlineUtil.getInlineType(getAnnotations());
|
||||
this.inlineStrategy = InlineUtil.getInlineType(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.types.lang
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations
|
||||
|
||||
public object AnnotationUtil {
|
||||
|
||||
public fun getAnnotationSingleArgument(descriptor: DeclarationDescriptor, annotationClass: ClassDescriptor) : CompileTimeConstant<out Any?>? {
|
||||
val annotation = getAnnotation(descriptor.getAnnotations(), annotationClass)
|
||||
|
||||
if (annotation != null) {
|
||||
val parameterDescriptor = annotationClass.getConstructors().elementAt(0).getValueParameters().first
|
||||
if (parameterDescriptor != null) {
|
||||
return annotation.getValueArgument(parameterDescriptor)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
public fun getAnnotation(annotations: Annotations, annotationClass: ClassDescriptor): AnnotationDescriptor? {
|
||||
for (annotation in annotations) {
|
||||
if (annotationClass == annotation.getType().getConstructor().getDeclarationDescriptor()) {
|
||||
return annotation
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -17,12 +17,11 @@
|
||||
package org.jetbrains.jet.lang.types.lang;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.resolve.constants.ArrayValue;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.constants.EnumValue;
|
||||
@@ -37,13 +36,11 @@ public class InlineUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static InlineStrategy getInlineType(@Nullable Annotations annotations) {
|
||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||
ClassDescriptor annotationClass = builtIns.getInlineClassAnnotation();
|
||||
AnnotationDescriptor annotation = getAnnotation(annotations, annotationClass);
|
||||
public static InlineStrategy getInlineType(@NotNull DeclarationDescriptor descriptor) {
|
||||
ClassDescriptor annotationClass = KotlinBuiltIns.getInstance().getInlineClassAnnotation();
|
||||
AnnotationDescriptor annotation = AnnotationUtil.instance$.getAnnotation(descriptor.getAnnotations(), annotationClass);
|
||||
if (annotation != null) {
|
||||
ValueParameterDescriptor parameterDescriptor = annotationClass.getConstructors().iterator().next().getValueParameters().get(0);
|
||||
CompileTimeConstant<?> argument = annotation.getValueArgument(parameterDescriptor);
|
||||
CompileTimeConstant<?> argument = AnnotationUtil.instance$.getAnnotationSingleArgument(descriptor, annotationClass);
|
||||
if (argument == null) {
|
||||
//default parameter
|
||||
return InlineStrategy.AS_FUNCTION;
|
||||
@@ -59,18 +56,6 @@ public class InlineUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static AnnotationDescriptor getAnnotation(@Nullable Annotations annotations, @NotNull ClassDescriptor annotationClass) {
|
||||
if (annotations != null) {
|
||||
for (AnnotationDescriptor annotation : annotations) {
|
||||
if (annotationClass.equals(annotation.getType().getConstructor().getDeclarationDescriptor())) {
|
||||
return annotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasOnlyLocalContinueAndBreak(@NotNull ValueParameterDescriptor descriptor) {
|
||||
return hasInlineOption(descriptor, InlineOption.LOCAL_CONTINUE_AND_BREAK);
|
||||
}
|
||||
@@ -80,30 +65,22 @@ public class InlineUtil {
|
||||
}
|
||||
|
||||
private static boolean hasInlineOption(@NotNull ValueParameterDescriptor descriptor, @NotNull InlineOption option) {
|
||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||
ClassDescriptor annotationClass = builtIns.getInlineOptionsClassAnnotation();
|
||||
AnnotationDescriptor optionsAnnotation = getAnnotation(descriptor.getAnnotations(), annotationClass);
|
||||
CompileTimeConstant<?> argument =
|
||||
AnnotationUtil.instance$.getAnnotationSingleArgument(descriptor, KotlinBuiltIns.getInstance()
|
||||
.getInlineOptionsClassAnnotation());
|
||||
|
||||
if (optionsAnnotation != null) {
|
||||
ValueParameterDescriptor parameterDescriptor = annotationClass.getConstructors().iterator().next().getValueParameters().get(0);
|
||||
CompileTimeConstant<?> argument = optionsAnnotation.getValueArgument(parameterDescriptor);
|
||||
if (argument instanceof ArrayValue) {
|
||||
List<CompileTimeConstant<?>> values = ((ArrayValue) argument).getValue();
|
||||
|
||||
if (argument == null) {
|
||||
return false;
|
||||
} else {
|
||||
if (argument instanceof ArrayValue) {
|
||||
List<CompileTimeConstant<?>> values = ((ArrayValue) argument).getValue();
|
||||
|
||||
for (CompileTimeConstant<?> value : values) {
|
||||
if (value instanceof EnumValue) {
|
||||
if (((EnumValue) value).getValue().getName().asString().equals(option.name())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (CompileTimeConstant<?> value : values) {
|
||||
if (value instanceof EnumValue) {
|
||||
if (((EnumValue) value).getValue().getName().asString().equals(option.name())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ public class JetPositionManager implements PositionManager {
|
||||
|
||||
if (call == null) return false;
|
||||
|
||||
InlineStrategy inlineType = InlineUtil.getInlineType(call.getResultingDescriptor().getAnnotations());
|
||||
InlineStrategy inlineType = InlineUtil.getInlineType(call.getResultingDescriptor());
|
||||
if (!inlineType.isInline()) return false;
|
||||
|
||||
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> entry : call.getValueArguments().entrySet()) {
|
||||
|
||||
Reference in New Issue
Block a user