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


Java PsiUtil.deparenthesizeExpression方法代码示例

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


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

示例1: checkSillyAssignment

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private void checkSillyAssignment(PsiAssignmentExpression assignment, ProblemsHolder holder) {
  if (assignment.getOperationTokenType() != JavaTokenType.EQ) return;
  PsiExpression lExpression = assignment.getLExpression();
  PsiExpression rExpression = assignment.getRExpression();
  if (rExpression == null) return;
  lExpression = PsiUtil.deparenthesizeExpression(lExpression);
  rExpression = PsiUtil.deparenthesizeExpression(rExpression);
  if (!(lExpression instanceof PsiReferenceExpression)) return;
  PsiReferenceExpression rRef;
  if (!(rExpression instanceof PsiReferenceExpression)) {
    if (!(rExpression instanceof PsiAssignmentExpression)) return;
    final PsiAssignmentExpression rAssignmentExpression = (PsiAssignmentExpression)rExpression;
    final PsiExpression assignee = PsiUtil.deparenthesizeExpression(rAssignmentExpression.getLExpression());
    if (!(assignee instanceof PsiReferenceExpression)) return;
    rRef = (PsiReferenceExpression)assignee;
  } else {
    rRef = (PsiReferenceExpression)rExpression;
  }
  PsiReferenceExpression lRef = (PsiReferenceExpression)lExpression;
  PsiManager manager = assignment.getManager();
  if (!sameInstanceReferences(lRef, rRef, manager)) return;
  final PsiVariable variable = (PsiVariable)lRef.resolve();
  if (variable == null) return;
  holder.registerProblem(assignment, InspectionsBundle.message("assignment.to.itself.problem.descriptor", variable.getName()),
                         ProblemHighlightType.LIKE_UNUSED_SYMBOL, createRemoveAssignmentFix());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:SillyAssignmentInspectionBase.java

示例2: register

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static void register(final HighlightInfo highlightInfo, PsiExpression expression, final PsiType lType) {
  expression = PsiUtil.deparenthesizeExpression(expression);
  if (!(expression instanceof PsiNewExpression)) return;
  final PsiType rType = expression.getType();
  PsiType newType = lType;
  if (rType instanceof PsiClassType && newType instanceof PsiClassType) {
    final PsiClassType.ClassResolveResult rResolveResult = ((PsiClassType)rType).resolveGenerics();
    PsiClass rClass = rResolveResult.getElement();
    if (rClass instanceof PsiAnonymousClass) {
      rClass = ((PsiAnonymousClass)rClass).getBaseClassType().resolve();
    }
    if (rClass != null) {
      final PsiClassType.ClassResolveResult lResolveResult = ((PsiClassType)newType).resolveGenerics();
      final PsiClass lClass = lResolveResult.getElement();
      if (lClass != null) {
        PsiSubstitutor substitutor = getInheritorSubstitutorForNewExpression(lClass, rClass, lResolveResult.getSubstitutor(), expression);
        if (substitutor != null) {
          newType = JavaPsiFacade.getInstance(lClass.getProject()).getElementFactory().createType(rClass, substitutor);
        }
      }
    }
  }
  PsiNewExpression newExpression = (PsiNewExpression)expression;
  QuickFixAction.registerQuickFixAction(highlightInfo, new ChangeNewOperatorTypeFix(newType, newExpression));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:ChangeNewOperatorTypeFix.java

示例3: visitAssignmentExpression

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitAssignmentExpression(PsiAssignmentExpression expression) {
  final PsiExpression rhs = PsiUtil.deparenthesizeExpression(expression.getRExpression());
  if (!(rhs instanceof PsiReferenceExpression)) {
    return;
  }
  final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)rhs;
  final PsiElement target = referenceExpression.resolve();
  if (!boundVariable.equals(target)) {
    return;
  }
  final PsiExpression lhs = PsiUtil.deparenthesizeExpression(expression.getLExpression());
  if (!(lhs instanceof PsiReferenceExpression)) {
    return;
  }
  final PsiReferenceExpression lReferenceExpression = (PsiReferenceExpression)lhs;
  final PsiElement lTarget = lReferenceExpression.resolve();
  if (lTarget instanceof PsiField) {
    escaped = true;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:ResourceInspection.java

示例4: visitCallExpression

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitCallExpression(PsiCallExpression callExpression) {
  final PsiExpressionList argumentList = callExpression.getArgumentList();
  if (argumentList == null) {
    return;
  }
  final PsiExpression[] expressions = argumentList.getExpressions();
  for (PsiExpression expression : expressions) {
    final PsiExpression expression1 = PsiUtil.deparenthesizeExpression(expression);
    if (!(expression1 instanceof PsiReferenceExpression)) {
      continue;
    }
    final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)expression1;
    final PsiElement target = referenceExpression.resolve();
    if (boundVariable.equals(target)) {
      escaped = true;
      break;
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:ResourceInspection.java

示例5: getFieldIfSimpleFieldAccess

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
private PsiField getFieldIfSimpleFieldAccess(PsiExpression expression) {
  expression = PsiUtil.deparenthesizeExpression(expression);
  if (expression == null) {
    return null;
  }
  if (!(expression instanceof PsiReferenceExpression)) {
    return null;
  }
  final PsiReferenceExpression reference = (PsiReferenceExpression)expression;
  final PsiExpression qualifierExpression = reference.getQualifierExpression();
  if (qualifierExpression != null) {
    return null;
  }
  final PsiElement referent = reference.resolve();
  if (!(referent instanceof PsiField)) {
    return null;
  }
  final PsiField field = (PsiField)referent;
  if (field.hasModifierProperty(PsiModifier.VOLATILE)) {
    return null;
  }
  else {
    return field;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:WhileLoopSpinsOnFieldInspection.java

示例6: checkExpression

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private void checkExpression(PsiExpression expression) {
  expression = PsiUtil.deparenthesizeExpression(expression);
  if (negate) {
    if (expression instanceof PsiPrefixExpression) {
      final PsiPrefixExpression prefixExpression =
        (PsiPrefixExpression)expression;
      final IElementType tokenType =
        prefixExpression.getOperationTokenType();
      if (tokenType != JavaTokenType.EXCL) {
        return;
      }
      expression = PsiUtil.deparenthesizeExpression(
        prefixExpression.getOperand());
      checkInstanceOfExpression(expression);
    }
  }
  else {
    checkInstanceOfExpression(expression);
  }
  if (expression instanceof PsiPolyadicExpression) {
    final PsiPolyadicExpression binaryExpression =
      (PsiPolyadicExpression)expression;
    visitPolyadicExpression(binaryExpression);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:InstanceOfUtils.java

示例7: getConstBoolean

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static Boolean getConstBoolean(PsiExpression operand) {
  if (operand == null) return null;
  operand = PsiUtil.deparenthesizeExpression(operand);
  if (operand == null) return null;
  String text = operand.getText();
  return PsiKeyword.TRUE.equals(text) ? Boolean.TRUE : PsiKeyword.FALSE.equals(text) ? Boolean.FALSE : null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:SimplifyBooleanExpressionFix.java

示例8: applyFix

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
  final PsiElement element = descriptor.getPsiElement();
  final PsiElement parent;
  if (element instanceof PsiReferenceExpression) {
    parent = element.getParent();
  } else {
    parent = element;
  }
  if (!(parent instanceof PsiAssignmentExpression)) return;
  final IElementType operationSign = ((PsiAssignmentExpression)parent).getOperationTokenType();
  PsiExpression rExpression = ((PsiAssignmentExpression)parent).getRExpression();
  if (JavaTokenType.EQ != operationSign && rExpression != null ) {
    rExpression = DeclarationJoinLinesHandler.getInitializerExpression(((PsiAssignmentExpression)parent).getLExpression(), 
                                                                       (PsiAssignmentExpression)parent);
  }
  final PsiElement gParent = parent.getParent();
  if ((gParent instanceof PsiExpression || gParent instanceof PsiExpressionList || gParent instanceof PsiReturnStatement) && rExpression != null) {
    if (!FileModificationService.getInstance().prepareFileForWrite(gParent.getContainingFile())) return;
    if (gParent instanceof PsiParenthesizedExpression) {
      gParent.replace(rExpression);
    } else {
      parent.replace(rExpression);
    }
    return;
  }

  PsiElement resolve = null;
  if (element instanceof PsiReferenceExpression) {
    resolve = ((PsiReferenceExpression)element).resolve();
  } else {
    final PsiExpression lExpr = PsiUtil.deparenthesizeExpression(((PsiAssignmentExpression)parent).getLExpression());
    if (lExpr instanceof PsiReferenceExpression) {
      resolve = ((PsiReferenceExpression)lExpr).resolve();
    }
  }
  if (!(resolve instanceof PsiVariable)) return;
  sideEffectAwareRemove(project, rExpression, parent, (PsiVariable)resolve);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:RemoveAssignmentFix.java

示例9: visitReturnStatement

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitReturnStatement(PsiReturnStatement statement) {
  final PsiExpression value = PsiUtil.deparenthesizeExpression(statement.getReturnValue());
  if (!(value instanceof PsiReferenceExpression)) {
    return;
  }
  final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)value;
  final PsiElement target = referenceExpression.resolve();
  if (boundVariable.equals(target)) {
    escaped = true;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:ResourceInspection.java

示例10: satisfiedBy

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
  if (!(element instanceof PsiAssignmentExpression)) {
    return false;
  }
  final PsiAssignmentExpression assignment = (PsiAssignmentExpression)element;
  final IElementType tokenType = assignment.getOperationTokenType();
  if (!JavaTokenType.EQ.equals(tokenType)) {
    return false;
  }
  final PsiExpression rhs = assignment.getRExpression();
  final PsiExpression expression = PsiUtil.deparenthesizeExpression(rhs);
  if (!(expression instanceof PsiPolyadicExpression)) {
    return false;
  }
  final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
  final PsiExpression[] operands = polyadicExpression.getOperands();
  if (operands.length < 2) {
    return false;
  }
  final IElementType rhsTokenType = polyadicExpression.getOperationTokenType();
  if (JavaTokenType.OROR.equals(rhsTokenType) || JavaTokenType.ANDAND.equals(rhsTokenType) ||
      JavaTokenType.EQEQ.equals(rhsTokenType) || JavaTokenType.NE.equals(rhsTokenType)) {
    return false;
  }
  final PsiExpression lhs = assignment.getLExpression();
  if (SideEffectChecker.mayHaveSideEffects(lhs)) {
    return false;
  }
  if (!EquivalenceChecker.expressionsAreEquivalent(lhs, operands[0])) {
    return false;
  }
  return !ErrorUtil.containsError(element);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:ReplaceableWithOperatorAssignmentPredicate.java

示例11: createCastExpression

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
static PsiExpression createCastExpression(PsiExpression original, Project project, PsiType type) {
  // remove nested casts
  PsiElement expression = PsiUtil.deparenthesizeExpression(original);
  if (expression == null) return null;

  if (type.equals(PsiType.NULL)) return null;
  if (type instanceof PsiEllipsisType) type = ((PsiEllipsisType)type).toArrayType();
  String text = "(" + type.getCanonicalText(false) + ")value";
  PsiElementFactory factory = JavaPsiFacade.getInstance(original.getProject()).getElementFactory();
  PsiTypeCastExpression typeCast = (PsiTypeCastExpression)factory.createExpressionFromText(text, original);
  typeCast = (PsiTypeCastExpression)JavaCodeStyleManager.getInstance(project).shortenClassReferences(typeCast);
  typeCast = (PsiTypeCastExpression)CodeStyleManager.getInstance(project).reformat(typeCast);

  if (expression instanceof PsiConditionalExpression) {
    // we'd better cast one branch of ternary expression if we can
    PsiConditionalExpression conditional = (PsiConditionalExpression)expression.copy();
    PsiExpression thenE = conditional.getThenExpression();
    PsiExpression elseE = conditional.getElseExpression();
    PsiType thenType = thenE == null ? null : thenE.getType();
    PsiType elseType = elseE == null ? null : elseE.getType();
    if (elseType != null && thenType != null) {
      boolean replaceThen = !TypeConversionUtil.isAssignable(type, thenType);
      boolean replaceElse = !TypeConversionUtil.isAssignable(type, elseType);
      if (replaceThen != replaceElse) {
        if (replaceThen) {
          assertNotNull(typeCast.getOperand()).replace(thenE);
          thenE.replace(typeCast);
        }
        else {
          assertNotNull(typeCast.getOperand()).replace(elseE);
          elseE.replace(typeCast);
        }
        return conditional;
      }
    }
  }

  assertNotNull(typeCast.getOperand()).replace(expression);

  return typeCast;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:42,代码来源:AddTypeCastFix.java

示例12: checkNullness

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@NotNull
private static Nullness checkNullness(final PsiElement element) {
  // null
  PsiElement value = element;
  if (value instanceof PsiExpression) {
    value = PsiUtil.deparenthesizeExpression((PsiExpression)value);
  }
  if (value instanceof PsiLiteralExpression) {
    return ((PsiLiteralExpression)value).getValue() == null ? Nullness.NULLABLE : Nullness.NOT_NULL;
  }

  // not null
  if (value instanceof PsiNewExpression) return Nullness.NOT_NULL;
  if (value instanceof PsiThisExpression) return Nullness.NOT_NULL;
  if (value instanceof PsiMethodCallExpression) {
    PsiMethod method = ((PsiMethodCallExpression)value).resolveMethod();
    if (method != null && NullableNotNullManager.isNotNull(method)) return Nullness.NOT_NULL;
    if (method != null && NullableNotNullManager.isNullable(method)) return Nullness.NULLABLE;
  }
  if (value instanceof PsiPolyadicExpression && ((PsiPolyadicExpression)value).getOperationTokenType() == JavaTokenType.PLUS) {
    return Nullness.NOT_NULL; // "xxx" + var
  }

  // unfortunately have to resolve here, since there can be no subnodes
  PsiElement context = value;
  if (value instanceof PsiReference) {
    PsiElement resolved = ((PsiReference)value).resolve();
    if (resolved instanceof PsiCompiledElement) {
      resolved = resolved.getNavigationElement();
    }
    value = resolved;
  }
  if (value instanceof PsiParameter && ((PsiParameter)value).getDeclarationScope() instanceof PsiCatchSection) {
    // exception thrown is always not null
    return Nullness.NOT_NULL;
  }

  if (value instanceof PsiLocalVariable || value instanceof PsiParameter) {
    Nullness result = DfaUtil.checkNullness((PsiVariable)value, context);
    if (result != Nullness.UNKNOWN) {
      return result;
    }
  }

  if (value instanceof PsiModifierListOwner) {
    if (NullableNotNullManager.isNotNull((PsiModifierListOwner)value)) return Nullness.NOT_NULL;
    if (NullableNotNullManager.isNullable((PsiModifierListOwner)value)) return Nullness.NULLABLE;
  }

  if (value instanceof PsiEnumConstant) return Nullness.NOT_NULL;
  return Nullness.UNKNOWN;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:53,代码来源:SliceNullnessAnalyzer.java

示例13: isZero

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
boolean isZero(PsiExpression expression) {
  if (m_ignoreExpressionsContainingConstants && PsiUtil.deparenthesizeExpression(expression) instanceof PsiReferenceExpression) {
    return false;
  }
  return ExpressionUtils.isZero(expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:PointlessArithmeticExpressionInspection.java

示例14: isOne

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
boolean isOne(PsiExpression expression) {
  if (m_ignoreExpressionsContainingConstants && PsiUtil.deparenthesizeExpression(expression) instanceof PsiReferenceExpression) {
    return false;
  }
  return ExpressionUtils.isOne(expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:PointlessArithmeticExpressionInspection.java

示例15: satisfiedBy

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public boolean satisfiedBy(@NotNull PsiElement element) {
  if (!(element instanceof PsiExpressionList)) {
    return false;
  }
  final PsiExpressionList argumentList = (PsiExpressionList)element;
  final PsiElement grandParent = argumentList.getParent();
  if (!(grandParent instanceof PsiMethodCallExpression)) {
    return false;
  }
  final PsiMethodCallExpression methodCallExpression =
    (PsiMethodCallExpression)grandParent;
  final PsiMethod method = methodCallExpression.resolveMethod();
  if (method == null || !method.isVarArgs()) {
    return false;
  }
  final PsiParameterList parameterList = method.getParameterList();
  final int parametersCount = parameterList.getParametersCount();
  final PsiExpression[] arguments = argumentList.getExpressions();
  if (arguments.length < parametersCount) {
    return false;
  }

  // after invoking the (false positive) quick fix for
  // "Unnecessarily qualified static usage" inspection
  // the psi gets into a bad state, this guards against that.
  // http://www.jetbrains.net/jira/browse/IDEADEV-40124
  final PsiReferenceExpression methodExpression =
    methodCallExpression.getMethodExpression();
  final PsiExpression qualifier =
    methodExpression.getQualifierExpression();
  if (qualifier == null) {
    final PsiReferenceParameterList typeParameterList =
      methodExpression.getParameterList();
    if (typeParameterList != null) {
      final PsiTypeElement[] typeParameterElements =
        typeParameterList.getTypeParameterElements();
      if (typeParameterElements.length > 0) {
        return false;
      }
    }
  }

  if (arguments.length != parametersCount) {
    return true;
  }
  final PsiExpression lastExpression =
    arguments[arguments.length - 1];
  final PsiExpression expression = PsiUtil.deparenthesizeExpression(
    lastExpression);
  if (expression instanceof PsiLiteralExpression) {
    final String text = expression.getText();
    if ("null".equals(text)) {
      // a single null argument is not wrapped in an array
      // on a vararg method call, but just passed as a null value
      return false;
    }
  }
  final PsiType lastArgumentType = lastExpression.getType();
  if (!(lastArgumentType instanceof PsiArrayType)) {
    return true;
  }
  final PsiArrayType arrayType = (PsiArrayType)lastArgumentType;
  final PsiType type = arrayType.getComponentType();
  final PsiParameter[] parameters = parameterList.getParameters();
  final PsiParameter lastParameter = parameters[parameters.length - 1];
  final PsiEllipsisType lastParameterType =
    (PsiEllipsisType)lastParameter.getType();
  final PsiType lastType = lastParameterType.getComponentType();
  final JavaResolveResult resolveResult =
    methodCallExpression.resolveMethodGenerics();
  final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
  final PsiType substitutedType = substitutor.substitute(lastType);
  return !substitutedType.equals(type);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:75,代码来源:VarargArgumentsPredicate.java


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