LightClassUtil: J2K
This commit is contained in:
@@ -32,7 +32,6 @@ import com.intellij.util.containers.SLRUCache;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
|
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
|
||||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
|
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
import org.jetbrains.kotlin.name.NamePackage;
|
import org.jetbrains.kotlin.name.NamePackage;
|
||||||
import org.jetbrains.kotlin.psi.JetClassOrObject;
|
import org.jetbrains.kotlin.psi.JetClassOrObject;
|
||||||
@@ -134,7 +133,7 @@ public class JavaElementFinder extends PsiElementFinder implements KotlinFinderM
|
|||||||
|
|
||||||
for (JetClassOrObject declaration : classOrObjectDeclarations) {
|
for (JetClassOrObject declaration : classOrObjectDeclarations) {
|
||||||
if (!(declaration instanceof JetEnumEntry)) {
|
if (!(declaration instanceof JetEnumEntry)) {
|
||||||
PsiClass lightClass = LightClassUtil.getPsiClass(declaration);
|
PsiClass lightClass = LightClassUtil.INSTANCE$.getPsiClass(declaration);
|
||||||
if (lightClass != null) {
|
if (lightClass != null) {
|
||||||
answer.add(lightClass);
|
answer.add(lightClass);
|
||||||
}
|
}
|
||||||
@@ -208,7 +207,7 @@ public class JavaElementFinder extends PsiElementFinder implements KotlinFinderM
|
|||||||
|
|
||||||
Collection<JetClassOrObject> declarations = lightClassGenerationSupport.findClassOrObjectDeclarationsInPackage(packageFQN, scope);
|
Collection<JetClassOrObject> declarations = lightClassGenerationSupport.findClassOrObjectDeclarationsInPackage(packageFQN, scope);
|
||||||
for (JetClassOrObject declaration : declarations) {
|
for (JetClassOrObject declaration : declarations) {
|
||||||
PsiClass aClass = LightClassUtil.getPsiClass(declaration);
|
PsiClass aClass = LightClassUtil.INSTANCE$.getPsiClass(declaration);
|
||||||
if (aClass != null) {
|
if (aClass != null) {
|
||||||
answer.add(aClass);
|
answer.add(aClass);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -499,7 +499,7 @@ public class KotlinJavaFileStubProvider<T extends WithFileStubAndExtraDiagnostic
|
|||||||
|
|
||||||
private static void checkForBuiltIns(@NotNull FqName fqName, @NotNull Collection<JetFile> files) {
|
private static void checkForBuiltIns(@NotNull FqName fqName, @NotNull Collection<JetFile> files) {
|
||||||
for (JetFile file : files) {
|
for (JetFile file : files) {
|
||||||
if (LightClassUtil.belongsToKotlinBuiltIns(file)) {
|
if (LightClassUtil.INSTANCE$.belongsToKotlinBuiltIns(file)) {
|
||||||
// We may not fail later due to some luck, but generating JetLightClasses for built-ins is a bad idea anyways
|
// We may not fail later due to some luck, but generating JetLightClasses for built-ins is a bad idea anyways
|
||||||
// If it fails later, there will be an exception logged
|
// If it fails later, there will be an exception logged
|
||||||
logErrorWithOSInfo(null, fqName, file.getVirtualFile());
|
logErrorWithOSInfo(null, fqName, file.getVirtualFile());
|
||||||
@@ -511,7 +511,7 @@ public class KotlinJavaFileStubProvider<T extends WithFileStubAndExtraDiagnostic
|
|||||||
String path = virtualFile == null ? "<null>" : virtualFile.getPath();
|
String path = virtualFile == null ? "<null>" : virtualFile.getPath();
|
||||||
LOG.error(
|
LOG.error(
|
||||||
"Could not generate LightClass for " + fqName + " declared in " + path + "\n" +
|
"Could not generate LightClass for " + fqName + " declared in " + path + "\n" +
|
||||||
"built-ins dir URL is " + LightClassUtil.getBuiltInsDirUrl() + "\n" +
|
"built-ins dir URL is " + LightClassUtil.INSTANCE$.getBuiltInsDirUrl() + "\n" +
|
||||||
"System: " + SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION + " Java Runtime: " + SystemInfo.JAVA_RUNTIME_VERSION,
|
"System: " + SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION + " Java Runtime: " + SystemInfo.JAVA_RUNTIME_VERSION,
|
||||||
cause);
|
cause);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,411 +14,331 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.asJava;
|
package org.jetbrains.kotlin.asJava
|
||||||
|
|
||||||
import com.intellij.openapi.application.ApplicationManager;
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.diagnostic.Logger;
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
import com.intellij.openapi.progress.ProcessCanceledException
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.util.Comparing
|
||||||
import com.intellij.openapi.util.Comparing;
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.vfs.StandardFileSystems
|
||||||
import com.intellij.openapi.vfs.StandardFileSystems;
|
import com.intellij.psi.*
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.psi.impl.java.stubs.PsiClassStub
|
||||||
import com.intellij.psi.*;
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
import com.intellij.psi.impl.java.stubs.PsiClassStub;
|
import com.intellij.psi.stubs.PsiFileStub
|
||||||
import com.intellij.psi.impl.light.LightTypeParameterListBuilder;
|
import com.intellij.psi.stubs.StubElement
|
||||||
import com.intellij.psi.search.GlobalSearchScope;
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
import com.intellij.psi.stubs.PsiFileStub;
|
import com.intellij.util.PathUtil
|
||||||
import com.intellij.psi.stubs.StubElement;
|
import com.intellij.util.SmartList
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import com.intellij.util.PathUtil;
|
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||||
import com.intellij.util.SmartList;
|
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
|
||||||
import kotlin.KotlinPackage;
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import kotlin.jvm.functions.Function1;
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.kotlin.utils.KotlinVfsUtil
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.kotlin.utils.rethrow
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import java.io.File
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
import java.net.MalformedURLException
|
||||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
|
import java.net.URL
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import java.util.*
|
||||||
import org.jetbrains.kotlin.psi.*;
|
|
||||||
import org.jetbrains.kotlin.utils.KotlinVfsUtil;
|
|
||||||
import org.jetbrains.kotlin.utils.UtilsPackage;
|
|
||||||
|
|
||||||
import java.io.File;
|
public object LightClassUtil {
|
||||||
import java.net.MalformedURLException;
|
private val LOG = Logger.getInstance(LightClassUtil::class.java)
|
||||||
import java.net.URL;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class LightClassUtil {
|
public val BUILT_INS_SRC_DIR: File = File("core/builtins/native", KotlinBuiltIns.BUILT_INS_PACKAGE_NAME.asString())
|
||||||
private static final Logger LOG = Logger.getInstance(LightClassUtil.class);
|
|
||||||
|
|
||||||
public static final File BUILT_INS_SRC_DIR = new File("core/builtins/native", KotlinBuiltIns.BUILT_INS_PACKAGE_NAME.asString());
|
public val builtInsDirUrl: URL by lazy { computeBuiltInsDir() }
|
||||||
|
|
||||||
private static final class BuiltinsDirUrlHolder {
|
|
||||||
private static final URL BUILT_INS_DIR_URL = computeBuiltInsDir();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the given file is loaded from the location where Kotlin's built-in classes are defined.
|
* Checks whether the given file is loaded from the location where Kotlin's built-in classes are defined.
|
||||||
* As of today, this is core/builtins/native/kotlin directory and files such as Any.kt, Nothing.kt etc.
|
* As of today, this is core/builtins/native/kotlin directory and files such as Any.kt, Nothing.kt etc.
|
||||||
*
|
|
||||||
* Used to skip JetLightClass creation for built-ins, because built-in classes have no Java counterparts
|
* Used to skip JetLightClass creation for built-ins, because built-in classes have no Java counterparts
|
||||||
*/
|
*/
|
||||||
public static boolean belongsToKotlinBuiltIns(@NotNull JetFile file) {
|
public fun belongsToKotlinBuiltIns(file: JetFile): Boolean {
|
||||||
VirtualFile virtualFile = file.getVirtualFile();
|
val virtualFile = file.virtualFile
|
||||||
if (virtualFile != null) {
|
if (virtualFile != null) {
|
||||||
VirtualFile parent = virtualFile.getParent();
|
val parent = virtualFile.parent
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
try {
|
try {
|
||||||
String jetVfsPathUrl = KotlinVfsUtil.convertFromUrl(getBuiltInsDirUrl());
|
val jetVfsPathUrl = KotlinVfsUtil.convertFromUrl(builtInsDirUrl)
|
||||||
String fileDirVfsUrl = parent.getUrl();
|
val fileDirVfsUrl = parent.url
|
||||||
if (jetVfsPathUrl.equals(fileDirVfsUrl)) {
|
if (jetVfsPathUrl == fileDirVfsUrl) {
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (MalformedURLException e) {
|
catch (e: MalformedURLException) {
|
||||||
LOG.error(e);
|
LOG.error(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We deliberately return false on error: who knows what weird URLs we might come across out there
|
// We deliberately return false on error: who knows what weird URLs we might come across out there
|
||||||
// it would be a pity if no light classes would be created in such cases
|
// it would be a pity if no light classes would be created in such cases
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
private fun computeBuiltInsDir(): URL {
|
||||||
public static URL getBuiltInsDirUrl() {
|
val builtInFilePath = "/" + KotlinBuiltIns.BUILT_INS_PACKAGE_NAME + "/Library.kt"
|
||||||
return BuiltinsDirUrlHolder.BUILT_INS_DIR_URL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
val url = KotlinBuiltIns::class.java.getResource(builtInFilePath)
|
||||||
private static URL computeBuiltInsDir() {
|
|
||||||
String builtInFilePath = "/" + KotlinBuiltIns.BUILT_INS_PACKAGE_NAME + "/Library.kt";
|
|
||||||
|
|
||||||
URL url = KotlinBuiltIns.class.getResource(builtInFilePath);
|
|
||||||
|
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||||
// HACK: Temp code. Get built-in files from the sources when running from test.
|
// HACK: Temp code. Get built-in files from the sources when running from test.
|
||||||
try {
|
try {
|
||||||
return new URL(StandardFileSystems.FILE_PROTOCOL, "",
|
return URL(StandardFileSystems.FILE_PROTOCOL, "",
|
||||||
FileUtil.toSystemIndependentName(BUILT_INS_SRC_DIR.getAbsolutePath()));
|
FileUtil.toSystemIndependentName(BUILT_INS_SRC_DIR.absolutePath))
|
||||||
}
|
}
|
||||||
catch (MalformedURLException e) {
|
catch (e: MalformedURLException) {
|
||||||
throw UtilsPackage.rethrow(e);
|
throw rethrow(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalStateException("Built-ins file wasn't found at url: " + builtInFilePath);
|
throw IllegalStateException("Built-ins file wasn't found at url: " + builtInFilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new URL(url.getProtocol(), url.getHost(), PathUtil.getParentPath(url.getFile()));
|
return URL(url.protocol, url.host, PathUtil.getParentPath(url.file))
|
||||||
}
|
}
|
||||||
catch (MalformedURLException e) {
|
catch (e: MalformedURLException) {
|
||||||
throw new AssertionError(e);
|
throw AssertionError(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
fun findClass(fqn: FqName, stub: StubElement<*>): PsiClass? {
|
||||||
/*package*/ static PsiClass findClass(@NotNull FqName fqn, @NotNull StubElement<?> stub) {
|
if (stub is PsiClassStub<*> && Comparing.equal(fqn.asString(), stub.qualifiedName)) {
|
||||||
if (stub instanceof PsiClassStub && Comparing.equal(fqn.asString(), ((PsiClassStub) stub).getQualifiedName())) {
|
return stub.getPsi()
|
||||||
return (PsiClass) stub.getPsi();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stub instanceof PsiClassStub || stub instanceof PsiFileStub) {
|
if (stub is PsiClassStub<*> || stub is PsiFileStub<*>) {
|
||||||
for (StubElement child : stub.getChildrenStubs()) {
|
for (child in stub.childrenStubs) {
|
||||||
PsiClass answer = findClass(fqn, child);
|
val answer = findClass(fqn, child)
|
||||||
if (answer != null) return answer;
|
if (answer != null) return answer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null
|
||||||
|
}/*package*/
|
||||||
|
|
||||||
|
public fun getPsiClass(classOrObject: JetClassOrObject?): PsiClass? {
|
||||||
|
if (classOrObject == null) return null
|
||||||
|
return LightClassGenerationSupport.getInstance(classOrObject.project).getPsiClass(classOrObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
public fun getLightClassAccessorMethod(accessor: JetPropertyAccessor): PsiMethod? {
|
||||||
public static PsiClass getPsiClass(@Nullable JetClassOrObject classOrObject) {
|
val property = PsiTreeUtil.getParentOfType(accessor, JetProperty::class.java) ?: return null
|
||||||
if (classOrObject == null) return null;
|
val wrappers = getPsiMethodWrappers(property, true)
|
||||||
return LightClassGenerationSupport.getInstance(classOrObject.getProject()).getPsiClass(classOrObject);
|
for (wrapper in wrappers) {
|
||||||
}
|
if ((accessor.isGetter && !wrapper.name.startsWith(JvmAbi.SETTER_PREFIX)) || (accessor.isSetter && wrapper.name.startsWith(JvmAbi.SETTER_PREFIX))) {
|
||||||
|
return wrapper
|
||||||
@Nullable
|
|
||||||
public static PsiMethod getLightClassAccessorMethod(@NotNull JetPropertyAccessor accessor) {
|
|
||||||
JetProperty property = PsiTreeUtil.getParentOfType(accessor, JetProperty.class);
|
|
||||||
if (property == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
List<PsiMethod> wrappers = getPsiMethodWrappers(property, true);
|
|
||||||
for (PsiMethod wrapper : wrappers) {
|
|
||||||
if ((accessor.isGetter() && !wrapper.getName().startsWith(JvmAbi.SETTER_PREFIX)) ||
|
|
||||||
(accessor.isSetter() && wrapper.getName().startsWith(JvmAbi.SETTER_PREFIX))) {
|
|
||||||
return wrapper;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
public fun getLightFieldForCompanionObject(companionObject: JetClassOrObject): PsiField? {
|
||||||
public static PsiField getLightFieldForCompanionObject(@NotNull JetClassOrObject companionObject) {
|
val outerPsiClass = getWrappingClass(companionObject)
|
||||||
PsiClass outerPsiClass = getWrappingClass(companionObject);
|
|
||||||
if (outerPsiClass != null) {
|
if (outerPsiClass != null) {
|
||||||
for (PsiField fieldOfParent : outerPsiClass.getFields()) {
|
for (fieldOfParent in outerPsiClass.fields) {
|
||||||
if ((fieldOfParent instanceof KotlinLightElement) &&
|
if ((fieldOfParent is KotlinLightElement<*, *>) && fieldOfParent.getOrigin() === companionObject) {
|
||||||
((KotlinLightElement<?, ?>) fieldOfParent).getOrigin() == companionObject) {
|
return fieldOfParent
|
||||||
return fieldOfParent;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public fun getLightClassPropertyMethods(property: JetProperty): PropertyAccessorsPsiMethods {
|
||||||
public static PropertyAccessorsPsiMethods getLightClassPropertyMethods(@NotNull JetProperty property) {
|
val getter = property.getter
|
||||||
JetPropertyAccessor getter = property.getGetter();
|
val setter = property.setter
|
||||||
JetPropertyAccessor setter = property.getSetter();
|
|
||||||
|
|
||||||
PsiMethod getterWrapper = getter != null ? getLightClassAccessorMethod(getter) : null;
|
val getterWrapper = if (getter != null) getLightClassAccessorMethod(getter) else null
|
||||||
PsiMethod setterWrapper = setter != null ? getLightClassAccessorMethod(setter) : null;
|
val setterWrapper = if (setter != null) getLightClassAccessorMethod(setter) else null
|
||||||
|
|
||||||
return extractPropertyAccessors(property, getterWrapper, setterWrapper);
|
return extractPropertyAccessors(property, getterWrapper, setterWrapper)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
private fun getLightClassBackingField(declaration: JetDeclaration): PsiField? {
|
||||||
private static PsiField getLightClassBackingField(JetDeclaration declaration) {
|
var psiClass: PsiClass = getWrappingClass(declaration) ?: return null
|
||||||
PsiClass psiClass = getWrappingClass(declaration);
|
|
||||||
if (psiClass == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (psiClass instanceof KotlinLightClass) {
|
if (psiClass is KotlinLightClass) {
|
||||||
JetClassOrObject origin = ((KotlinLightClass) psiClass).getOrigin();
|
val origin = psiClass.getOrigin()
|
||||||
if (origin instanceof JetObjectDeclaration && ((JetObjectDeclaration) origin).isCompanion()) {
|
if (origin is JetObjectDeclaration && origin.isCompanion()) {
|
||||||
JetClass containingClass = PsiTreeUtil.getParentOfType(origin, JetClass.class);
|
val containingClass = PsiTreeUtil.getParentOfType(origin, JetClass::class.java)
|
||||||
if (containingClass != null) {
|
if (containingClass != null) {
|
||||||
PsiClass containingLightClass = getPsiClass(containingClass);
|
val containingLightClass = getPsiClass(containingClass)
|
||||||
if (containingLightClass != null) {
|
if (containingLightClass != null) {
|
||||||
psiClass = containingLightClass;
|
psiClass = containingLightClass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (PsiField field : psiClass.getFields()) {
|
for (field in psiClass.fields) {
|
||||||
if (field instanceof KotlinLightField && ((KotlinLightField) field).getOrigin() == declaration) {
|
if (field is KotlinLightField<*, *> && field.getOrigin() === declaration) {
|
||||||
return field;
|
return field
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public fun getLightClassPropertyMethods(parameter: JetParameter): PropertyAccessorsPsiMethods {
|
||||||
public static PropertyAccessorsPsiMethods getLightClassPropertyMethods(@NotNull JetParameter parameter) {
|
return extractPropertyAccessors(parameter, null, null)
|
||||||
return extractPropertyAccessors(parameter, null, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
public fun getLightClassMethod(function: JetFunction): PsiMethod? {
|
||||||
public static PsiMethod getLightClassMethod(@NotNull JetFunction function) {
|
return getPsiMethodWrapper(function)
|
||||||
return getPsiMethodWrapper(function);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
private fun getPsiMethodWrapper(declaration: JetDeclaration): PsiMethod? {
|
||||||
private static PsiMethod getPsiMethodWrapper(@NotNull JetDeclaration declaration) {
|
val wrappers = getPsiMethodWrappers(declaration, false)
|
||||||
List<PsiMethod> wrappers = getPsiMethodWrappers(declaration, false);
|
return if (!wrappers.isEmpty()) wrappers.get(0) else null
|
||||||
return !wrappers.isEmpty() ? wrappers.get(0) : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
private fun getPsiMethodWrappers(declaration: JetDeclaration, collectAll: Boolean): List<PsiMethod> {
|
||||||
private static List<PsiMethod> getPsiMethodWrappers(@NotNull JetDeclaration declaration, boolean collectAll) {
|
val psiClass = getWrappingClass(declaration) ?: return emptyList()
|
||||||
PsiClass psiClass = getWrappingClass(declaration);
|
|
||||||
if (psiClass == null) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<PsiMethod> methods = new SmartList<PsiMethod>();
|
val methods = SmartList<PsiMethod>()
|
||||||
for (PsiMethod method : psiClass.getMethods()) {
|
for (method in psiClass.methods) {
|
||||||
try {
|
try {
|
||||||
if (method instanceof KotlinLightMethod && ((KotlinLightMethod) method).getOrigin() == declaration) {
|
if (method is KotlinLightMethod && method.getOrigin() === declaration) {
|
||||||
methods.add(method);
|
methods.add(method)
|
||||||
if (!collectAll) {
|
if (!collectAll) {
|
||||||
return methods;
|
return methods
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ProcessCanceledException e) {
|
catch (e: ProcessCanceledException) {
|
||||||
throw e;
|
throw e
|
||||||
}
|
}
|
||||||
catch (Throwable e) {
|
catch (e: Throwable) {
|
||||||
throw new IllegalStateException(
|
throw IllegalStateException(
|
||||||
"Error while wrapping declaration " + declaration.getName() +
|
"Error while wrapping declaration " + declaration.name + "Context\n:" + method, e)
|
||||||
"Context\n:" +
|
|
||||||
String.format("=== In file ===\n" +
|
|
||||||
"%s\n" +
|
|
||||||
"=== On element ===\n" +
|
|
||||||
"%s\n" +
|
|
||||||
"=== WrappedElement ===\n" +
|
|
||||||
"%s\n",
|
|
||||||
declaration.getContainingFile().getText(),
|
|
||||||
declaration.getText(),
|
|
||||||
method.toString()),
|
|
||||||
e
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return methods;
|
return methods
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
private fun getWrappingClass(declaration: JetDeclaration): PsiClass? {
|
||||||
private static PsiClass getWrappingClass(@NotNull JetDeclaration declaration) {
|
var declaration = declaration
|
||||||
if (declaration instanceof JetParameter) {
|
if (declaration is JetParameter) {
|
||||||
JetClassOrObject constructorClass = JetPsiUtil.getClassIfParameterIsProperty((JetParameter) declaration);
|
val constructorClass = JetPsiUtil.getClassIfParameterIsProperty(declaration)
|
||||||
if (constructorClass != null) {
|
if (constructorClass != null) {
|
||||||
return getPsiClass(constructorClass);
|
return getPsiClass(constructorClass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (declaration instanceof JetPropertyAccessor) {
|
if (declaration is JetPropertyAccessor) {
|
||||||
PsiElement propertyParent = declaration.getParent();
|
val propertyParent = declaration.parent
|
||||||
assert propertyParent instanceof JetProperty : "JetProperty is expected to be parent of accessor";
|
assert(propertyParent is JetProperty, "JetProperty is expected to be parent of accessor")
|
||||||
|
|
||||||
declaration = (JetProperty) propertyParent;
|
declaration = propertyParent as JetProperty
|
||||||
}
|
}
|
||||||
|
|
||||||
if (declaration instanceof JetConstructor) {
|
if (declaration is JetConstructor<*>) {
|
||||||
return getPsiClass(((JetConstructor) declaration).getContainingClassOrObject());
|
return getPsiClass(declaration.getContainingClassOrObject())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canGenerateLightClass(declaration)) {
|
if (!canGenerateLightClass(declaration)) {
|
||||||
// Can't get wrappers for internal declarations. Their classes are not generated during calcStub
|
// Can't get wrappers for internal declarations. Their classes are not generated during calcStub
|
||||||
// with ClassBuilderMode.LIGHT_CLASSES mode, and this produces "Class not found exception" in getDelegate()
|
// with ClassBuilderMode.LIGHT_CLASSES mode, and this produces "Class not found exception" in getDelegate()
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
PsiElement parent = declaration.getParent();
|
val parent = declaration.parent
|
||||||
|
|
||||||
if (parent instanceof JetFile) {
|
if (parent is JetFile) {
|
||||||
// top-level declaration
|
// top-level declaration
|
||||||
FqName fqName = PackageClassUtils.getPackageClassFqName(((JetFile) parent).getPackageFqName());
|
val fqName = PackageClassUtils.getPackageClassFqName(parent.packageFqName)
|
||||||
Project project = declaration.getProject();
|
val project = declaration.project
|
||||||
return JavaElementFinder.getInstance(project).findClass(fqName.asString(), GlobalSearchScope.allScope(project));
|
return JavaElementFinder.getInstance(project).findClass(fqName.asString(), GlobalSearchScope.allScope(project))
|
||||||
}
|
}
|
||||||
else if (parent instanceof JetClassBody) {
|
else if (parent is JetClassBody) {
|
||||||
assert parent.getParent() instanceof JetClassOrObject;
|
assert(parent.parent is JetClassOrObject)
|
||||||
return getPsiClass((JetClassOrObject) parent.getParent());
|
return getPsiClass(parent.parent as JetClassOrObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canGenerateLightClass(JetDeclaration declaration) {
|
public fun canGenerateLightClass(declaration: JetDeclaration): Boolean {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
return PsiTreeUtil.getParentOfType(declaration, JetFunction.class, JetProperty.class) == null;
|
return PsiTreeUtil.getParentOfType(declaration, JetFunction::class.java, JetProperty::class.java) == null
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
private fun extractPropertyAccessors(
|
||||||
private static PropertyAccessorsPsiMethods extractPropertyAccessors(
|
jetDeclaration: JetDeclaration,
|
||||||
@NotNull JetDeclaration jetDeclaration,
|
specialGetter: PsiMethod?, specialSetter: PsiMethod?): PropertyAccessorsPsiMethods {
|
||||||
@Nullable PsiMethod specialGetter, @Nullable PsiMethod specialSetter
|
var getterWrapper = specialGetter
|
||||||
) {
|
var setterWrapper = specialSetter
|
||||||
PsiMethod getterWrapper = specialGetter;
|
|
||||||
PsiMethod setterWrapper = specialSetter;
|
|
||||||
|
|
||||||
if (getterWrapper == null || setterWrapper == null) {
|
if (getterWrapper == null || setterWrapper == null) {
|
||||||
// If some getter or setter isn't found yet try to get it from wrappers for general declaration
|
// If some getter or setter isn't found yet try to get it from wrappers for general declaration
|
||||||
|
|
||||||
List<PsiMethod> wrappers = KotlinPackage.filter(
|
val wrappers = getPsiMethodWrappers(jetDeclaration, true).filter {
|
||||||
getPsiMethodWrappers(jetDeclaration, true),
|
it.name.startsWith(JvmAbi.GETTER_PREFIX) || it.name.startsWith(JvmAbi.SETTER_PREFIX)
|
||||||
new Function1<PsiMethod, Boolean>() {
|
}
|
||||||
@Override
|
|
||||||
public Boolean invoke(PsiMethod method) {
|
|
||||||
String name = method.getName();
|
|
||||||
return name.startsWith(JvmAbi.GETTER_PREFIX) || name.startsWith(JvmAbi.SETTER_PREFIX);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
assert wrappers.size() <= 2 : "Maximum two wrappers are expected to be generated for declaration: " + jetDeclaration.getText();
|
|
||||||
|
|
||||||
for (PsiMethod wrapper : wrappers) {
|
assert(wrappers.size() <= 2) { "Maximum two wrappers are expected to be generated for declaration: " + jetDeclaration.text }
|
||||||
|
|
||||||
|
for (wrapper in wrappers) {
|
||||||
if (wrapper.getName().startsWith(JvmAbi.SETTER_PREFIX)) {
|
if (wrapper.getName().startsWith(JvmAbi.SETTER_PREFIX)) {
|
||||||
assert setterWrapper == null || setterWrapper == specialSetter: String.format(
|
assert(setterWrapper == null || setterWrapper === specialSetter) {
|
||||||
"Setter accessor isn't expected to be reassigned (old: %s, new: %s)", setterWrapper, wrapper);
|
"Setter accessor isn't expected to be reassigned (old: $setterWrapper, new: $wrapper)"
|
||||||
|
}
|
||||||
|
|
||||||
setterWrapper = wrapper;
|
setterWrapper = wrapper
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert getterWrapper == null || getterWrapper == specialGetter: String.format(
|
assert(getterWrapper == null || getterWrapper === specialGetter) {
|
||||||
"Getter accessor isn't expected to be reassigned (old: %s, new: %s)", getterWrapper, wrapper);
|
"Getter accessor isn't expected to be reassigned (old: $getterWrapper, new: $wrapper)"
|
||||||
|
}
|
||||||
|
|
||||||
getterWrapper = wrapper;
|
getterWrapper = wrapper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PsiField backingField = getLightClassBackingField(jetDeclaration);
|
val backingField = getLightClassBackingField(jetDeclaration)
|
||||||
return new PropertyAccessorsPsiMethods(getterWrapper, setterWrapper, backingField);
|
return PropertyAccessorsPsiMethods(getterWrapper, setterWrapper, backingField)
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public fun buildLightTypeParameterList(
|
||||||
public static PsiTypeParameterList buildLightTypeParameterList(PsiTypeParameterListOwner owner, JetDeclaration declaration) {
|
owner: PsiTypeParameterListOwner,
|
||||||
LightTypeParameterListBuilder builder = new KotlinLightTypeParameterListBuilder(owner.getManager());
|
declaration: JetDeclaration): PsiTypeParameterList {
|
||||||
if (declaration instanceof JetTypeParameterListOwner) {
|
val builder = KotlinLightTypeParameterListBuilder(owner.manager)
|
||||||
JetTypeParameterListOwner typeParameterListOwner = (JetTypeParameterListOwner) declaration;
|
if (declaration is JetTypeParameterListOwner) {
|
||||||
List<JetTypeParameter> parameters = typeParameterListOwner.getTypeParameters();
|
val parameters = declaration.typeParameters
|
||||||
for (int i = 0; i < parameters.size(); i++) {
|
for (i in parameters.indices) {
|
||||||
JetTypeParameter jetTypeParameter = parameters.get(i);
|
val jetTypeParameter = parameters.get(i)
|
||||||
String name = jetTypeParameter.getName();
|
val name = jetTypeParameter.name
|
||||||
String safeName = name == null ? "__no_name__" : name;
|
val safeName = name ?: "__no_name__"
|
||||||
builder.addParameter(new KotlinLightTypeParameter(owner, i, safeName));
|
builder.addParameter(KotlinLightTypeParameter(owner, i, safeName))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return builder;
|
return builder
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PropertyAccessorsPsiMethods implements Iterable<PsiMethod> {
|
public class PropertyAccessorsPsiMethods(public val getter: PsiMethod?, public val setter: PsiMethod?, public val backingField: PsiField?) : Iterable<PsiMethod> {
|
||||||
private final PsiMethod getter;
|
private val accessors = ArrayList<PsiMethod>(2)
|
||||||
private final PsiMethod setter;
|
|
||||||
private final PsiField backingField;
|
|
||||||
private final Collection<PsiMethod> accessors = new ArrayList<PsiMethod>(2);
|
|
||||||
|
|
||||||
PropertyAccessorsPsiMethods(@Nullable PsiMethod getter, @Nullable PsiMethod setter, @Nullable PsiField backingField) {
|
init {
|
||||||
this.getter = getter;
|
|
||||||
if (getter != null) {
|
if (getter != null) {
|
||||||
accessors.add(getter);
|
accessors.add(getter)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setter = setter;
|
|
||||||
if (setter != null) {
|
if (setter != null) {
|
||||||
accessors.add(setter);
|
accessors.add(setter)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.backingField = backingField;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
override fun iterator(): Iterator<PsiMethod> {
|
||||||
public PsiMethod getGetter() {
|
return accessors.iterator()
|
||||||
return getter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public PsiMethod getSetter() {
|
|
||||||
return setter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public PsiField getBackingField() {
|
|
||||||
return backingField;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Iterator<PsiMethod> iterator() {
|
|
||||||
return accessors.iterator();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private LightClassUtil() {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,14 +17,12 @@
|
|||||||
package org.jetbrains.kotlin.asJava
|
package org.jetbrains.kotlin.asJava
|
||||||
|
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
import com.intellij.util.containers.ContainerUtil
|
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import java.util.Collections
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||||
import java.util.ArrayList
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration
|
import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
|
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
public fun JetClassOrObject.toLightClass(): KotlinLightClass? = LightClassUtil.getPsiClass(this) as KotlinLightClass?
|
public fun JetClassOrObject.toLightClass(): KotlinLightClass? = LightClassUtil.getPsiClass(this) as KotlinLightClass?
|
||||||
|
|
||||||
@@ -59,8 +57,8 @@ public fun PsiElement.toLightMethods(): List<PsiMethod> =
|
|||||||
public fun PsiElement.getRepresentativeLightMethod(): PsiMethod? =
|
public fun PsiElement.getRepresentativeLightMethod(): PsiMethod? =
|
||||||
when (this) {
|
when (this) {
|
||||||
is JetFunction -> LightClassUtil.getLightClassMethod(this)
|
is JetFunction -> LightClassUtil.getLightClassMethod(this)
|
||||||
is JetProperty -> LightClassUtil.getLightClassPropertyMethods(this).getGetter()
|
is JetProperty -> LightClassUtil.getLightClassPropertyMethods(this).getter
|
||||||
is JetParameter -> LightClassUtil.getLightClassPropertyMethods(this).getGetter()
|
is JetParameter -> LightClassUtil.getLightClassPropertyMethods(this).getter
|
||||||
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(this)
|
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(this)
|
||||||
is PsiMethod -> this
|
is PsiMethod -> this
|
||||||
else -> null
|
else -> null
|
||||||
|
|||||||
+2
-2
@@ -359,7 +359,7 @@ public class JetSourceNavigationHelper {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static PsiClass getOriginalPsiClassOrCreateLightClass(@NotNull JetClassOrObject classOrObject) {
|
public static PsiClass getOriginalPsiClassOrCreateLightClass(@NotNull JetClassOrObject classOrObject) {
|
||||||
if (LightClassUtil.belongsToKotlinBuiltIns(classOrObject.getContainingJetFile())) {
|
if (LightClassUtil.INSTANCE$.belongsToKotlinBuiltIns(classOrObject.getContainingJetFile())) {
|
||||||
Name className = classOrObject.getNameAsName();
|
Name className = classOrObject.getNameAsName();
|
||||||
assert className != null : "Class from BuiltIns should have a name";
|
assert className != null : "Class from BuiltIns should have a name";
|
||||||
ClassDescriptor classDescriptor = KotlinBuiltIns.getInstance().getBuiltInClassByName(className);
|
ClassDescriptor classDescriptor = KotlinBuiltIns.getInstance().getBuiltInClassByName(className);
|
||||||
@@ -372,7 +372,7 @@ public class JetSourceNavigationHelper {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return LightClassUtil.getPsiClass(classOrObject);
|
return LightClassUtil.INSTANCE$.getPsiClass(classOrObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
+1
-4
@@ -21,7 +21,6 @@ import com.intellij.openapi.components.ServiceManager
|
|||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.startup.StartupManager
|
import com.intellij.openapi.startup.StartupManager
|
||||||
import com.intellij.openapi.vfs.VfsUtilCore
|
import com.intellij.openapi.vfs.VfsUtilCore
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
|
||||||
import com.intellij.openapi.vfs.VirtualFileManager
|
import com.intellij.openapi.vfs.VirtualFileManager
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiManager
|
import com.intellij.psi.PsiManager
|
||||||
@@ -43,9 +42,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
|||||||
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
|
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
||||||
import org.jetbrains.kotlin.utils.rethrow
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.MalformedURLException
|
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
public class BuiltInsReferenceResolver(val project: Project, val startupManager: StartupManager) {
|
public class BuiltInsReferenceResolver(val project: Project, val startupManager: StartupManager) {
|
||||||
@@ -178,7 +175,7 @@ public class BuiltInsReferenceResolver(val project: Project, val startupManager:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fun getBuiltInsDirUrls(): Set<URL> {
|
public fun getBuiltInsDirUrls(): Set<URL> {
|
||||||
val defaultBuiltIns = LightClassUtil.getBuiltInsDirUrl()
|
val defaultBuiltIns = LightClassUtil.builtInsDirUrl
|
||||||
// In production, the above URL is enough as it contains sources for both native and compilable built-ins
|
// In production, the above URL is enough as it contains sources for both native and compilable built-ins
|
||||||
// (it's simply the "kotlin" directory in kotlin-plugin.jar)
|
// (it's simply the "kotlin" directory in kotlin-plugin.jar)
|
||||||
// But in tests, sources of built-ins are not added to the classpath automatically, so we manually specify URLs for both:
|
// But in tests, sources of built-ins are not added to the classpath automatically, so we manually specify URLs for both:
|
||||||
|
|||||||
+2
-2
@@ -32,8 +32,8 @@ import java.util.*
|
|||||||
|
|
||||||
fun PsiNamedElement.getAccessorNames(readable: Boolean = true, writable: Boolean = true): List<String> {
|
fun PsiNamedElement.getAccessorNames(readable: Boolean = true, writable: Boolean = true): List<String> {
|
||||||
fun PropertyAccessorsPsiMethods.toNameList(): List<String> {
|
fun PropertyAccessorsPsiMethods.toNameList(): List<String> {
|
||||||
val getter = getGetter()
|
val getter = getter
|
||||||
val setter = getSetter()
|
val setter = setter
|
||||||
|
|
||||||
val result = ArrayList<String>()
|
val result = ArrayList<String>()
|
||||||
if (readable && getter != null) result.add(getter.getName())
|
if (readable && getter != null) result.add(getter.getName())
|
||||||
|
|||||||
+1
-2
@@ -21,7 +21,6 @@ import com.intellij.find.findUsages.FindClassUsagesDialog;
|
|||||||
import com.intellij.find.findUsages.FindUsagesHandler;
|
import com.intellij.find.findUsages.FindUsagesHandler;
|
||||||
import com.intellij.find.findUsages.FindUsagesOptions;
|
import com.intellij.find.findUsages.FindUsagesOptions;
|
||||||
import com.intellij.find.findUsages.JavaClassFindUsagesOptions;
|
import com.intellij.find.findUsages.JavaClassFindUsagesOptions;
|
||||||
import com.intellij.openapi.diagnostic.Logger;
|
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.util.Key;
|
import com.intellij.openapi.util.Key;
|
||||||
import com.intellij.psi.PsiClass;
|
import com.intellij.psi.PsiClass;
|
||||||
@@ -63,7 +62,7 @@ public class KotlinFindClassUsagesDialog extends FindClassUsagesDialog {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static PsiClass getRepresentingPsiClass(@NotNull JetClassOrObject classOrObject) {
|
private static PsiClass getRepresentingPsiClass(@NotNull JetClassOrObject classOrObject) {
|
||||||
PsiClass lightClass = LightClassUtil.getPsiClass(classOrObject);
|
PsiClass lightClass = LightClassUtil.INSTANCE$.getPsiClass(classOrObject);
|
||||||
if (lightClass != null) return lightClass;
|
if (lightClass != null) return lightClass;
|
||||||
|
|
||||||
// TODO: Remove this code when light classes are generated for builtins
|
// TODO: Remove this code when light classes are generated for builtins
|
||||||
|
|||||||
@@ -92,17 +92,17 @@ public abstract class KotlinCallTreeStructure extends HierarchyTreeStructure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (element instanceof JetNamedFunction || element instanceof JetSecondaryConstructor) {
|
if (element instanceof JetNamedFunction || element instanceof JetSecondaryConstructor) {
|
||||||
return LightClassUtil.getLightClassMethod((JetFunction) element);
|
return LightClassUtil.INSTANCE$.getLightClassMethod((JetFunction) element);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element instanceof JetProperty) {
|
if (element instanceof JetProperty) {
|
||||||
LightClassUtil.PropertyAccessorsPsiMethods propertyMethods =
|
LightClassUtil.PropertyAccessorsPsiMethods propertyMethods =
|
||||||
LightClassUtil.getLightClassPropertyMethods((JetProperty) element);
|
LightClassUtil.INSTANCE$.getLightClassPropertyMethods((JetProperty) element);
|
||||||
return (propertyMethods.getGetter() != null) ? propertyMethods.getGetter() : propertyMethods.getSetter();
|
return (propertyMethods.getGetter() != null) ? propertyMethods.getGetter() : propertyMethods.getSetter();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element instanceof JetClassOrObject) {
|
if (element instanceof JetClassOrObject) {
|
||||||
PsiClass psiClass = LightClassUtil.getPsiClass((JetClassOrObject) element);
|
PsiClass psiClass = LightClassUtil.INSTANCE$.getPsiClass((JetClassOrObject) element);
|
||||||
if (psiClass == null) return null;
|
if (psiClass == null) return null;
|
||||||
|
|
||||||
PsiMethod[] constructors = psiClass.getConstructors();
|
PsiMethod[] constructors = psiClass.getConstructors();
|
||||||
|
|||||||
+3
-3
@@ -107,18 +107,18 @@ public class KotlinCallerMethodsTreeStructure extends KotlinCallTreeStructure {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (element instanceof JetNamedFunction || element instanceof JetSecondaryConstructor) {
|
if (element instanceof JetNamedFunction || element instanceof JetSecondaryConstructor) {
|
||||||
PsiMethod lightMethod = LightClassUtil.getLightClassMethod((JetFunction) element);
|
PsiMethod lightMethod = LightClassUtil.INSTANCE$.getLightClassMethod((JetFunction) element);
|
||||||
processPsiMethodCallers(Collections.singleton(lightMethod), descriptor, methodToDescriptorMap, searchScope, false);
|
processPsiMethodCallers(Collections.singleton(lightMethod), descriptor, methodToDescriptorMap, searchScope, false);
|
||||||
}
|
}
|
||||||
if (element instanceof JetProperty) {
|
if (element instanceof JetProperty) {
|
||||||
LightClassUtil.PropertyAccessorsPsiMethods propertyMethods =
|
LightClassUtil.PropertyAccessorsPsiMethods propertyMethods =
|
||||||
LightClassUtil.getLightClassPropertyMethods((JetProperty) element);
|
LightClassUtil.INSTANCE$.getLightClassPropertyMethods((JetProperty) element);
|
||||||
processPsiMethodCallers(propertyMethods, descriptor, methodToDescriptorMap, searchScope, false);
|
processPsiMethodCallers(propertyMethods, descriptor, methodToDescriptorMap, searchScope, false);
|
||||||
}
|
}
|
||||||
if (element instanceof JetClassOrObject) {
|
if (element instanceof JetClassOrObject) {
|
||||||
JetPrimaryConstructor constructor = ((JetClassOrObject) element).getPrimaryConstructor();
|
JetPrimaryConstructor constructor = ((JetClassOrObject) element).getPrimaryConstructor();
|
||||||
if (constructor != null) {
|
if (constructor != null) {
|
||||||
PsiMethod lightMethod = LightClassUtil.getLightClassMethod(constructor);
|
PsiMethod lightMethod = LightClassUtil.INSTANCE$.getLightClassMethod(constructor);
|
||||||
processPsiMethodCallers(Collections.singleton(lightMethod), descriptor, methodToDescriptorMap, searchScope, false);
|
processPsiMethodCallers(Collections.singleton(lightMethod), descriptor, methodToDescriptorMap, searchScope, false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -517,7 +517,7 @@ public fun createJavaMethod(template: PsiMethod, targetClass: PsiClass): PsiMeth
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun createJavaField(property: JetProperty, targetClass: PsiClass): PsiField {
|
fun createJavaField(property: JetProperty, targetClass: PsiClass): PsiField {
|
||||||
val template = LightClassUtil.getLightClassPropertyMethods(property).getGetter()
|
val template = LightClassUtil.getLightClassPropertyMethods(property).getter
|
||||||
?: throw AssertionError("Can't generate light method: ${property.getElementTextWithContext()}")
|
?: throw AssertionError("Can't generate light method: ${property.getElementTextWithContext()}")
|
||||||
|
|
||||||
val factory = PsiElementFactory.SERVICE.getInstance(template.getProject())
|
val factory = PsiElementFactory.SERVICE.getInstance(template.getProject())
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class JetTestNgConfigurationProducer extends TestNGConfigurationProducer
|
|||||||
JetElement owner = PsiTreeUtil.getParentOfType(function, JetFunction.class, JetClass.class);
|
JetElement owner = PsiTreeUtil.getParentOfType(function, JetFunction.class, JetClass.class);
|
||||||
|
|
||||||
if (owner instanceof JetClass) {
|
if (owner instanceof JetClass) {
|
||||||
PsiClass delegate = LightClassUtil.getPsiClass((JetClass) owner);
|
PsiClass delegate = LightClassUtil.INSTANCE$.getPsiClass((JetClass) owner);
|
||||||
if (delegate != null) {
|
if (delegate != null) {
|
||||||
for (PsiMethod method : delegate.getMethods()) {
|
for (PsiMethod method : delegate.getMethods()) {
|
||||||
if (method.getNavigationElement() == function) {
|
if (method.getNavigationElement() == function) {
|
||||||
@@ -97,7 +97,7 @@ public class JetTestNgConfigurationProducer extends TestNGConfigurationProducer
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PsiClass delegate = LightClassUtil.getPsiClass(jetClass);
|
PsiClass delegate = LightClassUtil.INSTANCE$.getPsiClass(jetClass);
|
||||||
if (!isTestNGClass(delegate)) {
|
if (!isTestNGClass(delegate)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -68,7 +68,7 @@ public class KotlinDefinitionsSearcher implements QueryExecutor<PsiElement, Defi
|
|||||||
PsiClass psiClass = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {
|
PsiClass psiClass = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {
|
||||||
@Override
|
@Override
|
||||||
public PsiClass compute() {
|
public PsiClass compute() {
|
||||||
return LightClassUtil.getPsiClass(klass);
|
return LightClassUtil.INSTANCE$.getPsiClass(klass);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (psiClass != null) {
|
if (psiClass != null) {
|
||||||
@@ -81,7 +81,7 @@ public class KotlinDefinitionsSearcher implements QueryExecutor<PsiElement, Defi
|
|||||||
PsiMethod psiMethod = ApplicationManager.getApplication().runReadAction(new Computable<PsiMethod>() {
|
PsiMethod psiMethod = ApplicationManager.getApplication().runReadAction(new Computable<PsiMethod>() {
|
||||||
@Override
|
@Override
|
||||||
public PsiMethod compute() {
|
public PsiMethod compute() {
|
||||||
return LightClassUtil.getLightClassMethod(function);
|
return LightClassUtil.INSTANCE$.getLightClassMethod(function);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ public class KotlinDefinitionsSearcher implements QueryExecutor<PsiElement, Defi
|
|||||||
new Computable<LightClassUtil.PropertyAccessorsPsiMethods>() {
|
new Computable<LightClassUtil.PropertyAccessorsPsiMethods>() {
|
||||||
@Override
|
@Override
|
||||||
public LightClassUtil.PropertyAccessorsPsiMethods compute() {
|
public LightClassUtil.PropertyAccessorsPsiMethods compute() {
|
||||||
return LightClassUtil.getLightClassPropertyMethods(parameter);
|
return LightClassUtil.INSTANCE$.getLightClassPropertyMethods(parameter);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ public class KotlinDefinitionsSearcher implements QueryExecutor<PsiElement, Defi
|
|||||||
new Computable<LightClassUtil.PropertyAccessorsPsiMethods>() {
|
new Computable<LightClassUtil.PropertyAccessorsPsiMethods>() {
|
||||||
@Override
|
@Override
|
||||||
public LightClassUtil.PropertyAccessorsPsiMethods compute() {
|
public LightClassUtil.PropertyAccessorsPsiMethods compute() {
|
||||||
return LightClassUtil.getLightClassPropertyMethods(property);
|
return LightClassUtil.INSTANCE$.getLightClassPropertyMethods(property);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ public class JetJavaFacadeTest extends JetLightCodeInsightFixtureTestCase {
|
|||||||
assertInstanceOf(element, JetClass.class);
|
assertInstanceOf(element, JetClass.class);
|
||||||
JetClass aClass = (JetClass) element;
|
JetClass aClass = (JetClass) element;
|
||||||
|
|
||||||
PsiClass createdByWrapDelegate = LightClassUtil.getPsiClass(aClass);
|
PsiClass createdByWrapDelegate = LightClassUtil.INSTANCE$.getPsiClass(aClass);
|
||||||
assertNull(createdByWrapDelegate);
|
assertNull(createdByWrapDelegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +220,7 @@ public class JetJavaFacadeTest extends JetLightCodeInsightFixtureTestCase {
|
|||||||
JetNamedFunction jetFunction = getPreparedElement(JetNamedFunction.class);
|
JetNamedFunction jetFunction = getPreparedElement(JetNamedFunction.class);
|
||||||
|
|
||||||
// Should not fail!
|
// Should not fail!
|
||||||
PsiMethod psiMethod = LightClassUtil.getLightClassMethod(jetFunction);
|
PsiMethod psiMethod = LightClassUtil.INSTANCE$.getLightClassMethod(jetFunction);
|
||||||
|
|
||||||
checkDeclarationMethodWrapped(shouldBeWrapped, jetFunction, psiMethod);
|
checkDeclarationMethodWrapped(shouldBeWrapped, jetFunction, psiMethod);
|
||||||
}
|
}
|
||||||
@@ -229,7 +229,7 @@ public class JetJavaFacadeTest extends JetLightCodeInsightFixtureTestCase {
|
|||||||
JetParameter jetParameter = getPreparedElement(JetParameter.class);
|
JetParameter jetParameter = getPreparedElement(JetParameter.class);
|
||||||
|
|
||||||
// Should not fail!
|
// Should not fail!
|
||||||
LightClassUtil.PropertyAccessorsPsiMethods propertyAccessors = LightClassUtil.getLightClassPropertyMethods(jetParameter);
|
LightClassUtil.PropertyAccessorsPsiMethods propertyAccessors = LightClassUtil.INSTANCE$.getLightClassPropertyMethods(jetParameter);
|
||||||
|
|
||||||
checkDeclarationMethodWrapped(shouldWrapGetter, jetParameter, propertyAccessors.getGetter());
|
checkDeclarationMethodWrapped(shouldWrapGetter, jetParameter, propertyAccessors.getGetter());
|
||||||
checkDeclarationMethodWrapped(shouldWrapSetter, jetParameter, propertyAccessors.getSetter());
|
checkDeclarationMethodWrapped(shouldWrapSetter, jetParameter, propertyAccessors.getSetter());
|
||||||
@@ -239,7 +239,7 @@ public class JetJavaFacadeTest extends JetLightCodeInsightFixtureTestCase {
|
|||||||
JetProperty jetProperty = getPreparedElement(JetProperty.class);
|
JetProperty jetProperty = getPreparedElement(JetProperty.class);
|
||||||
|
|
||||||
// Should not fail!
|
// Should not fail!
|
||||||
LightClassUtil.PropertyAccessorsPsiMethods propertyAccessors = LightClassUtil.getLightClassPropertyMethods(jetProperty);
|
LightClassUtil.PropertyAccessorsPsiMethods propertyAccessors = LightClassUtil.INSTANCE$.getLightClassPropertyMethods(jetProperty);
|
||||||
|
|
||||||
checkDeclarationMethodWrapped(shouldWrapGetter, jetProperty, propertyAccessors.getGetter());
|
checkDeclarationMethodWrapped(shouldWrapGetter, jetProperty, propertyAccessors.getGetter());
|
||||||
checkDeclarationMethodWrapped(shouldWrapSetter, jetProperty, propertyAccessors.getSetter());
|
checkDeclarationMethodWrapped(shouldWrapSetter, jetProperty, propertyAccessors.getSetter());
|
||||||
@@ -249,7 +249,7 @@ public class JetJavaFacadeTest extends JetLightCodeInsightFixtureTestCase {
|
|||||||
JetPropertyAccessor jetPropertyAccessor = getPreparedElement(JetPropertyAccessor.class);
|
JetPropertyAccessor jetPropertyAccessor = getPreparedElement(JetPropertyAccessor.class);
|
||||||
|
|
||||||
// Should not fail!
|
// Should not fail!
|
||||||
PsiMethod propertyAccessors = LightClassUtil.getLightClassAccessorMethod(jetPropertyAccessor);
|
PsiMethod propertyAccessors = LightClassUtil.INSTANCE$.getLightClassAccessorMethod(jetPropertyAccessor);
|
||||||
checkDeclarationMethodWrapped(shouldWrapAccessor,
|
checkDeclarationMethodWrapped(shouldWrapAccessor,
|
||||||
PsiTreeUtil.getParentOfType(jetPropertyAccessor, JetProperty.class),
|
PsiTreeUtil.getParentOfType(jetPropertyAccessor, JetProperty.class),
|
||||||
propertyAccessors);
|
propertyAccessors);
|
||||||
@@ -296,7 +296,7 @@ public class JetJavaFacadeTest extends JetLightCodeInsightFixtureTestCase {
|
|||||||
assertNotNull("Caret should be placed to class definition", jetClass);
|
assertNotNull("Caret should be placed to class definition", jetClass);
|
||||||
|
|
||||||
// Should not fail!
|
// Should not fail!
|
||||||
KotlinLightClass lightClass = (KotlinLightClass) LightClassUtil.getPsiClass(jetClass);
|
KotlinLightClass lightClass = (KotlinLightClass) LightClassUtil.INSTANCE$.getPsiClass(jetClass);
|
||||||
|
|
||||||
assertNotNull(String.format("Failed to wrap jetClass '%s' to class", jetClass.getText()), lightClass);
|
assertNotNull(String.format("Failed to wrap jetClass '%s' to class", jetClass.getText()), lightClass);
|
||||||
|
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ public class LightClassEqualsTest extends JetLightCodeInsightFixtureTestCase {
|
|||||||
private static void doTestEquals(@Nullable JetClassOrObject origin) {
|
private static void doTestEquals(@Nullable JetClassOrObject origin) {
|
||||||
assertNotNull(origin);
|
assertNotNull(origin);
|
||||||
|
|
||||||
PsiClass lightClass1 = LightClassUtil.getPsiClass(origin);
|
PsiClass lightClass1 = LightClassUtil.INSTANCE$.getPsiClass(origin);
|
||||||
PsiClass lightClass2 = LightClassUtil.getPsiClass(origin);
|
PsiClass lightClass2 = LightClassUtil.INSTANCE$.getPsiClass(origin);
|
||||||
assertNotNull(lightClass1);
|
assertNotNull(lightClass1);
|
||||||
assertNotNull(lightClass2);
|
assertNotNull(lightClass2);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user