本文整理汇总了Java中com.intellij.psi.controlFlow.ControlFlowUtil.VariableInfo方法的典型用法代码示例。如果您正苦于以下问题:Java ControlFlowUtil.VariableInfo方法的具体用法?Java ControlFlowUtil.VariableInfo怎么用?Java ControlFlowUtil.VariableInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.controlFlow.ControlFlowUtil
的用法示例。
在下文中一共展示了ControlFlowUtil.VariableInfo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isReassigned
import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
public static boolean isReassigned(@NotNull PsiVariable variable, @NotNull Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems)
{
if(variable instanceof PsiLocalVariable)
{
final PsiElement parent = variable.getParent();
if(parent == null)
{
return false;
}
final PsiElement declarationScope = parent.getParent();
if(declarationScope == null)
{
return false;
}
Collection<ControlFlowUtil.VariableInfo> codeBlockProblems = getFinalVariableProblemsInBlock(finalVarProblems, declarationScope);
return codeBlockProblems.contains(new ControlFlowUtil.VariableInfo(variable, null));
}
if(variable instanceof PsiParameter)
{
final PsiParameter parameter = (PsiParameter) variable;
return isAssigned(parameter);
}
return false;
}
示例2: getFinalVariableProblemsInBlock
import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
@NotNull
private static Collection<ControlFlowUtil.VariableInfo> getFinalVariableProblemsInBlock(@NotNull Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems,
@NotNull PsiElement codeBlock)
{
Collection<ControlFlowUtil.VariableInfo> codeBlockProblems = finalVarProblems.get(codeBlock);
if(codeBlockProblems == null)
{
try
{
final ControlFlow controlFlow = getControlFlowNoConstantEvaluate(codeBlock);
codeBlockProblems = ControlFlowUtil.getInitializedTwice(controlFlow);
}
catch(AnalysisCanceledException e)
{
codeBlockProblems = Collections.emptyList();
}
finalVarProblems.put(codeBlock, codeBlockProblems);
}
return codeBlockProblems;
}
示例3: canBeFinal
import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
private static boolean canBeFinal(@NotNull PsiVariable variable, @NotNull List<PsiReferenceExpression> references) {
// if there is at least one assignment to this variable, it cannot be final
Map<PsiElement, Collection<PsiReferenceExpression>> uninitializedVarProblems = new THashMap<PsiElement, Collection<PsiReferenceExpression>>();
Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems = new THashMap<PsiElement, Collection<ControlFlowUtil.VariableInfo>>();
for (PsiReferenceExpression expression : references) {
if (ControlFlowUtil.isVariableAssignedInLoop(expression, variable)) return false;
HighlightInfo highlightInfo = HighlightControlFlowUtil.checkVariableInitializedBeforeUsage(expression, variable, uninitializedVarProblems,
variable.getContainingFile());
if (highlightInfo != null) return false;
highlightInfo = HighlightControlFlowUtil.checkFinalVariableMightAlreadyHaveBeenAssignedTo(variable, expression, finalVarProblems);
if (highlightInfo != null) return false;
if (variable instanceof PsiParameter && PsiUtil.isAccessedForWriting(expression)) return false;
}
return true;
}
示例4: canBeFinal
import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
private static boolean canBeFinal(PsiVariable variable, List<PsiReferenceExpression> references) {
// if there is at least one assignment to this variable, it cannot be final
Map<PsiElement, Collection<PsiReferenceExpression>> uninitializedVarProblems = new THashMap<PsiElement, Collection<PsiReferenceExpression>>();
Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems = new THashMap<PsiElement, Collection<ControlFlowUtil.VariableInfo>>();
for (PsiReferenceExpression expression : references) {
if (ControlFlowUtil.isVariableAssignedInLoop(expression, variable)) return false;
HighlightInfo highlightInfo = HighlightControlFlowUtil.checkVariableInitializedBeforeUsage(expression, variable, uninitializedVarProblems,
variable.getContainingFile());
if (highlightInfo != null) return false;
highlightInfo = HighlightControlFlowUtil.checkFinalVariableMightAlreadyHaveBeenAssignedTo(variable, expression, finalVarProblems);
if (highlightInfo != null) return false;
if (variable instanceof PsiParameter && PsiUtil.isAccessedForWriting(expression)) return false;
}
return true;
}
示例5: declareLocalVariables
import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
private void declareLocalVariables() throws IncorrectOperationException {
final PsiElement codeFragment = ControlFlowUtil.findCodeFragment(getMatchStart());
try {
final Project project = getMatchStart().getProject();
final ControlFlow controlFlow = ControlFlowFactory.getInstance(project)
.getControlFlow(codeFragment, new LocalsControlFlowPolicy(codeFragment));
final int endOffset = controlFlow.getEndOffset(getMatchEnd());
final int startOffset = controlFlow.getStartOffset(getMatchStart());
final List<PsiVariable> usedVariables = ControlFlowUtil.getUsedVariables(controlFlow, endOffset, controlFlow.getSize());
Collection<ControlFlowUtil.VariableInfo> reassigned = ControlFlowUtil.getInitializedTwice(controlFlow, endOffset, controlFlow.getSize());
final Collection<PsiVariable> outVariables = ControlFlowUtil.getWrittenVariables(controlFlow, startOffset, endOffset, false);
for (PsiVariable variable : usedVariables) {
if (!outVariables.contains(variable)) {
final PsiIdentifier identifier = variable.getNameIdentifier();
if (identifier != null) {
final TextRange textRange = checkRange(identifier);
final TextRange startRange = checkRange(getMatchStart());
final TextRange endRange = checkRange(getMatchEnd());
if (textRange.getStartOffset() >= startRange.getStartOffset() && textRange.getEndOffset() <= endRange.getEndOffset()) {
final String name = variable.getName();
LOG.assertTrue(name != null);
PsiDeclarationStatement statement =
JavaPsiFacade.getInstance(project).getElementFactory().createVariableDeclarationStatement(name, variable.getType(), null);
if (reassigned.contains(new ControlFlowUtil.VariableInfo(variable, null))) {
final PsiElement[] psiElements = statement.getDeclaredElements();
final PsiModifierList modifierList = ((PsiVariable)psiElements[0]).getModifierList();
LOG.assertTrue(modifierList != null);
modifierList.setModifierProperty(PsiModifier.FINAL, false);
}
getMatchStart().getParent().addBefore(statement, getMatchStart());
}
}
}
}
}
catch (AnalysisCanceledException e) {
//skip match
}
}
示例6: isEffectivelyFinal
import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
public static boolean isEffectivelyFinal(@NotNull PsiVariable variable, @NotNull PsiElement scope, @Nullable PsiJavaCodeReferenceElement context)
{
boolean effectivelyFinal;
if(variable instanceof PsiParameter)
{
effectivelyFinal = notAccessedForWriting(variable, new LocalSearchScope(((PsiParameter) variable).getDeclarationScope()));
}
else
{
final ControlFlow controlFlow;
try
{
PsiElement codeBlock = PsiUtil.getVariableCodeBlock(variable, context);
if(codeBlock == null)
{
return true;
}
controlFlow = getControlFlow(codeBlock);
}
catch(AnalysisCanceledException e)
{
return true;
}
final List<PsiReferenceExpression> readBeforeWriteLocals = ControlFlowUtil.getReadBeforeWriteLocals(controlFlow);
for(PsiReferenceExpression expression : readBeforeWriteLocals)
{
if(expression.resolve() == variable)
{
return PsiUtil.isAccessedForReading(expression);
}
}
final Collection<ControlFlowUtil.VariableInfo> initializedTwice = ControlFlowUtil.getInitializedTwice(controlFlow);
effectivelyFinal = !initializedTwice.contains(new ControlFlowUtil.VariableInfo(variable, null));
if(effectivelyFinal)
{
effectivelyFinal = notAccessedForWriting(variable, new LocalSearchScope(scope));
}
}
return effectivelyFinal;
}
示例7: getInitializedTwice
import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
public Collection<ControlFlowUtil.VariableInfo> getInitializedTwice(int start)
{
return ControlFlowUtil.getInitializedTwice(myControlFlow, start, myControlFlow.getSize());
}