Tests for additional lazy resolve (local classes/objects in class initializers)
This commit is contained in:
@@ -1009,7 +1009,7 @@ public class JetPsiUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetElement getEnclosingElementForLocalDeclaration(@Nullable JetNamedDeclaration declaration) {
|
||||
public static JetElement getEnclosingElementForLocalDeclaration(@Nullable JetDeclaration declaration) {
|
||||
if (declaration instanceof JetTypeParameter) {
|
||||
declaration = PsiTreeUtil.getParentOfType(declaration, JetNamedDeclaration.class);
|
||||
}
|
||||
@@ -1030,7 +1030,7 @@ public class JetPsiUtil {
|
||||
return (container instanceof JetClassInitializer) ? ((JetClassInitializer) container).getBody() : container;
|
||||
}
|
||||
|
||||
public static boolean isLocal(@NotNull JetNamedDeclaration declaration) {
|
||||
public static boolean isLocal(@NotNull JetDeclaration declaration) {
|
||||
return getEnclosingElementForLocalDeclaration(declaration) != null;
|
||||
}
|
||||
|
||||
|
||||
+18
-6
@@ -41,14 +41,19 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractLazyResolveDescriptorRendererTest extends KotlinTestWithEnvironment {
|
||||
|
||||
@Override
|
||||
protected JetCoreEnvironment createEnvironment() {
|
||||
return createEnvironmentWithMockJdk(ConfigurationKind.ALL);
|
||||
}
|
||||
|
||||
protected DeclarationDescriptor getDescriptor(JetDeclaration declaration, ResolveSession resolveSession) {
|
||||
return resolveSession.resolveToDescriptor(declaration);
|
||||
}
|
||||
|
||||
protected void doTest(@NotNull String testFile) throws IOException {
|
||||
JetFile psiFile = JetPsiFactory.createFile(getProject(), FileUtil.loadFile(new File(testFile), true));
|
||||
String fileText = FileUtil.loadFile(new File(testFile), true);
|
||||
|
||||
JetFile psiFile = JetPsiFactory.createFile(getProject(), fileText);
|
||||
Collection<JetFile> files = Lists.newArrayList(psiFile);
|
||||
|
||||
final ModuleDescriptorImpl lazyModule = AnalyzerFacadeForJVM.createJavaModule("<lazy module>");
|
||||
@@ -82,13 +87,13 @@ public abstract class AbstractLazyResolveDescriptorRendererTest extends KotlinTe
|
||||
}
|
||||
if (declaringElement instanceof JetNamedFunction) {
|
||||
JetNamedFunction jetNamedFunction = (JetNamedFunction) declaringElement;
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) resolveSession.resolveToDescriptor(jetNamedFunction);
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) getDescriptor(jetNamedFunction, resolveSession);
|
||||
addCorrespondingParameterDescriptor(functionDescriptor, parameter);
|
||||
}
|
||||
else if (declaringElement instanceof JetClass) {
|
||||
// Primary constructor parameter
|
||||
JetClass jetClass = (JetClass) declaringElement;
|
||||
ClassDescriptor classDescriptor = resolveSession.getClassDescriptor(jetClass);
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) getDescriptor(jetClass, resolveSession);
|
||||
addCorrespondingParameterDescriptor(classDescriptor.getConstructors().iterator().next(), parameter);
|
||||
}
|
||||
else {
|
||||
@@ -102,23 +107,30 @@ public abstract class AbstractLazyResolveDescriptorRendererTest extends KotlinTe
|
||||
descriptors.add(valueParameterDescriptor);
|
||||
}
|
||||
}
|
||||
parameter.acceptChildren(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPropertyAccessor(@NotNull JetPropertyAccessor accessor) {
|
||||
JetProperty parent = (JetProperty) accessor.getParent();
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) resolveSession.resolveToDescriptor(parent);
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) getDescriptor(parent, resolveSession);
|
||||
if (accessor.isGetter()) {
|
||||
descriptors.add(propertyDescriptor.getGetter());
|
||||
}
|
||||
else {
|
||||
descriptors.add(propertyDescriptor.getSetter());
|
||||
}
|
||||
accessor.acceptChildren(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAnonymousInitializer(@NotNull JetClassInitializer initializer) {
|
||||
initializer.acceptChildren(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDeclaration(@NotNull JetDeclaration element) {
|
||||
DeclarationDescriptor descriptor = resolveSession.resolveToDescriptor(element);
|
||||
DeclarationDescriptor descriptor = getDescriptor(element, resolveSession);
|
||||
descriptors.add(descriptor);
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
descriptors.addAll(((ClassDescriptor) descriptor).getConstructors());
|
||||
|
||||
@@ -83,6 +83,7 @@ import org.jetbrains.jet.j2k.test.AbstractJavaToKotlinConverterBasicTest
|
||||
import org.jetbrains.jet.plugin.conversion.copy.AbstractJavaToKotlinCopyPasteConversionTest
|
||||
import org.jetbrains.jet.shortenRefs.AbstractShortenRefsTest
|
||||
import org.jetbrains.jet.completion.handlers.AbstractSmartCompletionHandlerTest
|
||||
import org.jetbrains.jet.resolve.AbstractAdditionalLazyResolveDescriptorRendererTest
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
System.setProperty("java.awt.headless", "true")
|
||||
@@ -227,6 +228,10 @@ fun main(args: Array<String>) {
|
||||
|
||||
|
||||
testGroup("idea/tests", "idea/testData") {
|
||||
testClass(javaClass<AbstractAdditionalLazyResolveDescriptorRendererTest>()) {
|
||||
model("resolve/additionalLazyResolve", testMethod = "doTest")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractJetPsiMatcherTest>()) {
|
||||
model("jetPsiMatcher/expressions", testMethod = "doTestExpressions")
|
||||
model("jetPsiMatcher/types", testMethod = "doTestTypes")
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package test
|
||||
|
||||
open class A
|
||||
|
||||
class MyClass() {
|
||||
{
|
||||
val a = object: A() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//package test
|
||||
//internal open class A defined in test
|
||||
//public constructor A() defined in test.A
|
||||
//internal final class MyClass defined in test
|
||||
//public constructor MyClass() defined in test.MyClass
|
||||
//val a: test.MyClass.<init>.<no name provided> defined in test.MyClass.<init>
|
||||
//internal final class <no name provided> : test.A defined in test.MyClass.<init>
|
||||
//private constructor <no name provided>() defined in test.MyClass.<init>.<no name provided>
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package test
|
||||
|
||||
open class A
|
||||
|
||||
class MyClass(
|
||||
a: A = object: A() {
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
//package test
|
||||
//internal open class A defined in test
|
||||
//public constructor A() defined in test.A
|
||||
//internal final class MyClass defined in test
|
||||
//public constructor MyClass(a: test.A = ...) defined in test.MyClass
|
||||
//value-parameter val a: test.A = ... defined in test.MyClass.<init>
|
||||
//internal final class <no name provided> : test.A defined in test.MyClass.<init>
|
||||
//private constructor <no name provided>() defined in test.MyClass.<init>.<no name provided>
|
||||
@@ -0,0 +1,19 @@
|
||||
package test
|
||||
|
||||
open class A
|
||||
|
||||
class MyClass() {
|
||||
{
|
||||
class B: A() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//package test
|
||||
//internal open class A defined in test
|
||||
//public constructor A() defined in test.A
|
||||
//internal final class MyClass defined in test
|
||||
//public constructor MyClass() defined in test.MyClass
|
||||
//internal final class B : test.A defined in test.MyClass.<init>
|
||||
//public constructor B() defined in test.MyClass.<init>.B
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package test
|
||||
|
||||
open class A
|
||||
|
||||
class MyClass(
|
||||
a: A = run {
|
||||
class B: A() {
|
||||
|
||||
}
|
||||
|
||||
B()
|
||||
}
|
||||
)
|
||||
|
||||
//package test
|
||||
//internal open class A defined in test
|
||||
//public constructor A() defined in test.A
|
||||
//internal final class MyClass defined in test
|
||||
//public constructor MyClass(a: test.A = ...) defined in test.MyClass
|
||||
//value-parameter val a: test.A = ... defined in test.MyClass.<init>
|
||||
//internal final class B : test.A defined in test.MyClass.<init>.<anonymous>
|
||||
//public constructor B() defined in test.MyClass.<init>.<anonymous>.B
|
||||
@@ -0,0 +1,19 @@
|
||||
package test
|
||||
|
||||
open class A
|
||||
|
||||
class MyClass() {
|
||||
{
|
||||
object O: A() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//package test
|
||||
//internal open class A defined in test
|
||||
//public constructor A() defined in test.A
|
||||
//internal final class MyClass defined in test
|
||||
//public constructor MyClass() defined in test.MyClass
|
||||
//internal object O : test.A defined in test.MyClass.<init>
|
||||
//private constructor O() defined in test.MyClass.<init>.O
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package test
|
||||
|
||||
open class A
|
||||
|
||||
class MyClass(
|
||||
a: A = run {
|
||||
object O: A() {
|
||||
|
||||
}
|
||||
|
||||
O
|
||||
}
|
||||
)
|
||||
|
||||
//package test
|
||||
//internal open class A defined in test
|
||||
//public constructor A() defined in test.A
|
||||
//internal final class MyClass defined in test
|
||||
//public constructor MyClass(a: test.A = ...) defined in test.MyClass
|
||||
//value-parameter val a: test.A = ... defined in test.MyClass.<init>
|
||||
//internal object O : test.A defined in test.MyClass.<init>.<anonymous>
|
||||
//private constructor O() defined in test.MyClass.<init>.<anonymous>.O
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.resolve;
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClassInitializer;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveDescriptorRendererTest;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.plugin.project.ResolveElementCache;
|
||||
|
||||
public abstract class AbstractAdditionalLazyResolveDescriptorRendererTest extends AbstractLazyResolveDescriptorRendererTest {
|
||||
@Override
|
||||
protected DeclarationDescriptor getDescriptor(JetDeclaration declaration, ResolveSession resolveSession) {
|
||||
if (declaration instanceof JetClassInitializer || JetPsiUtil.isLocal(declaration)) {
|
||||
ResolveElementCache resolveElementCache = new ResolveElementCache(resolveSession, getProject());
|
||||
return resolveElementCache.resolveToElement(declaration).get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
||||
}
|
||||
return resolveSession.resolveToDescriptor(declaration);
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.resolve;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
|
||||
import org.jetbrains.jet.resolve.AbstractAdditionalLazyResolveDescriptorRendererTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/resolve/additionalLazyResolve")
|
||||
public class AdditionalLazyResolveDescriptorRendererTestGenerated extends AbstractAdditionalLazyResolveDescriptorRendererTest {
|
||||
public void testAllFilesPresentInAdditionalLazyResolve() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/resolve/additionalLazyResolve"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("anonymousObjectInClassInitializer.kt")
|
||||
public void testAnonymousObjectInClassInitializer() throws Exception {
|
||||
doTest("idea/testData/resolve/additionalLazyResolve/anonymousObjectInClassInitializer.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("anonymousObjectInClassParameterInitializer.kt")
|
||||
public void testAnonymousObjectInClassParameterInitializer() throws Exception {
|
||||
doTest("idea/testData/resolve/additionalLazyResolve/anonymousObjectInClassParameterInitializer.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localClassInClassInitializer.kt")
|
||||
public void testLocalClassInClassInitializer() throws Exception {
|
||||
doTest("idea/testData/resolve/additionalLazyResolve/localClassInClassInitializer.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localClassInClosureInClassParameterInitializer.kt")
|
||||
public void testLocalClassInClosureInClassParameterInitializer() throws Exception {
|
||||
doTest("idea/testData/resolve/additionalLazyResolve/localClassInClosureInClassParameterInitializer.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localObjectInClassInitializer.kt")
|
||||
public void testLocalObjectInClassInitializer() throws Exception {
|
||||
doTest("idea/testData/resolve/additionalLazyResolve/localObjectInClassInitializer.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localObjectInClosureInClassParameterInitializer.kt")
|
||||
public void testLocalObjectInClosureInClassParameterInitializer() throws Exception {
|
||||
doTest("idea/testData/resolve/additionalLazyResolve/localObjectInClosureInClassParameterInitializer.kt");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user