Lazy resolve passes DescriptorRenderer tests except for the Enum case

This commit is contained in:
Andrey Breslav
2012-06-14 13:16:37 +04:00
parent 036981f368
commit b3272feb63
4 changed files with 275 additions and 0 deletions
@@ -150,6 +150,10 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
.resolveObjectDeclaration(thisDescriptor, objectDeclaration, classifier, resolveSession.getTrace());
result.add(propertyDescriptor);
}
else if (classOrObjectDeclaration instanceof JetEnumEntry) {
JetEnumEntry jetEnumEntry = (JetEnumEntry) classOrObjectDeclaration;
throw new UnsupportedOperationException("Enums are not supported yet: " + jetEnumEntry + " " + jetEnumEntry.getText());
}
getNonDeclaredProperties(name, result);
@@ -0,0 +1,7 @@
trait TheTrait {
class object {
}
}
//internal trait TheTrait defined in root package
//object defined in TheTrait
@@ -0,0 +1,131 @@
/*
* 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.lang.resolve.lazy;
import com.google.common.collect.Lists;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.impl.DocumentImpl;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerForJvm;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.resolve.DescriptorRenderer;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static org.junit.Assert.assertEquals;
/**
* @author abreslav
*/
public class AbstractLazyResolveDescriptorRendererTest extends AbstractLazyResolveTest {
protected void doTest(@NotNull String testFile) throws IOException {
InjectorForTopDownAnalyzerForJvm injectorForTopDownAnalyzer = getEagerInjectorForTopDownAnalyzer();
JetFile psiFile = JetPsiFactory.createFile(project, FileUtil.loadFile(new File(testFile), true));
Collection<JetFile> files = Lists.newArrayList(psiFile);
ModuleDescriptor lazyModule = new ModuleDescriptor(Name.special("<lazy module>"));
final ResolveSession resolveSession = new ResolveSession(project, lazyModule, injectorForTopDownAnalyzer.getJavaBridgeConfiguration(),
new FileBasedDeclarationProviderFactory(files));
final List<DeclarationDescriptor> descriptors = new ArrayList<DeclarationDescriptor>();
psiFile.accept(new JetVisitorVoid() {
@Override
public void visitJetFile(JetFile file) {
String qualifiedName = file.getNamespaceHeader().getQualifiedName();
if (!qualifiedName.isEmpty()) {
NamespaceDescriptor packageDescriptor = resolveSession.getPackageDescriptorByFqName(new FqName(qualifiedName));
descriptors.add(packageDescriptor);
}
file.acceptChildren(this);
}
@Override
public void visitClassObject(JetClassObject classObject) {
classObject.acceptChildren(this);
}
@Override
public void visitParameter(JetParameter parameter) {
PsiElement declaringElement = parameter.getParent().getParent();
if (declaringElement instanceof JetFunctionType) {
return;
}
if (declaringElement instanceof JetNamedFunction) {
JetNamedFunction jetNamedFunction = (JetNamedFunction) declaringElement;
FunctionDescriptor functionDescriptor = (FunctionDescriptor) resolveSession.resolveToDescriptor(jetNamedFunction);
for (ValueParameterDescriptor valueParameterDescriptor : functionDescriptor.getValueParameters()) {
if (valueParameterDescriptor.getName().equals(parameter.getNameAsName())) {
descriptors.add(valueParameterDescriptor);
}
}
}
else {
super.visitParameter(parameter);
}
}
@Override
public void visitPropertyAccessor(JetPropertyAccessor accessor) {
JetProperty parent = (JetProperty) accessor.getParent();
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) resolveSession.resolveToDescriptor(parent);
if (accessor.isGetter()) {
descriptors.add(propertyDescriptor.getGetter());
}
else {
descriptors.add(propertyDescriptor.getSetter());
}
}
@Override
public void visitDeclaration(JetDeclaration element) {
DeclarationDescriptor descriptor = resolveSession.resolveToDescriptor(element);
descriptors.add(descriptor);
element.acceptChildren(this);
}
@Override
public void visitJetElement(JetElement element) {
element.acceptChildren(this);
}
});
StringBuilder renderedDescriptors = new StringBuilder();
for (DeclarationDescriptor descriptor : descriptors) {
if (renderedDescriptors.length() != 0) {
renderedDescriptors.append("\n");
}
renderedDescriptors.append(DescriptorRenderer.TEXT.render(descriptor));
}
Document document = new DocumentImpl(psiFile.getText());
assertEquals(JetTestUtils.getLastCommentedLines(document), renderedDescriptors.toString());
}
}
@@ -0,0 +1,133 @@
/*
* 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.lang.resolve.lazy;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import java.io.File;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
/* This class is generated by LazyResolveTestGenerator. DO NOT MODIFY MANUALLY */
@RunWith(Suite.class)
@Suite.SuiteClasses({
LazyResolveDescriptorRendererTestGenerated.Renderer.class,
LazyResolveDescriptorRendererTestGenerated.DescriptorRenderer.class
})
public class LazyResolveDescriptorRendererTestGenerated {
public static class Renderer extends AbstractLazyResolveDescriptorRendererTest {
@Test
public void allTestsPresentInRenderer() throws Exception {
allTestsPresent(Renderer.class, new File("compiler/testData/renderer"), true);
}
@Test
public void testClasses() throws Exception {
doTest("compiler/testData/renderer/Classes.kt");
}
@Test
public void testEnum() throws Exception {
doTest("compiler/testData/renderer/Enum.kt");
}
@Test
public void testErrorType() throws Exception {
doTest("compiler/testData/renderer/ErrorType.kt");
}
@Test
public void testFunctionTypes() throws Exception {
doTest("compiler/testData/renderer/FunctionTypes.kt");
}
@Test
public void testGlobalFunctions() throws Exception {
doTest("compiler/testData/renderer/GlobalFunctions.kt");
}
@Test
public void testGlobalProperties() throws Exception {
doTest("compiler/testData/renderer/GlobalProperties.kt");
}
@Test
public void testTupleTypes() throws Exception {
doTest("compiler/testData/renderer/TupleTypes.kt");
}
public static void allTestsPresent(Class<?> clazz, File testDataDir, boolean recursive) {
Set<String> methodNames = new HashSet<String>();
for (Method method : clazz.getDeclaredMethods()) {
if (method.isAnnotationPresent(Test.class)) {
methodNames.add(method.getName().toLowerCase() + ".kt");
}
}
for (File file : testDataDir.listFiles()) {
if (file.isDirectory()) {
if (recursive) {
allTestsPresent(clazz, file, recursive);
}
}
else {
String name = file.getName();
if (name.endsWith(".kt") && !methodNames.contains("test" + name.toLowerCase())) {
Assert.fail("Test data file missing from the generated test class: " + file + "\nPlease re-run the generator: LazyResolveTestGenerator");
}
}
}
}
}
public static class DescriptorRenderer extends AbstractLazyResolveDescriptorRendererTest {
@Test
public void allTestsPresentInDescriptorRenderer() throws Exception {
allTestsPresent(DescriptorRenderer.class, new File("compiler/testData/lazyResolve/descriptorRenderer"), true);
}
@Test
public void testClassObject() throws Exception {
doTest("compiler/testData/lazyResolve/descriptorRenderer/ClassObject.kt");
}
public static void allTestsPresent(Class<?> clazz, File testDataDir, boolean recursive) {
Set<String> methodNames = new HashSet<String>();
for (Method method : clazz.getDeclaredMethods()) {
if (method.isAnnotationPresent(Test.class)) {
methodNames.add(method.getName().toLowerCase() + ".kt");
}
}
for (File file : testDataDir.listFiles()) {
if (file.isDirectory()) {
if (recursive) {
allTestsPresent(clazz, file, recursive);
}
}
else {
String name = file.getName();
if (name.endsWith(".kt") && !methodNames.contains("test" + name.toLowerCase())) {
Assert.fail("Test data file missing from the generated test class: " + file + "\nPlease re-run the generator: LazyResolveTestGenerator");
}
}
}
}
}
}