com.intellij.codeInspection.dataFlow.DfaUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-analysis-impl Show documentation
Show all versions of java-analysis-impl Show documentation
A packaging of the IntelliJ Community Edition java-analysis-impl library.
This is release number 1 of trunk branch 142.
The newest version!
/*
* Copyright 2000-2009 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.codeInspection.dataFlow;
import com.intellij.codeInspection.dataFlow.instructions.*;
import com.intellij.codeInspection.dataFlow.value.DfaValue;
import com.intellij.codeInspection.dataFlow.value.DfaVariableValue;
import com.intellij.openapi.util.MultiValuesMap;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.Function;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.FList;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* @author Gregory.Shrago
*/
public class DfaUtil {
@Nullable("null means DFA analysis has failed (too complex to analyze)")
public static Collection getCachedVariableValues(@Nullable final PsiVariable variable, @Nullable final PsiElement context) {
if (variable == null || context == null) return Collections.emptyList();
final PsiElement codeBlock = DfaPsiUtil.getEnclosingCodeBlock(variable, context);
if (codeBlock == null) return Collections.emptyList();
final Map value = getCachedPlaceResults(codeBlock);
if (value == null) return null;
ValuableInstructionVisitor.PlaceResult placeResult = value.get(context);
final Collection> concatenations = placeResult == null ? null : placeResult.myValues.get(variable);
if (concatenations != null) {
return ContainerUtil.map(concatenations, new Function, PsiExpression>() {
@Override
public PsiExpression fun(FList expressions) {
return concatenateExpressions(expressions);
}
});
}
return Collections.emptyList();
}
@Nullable("null means DFA analysis has failed (too complex to analyze)")
private static Map getCachedPlaceResults(@NotNull final PsiElement codeBlock) {
return CachedValuesManager.getCachedValue(codeBlock, new CachedValueProvider
© 2015 - 2025 Weber Informatics LLC | Privacy Policy