diff --git a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightClassForExplicitDeclaration.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightClassForExplicitDeclaration.java index aee21457a4e..483089bce85 100644 --- a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightClassForExplicitDeclaration.java +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightClassForExplicitDeclaration.java @@ -398,7 +398,7 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC @Override public PsiModifierList getModifierList() { if (modifierList == null) { - modifierList = new LightModifierList(getManager(), JetLanguage.INSTANCE, computeModifiers()); + modifierList = new KotlinLightModifierList(KotlinLightClassForExplicitDeclaration.this.computeModifiers()); } return modifierList; } @@ -576,4 +576,38 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC return false; } + + private class KotlinLightModifierList extends LightModifierList { + public KotlinLightModifierList(@NotNull String[] modifiers) { + super(KotlinLightClassForExplicitDeclaration.this.getManager(), JetLanguage.INSTANCE, modifiers); + } + + private PsiAnnotationOwner getDelegate() { + return KotlinLightClassForExplicitDeclaration.this.getDelegate().getModifierList(); + } + + @Override + @NotNull + public PsiAnnotation[] getAnnotations() { + return getDelegate().getAnnotations(); + } + + @Override + @NotNull + public PsiAnnotation[] getApplicableAnnotations() { + return getDelegate().getApplicableAnnotations(); + } + + @Override + @Nullable + public PsiAnnotation findAnnotation(@NotNull @NonNls String qualifiedName) { + return getDelegate().findAnnotation(qualifiedName); + } + + @Override + @NotNull + public PsiAnnotation addAnnotation(@NotNull @NonNls String qualifiedName) { + return getDelegate().addAnnotation(qualifiedName); + } + } } diff --git a/compiler/testData/asJava/annotations/ExtraAnnotations.annotations.txt b/compiler/testData/asJava/annotations/ExtraAnnotations.annotations.txt new file mode 100644 index 00000000000..7c36ebb6c83 --- /dev/null +++ b/compiler/testData/asJava/annotations/ExtraAnnotations.annotations.txt @@ -0,0 +1 @@ +@Foo(s = "...") \ No newline at end of file diff --git a/compiler/testData/asJava/annotations/ExtraAnnotations.kt b/compiler/testData/asJava/annotations/ExtraAnnotations.kt new file mode 100644 index 00000000000..7325aad2694 --- /dev/null +++ b/compiler/testData/asJava/annotations/ExtraAnnotations.kt @@ -0,0 +1,4 @@ +annotation class Foo(val s: String) + +[Foo("...")] +class ExtraAnnotations \ No newline at end of file diff --git a/compiler/testData/asJava/annotations/NestedClass.annotations.txt b/compiler/testData/asJava/annotations/NestedClass.annotations.txt new file mode 100644 index 00000000000..a94db633507 --- /dev/null +++ b/compiler/testData/asJava/annotations/NestedClass.annotations.txt @@ -0,0 +1 @@ +@Ann diff --git a/compiler/testData/asJava/annotations/NestedClass.kt b/compiler/testData/asJava/annotations/NestedClass.kt new file mode 100644 index 00000000000..e3013fa2b62 --- /dev/null +++ b/compiler/testData/asJava/annotations/NestedClass.kt @@ -0,0 +1,5 @@ +annotation class Ann + +class Outer { + Ann class Nested +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/asJava/LightClassAnnotationsTest.java b/compiler/tests/org/jetbrains/jet/asJava/LightClassAnnotationsTest.java new file mode 100644 index 00000000000..db72c3b0511 --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/asJava/LightClassAnnotationsTest.java @@ -0,0 +1,69 @@ +/* + * 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.asJava; + +import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiModifierList; +import com.intellij.psi.search.GlobalSearchScope; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys; +import org.jetbrains.jet.config.CompilerConfiguration; + +import java.io.File; +import java.util.Collections; +import java.util.List; + +public class LightClassAnnotationsTest extends KotlinAsJavaTestBase { + private final File testDir = new File("compiler/testData/asJava/annotations"); + + @Override + protected List getKotlinSourceRoots() { + return Collections.singletonList(new File(testDir, getTestName(false) + ".kt")); + } + + @Override + protected void extraConfiguration(@NotNull CompilerConfiguration configuration) { + configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, JetTestUtils.getAnnotationsJar()); + } + + public void testExtraAnnotations() throws Exception { + doTest(getTestName(false)); + } + + public void testNestedClass() throws Exception { + doTest("Outer.Nested"); + } + + private void doTest(@NotNull String fqName) { + PsiClass psiClass = finder.findClass(fqName, GlobalSearchScope.allScope(getProject())); + if (!(psiClass instanceof KotlinLightClass)) { + throw new IllegalStateException("Not a light class: " + psiClass + " (" + fqName + ")"); + } + + PsiModifierList modifierList = psiClass.getModifierList(); + assert modifierList != null : "No modifier list for " + psiClass.getText(); + + StringBuilder sb = new StringBuilder(); + for (PsiAnnotation annotation : modifierList.getAnnotations()) { + sb.append(annotation.getText()).append("\n"); + } + + JetTestUtils.assertEqualsToFile(new File(testDir, getTestName(false) + ".annotations.txt"), sb.toString()); + } +}