From a7f3e12aec990c838835200387498801d1fdc138 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Fri, 11 May 2012 21:41:54 +0400 Subject: [PATCH] Added test checking that StandardLibraryReferenceResolver returns not null for all members of jet namespace. --- .../StandardLibraryReferenceResolverTest.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 idea/tests/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolverTest.java diff --git a/idea/tests/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolverTest.java b/idea/tests/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolverTest.java new file mode 100644 index 00000000000..c5fb704168c --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolverTest.java @@ -0,0 +1,72 @@ +/* + * Copyright 2010-2012 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.plugin.references; + +import com.intellij.testFramework.LightCodeInsightTestCase; +import org.jetbrains.jet.lang.descriptors.ClassDescriptor; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor; +import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; +import org.jetbrains.jet.lang.types.lang.JetStandardClasses; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * @author Evgeny Gerashchenko + * @since 5/11/12 + */ +public class StandardLibraryReferenceResolverTest extends LightCodeInsightTestCase { + public void testAllReferencesResolved() { + StandardLibraryReferenceResolver referenceResolver = getProject().getComponent(StandardLibraryReferenceResolver.class); + for (DeclarationDescriptor descriptor : getAllStandardDescriptors(JetStandardClasses.STANDARD_CLASSES_NAMESPACE)) { + if (descriptor instanceof NamespaceDescriptor && "jet".equals(descriptor.getName())) continue; + assertNotNull("Can't resolve " + descriptor, referenceResolver.resolveStandardLibrarySymbol(descriptor)); + } + } + + private static Collection getAllStandardDescriptors(DeclarationDescriptor baseDescriptor) { + final ArrayList descriptors = new ArrayList(); + baseDescriptor.acceptVoid(new DeclarationDescriptorVisitor() { + private Void visitDescriptors(Collection descriptors) { + for (DeclarationDescriptor descriptor : descriptors) { + descriptor.acceptVoid(this); + } + return null; + } + + @Override + public Void visitClassDescriptor(ClassDescriptor descriptor, Void data) { + descriptors.add(descriptor); + return visitDescriptors(descriptor.getDefaultType().getMemberScope().getAllDescriptors()); + } + + @Override + public Void visitNamespaceDescriptor(NamespaceDescriptor descriptor, Void data) { + descriptors.add(descriptor); + return visitDescriptors(descriptor.getMemberScope().getAllDescriptors()); + } + + @Override + public Void visitDeclarationDescriptor(DeclarationDescriptor descriptor, Void data) { + descriptors.add(descriptor); + return null; + } + }); + return descriptors; + } +}