use of org.jetbrains.kotlin.psi.KtClass in project kotlin by JetBrains.
the class ReferenceUtils method renderAsGotoImplementation.
public static String renderAsGotoImplementation(@NotNull PsiElement element) {
PsiElement navigationElement = element.getNavigationElement();
if (navigationElement instanceof KtObjectDeclaration && ((KtObjectDeclaration) navigationElement).isCompanion()) {
//default presenter return null for companion object
KtClass containingClass = PsiTreeUtil.getParentOfType(navigationElement, KtClass.class);
assert containingClass != null;
return "companion object of " + renderAsGotoImplementation(containingClass);
}
if (navigationElement instanceof KtStringTemplateExpression) {
return KtPsiUtilKt.getPlainContent((KtStringTemplateExpression) navigationElement);
}
Assert.assertTrue(navigationElement instanceof NavigationItem);
ItemPresentation presentation = ((NavigationItem) navigationElement).getPresentation();
if (presentation == null) {
String elementText = element.getText();
return elementText != null ? elementText : navigationElement.getText();
}
String presentableText = presentation.getPresentableText();
String locationString = presentation.getLocationString();
if (locationString == null && element.getParent() instanceof PsiAnonymousClass) {
locationString = "<anonymous>";
}
return locationString == null || navigationElement instanceof PsiPackage ? // for PsiPackage, presentableText is FQ name of current package
presentableText : locationString + "." + presentableText;
}
use of org.jetbrains.kotlin.psi.KtClass in project kotlin by JetBrains.
the class StdlibTest method testStdlib.
public void testStdlib() throws ClassNotFoundException {
GenerationState state = KotlinToJVMBytecodeCompiler.INSTANCE.analyzeAndGenerate(getEnvironment());
if (state == null) {
fail("There were compilation errors");
}
classLoader = new GeneratedClassLoader(state.getFactory(), ForTestCompileRuntime.runtimeAndReflectJarClassLoader()) {
@Override
public Class<?> loadClass(@NotNull String name) throws ClassNotFoundException {
if (name.startsWith("junit.") || name.startsWith("org.junit.")) {
return StdlibTest.class.getClassLoader().loadClass(name);
}
return super.loadClass(name);
}
};
TestSuite tests = new TestSuite("Standard Library Tests");
for (KtFile file : getEnvironment().getSourceFiles()) {
// Skip JS tests
if (file.getVirtualFile().getPath().contains("/js/"))
continue;
for (KtDeclaration declaration : file.getDeclarations()) {
if (!(declaration instanceof KtClass))
continue;
ClassDescriptor descriptor = (ClassDescriptor) BindingContextUtils.getNotNull(state.getBindingContext(), BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
Test test = createTest(classLoader, state.getTypeMapper().mapClass(descriptor).getClassName());
if (test != null) {
tests.addTest(test);
}
}
}
TestResult result = new TestRunner(System.err).doRun(tests);
if (!result.wasSuccessful()) {
fail("Some stdlib tests failed, see stderr for details");
}
}
use of org.jetbrains.kotlin.psi.KtClass in project kotlin by JetBrains.
the class KotlinStubsTest method testSuperclassNames.
public void testSuperclassNames() {
PsiFile psiFile = myFixture.configureByText("foo.kt", "import java.util.ArrayList as alist\nclass C(): alist() { }");
List<KtDeclaration> declarations = ((KtFile) psiFile).getDeclarations();
KtClass ktClass = (KtClass) declarations.get(0);
KotlinClassStub stub = KtStubElementTypes.CLASS.createStub(ktClass, null);
List<String> names = stub.getSuperNames();
assertSameElements(names, "ArrayList", "alist");
}
use of org.jetbrains.kotlin.psi.KtClass in project kotlin by JetBrains.
the class KotlinStubsTest method testClassIsTrait.
public void testClassIsTrait() {
PsiFile psiFile = myFixture.configureByText("foo.kt", "interface Test { }");
List<KtDeclaration> declarations = ((KtFile) psiFile).getDeclarations();
KtClass ktClass = (KtClass) declarations.get(0);
KotlinClassStub stub = KtStubElementTypes.CLASS.createStub(ktClass, null);
assertEquals(true, stub.isInterface());
}
use of org.jetbrains.kotlin.psi.KtClass in project kotlin by JetBrains.
the class KotlinFindClassUsagesDialog method getRepresentingPsiClass.
@NotNull
private static PsiClass getRepresentingPsiClass(@NotNull KtClassOrObject classOrObject) {
PsiClass lightClass = toLightClass(classOrObject);
if (lightClass != null)
return lightClass;
// TODO: Remove this code when light classes are generated for builtins
PsiElementFactory factory = PsiElementFactory.SERVICE.getInstance(classOrObject.getProject());
String name = classOrObject.getName();
if (name == null || name.isEmpty()) {
name = "Anonymous";
}
PsiClass javaClass;
if (classOrObject instanceof KtClass) {
KtClass klass = (KtClass) classOrObject;
javaClass = !klass.isInterface() ? factory.createClass(name) : klass.isAnnotation() ? factory.createAnnotationType(name) : factory.createInterface(name);
} else {
javaClass = factory.createClass(name);
}
//noinspection ConstantConditions
javaClass.getModifierList().setModifierProperty(PsiModifier.FINAL, !(classOrObject instanceof KtClass && KtPsiUtilKt.isInheritable((KtClass) classOrObject)));
javaClass.putUserData(ORIGINAL_CLASS, classOrObject);
return javaClass;
}
Aggregations