KT-1592 don't write default values for annotations
This commit is contained in:
@@ -22,6 +22,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
|||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.DefaultValueArgument;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedValueArgument;
|
import org.jetbrains.jet.lang.resolve.calls.ResolvedValueArgument;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||||
@@ -76,13 +77,16 @@ public abstract class AnnotationCodegen {
|
|||||||
AnnotationVisitor annotationVisitor = visitAnnotation(internalName, rp == RetentionPolicy.RUNTIME);
|
AnnotationVisitor annotationVisitor = visitAnnotation(internalName, rp == RetentionPolicy.RUNTIME);
|
||||||
|
|
||||||
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> entry : resolvedCall.getValueArguments().entrySet()) {
|
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> entry : resolvedCall.getValueArguments().entrySet()) {
|
||||||
List<JetExpression> valueArguments = entry.getValue().getArgumentExpressions();
|
ResolvedValueArgument valueArgument = entry.getValue();
|
||||||
assert valueArguments.size() == 1 : "Number of assertions on " + resolvedCall.getResultingDescriptor() + " = " + valueArguments.size(); // todo
|
if (!(valueArgument instanceof DefaultValueArgument)) {
|
||||||
CompileTimeConstant<?> compileTimeConstant = bindingContext.get(BindingContext.COMPILE_TIME_VALUE, valueArguments.get(0));
|
List<JetExpression> valueArguments = valueArgument.getArgumentExpressions();
|
||||||
assert compileTimeConstant != null;
|
assert valueArguments.size() == 1 : "Number of assertions on " + resolvedCall.getResultingDescriptor() + " = " + valueArguments.size(); // todo
|
||||||
|
CompileTimeConstant<?> compileTimeConstant = bindingContext.get(BindingContext.COMPILE_TIME_VALUE, valueArguments.get(0));
|
||||||
|
assert compileTimeConstant != null;
|
||||||
|
|
||||||
Object value = compileTimeConstant.getValue();
|
Object value = compileTimeConstant.getValue();
|
||||||
annotationVisitor.visit(entry.getKey().getName(), value);
|
annotationVisitor.visit(entry.getKey().getName(), value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
annotationVisitor.visitEnd();
|
annotationVisitor.visitEnd();
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
Test fun box(m : java.lang.reflect.Method) = "OK"
|
||||||
@@ -17,12 +17,18 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author alex.tkachman
|
* @author alex.tkachman
|
||||||
*/
|
*/
|
||||||
@@ -32,6 +38,13 @@ public class StdlibTest extends CodegenTestCase {
|
|||||||
super.setUp();
|
super.setUp();
|
||||||
createEnvironmentWithFullJdk();
|
createEnvironmentWithFullJdk();
|
||||||
myEnvironment.addToClasspath(ForTestCompileStdlib.stdlibJarForTests());
|
myEnvironment.addToClasspath(ForTestCompileStdlib.stdlibJarForTests());
|
||||||
|
File junitJar = new File("libraries/testlib/lib/junit-4.9.jar");
|
||||||
|
|
||||||
|
if (!junitJar.exists()) {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
myEnvironment.addToClasspath(junitJar);
|
||||||
CompileEnvironment.ensureRuntime(myEnvironment);
|
CompileEnvironment.ensureRuntime(myEnvironment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,4 +141,27 @@ public class StdlibTest extends CodegenTestCase {
|
|||||||
public void testKt1515() throws Exception {
|
public void testKt1515() throws Exception {
|
||||||
blackBoxFile("regressions/kt1515.kt");
|
blackBoxFile("regressions/kt1515.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testKt1592 () throws MalformedURLException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||||
|
loadFile("regressions/kt1592.kt");
|
||||||
|
ClassFileFactory codegens = generateClassesInFile();
|
||||||
|
GeneratedClassLoader loader = createClassLoader(codegens);
|
||||||
|
|
||||||
|
try {
|
||||||
|
String fqName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(myFile), true).replace("/", ".");
|
||||||
|
Class<?> namespaceClass = loader.loadClass(fqName);
|
||||||
|
Method method = namespaceClass.getMethod("box", Method.class);
|
||||||
|
method.setAccessible(true);
|
||||||
|
Test annotation = method.getAnnotation(Test.class);
|
||||||
|
assertEquals(annotation.timeout(), 0l);
|
||||||
|
assertEquals(annotation.expected(), Test.None.class);
|
||||||
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
System.out.println(generateToText());
|
||||||
|
throw new RuntimeException(t);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
loader.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user