Resolve java.lang.Class as annotation argument
This commit is contained in:
+2
@@ -48,4 +48,6 @@ public interface AnnotationArgumentVisitor<R, D> {
|
||||
R visitArrayValue(ArrayValue value, D data);
|
||||
|
||||
R visitAnnotationValue(AnnotationValue value, D data);
|
||||
|
||||
R visitJavaClassValue(JavaClassValue value, D data);
|
||||
}
|
||||
|
||||
@@ -30,10 +30,7 @@ import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.constants.AnnotationValue;
|
||||
import org.jetbrains.jet.lang.resolve.constants.ArrayValue;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.constants.EnumValue;
|
||||
import org.jetbrains.jet.lang.resolve.constants.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
@@ -312,6 +309,10 @@ public class AnnotationResolver {
|
||||
return new AnnotationValue(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
if (AnnotationUtils.isJavaClassMethodCall(call)) {
|
||||
return new JavaClassValue(resultingDescriptor.getReturnType());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -102,6 +102,19 @@ public class AnnotationUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isJavaClassMethodCall(@NotNull ResolvedCall resolvedCall) {
|
||||
List<AnnotationDescriptor> annotations = resolvedCall.getResultingDescriptor().getOriginal().getAnnotations();
|
||||
if (annotations != null) {
|
||||
for (AnnotationDescriptor annotation : annotations) {
|
||||
//noinspection ConstantConditions
|
||||
if ("Intrinsic".equals(annotation.getType().getConstructor().getDeclarationDescriptor().getName().asString())) {
|
||||
return "kotlin.javaClass.function".equals(annotation.getAllValueArguments().values().iterator().next().getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isJavaLangClass(ClassDescriptor descriptor) {
|
||||
return "java.lang.Class".equals(DescriptorUtils.getFQName(descriptor).asString());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
public class JavaClassValue implements CompileTimeConstant<JetType> {
|
||||
|
||||
private final JetType value;
|
||||
|
||||
public JavaClassValue(JetType value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType getValue() {
|
||||
return value.getArguments().iterator().next().getType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitJavaClassValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getValue() + ".class";
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ annotation class AnnStringVararg(vararg a: String)
|
||||
annotation class AnnStringArray(a: Array<String>)
|
||||
annotation class AnnArrayOfEnum(a: Array<MyEnum>)
|
||||
annotation class AnnAnn(a: AnnInt)
|
||||
annotation class AnnClass(a: Class<*>)
|
||||
|
||||
enum class MyEnum {
|
||||
A
|
||||
|
||||
+6
@@ -119,6 +119,12 @@ public class AnnotationDescriptorResolveTest extends JetLiteFixture {
|
||||
doTest(content, expectedAnnotation);
|
||||
}
|
||||
|
||||
public void testJavaClassAnnotation() throws Exception {
|
||||
String content = getContent("AnnClass(javaClass<MyClass>())");
|
||||
String expectedAnnotation = "AnnClass[a = MyClass.class: java.lang.Class<test.MyClass>]";
|
||||
doTest(content, expectedAnnotation);
|
||||
}
|
||||
|
||||
private void doTest(@NotNull String content, @NotNull String expectedAnnotation) {
|
||||
NamespaceDescriptor test = getNamespaceDescriptor(content);
|
||||
ClassDescriptor myClass = getClassDescriptor(test, "MyClass");
|
||||
|
||||
Reference in New Issue
Block a user