use of org.jetbrains.kotlin.psi.KtDeclaration in project kotlin by JetBrains.
the class AbstractPsiCheckerTest method checkResolveToDescriptor.
void checkResolveToDescriptor() {
KtFile file = (KtFile) myFixture.getFile();
file.accept(new KtTreeVisitorVoid() {
@Override
public void visitDeclaration(@NotNull KtDeclaration dcl) {
if (areDescriptorsCreatedForDeclaration(dcl)) {
// check for exceptions
ResolutionUtils.resolveToDescriptor(dcl, BodyResolveMode.FULL);
}
dcl.acceptChildren(this, null);
}
});
}
use of org.jetbrains.kotlin.psi.KtDeclaration 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.KtDeclaration in project kotlin by JetBrains.
the class JetTestFunctionDetector method getTestFunctions.
@NotNull
private static List<FunctionDescriptor> getTestFunctions(@NotNull BindingContext bindingContext, @NotNull List<KtDeclaration> declarations) {
List<FunctionDescriptor> answer = Lists.newArrayList();
for (KtDeclaration declaration : declarations) {
MemberScope scope = null;
if (declaration instanceof KtClass) {
KtClass klass = (KtClass) declaration;
ClassDescriptor classDescriptor = BindingUtils.getClassDescriptor(bindingContext, klass);
if (classDescriptor.getModality() != Modality.ABSTRACT) {
scope = classDescriptor.getDefaultType().getMemberScope();
}
}
if (scope != null) {
Collection<DeclarationDescriptor> allDescriptors = DescriptorUtils.getAllDescriptors(scope);
List<FunctionDescriptor> testFunctions = ContainerUtil.mapNotNull(allDescriptors, new Function<DeclarationDescriptor, FunctionDescriptor>() {
@Override
public FunctionDescriptor fun(DeclarationDescriptor descriptor) {
if (descriptor instanceof FunctionDescriptor) {
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
if (isTest(functionDescriptor))
return functionDescriptor;
}
return null;
}
});
answer.addAll(testFunctions);
}
}
return answer;
}
use of org.jetbrains.kotlin.psi.KtDeclaration in project kotlin by JetBrains.
the class KtFileTreeNode method getChildrenImpl.
@Override
public Collection<AbstractTreeNode> getChildrenImpl() {
KtFile file = (KtFile) getValue();
if (file == null)
return Collections.emptyList();
ArrayList<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
if (getSettings().isShowMembers()) {
List<KtDeclaration> declarations = file.getDeclarations();
for (KtDeclaration declaration : declarations) {
if (declaration instanceof KtClassOrObject) {
result.add(new KtClassOrObjectTreeNode(file.getProject(), (KtClassOrObject) declaration, getSettings()));
} else if (getSettings().isShowMembers()) {
result.add(new KtDeclarationTreeNode(getProject(), declaration, getSettings()));
}
}
}
return result;
}
use of org.jetbrains.kotlin.psi.KtDeclaration 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");
}
Aggregations