From d308509cb79e7c14bed2041ee1408181e488461d Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Mon, 14 Aug 2017 09:44:18 +0700 Subject: [PATCH] CFGBuilder: special type for temp variable (IDEA-CR-23774) --- .../codeInspection/dataFlow/CFGBuilder.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/CFGBuilder.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/CFGBuilder.java index 07864c3e16c1..6ff54eb7b78b 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/CFGBuilder.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/CFGBuilder.java @@ -584,7 +584,7 @@ public class CFGBuilder { if(type == null) { type = PsiType.VOID; } - return new LightVariableBuilder<>("tmp$" + myAnalyzer.getInstructionCount(), type, myAnalyzer.getContext()); + return new TempVariable(myAnalyzer.getInstructionCount(), type, myAnalyzer.getContext()); } /** @@ -598,7 +598,19 @@ public class CFGBuilder { return this; } + /** + * Checks whether supplied variable is a temporary variable created previously via {@link #createTempVariable(PsiType)} + * + * @param variable to check + * @return true if supplied variable is a temp variable. + */ public static boolean isTempVariable(PsiModifierListOwner variable) { - return variable instanceof LightVariableBuilder && ((LightVariableBuilder)variable).getName().startsWith("tmp$"); + return variable instanceof TempVariable; + } + + private static class TempVariable extends LightVariableBuilder { + TempVariable(int index, @NotNull PsiType type, @NotNull PsiElement navigationElement) { + super("tmp$" + index, type, navigationElement); + } } }