提交 cc8d263f 编写于 作者: A Alex Tkachman

preliminary support for intrinsics in std lib. javaClass<T>

上级 2796c914
......@@ -72,7 +72,7 @@ public class IntrinsicMethods {
myProject = project;
myStdLib = stdlib;
namedMethods.put("std.javaClass.property", new JavaClassProperty());
namedMethods.put("\"std.javaClass.function\"", new JavaClassFunction());
List<String> primitiveCastMethods = OperatorConventions.NUMBER_CONVERSIONS.asList();
for (String method : primitiveCastMethods) {
......
/*
* Copyright 2000-2012 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.codegen.intrinsics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.psi.JetCallExpression;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
import org.jetbrains.jet.lang.types.TypeProjection;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.InstructionAdapter;
import java.util.List;
/**
* @author alex.tkachman
*/
public class JavaClassFunction implements IntrinsicMethod {
@Override
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, @Nullable PsiElement element, @Nullable List<JetExpression> arguments, StackValue receiver) {
JetCallExpression call = (JetCallExpression) element;
ResolvedCall<? extends CallableDescriptor> resolvedCall = codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, call.getCalleeExpression());
CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor();
Type type = codegen.getTypeMapper().mapType(resultingDescriptor.getReturnType().getArguments().get(0).getType());
v.aconst(type);
return StackValue.onStack(type);
}
}
......@@ -34,7 +34,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.OverrideResolver;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.constants.*;
import org.jetbrains.jet.lang.resolve.java.alt.AltClassFinder;
import org.jetbrains.jet.lang.resolve.java.kt.JetClassAnnotation;
import org.jetbrains.jet.lang.types.*;
......@@ -1425,7 +1425,14 @@ public class JavaDescriptorResolver {
return null;
}
annotation.setAnnotationType(clazz.getDefaultType());
annotation.setValueArguments(new ArrayList<CompileTimeConstant<?>>()); // TODO
ArrayList<CompileTimeConstant<?>> valueArguments = new ArrayList<CompileTimeConstant<?>>();
if("jet.runtime.Intrinsic".equals(psiAnnotation.getQualifiedName())) {
// temporary hack
valueArguments.add(new StringValue(psiAnnotation.findAttributeValue("value").getText()));
annotation.setValueArguments(valueArguments); // TODO
}
else
annotation.setValueArguments(valueArguments); // TODO
return annotation;
}
......
......@@ -2,7 +2,10 @@ import std.*
val test = "lala".javaClass
val test2 = javaClass<Iterator<Int>> ()
fun box(): String {
if(test.getCanonicalName() != "java.lang.String") return "fail"
if(test2.getCanonicalName() != "jet.Iterator") return "fail"
return "OK"
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ import java.lang.Object
import jet.runtime.Intrinsic
val <T> T.javaClass : Class<T>
val <out T> T.javaClass : Class<T>
[Intrinsic("std.javaClass.property")] get() = (this as java.lang.Object).getClass() as Class<T>
[Intrinsic("std.javaClass.function")] fun <T> javaClass() : Class<T> = null as Class<T>
[Intrinsic("std.javaClass.function")] fun <out T> javaClass() : Class<T> = null as Class<T>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册