本文整理汇总了Java中com.siyeh.ig.psiutils.VariableAccessUtils.collectUsedVariables方法的典型用法代码示例。如果您正苦于以下问题:Java VariableAccessUtils.collectUsedVariables方法的具体用法?Java VariableAccessUtils.collectUsedVariables怎么用?Java VariableAccessUtils.collectUsedVariables使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.siyeh.ig.psiutils.VariableAccessUtils
的用法示例。
在下文中一共展示了VariableAccessUtils.collectUsedVariables方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: satisfiedBy
import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiJavaToken)) {
return false;
}
final PsiJavaToken token = (PsiJavaToken)element;
final PsiElement parent = token.getParent();
if (!(parent instanceof PsiIfStatement)) {
return false;
}
final PsiIfStatement ifStatement = (PsiIfStatement)parent;
final PsiElement nextStatement =
PsiTreeUtil.skipSiblingsForward(ifStatement,
PsiWhiteSpace.class);
if (!(nextStatement instanceof PsiIfStatement)) {
return false;
}
final PsiIfStatement nextIfStatement = (PsiIfStatement)nextStatement;
if (ErrorUtil.containsError(ifStatement)) {
return false;
}
if (ErrorUtil.containsError(nextIfStatement)) {
return false;
}
if (!ifStatementsCanBeMerged(ifStatement, nextIfStatement)) {
return false;
}
final PsiExpression condition = ifStatement.getCondition();
final Set<PsiVariable> variables =
VariableAccessUtils.collectUsedVariables(condition);
final PsiStatement thenBranch = ifStatement.getThenBranch();
if (VariableAccessUtils.isAnyVariableAssigned(variables, thenBranch)) {
return false;
}
final PsiStatement elseBranch = ifStatement.getElseBranch();
return !VariableAccessUtils.isAnyVariableAssigned(variables,
elseBranch);
}
示例2: satisfiedBy
import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
public boolean satisfiedBy(PsiElement element)
{
if(!(element instanceof PsiJavaToken))
{
return false;
}
final PsiJavaToken token = (PsiJavaToken) element;
final PsiElement parent = token.getParent();
if(!(parent instanceof PsiIfStatement))
{
return false;
}
final PsiIfStatement ifStatement = (PsiIfStatement) parent;
final PsiElement nextStatement = PsiTreeUtil.skipSiblingsForward(ifStatement, PsiWhiteSpace.class);
if(!(nextStatement instanceof PsiIfStatement))
{
return false;
}
final PsiIfStatement nextIfStatement = (PsiIfStatement) nextStatement;
if(ErrorUtil.containsError(ifStatement))
{
return false;
}
if(ErrorUtil.containsError(nextIfStatement))
{
return false;
}
if(!ifStatementsCanBeMerged(ifStatement, nextIfStatement))
{
return false;
}
final PsiExpression condition = ifStatement.getCondition();
final Set<PsiVariable> variables = VariableAccessUtils.collectUsedVariables(condition);
final PsiStatement thenBranch = ifStatement.getThenBranch();
if(VariableAccessUtils.isAnyVariableAssigned(variables, thenBranch))
{
return false;
}
final PsiStatement elseBranch = ifStatement.getElseBranch();
return !VariableAccessUtils.isAnyVariableAssigned(variables, elseBranch);
}