Add LazyResolveByStubTest
Tests that lazy resolve uses stubs instead of AST
This commit is contained in:
@@ -110,6 +110,7 @@ import org.jetbrains.jet.plugin.debugger.evaluate.AbstractKotlinEvaluateExpressi
|
|||||||
import org.jetbrains.jet.plugin.debugger.evaluate.AbstractSelectExpressionForDebuggerTest
|
import org.jetbrains.jet.plugin.debugger.evaluate.AbstractSelectExpressionForDebuggerTest
|
||||||
import org.jetbrains.jet.plugin.debugger.evaluate.AbstractCodeFragmentCompletionTest
|
import org.jetbrains.jet.plugin.debugger.evaluate.AbstractCodeFragmentCompletionTest
|
||||||
import org.jetbrains.jet.plugin.debugger.evaluate.AbstractCodeFragmentHighlightingTest
|
import org.jetbrains.jet.plugin.debugger.evaluate.AbstractCodeFragmentHighlightingTest
|
||||||
|
import org.jetbrains.jet.plugin.stubs.AbstractLazyResolveByStubTest
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
System.setProperty("java.awt.headless", "true")
|
System.setProperty("java.awt.headless", "true")
|
||||||
@@ -611,6 +612,13 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testGroup("idea/tests", "compiler/testData") {
|
||||||
|
testClass(javaClass<AbstractLazyResolveByStubTest>()) {
|
||||||
|
model("loadJava/compiledKotlin", testMethod = "doTestCheckingPrimaryConstructorsAndAccessors")
|
||||||
|
model("loadJava/compiledJavaCompareWithKotlin", testMethod = "doTestNotCheckingPrimaryConstructors")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
testGroup("j2k/tests/test", "j2k/tests/testData") {
|
testGroup("j2k/tests/test", "j2k/tests/testData") {
|
||||||
testClass(javaClass<AbstractJavaToKotlinConverterPluginTest>()) {
|
testClass(javaClass<AbstractJavaToKotlinConverterPluginTest>()) {
|
||||||
model("ast", extension = "java")
|
model("ast", extension = "java")
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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.stubs;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.intellij.codeInsight.CodeInsightTestCase;
|
||||||
|
import com.intellij.openapi.module.Module;
|
||||||
|
import com.intellij.openapi.roots.ContentEntry;
|
||||||
|
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||||
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
|
import com.intellij.testFramework.LightProjectDescriptor;
|
||||||
|
import com.intellij.util.Consumer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
|
import org.jetbrains.jet.plugin.JetWithJdkAndRuntimeLightProjectDescriptor;
|
||||||
|
import org.jetbrains.jet.plugin.caches.resolve.KotlinCacheService;
|
||||||
|
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||||
|
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies;
|
||||||
|
import org.jetbrains.jet.test.util.RecursiveDescriptorComparator;
|
||||||
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static com.intellij.openapi.roots.ModuleRootModificationUtil.updateModel;
|
||||||
|
import static org.jetbrains.jet.test.util.DescriptorValidator.ValidationVisitor.FORBID_ERROR_TYPES;
|
||||||
|
|
||||||
|
public abstract class AbstractLazyResolveByStubTest extends CodeInsightTestCase {
|
||||||
|
|
||||||
|
protected void doTestCheckingPrimaryConstructorsAndAccessors(String testFileName) throws Exception {
|
||||||
|
doTest(testFileName, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doTestNotCheckingPrimaryConstructors(String testFileName) throws Exception {
|
||||||
|
doTest(testFileName, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doTest(@NotNull String path, boolean checkPrimaryConstructors, boolean checkPropertyAccessors) throws Exception {
|
||||||
|
configureByFile(path);
|
||||||
|
AstAccessControl.instance$.prohibitAstAccessForKotlinFiles(getProject(), getTestRootDisposable());
|
||||||
|
configureModule(getModule(), JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE);
|
||||||
|
ResolveSessionForBodies resolveSession = KotlinCacheService.object$.getInstance(getFile().getProject()).getLazyResolveSession((JetFile) getFile());
|
||||||
|
ModuleDescriptor module = resolveSession.getModuleDescriptor();
|
||||||
|
PackageViewDescriptor packageViewDescriptor = module.getPackage(new FqName("test"));
|
||||||
|
Assert.assertNotNull(packageViewDescriptor);
|
||||||
|
|
||||||
|
File fileToCompareTo = new File(FileUtil.getNameWithoutExtension(path) + ".txt");
|
||||||
|
|
||||||
|
RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(
|
||||||
|
packageViewDescriptor,
|
||||||
|
RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT.filterRecursion(
|
||||||
|
new Predicate<FqName>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(FqName fqName) {
|
||||||
|
return !KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.equals(fqName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.checkPrimaryConstructors(checkPrimaryConstructors)
|
||||||
|
.checkPropertyAccessors(checkPropertyAccessors)
|
||||||
|
.withValidationStrategy(FORBID_ERROR_TYPES),
|
||||||
|
fileToCompareTo
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void configureModule(@NotNull final Module module, @NotNull final LightProjectDescriptor descriptor) {
|
||||||
|
updateModel(module, new Consumer<ModifiableRootModel>() {
|
||||||
|
@Override
|
||||||
|
public void consume(ModifiableRootModel model) {
|
||||||
|
if (descriptor.getSdk() != null) {
|
||||||
|
model.setSdk(descriptor.getSdk());
|
||||||
|
}
|
||||||
|
ContentEntry entry = model.getContentEntries()[0];
|
||||||
|
descriptor.configureModule(module, model, entry);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTestDataPath() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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.stubs
|
||||||
|
|
||||||
|
import com.intellij.psi.impl.PsiManagerImpl
|
||||||
|
import com.intellij.psi.PsiManager
|
||||||
|
import com.intellij.openapi.vfs.VirtualFileFilter
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import org.jetbrains.jet.plugin.JetFileType
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.Disposable
|
||||||
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
|
import com.intellij.openapi.vfs.VfsUtil
|
||||||
|
import com.intellij.openapi.vfs.VfsUtilCore
|
||||||
|
import org.jetbrains.jet.InTextDirectivesUtils
|
||||||
|
|
||||||
|
object AstAccessControl {
|
||||||
|
|
||||||
|
val ALLOW_AST_ACCESS_DIRECTIVE = "ALLOW_AST_ACCESS"
|
||||||
|
|
||||||
|
fun prohibitAstAccessForKotlinFiles(project: Project, disposable: Disposable) {
|
||||||
|
val manager = (PsiManager.getInstance(project) as PsiManagerImpl)
|
||||||
|
val filter = VirtualFileFilter {
|
||||||
|
file ->
|
||||||
|
if (file!!.getFileType() != JetFileType.INSTANCE) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
val text = VfsUtilCore.loadText(file)
|
||||||
|
!InTextDirectivesUtils.isDirectiveDefined(text, ALLOW_AST_ACCESS_DIRECTIVE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
manager.setAssertOnFileLoadingFilter(filter, disposable)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user