From 3145faff604ca9d53d7c08aafd853a0953152f02 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Thu, 25 Mar 2021 11:10:16 +0700 Subject: [PATCH] [java] Property tests: check that expression passed to extract variable could be found via findExpressionInRange GitOrigin-RevId: c0c036e21b615411335386742f76f134ef927988 --- .../java/propertyBased/IntroduceVariableActionOnFile.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/java/java-tests/testSrc/com/intellij/java/propertyBased/IntroduceVariableActionOnFile.java b/java/java-tests/testSrc/com/intellij/java/propertyBased/IntroduceVariableActionOnFile.java index 9c59f5ffa0b4..b64dbe6e639d 100644 --- a/java/java-tests/testSrc/com/intellij/java/propertyBased/IntroduceVariableActionOnFile.java +++ b/java/java-tests/testSrc/com/intellij/java/propertyBased/IntroduceVariableActionOnFile.java @@ -1,6 +1,7 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.propertyBased; +import com.intellij.codeInsight.CodeInsightUtil; import com.intellij.codeInsight.template.impl.TemplateManagerImpl; import com.intellij.codeInsight.template.impl.TemplateState; import com.intellij.java.refactoring.InplaceIntroduceVariableTest; @@ -22,6 +23,7 @@ import com.intellij.refactoring.util.CommonRefactoringUtil; import com.intellij.testFramework.propertyBased.ActionOnFile; import com.intellij.testFramework.propertyBased.RandomActivityInterceptor; import com.intellij.ui.UiInterceptors; +import com.intellij.util.containers.ContainerUtil; import one.util.streamex.EntryStream; import org.jetbrains.annotations.NotNull; import org.jetbrains.jetCheck.Generator; @@ -44,6 +46,10 @@ public class IntroduceVariableActionOnFile extends ActionOnFile { PsiElement element = getFile().findElementAt(offset); if (element == null) return; List expressions = PsiTreeUtil.collectParents(element, PsiExpression.class, true, e -> false); + expressions = ContainerUtil.filter(expressions, ex -> { + TextRange exRange = ex.getTextRange(); + return CodeInsightUtil.findExpressionInRange(getFile(), exRange.getStartOffset(), exRange.getEndOffset()) == ex; + }); if (expressions.isEmpty()) return; PsiExpression expression = env.generateValue(Generator.sampledFrom(expressions), null); TextRange range = expression.getTextRange();