Search in sources :

Example 1 with KtLightClass

use of org.jetbrains.kotlin.asJava.classes.KtLightClass in project kotlin by JetBrains.

the class KotlinLightClassCoherenceTest method doTest.

@NotNull
protected PsiClass doTest(String qualifiedName) {
    KtLightClass psiClass = (KtLightClass) finder.findClass(qualifiedName, GlobalSearchScope.allScope(getProject()));
    assertNotNull("Class not found: " + qualifiedName, psiClass);
    Asserter asserter = new Asserter();
    asserter.assertModifiersCoherent(psiClass);
    asserter.assertPropertyCoherent(psiClass, "isInterface");
    asserter.assertPropertyCoherent(psiClass, "isAnnotationType");
    asserter.assertPropertyCoherent(psiClass, "isEnum");
    asserter.assertPropertyCoherent(psiClass, "hasTypeParameters");
    asserter.assertPropertyCoherent(psiClass, "isDeprecated");
    asserter.reportFailures();
    return psiClass;
}
Also used : KtLightClass(org.jetbrains.kotlin.asJava.classes.KtLightClass) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with KtLightClass

use of org.jetbrains.kotlin.asJava.classes.KtLightClass in project kotlin by JetBrains.

the class LightClassAnnotationsTest method doTest.

private void doTest(@NotNull String fqName) {
    PsiClass psiClass = finder.findClass(fqName, GlobalSearchScope.allScope(getProject()));
    if (!(psiClass instanceof KtLightClass)) {
        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");
    }
    KotlinTestUtils.assertEqualsToFile(new File(testDir, getTestName(false) + ".annotations.txt"), sb.toString());
}
Also used : PsiClass(com.intellij.psi.PsiClass) KtLightClass(org.jetbrains.kotlin.asJava.classes.KtLightClass) PsiAnnotation(com.intellij.psi.PsiAnnotation) File(java.io.File) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 3 with KtLightClass

use of org.jetbrains.kotlin.asJava.classes.KtLightClass in project kotlin by JetBrains.

the class KotlinJavaFacadeTest method doTestWrapClass.

private void doTestWrapClass() {
    myFixture.configureByFile(fileName());
    int offset = myFixture.getEditor().getCaretModel().getOffset();
    PsiElement elementAt = myFixture.getFile().findElementAt(offset);
    assertNotNull("Caret should be set for tested file", elementAt);
    KtClass ktClass = PsiTreeUtil.getParentOfType(elementAt, KtClass.class);
    assertNotNull("Caret should be placed to class definition", ktClass);
    // Should not fail!
    KtLightClass lightClass = toLightClass(ktClass);
    assertNotNull(String.format("Failed to wrap jetClass '%s' to class", ktClass.getText()), lightClass);
    // This invokes codegen with ClassBuilderMode = LIGHT_CLASSES
    // No exception/error should happen here
    lightClass.getClsDelegate();
}
Also used : KtLightClass(org.jetbrains.kotlin.asJava.classes.KtLightClass)

Aggregations

KtLightClass (org.jetbrains.kotlin.asJava.classes.KtLightClass)3 PsiAnnotation (com.intellij.psi.PsiAnnotation)1 PsiClass (com.intellij.psi.PsiClass)1 PsiModifierList (com.intellij.psi.PsiModifierList)1 File (java.io.File)1 NotNull (org.jetbrains.annotations.NotNull)1