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


Java PsiUtilCore.hasErrorElementChild方法代码示例

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


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

示例1: visitMethodCallExpression

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
  super.visitMethodCallExpression(expression);
  final PsiReferenceExpression methodExpression = expression.getMethodExpression();
  final String name = methodExpression.getReferenceName();
  if (!"setScale".equals(name) && !"divide".equals(name)) {
    return;
  }
  final PsiExpressionList argumentList = expression.getArgumentList();
  if (PsiUtilCore.hasErrorElementChild(argumentList)) {
    return;
  }
  final PsiExpression[] arguments = argumentList.getExpressions();
  if (arguments.length != 2 && arguments.length != 3) {
    return;
  }
  final PsiExpression argument = arguments[arguments.length - 1];
  if (!PsiType.INT.equals(argument.getType())) {
    return;
  }
  if (!TypeUtils.expressionHasTypeOrSubtype(expression, "java.math.BigDecimal")) {
    return;
  }
  registerMethodCallError(expression, argument);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:BigDecimalLegacyMethodInspection.java

示例2: visitMethodCallExpression

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
  super.visitMethodCallExpression(expression);
  final PsiReferenceExpression methodExpression = expression.getMethodExpression();
  final String name = methodExpression.getReferenceName();
  if (!"setScale".equals(name) && !"divide".equals(name)) {
    return;
  }
  final PsiExpressionList argumentList = expression.getArgumentList();
  if (PsiUtilCore.hasErrorElementChild(argumentList)) {
    return;
  }
  final PsiExpression[] arguments = argumentList.getExpressions();
  if (arguments.length != 1) {
    return;
  }
  if (!TypeUtils.expressionHasTypeOrSubtype(expression, "java.math.BigDecimal")) {
    return;
  }
  registerMethodCallError(expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:BigDecimalMethodWithoutRoundingCalledInspection.java

示例3: processImport

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Nullable
private HighlightInfo processImport(@NotNull PsiImportStatementBase importStatement, @NotNull HighlightDisplayKey unusedImportKey) {
  // jsp include directive hack
  if (importStatement.isForeignFileImport()) return null;

  if (PsiUtilCore.hasErrorElementChild(importStatement)) return null;

  boolean isRedundant = myRefCountHolder.isRedundant(importStatement);
  if (!isRedundant && !(importStatement instanceof PsiImportStaticStatement)) {
    //check import from same package
    String packageName = ((PsiClassOwner)importStatement.getContainingFile()).getPackageName();
    PsiJavaCodeReferenceElement reference = importStatement.getImportReference();
    PsiElement resolved = reference == null ? null : reference.resolve();
    if (resolved instanceof PsiPackage) {
      isRedundant = packageName.equals(((PsiQualifiedNamedElement)resolved).getQualifiedName());
    }
    else if (resolved instanceof PsiClass && !importStatement.isOnDemand()) {
      String qName = ((PsiClass)resolved).getQualifiedName();
      if (qName != null) {
        String name = ((PomNamedTarget)resolved).getName();
        isRedundant = qName.equals(packageName + '.' + name);
      }
    }
  }

  if (isRedundant) {
    return registerRedundantImport(importStatement, unusedImportKey);
  }

  int entryIndex = JavaCodeStyleManager.getInstance(myProject).findEntryIndex(importStatement);
  if (entryIndex < myCurrentEntryIndex) {
    myHasMissortedImports = true;
  }
  myCurrentEntryIndex = entryIndex;

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

示例4: visitMethod

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public void visitMethod(@NotNull PsiMethod method) {
  super.visitMethod(method);
  if (!method.isConstructor() || method.getNameIdentifier() == null) {
    return;
  }
  final PsiClass containingClass = method.getContainingClass();
  if (containingClass == null) {
    return;
  }
  if (containingClass.isEnum()) {
    return;
  }
  if (m_ignoreForObjectSubclasses) {
    final PsiClass superClass = containingClass.getSuperClass();
    if (superClass != null) {
      final String superClassName = superClass.getQualifiedName();
      if (CommonClassNames.JAVA_LANG_OBJECT.equals(
        superClassName)) {
        return;
      }
    }
  }
  final PsiCodeBlock body = method.getBody();
  if (body == null) {
    return;
  }
  final PsiStatement[] statements = body.getStatements();
  if (statements.length == 0) {
    registerMethodError(method);
    return;
  }
  final PsiStatement firstStatement = statements[0];
  if (isConstructorCall(firstStatement) || PsiUtilCore.hasErrorElementChild(firstStatement)) {
    return;
  }
  registerMethodError(method);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:ImplicitCallToSuperInspection.java

示例5: visitPolyadicExpression

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public void visitPolyadicExpression(@NotNull PsiPolyadicExpression expression) {
  super.visitPolyadicExpression(expression);
  final IElementType sign = expression.getOperationTokenType();
  if (!bitwiseTokens.contains(sign)) {
    return;
  }
  if (PsiUtilCore.hasErrorElementChild(expression)) {
    return;
  }
  final PsiExpression[] operands = expression.getOperands();
  for (PsiExpression operand : operands) {
    if (operand == null) {
      return;
    }
    final PsiType type = operand.getType();
    if (type == null || type.equals(PsiType.BOOLEAN) ||
        type.equalsToText(CommonClassNames.JAVA_LANG_BOOLEAN)) {
      return;
    }
  }
  final boolean isPointless;
  if (sign.equals(JavaTokenType.AND) || sign.equals(JavaTokenType.OR) ||
      sign.equals(JavaTokenType.XOR)) {
    isPointless = booleanExpressionIsPointless(operands);
  }
  else if (sign.equals(JavaTokenType.LTLT) ||
           sign.equals(JavaTokenType.GTGT) ||
           sign.equals(JavaTokenType.GTGTGT)) {
    isPointless = shiftExpressionIsPointless(operands);
  }
  else {
    isPointless = false;
  }
  if (!isPointless) {
    return;
  }
  registerError(expression, expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:PointlessBitwiseExpressionInspection.java

示例6: isTrivial

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
public static boolean isTrivial(PsiIfStatement ifStatement) {
  if (PsiUtilCore.hasErrorElementChild(ifStatement)) {
    return false;
  }
  if (isSimplifiableAssignment(ifStatement)) {
    return true;
  }
  if (isSimplifiableReturn(ifStatement)) {
    return true;
  }
  if (isSimplifiableImplicitReturn(ifStatement)) {
    return true;
  }
  if (isSimplifiableAssignmentNegated(ifStatement)) {
    return true;
  }
  if (isSimplifiableReturnNegated(ifStatement)) {
    return true;
  }
  if (isSimplifiableImplicitReturnNegated(ifStatement)) {
    return true;
  }
  if (isSimplifiableImplicitAssignment(ifStatement)) {
    return true;
  }
  if (isSimplifiableImplicitAssignmentNegated(ifStatement)) {
    return true;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:TrivialIfInspection.java

示例7: visitPolyadicExpression

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public void visitPolyadicExpression(@NotNull PsiPolyadicExpression expression) {
  super.visitPolyadicExpression(expression);
  final PsiType expressionType = expression.getType();
  if (expressionType == null ||
      PsiType.DOUBLE.equals(expressionType) ||
      PsiType.FLOAT.equals(expressionType)) {
    return;
  }
  if (!arithmeticTokens.contains(expression.getOperationTokenType())) {
    return;
  }
  if (ExpressionUtils.hasStringType(expression) || PsiUtilCore.hasErrorElementChild(expression)) {
    return;
  }
  final PsiExpression[] operands = expression.getOperands();
  final IElementType tokenType = expression.getOperationTokenType();
  final boolean isPointless;
  if (tokenType.equals(JavaTokenType.PLUS)) {
    isPointless = additionExpressionIsPointless(operands);
  }
  else if (tokenType.equals(JavaTokenType.MINUS)) {
    isPointless = subtractionExpressionIsPointless(operands);
  }
  else if (tokenType.equals(JavaTokenType.ASTERISK)) {
    isPointless = multiplyExpressionIsPointless(operands);
  }
  else if (tokenType.equals(JavaTokenType.DIV) || tokenType.equals(JavaTokenType.PERC)) {
    isPointless = divideExpressionIsPointless(operands);
  }
  else {
    isPointless = false;
  }
  if (!isPointless) {
    return;
  }
  registerError(expression, expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:PointlessArithmeticExpressionInspection.java

示例8: getSelectedExpression

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Nullable
public static PyExpression getSelectedExpression(@NotNull final Project project,
                                                 @NotNull PsiFile file,
                                                 @NotNull final PsiElement element1,
                                                 @NotNull final PsiElement element2) {
  PsiElement parent = PsiTreeUtil.findCommonParent(element1, element2);
  if (parent != null && !(parent instanceof PyElement)) {
    parent = PsiTreeUtil.getParentOfType(parent, PyElement.class);
  }
  if (parent == null) {
    return null;
  }
  // If it is PyIfPart for example, parent if statement, we should deny
  if (!(parent instanceof PyExpression)){
    return null;
  }
  // We cannot extract anything within import statements
  if (PsiTreeUtil.getParentOfType(parent, PyImportStatement.class, PyFromImportStatement.class) != null){
    return null;
  }
  if ((element1 == PsiTreeUtil.getDeepestFirst(parent)) && (element2 == PsiTreeUtil.getDeepestLast(parent))) {
    return (PyExpression) parent;
  }

  // Check if selection breaks AST node in binary expression
  if (parent instanceof PyBinaryExpression) {
    final String selection = file.getText().substring(element1.getTextOffset(), element2.getTextOffset() + element2.getTextLength());
    final PyElementGenerator generator = PyElementGenerator.getInstance(project);
    final LanguageLevel langLevel = LanguageLevel.forElement(element1);
    final PyExpression expression = generator.createFromText(langLevel, PyAssignmentStatement.class, "z=" + selection).getAssignedValue();
    if (!(expression instanceof PyBinaryExpression) || PsiUtilCore.hasErrorElementChild(expression)) {
      return null;
    }
    final String parentText = parent.getText();
    final int startOffset = element1.getTextOffset() - parent.getTextOffset() - 1;
    if (startOffset < 0) {
      return null;
    }
    final int endOffset = element2.getTextOffset() + element2.getTextLength() - parent.getTextOffset();

    final String prefix = parentText.substring(0, startOffset);
    final String suffix = parentText.substring(endOffset, parentText.length());
    final TextRange textRange = TextRange.from(startOffset, endOffset - startOffset);
    final PsiElement fakeExpression = generator.createFromText(langLevel, parent.getClass(), prefix + "python" + suffix);
    if (PsiUtilCore.hasErrorElementChild(fakeExpression)) {
      return null;
    }

    expression.putUserData(PyReplaceExpressionUtil.SELECTION_BREAKS_AST_NODE, Pair.create(parent, textRange));
    return expression;
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:54,代码来源:PyRefactoringUtil.java

示例9: visitExpressionStatement

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public void visitExpressionStatement(@NotNull PsiExpressionStatement statement) {
  super.visitExpressionStatement(statement);
  final PsiExpression expression = statement.getExpression();
  if (!(expression instanceof PsiMethodCallExpression)) {
    return;
  }
  final PsiMethodCallExpression call = (PsiMethodCallExpression)expression;
  final PsiMethod method = call.resolveMethod();
  if (method == null || method.isConstructor()) {
    return;
  }
  final PsiType returnType = method.getReturnType();
  if (PsiType.VOID.equals(returnType)) {
    return;
  }
  final PsiClass aClass = method.getContainingClass();
  if (aClass == null) {
    return;
  }
  if (PsiUtilCore.hasErrorElementChild(statement)) {
    return;
  }
  if (m_reportAllNonLibraryCalls && !LibraryUtil.classIsInLibrary(aClass)) {
    registerMethodCallError(call, aClass);
    return;
  }

  PsiAnnotation anno = ControlFlowAnalyzer.findContractAnnotation(method);
  boolean honorInferred = Registry.is("ide.ignore.call.result.inspection.honor.inferred.pure");
  if (anno != null && 
      (honorInferred || !AnnotationUtil.isInferredAnnotation(anno)) && 
      Boolean.TRUE.equals(AnnotationUtil.getBooleanAttributeValue(anno, "pure"))) {
    registerMethodCallError(call, aClass);
    return;
  }

  final PsiReferenceExpression methodExpression = call.getMethodExpression();
  final String methodName = methodExpression.getReferenceName();
  if (methodName == null) {
    return;
  }
  for (int i = 0; i < methodNamePatterns.size(); i++) {
    final String methodNamePattern = methodNamePatterns.get(i);
    if (!methodNamesMatch(methodName, methodNamePattern)) {
      continue;
    }
    final String className = classNames.get(i);
    if (!InheritanceUtil.isInheritor(aClass, className)) {
      continue;
    }
    registerMethodCallError(call, aClass);
    return;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:56,代码来源:IgnoreResultOfCallInspectionBase.java

示例10: isUnclearExpression

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Contract("null, _ -> false")
public static boolean isUnclearExpression(PsiExpression expression, PsiElement parent) {
  if (expression instanceof PsiAssignmentExpression) {
    final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)expression;
    final IElementType tokenType = assignmentExpression.getOperationTokenType();
    if (parent instanceof PsiVariable) {
      if (!tokenType.equals(JavaTokenType.EQ)) {
        return true;
      }
    }
    else if (parent instanceof PsiAssignmentExpression) {
      final PsiAssignmentExpression nestedAssignment = (PsiAssignmentExpression)parent;
      final IElementType nestedTokenType = nestedAssignment.getOperationTokenType();
      if (!tokenType.equals(nestedTokenType)) {
        return true;
      }
    }
    return isUnclearExpression(assignmentExpression.getRExpression(), assignmentExpression);
  }
  else if (expression instanceof PsiConditionalExpression) {
    final PsiConditionalExpression conditionalExpression = (PsiConditionalExpression)expression;
    if (PsiUtilCore.hasErrorElementChild(expression)) {
      return false;
    }
    return (parent instanceof PsiConditionalExpression) ||
           isUnclearExpression(conditionalExpression.getCondition(), conditionalExpression) ||
           isUnclearExpression(conditionalExpression.getThenExpression(), conditionalExpression) ||
           isUnclearExpression(conditionalExpression.getElseExpression(), conditionalExpression);
  }
  else if (expression instanceof PsiPolyadicExpression) {
    if ((parent instanceof PsiConditionalExpression) || (parent instanceof PsiPolyadicExpression) ||
        (parent instanceof PsiInstanceOfExpression)) {
      return true;
    }
    final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
    for (PsiExpression operand : polyadicExpression.getOperands()) {
      final PsiType type = operand.getType();
      if ((type == null) || type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
        return false;
      }
      if (isUnclearExpression(operand, polyadicExpression)) {
        return true;
      }
    }
  }
  else if (expression instanceof PsiInstanceOfExpression) {
    if ((parent instanceof PsiPolyadicExpression) || (parent instanceof PsiConditionalExpression)) {
      return true;
    }
    final PsiInstanceOfExpression instanceOfExpression = (PsiInstanceOfExpression)expression;
    return isUnclearExpression(instanceOfExpression.getOperand(), instanceOfExpression);
  }
  else if (expression instanceof PsiParenthesizedExpression) {
    final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)expression;
    final PsiExpression nestedExpression = parenthesizedExpression.getExpression();
    return isUnclearExpression(nestedExpression, parenthesizedExpression);
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:60,代码来源:UnclearBinaryExpressionInspection.java

示例11: containsError

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
/**
 * Checks only immediate children. No expensive full tree traversal.
 *
 * @return true, if an PsiErrorElement was found, false otherwise.
 */
public static boolean containsError(PsiElement element) {
  // check only immediate children, full tree traversal is too expensive
  return PsiUtilCore.hasErrorElementChild(element);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:ErrorUtil.java


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