mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
New test runners: findElement renamed to toElement and moved to QualifiedNameExt according to review IDEA-CR-17341
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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 com.jetbrains.extenstions
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.QualifiedName
|
||||
import com.jetbrains.python.psi.PyClass
|
||||
import com.jetbrains.python.psi.impl.PyPsiFacadeImpl
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext
|
||||
|
||||
/**
|
||||
* Resolves qname of any symbol to appropriate PSI element.
|
||||
*/
|
||||
fun QualifiedName.toElement(module: Module, context: TypeEvalContext): PsiElement? {
|
||||
val facade = PyPsiFacadeImpl.getInstance(module.project)
|
||||
var currentName = this
|
||||
|
||||
|
||||
var element: PsiElement? = null
|
||||
|
||||
// Drill as deep, as we can
|
||||
var lastElement: String? = null
|
||||
while (currentName.componentCount > 0 && element == null) {
|
||||
|
||||
element = facade.qualifiedNameResolver(currentName).fromModule(module).withMembers().firstResult()
|
||||
if (element != null) {
|
||||
break
|
||||
}
|
||||
lastElement = this.lastComponent!!
|
||||
currentName = this.removeLastComponent()
|
||||
}
|
||||
|
||||
if (lastElement != null && element is PyClass) {
|
||||
// Drill in class
|
||||
val method = element.findMethodByName(lastElement, true, context)
|
||||
if (method != null) {
|
||||
return method
|
||||
}
|
||||
|
||||
}
|
||||
return element
|
||||
}
|
||||
@@ -39,11 +39,14 @@ import com.intellij.openapi.util.JDOMExternalizerUtil
|
||||
import com.intellij.openapi.util.Pair
|
||||
import com.intellij.openapi.util.Ref
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.openapi.util.registry.RegistryValue
|
||||
import com.intellij.psi.PsiDirectory
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.util.QualifiedName
|
||||
import com.jetbrains.extenstions.asList
|
||||
import com.jetbrains.extenstions.toElement
|
||||
import com.jetbrains.python.psi.PyClass
|
||||
import com.jetbrains.python.psi.PyFile
|
||||
import com.jetbrains.python.psi.PyFunction
|
||||
@@ -74,39 +77,6 @@ fun isUniversalModeEnabled(): Boolean = Registry.`is`("python.tests.enableUniver
|
||||
|
||||
internal fun getAdditionalArgumentsPropertyName() = PyUniversalTestConfiguration::additionalArguments.name
|
||||
|
||||
/**
|
||||
* Resolves qname of any symbol to appropriate PSI element.
|
||||
*/
|
||||
private fun findElementByQualifiedName(name: QualifiedName, module: Module, context: TypeEvalContext): PsiElement? {
|
||||
val facade = PyPsiFacadeImpl.getInstance(module.project)
|
||||
var currentName = name
|
||||
|
||||
|
||||
var element: PsiElement? = null
|
||||
|
||||
// Drill as deep, as we can
|
||||
var lastElement: String? = null
|
||||
while (currentName.componentCount > 0 && element == null) {
|
||||
|
||||
element = facade.qualifiedNameResolver(currentName).fromModule(module).withMembers().firstResult()
|
||||
if (element != null) {
|
||||
break
|
||||
}
|
||||
lastElement = name.lastComponent!!
|
||||
currentName = name.removeLastComponent()
|
||||
}
|
||||
|
||||
if (lastElement != null && element is PyClass) {
|
||||
// Drill in class
|
||||
val method = element.findMethodByName(lastElement, true, context)
|
||||
if (method != null) {
|
||||
return method
|
||||
}
|
||||
|
||||
}
|
||||
return element
|
||||
}
|
||||
|
||||
/**
|
||||
* @return factory chosen by user in "test runner" settings
|
||||
*/
|
||||
@@ -123,8 +93,8 @@ private object PyUniversalTestsLocator : SMTestLocator {
|
||||
if (scope !is ModuleWithDependenciesScope) {
|
||||
return ArrayList()
|
||||
}
|
||||
val result = findElementByQualifiedName(QualifiedName.fromDottedString(path), scope.module,
|
||||
TypeEvalContext.userInitiated(project, null))
|
||||
val result = QualifiedName.fromDottedString(path).toElement(scope.module,
|
||||
TypeEvalContext.userInitiated(project, null))
|
||||
if (result != null) {
|
||||
return arrayListOf(PsiLocation.fromPsiElement(result))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user