当前位置: 首页>>代码示例>>Java>>正文


Java VariableAccessUtils.variableIsUsed方法代码示例

本文整理汇总了Java中com.siyeh.ig.psiutils.VariableAccessUtils.variableIsUsed方法的典型用法代码示例。如果您正苦于以下问题:Java VariableAccessUtils.variableIsUsed方法的具体用法?Java VariableAccessUtils.variableIsUsed怎么用?Java VariableAccessUtils.variableIsUsed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.siyeh.ig.psiutils.VariableAccessUtils的用法示例。


在下文中一共展示了VariableAccessUtils.variableIsUsed方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isVariableUsedInFollowingDeclarations

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
private boolean isVariableUsedInFollowingDeclarations(PsiVariable variable, PsiDeclarationStatement declarationStatement) {
  final PsiElement[] declaredElements = declarationStatement.getDeclaredElements();
  if (declaredElements.length == 1) {
    return false;
  }
  boolean check = false;
  for (PsiElement declaredElement : declaredElements) {
    if (!check && variable.equals(declaredElement)) {
      check = true;
    } else {
      if (VariableAccessUtils.variableIsUsed(variable, declaredElement)) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:UnnecessaryLocalVariableInspectionBase.java

示例2: checkVariableUsage

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
private void checkVariableUsage(PsiReferenceExpression referenceExpression, PsiElement thenContext, PsiElement elseContext) {
  if (thenContext == null) {
    return;
  }
  final PsiElement target = referenceExpression.resolve();
  if (!(target instanceof PsiVariable)) {
    return;
  }
  final PsiVariable variable = (PsiVariable)target;
  if (contextExits(thenContext) || VariableAccessUtils.variableIsAssigned(variable, thenContext)) {
    return;
  }
  if (elseContext != null && (contextExits(elseContext) || VariableAccessUtils.variableIsUsed(variable, elseContext))) {
    return;
  }
  registerError(referenceExpression);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:VariableNotUsedInsideIfInspection.java

示例3: checkVariableUsage

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
private void checkVariableUsage(PsiReferenceExpression referenceExpression,
                                PsiElement thenContext, PsiElement elseContext) {
  if (thenContext == null) {
    return;
  }
  final PsiElement target = referenceExpression.resolve();
  if (!(target instanceof PsiVariable)) {
    return;
  }
  final PsiVariable variable = (PsiVariable)target;
  if (contextExits(thenContext) || VariableAccessUtils.variableIsAssigned(variable, thenContext)) {
    return;
  }
  if (elseContext != null &&
      (contextExits(elseContext) || VariableAccessUtils.variableIsUsed(variable, elseContext))) {
    return;
  }
  registerError(referenceExpression);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:20,代码来源:VariableNotUsedInsideIfInspection.java

示例4: visitAssignmentExpression

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
@Override
public void visitAssignmentExpression(@NotNull PsiAssignmentExpression expression) {
  super.visitAssignmentExpression(expression);
  final PsiExpression lhs = expression.getLExpression();
  final PsiParameter parameter = getParameter(lhs);
  if (parameter == null) {
    return;
  }
  if (ignoreTransformationOfOriginalParameter) {
    final PsiExpression rhs = expression.getRExpression();
    if (rhs != null && VariableAccessUtils.variableIsUsed(parameter, rhs)) {
      return;
    }
    final IElementType tokenType =
      expression.getOperationTokenType();
    if (tokenType == JavaTokenType.PLUSEQ ||
        tokenType == JavaTokenType.MINUSEQ ||
        tokenType == JavaTokenType.ASTERISKEQ ||
        tokenType == JavaTokenType.DIVEQ ||
        tokenType == JavaTokenType.ANDEQ ||
        tokenType == JavaTokenType.OREQ ||
        tokenType == JavaTokenType.XOREQ ||
        tokenType == JavaTokenType.PERCEQ ||
        tokenType == JavaTokenType.LTLTEQ ||
        tokenType == JavaTokenType.GTGTEQ ||
        tokenType == JavaTokenType.GTGTGTEQ) {
      return;
    }
  }
  registerError(lhs);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:BaseAssignmentToParameterInspection.java

示例5: isAppendedRepeatedly

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
private boolean isAppendedRepeatedly(PsiExpression expression) {
  PsiElement parent = expression.getParent();
  while (parent instanceof PsiParenthesizedExpression || parent instanceof PsiPolyadicExpression) {
    parent = parent.getParent();
  }
  if (!(parent instanceof PsiAssignmentExpression)) {
    return false;
  }
  final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)parent;
  PsiExpression lhs = assignmentExpression.getLExpression();
  while (lhs instanceof PsiParenthesizedExpression) {
    final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)lhs;
    lhs = parenthesizedExpression.getExpression();
  }
  if (!(lhs instanceof PsiReferenceExpression)) {
    return false;
  }
  if (assignmentExpression.getOperationTokenType() == JavaTokenType.PLUSEQ) {
    return true;
  }
  final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)lhs;
  final PsiElement element = referenceExpression.resolve();
  if (!(element instanceof PsiVariable)) {
    return false;
  }
  final PsiVariable variable = (PsiVariable)element;
  final PsiExpression rhs = assignmentExpression.getRExpression();
  return rhs != null && VariableAccessUtils.variableIsUsed(variable, rhs);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:StringConcatenationInLoopsInspection.java

示例6: checkVariableUsage

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
private boolean checkVariableUsage(PsiReferenceExpression referenceExpression, PsiElement thenContext, PsiElement elseContext) {
  final PsiElement target = referenceExpression.resolve();
  if (!(target instanceof PsiVariable)) {
    return false;
  }
  final PsiVariable variable = (PsiVariable)target;
  if (thenContext != null && (contextExits(thenContext) || VariableAccessUtils.variableIsAssigned(variable, thenContext))) {
    return false;
  }
  if (elseContext == null || VariableAccessUtils.variableIsUsed(variable, elseContext)) {
    return false;
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:VariableNotUsedInsideIfInspection.java

示例7: visitAssignmentExpression

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
@Override
public void visitAssignmentExpression(
  @NotNull PsiAssignmentExpression expression) {
  super.visitAssignmentExpression(expression);
  final PsiExpression rhs = expression.getRExpression();
  if (rhs == null) {
    return;
  }
  final PsiExpression lhs = expression.getLExpression();
  final PsiField volatileField = findNonSynchronizedVolatileField(lhs);
  if (volatileField == null) {
    return;
  }
  final IElementType tokenType = expression.getOperationTokenType();
  if (tokenType.equals(JavaTokenType.PLUSEQ) ||
      tokenType.equals(JavaTokenType.MINUSEQ) ||
      tokenType.equals(JavaTokenType.ASTERISKEQ) ||
      tokenType.equals(JavaTokenType.DIVEQ) ||
      tokenType.equals(JavaTokenType.ANDEQ) ||
      tokenType.equals(JavaTokenType.OREQ) ||
      tokenType.equals(JavaTokenType.XOREQ) ||
      tokenType.equals(JavaTokenType.PERCEQ) ||
      tokenType.equals(JavaTokenType.LTLTEQ) ||
      tokenType.equals(JavaTokenType.GTGTEQ) ||
      tokenType.equals(JavaTokenType.GTGTGTEQ)) {
    registerError(lhs);
    return;
  }
  if (VariableAccessUtils.variableIsUsed(volatileField, rhs)) {
    registerError(lhs);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:NonAtomicOperationOnVolatileFieldInspection.java

示例8: visitAssignmentExpression

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
@Override
public void visitAssignmentExpression(
  @NotNull PsiAssignmentExpression expression) {
  super.visitAssignmentExpression(expression);
  final PsiExpression lhs = expression.getLExpression();
  final PsiParameter parameter = getMethodParameter(lhs);
  if (parameter == null) {
    return;
  }
  if (ignoreTransformationOfOriginalParameter) {
    final PsiExpression rhs = expression.getRExpression();
    if (rhs != null && VariableAccessUtils.variableIsUsed(parameter, rhs)) {
      return;
    }
    final IElementType tokenType =
      expression.getOperationTokenType();
    if (tokenType == JavaTokenType.PLUSEQ ||
        tokenType == JavaTokenType.MINUSEQ ||
        tokenType == JavaTokenType.ASTERISKEQ ||
        tokenType == JavaTokenType.DIVEQ ||
        tokenType == JavaTokenType.ANDEQ ||
        tokenType == JavaTokenType.OREQ ||
        tokenType == JavaTokenType.XOREQ ||
        tokenType == JavaTokenType.PERCEQ ||
        tokenType == JavaTokenType.LTLTEQ ||
        tokenType == JavaTokenType.GTGTEQ ||
        tokenType == JavaTokenType.GTGTGTEQ) {
      return;
    }
  }
  registerError(lhs);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:33,代码来源:AssignmentToMethodParameterInspection.java

示例9: isImmediatelyAssigned

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
private boolean isImmediatelyAssigned(PsiVariable variable) {
  final PsiCodeBlock containingScope = PsiTreeUtil.getParentOfType(variable, PsiCodeBlock.class, true, PsiClass.class);
  if (containingScope == null) {
    return false;
  }
  final PsiElement parent = variable.getParent();
  if (!(parent instanceof PsiDeclarationStatement)) {
    return false;
  }
  final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)parent;
  PsiStatement nextStatement = null;
  int followingStatementNumber = 0;
  final PsiStatement[] statements = containingScope.getStatements();
  for (int i = 0; i < (statements.length - 1); i++) {
    if (statements[i].equals(declarationStatement)) {
      nextStatement = statements[i + 1];
      followingStatementNumber = i + 2;
      break;
    }
  }
  if (!(nextStatement instanceof PsiExpressionStatement)) {
    return false;
  }
  final PsiExpressionStatement expressionStatement = (PsiExpressionStatement)nextStatement;
  final PsiExpression expression = expressionStatement.getExpression();
  if (!(expression instanceof PsiAssignmentExpression)) {
    return false;
  }
  final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)expression;
  final IElementType tokenType = assignmentExpression.getOperationTokenType();
  if (tokenType != JavaTokenType.EQ) {
    return false;
  }
  final PsiExpression rhs = ParenthesesUtils.stripParentheses(assignmentExpression.getRExpression());
  if (!(rhs instanceof PsiReferenceExpression)) {
    return false;
  }
  final PsiReferenceExpression reference = (PsiReferenceExpression)rhs;
  final PsiElement referent = reference.resolve();
  if (referent == null || !referent.equals(variable)) {
    return false;
  }
  final PsiExpression lhs = assignmentExpression.getLExpression();
  if (lhs instanceof PsiArrayAccessExpression) {
    return false;
  }
  if (isVariableUsedInFollowingDeclarations(variable, declarationStatement)) {
    return false;
  }
  for (int i = followingStatementNumber; i < statements.length; i++) {
    if (VariableAccessUtils.variableIsUsed(variable, statements[i])) {
      return false;
    }
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:57,代码来源:UnnecessaryLocalVariableInspectionBase.java

示例10: visitAssignmentExpression

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
@Override
public void visitAssignmentExpression(
  @NotNull PsiAssignmentExpression assignment) {
  super.visitAssignmentExpression(assignment);
  final PsiElement assignmentParent = assignment.getParent();
  if (!(assignmentParent instanceof PsiExpressionStatement)) {
    return;
  }
  final PsiExpression lhs = assignment.getLExpression();
  if (!(lhs instanceof PsiReferenceExpression)) {
    return;
  }
  final PsiReferenceExpression reference =
    (PsiReferenceExpression)lhs;
  final PsiElement referent = reference.resolve();
  if (!(referent instanceof PsiLocalVariable)) {
    return;
  }
  final PsiVariable variable = (PsiVariable)referent;

  //TODO: this is safe, but can be weakened
  if (variable.getInitializer() == null) {
    return;
  }
  final IElementType tokenType = assignment.getOperationTokenType();
  if (!JavaTokenType.EQ.equals(tokenType)) {
    return;
  }
  final PsiExpression rhs = assignment.getRExpression();
  if (rhs != null &&
      VariableAccessUtils.variableIsUsed(variable, rhs)) {
    return;
  }
  final PsiCodeBlock variableBlock =
    PsiTreeUtil.getParentOfType(variable, PsiCodeBlock.class);
  if (variableBlock == null) {
    return;
  }

  if (loopExistsBetween(assignment, variableBlock)) {
    return;
  }
  if (tryExistsBetween(assignment, variableBlock)) {
    // this could be weakened, slightly, if it could be verified
    // that a variable is used in only one branch of a try statement
    return;
  }
  final PsiElement assignmentBlock =
    assignmentParent.getParent();
  if (assignmentBlock == null) {
    return;
  }
  if (variableBlock.equals(assignmentBlock)) {
    registerError(lhs);
  }
  final PsiStatement[] statements = variableBlock.getStatements();
  final PsiElement containingStatement =
    getChildWhichContainsElement(variableBlock, assignment);
  int statementPosition = -1;
  for (int i = 0; i < statements.length; i++) {
    if (statements[i].equals(containingStatement)) {
      statementPosition = i;
      break;
    }
  }
  if (statementPosition == -1) {
    return;
  }
  for (int i = statementPosition + 1; i < statements.length; i++) {
    if (VariableAccessUtils.variableIsUsed(variable, statements[i])) {
      return;
    }
  }
  registerError(lhs);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:76,代码来源:ReuseOfLocalVariableInspectionBase.java

示例11: isImmediatelyAssigned

import com.siyeh.ig.psiutils.VariableAccessUtils; //导入方法依赖的package包/类
private boolean isImmediatelyAssigned(PsiVariable variable) {
  final PsiCodeBlock containingScope = PsiTreeUtil.getParentOfType(variable, PsiCodeBlock.class, true, PsiClass.class);
  if (containingScope == null) {
    return false;
  }
  final PsiElement parent = variable.getParent();
  if (!(parent instanceof PsiDeclarationStatement)) {
    return false;
  }
  final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)parent;
  PsiStatement nextStatement = null;
  int followingStatementNumber = 0;
  final PsiStatement[] statements = containingScope.getStatements();
  for (int i = 0; i < (statements.length - 1); i++) {
    if (statements[i].equals(declarationStatement)) {
      nextStatement = statements[i + 1];
      followingStatementNumber = i + 2;
      break;
    }
  }
  if (!(nextStatement instanceof PsiExpressionStatement)) {
    return false;
  }
  final PsiExpressionStatement expressionStatement = (PsiExpressionStatement)nextStatement;
  final PsiExpression expression = expressionStatement.getExpression();
  if (!(expression instanceof PsiAssignmentExpression)) {
    return false;
  }
  final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)expression;
  final IElementType tokenType = assignmentExpression.getOperationTokenType();
  if (tokenType != JavaTokenType.EQ) {
    return false;
  }
  final PsiExpression rhs = assignmentExpression.getRExpression();
  if (!(rhs instanceof PsiReferenceExpression)) {
    return false;
  }
  final PsiReferenceExpression reference = (PsiReferenceExpression)rhs;
  final PsiElement referent = reference.resolve();
  if (referent == null || !referent.equals(variable)) {
    return false;
  }
  final PsiExpression lhs = assignmentExpression.getLExpression();
  if (lhs instanceof PsiArrayAccessExpression) {
    return false;
  }
  if (isVariableUsedInFollowingDeclarations(variable, declarationStatement)) {
    return false;
  }
  for (int i = followingStatementNumber; i < statements.length; i++) {
    if (VariableAccessUtils.variableIsUsed(variable, statements[i])) {
      return false;
    }
  }
  return true;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:57,代码来源:UnnecessaryLocalVariableInspection.java


注:本文中的com.siyeh.ig.psiutils.VariableAccessUtils.variableIsUsed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。