From 3b774a8c826e4d3353973ae07b7e2e0a69ce51da Mon Sep 17 00:00:00 2001 From: Nicolay Mitropolsky Date: Wed, 6 May 2020 13:30:11 +0300 Subject: [PATCH] Uast: `CACHED_UELEMENT_KEY` removed (IDEA-234777) GitOrigin-RevId: 5087be2e5ea595801d664eb438c45e89603c4b6c --- .../src/META-INF/JavaAnalysisPlugin.xml | 1 - .../uast/UastElementAnchorProvider.java | 56 ------------------- .../src/org/jetbrains/uast/UastContext.kt | 17 ------ 3 files changed, 74 deletions(-) delete mode 100644 java/java-analysis-impl/src/com/intellij/uast/UastElementAnchorProvider.java diff --git a/java/java-analysis-impl/src/META-INF/JavaAnalysisPlugin.xml b/java/java-analysis-impl/src/META-INF/JavaAnalysisPlugin.xml index 58ecde76ddb5..b5cdecd0ba43 100644 --- a/java/java-analysis-impl/src/META-INF/JavaAnalysisPlugin.xml +++ b/java/java-analysis-impl/src/META-INF/JavaAnalysisPlugin.xml @@ -40,7 +40,6 @@ - diff --git a/java/java-analysis-impl/src/com/intellij/uast/UastElementAnchorProvider.java b/java/java-analysis-impl/src/com/intellij/uast/UastElementAnchorProvider.java deleted file mode 100644 index 9134f5d86a30..000000000000 --- a/java/java-analysis-impl/src/com/intellij/uast/UastElementAnchorProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.intellij.uast; - -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.psi.PsiElement; -import com.intellij.psi.impl.smartPointers.SmartPointerAnchorProvider; -import com.intellij.reference.SoftReference; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.uast.UElement; -import org.jetbrains.uast.UastContextKt; - -/** - * @author yole - * @deprecated relies on usage UElement as a PsiElement, which is considered as a bad practice (IDEA-182835), - * and also leads to inappropriate caching of UElements - */ -@Deprecated -public class UastElementAnchorProvider extends SmartPointerAnchorProvider { - @Nullable - @Override - public PsiElement getAnchor(@NotNull PsiElement element) { - if (element instanceof UElement) { - Logger.getInstance(UastElementAnchorProvider.class) - .error("creating a SmartPointer on a UElement " + element + - ", please avoid doing that, using UElement as PsiElement is a bad practice," + - " use UastSmartPointer instead"); - PsiElement psi = ((UElement)element).getPsi(); - if (psi != null) { - psi.putUserData(UastContextKt.getCACHED_UELEMENT_KEY(), new SoftReference<>((UElement)element)); - } - return psi; - } - return null; - } - - @Nullable - @Override - public PsiElement restoreElement(@NotNull PsiElement anchor) { - return (PsiElement)UastContextKt.toUElement(anchor); - } -} diff --git a/uast/uast-common/src/org/jetbrains/uast/UastContext.kt b/uast/uast-common/src/org/jetbrains/uast/UastContext.kt index e07eaab0234c..4004b50b86cf 100644 --- a/uast/uast-common/src/org/jetbrains/uast/UastContext.kt +++ b/uast/uast-common/src/org/jetbrains/uast/UastContext.kt @@ -17,13 +17,7 @@ package org.jetbrains.uast import com.intellij.lang.Language import com.intellij.openapi.project.Project -import com.intellij.openapi.util.Key import com.intellij.psi.* -import com.intellij.reference.SoftReference - -@Deprecated("no proper caching for UAST is implemented, please avoid relying on this key") -internal val CACHED_UELEMENT_KEY: Key> = Key.create>("org.jetbrains.uast.cachedElement") - @Deprecated("use UastFacade or UastLanguagePlugin instead", ReplaceWith("UastFacade")) class UastContext(val project: Project) : UastLanguagePlugin by UastFacade { @@ -60,11 +54,6 @@ object UastFacade : UastLanguagePlugin { override fun isFileSupported(fileName: String): Boolean = languagePlugins.any { it.isFileSupported(fileName) } override fun convertElement(element: PsiElement, parent: UElement?, requiredType: Class?): UElement? { - val cachedElement = element.getUserData(CACHED_UELEMENT_KEY)?.get() - if (cachedElement != null) { - return if (requiredType == null || requiredType.isInstance(cachedElement)) cachedElement else null - } - return findPlugin(element)?.convertElement(element, parent, requiredType) } @@ -72,12 +61,6 @@ object UastFacade : UastLanguagePlugin { if (element is PsiWhiteSpace) { return null } - - val cachedElement = element.getUserData(CACHED_UELEMENT_KEY)?.get() - if (cachedElement != null) { - return if (requiredType == null || requiredType.isInstance(cachedElement)) cachedElement else null - } - return findPlugin(element)?.convertElementWithParent(element, requiredType) }