Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
36,500
void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { final GrExpression expression = (GrExpression) element; final String newExpression = calculateReplacementExpression(expression); GrInspectionUtil.replaceExpression(expression, newExpression); }
applyFix
36,501
void (@NotNull GrBinaryExpression expression) { super.visitBinaryExpression(expression); if (isFake(expression)) return; final GrExpression rhs = expression.getRightOperand(); if (rhs == null) return; final IElementType sign = expression.getOperationTokenType(); if (!arithmeticTokens.contains(sign)) return; final GrExpression lhs = expression.getLeftOperand(); final boolean isPointless; if (sign.equals(GroovyTokenTypes.mPLUS)) { isPointless = additionExpressionIsPointless(lhs, rhs); } else if (sign.equals(GroovyTokenTypes.mMINUS)) { isPointless = subtractionExpressionIsPointless(rhs); } else if (sign.equals(GroovyTokenTypes.mSTAR)) { isPointless = multiplyExpressionIsPointless(lhs, rhs); } else if (sign.equals(GroovyTokenTypes.mDIV)) { isPointless = divideExpressionIsPointless(rhs); } else { isPointless = false; } if (!isPointless) { return; } registerError(expression); }
visitBinaryExpression
36,502
boolean (GrExpression rhs) { return isZero(rhs); }
subtractionExpressionIsPointless
36,503
boolean (GrExpression lhs, GrExpression rhs) { return isZero(lhs) || isZero(rhs); }
additionExpressionIsPointless
36,504
boolean (GrExpression lhs, GrExpression rhs) { return isZero(lhs) || isZero(rhs) || isOne(lhs) || isOne(rhs); }
multiplyExpressionIsPointless
36,505
boolean (GrExpression rhs) { return isOne(rhs); }
divideExpressionIsPointless
36,506
boolean (GrExpression expression) { final PsiElement inner = PsiUtil.skipParentheses(expression, false); if (inner == null) return false; @NonNls final String text = inner.getText(); return "0".equals(text) || "0x0".equals(text) || "0X0".equals(text) || "0.0".equals(text) || "0L".equals(text) || "0l".equals(text) || "0b0".equals(text) || "0B0".equals(text); }
isZero
36,507
boolean (GrExpression expression) { final PsiElement inner = PsiUtil.skipParentheses(expression, false); if (inner == null) return false; @NonNls final String text = inner.getText(); return "1".equals(text) || "0x1".equals(text) || "0X1".equals(text) || "1.0".equals(text) || "1L".equals(text) || "1l".equals(text) || "0b0".equals(text) || "0B0".equals(text); }
isOne
36,508
BaseInspectionVisitor () { return new BaseInspectionVisitor() { @Override public void visitAnnotation(@NotNull GrAnnotation annotation) { checkTarget(annotation); checkDelegatesTo(annotation); } private void checkTarget(GrAnnotation annotation) { if (!GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO_TARGET.equals(annotation.getQualifiedName())) return; final PsiElement owner = annotation.getParent().getParent(); if (!(owner instanceof GrParameter)) return; final boolean isTargetDeclared = annotation.findDeclaredAttributeValue("value") != null; String targetName = GrAnnotationUtil.inferStringAttribute(annotation, "value"); final GrParameterList parameterList = (GrParameterList)owner.getParent(); for (GrParameter parameter : parameterList.getParameters()) { final PsiAnnotation delegatesTo = parameter.getModifierList().findAnnotation(GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO); if (delegatesTo != null) { if (isTargetDeclared) { final String curTarget = GrAnnotationUtil.inferStringAttribute(delegatesTo, "target"); if (curTarget != null && curTarget.equals(targetName)) { return; //target is used } } else { if (delegatesTo.findDeclaredAttributeValue("target") == null && delegatesTo.findDeclaredAttributeValue("value") == null) { return; // target is used } } } } registerError(annotation.getClassReference(), GroovyBundle.message("target.annotation.is.unused"), LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } private void checkDelegatesTo(GrAnnotation annotation) { if (!GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO.equals(annotation.getQualifiedName())) return; final PsiElement owner = annotation.getParent().getParent(); if (!(owner instanceof GrParameter)) return; final PsiAnnotationMemberValue targetPair = annotation.findDeclaredAttributeValue("target"); if (targetPair == null) return; String targetName = GrAnnotationUtil.inferStringAttribute(annotation, "target"); final GrParameterList parameterList = (GrParameterList)owner.getParent(); for (GrParameter parameter : parameterList.getParameters()) { final PsiAnnotation target = parameter.getModifierList().findAnnotation(GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO_TARGET); if (target != null) { final String curTarget = GrAnnotationUtil.inferStringAttribute(target, "value"); if (curTarget != null && curTarget.equals(targetName)) { return; //target is used } } } registerError(targetPair, GroovyBundle.message("target.0.does.not.exist", targetName != null ? targetName : "?"), LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } }; }
buildVisitor
36,509
void (@NotNull GrAnnotation annotation) { checkTarget(annotation); checkDelegatesTo(annotation); }
visitAnnotation
36,510
void (GrAnnotation annotation) { if (!GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO_TARGET.equals(annotation.getQualifiedName())) return; final PsiElement owner = annotation.getParent().getParent(); if (!(owner instanceof GrParameter)) return; final boolean isTargetDeclared = annotation.findDeclaredAttributeValue("value") != null; String targetName = GrAnnotationUtil.inferStringAttribute(annotation, "value"); final GrParameterList parameterList = (GrParameterList)owner.getParent(); for (GrParameter parameter : parameterList.getParameters()) { final PsiAnnotation delegatesTo = parameter.getModifierList().findAnnotation(GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO); if (delegatesTo != null) { if (isTargetDeclared) { final String curTarget = GrAnnotationUtil.inferStringAttribute(delegatesTo, "target"); if (curTarget != null && curTarget.equals(targetName)) { return; //target is used } } else { if (delegatesTo.findDeclaredAttributeValue("target") == null && delegatesTo.findDeclaredAttributeValue("value") == null) { return; // target is used } } } } registerError(annotation.getClassReference(), GroovyBundle.message("target.annotation.is.unused"), LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); }
checkTarget
36,511
void (GrAnnotation annotation) { if (!GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO.equals(annotation.getQualifiedName())) return; final PsiElement owner = annotation.getParent().getParent(); if (!(owner instanceof GrParameter)) return; final PsiAnnotationMemberValue targetPair = annotation.findDeclaredAttributeValue("target"); if (targetPair == null) return; String targetName = GrAnnotationUtil.inferStringAttribute(annotation, "target"); final GrParameterList parameterList = (GrParameterList)owner.getParent(); for (GrParameter parameter : parameterList.getParameters()) { final PsiAnnotation target = parameter.getModifierList().findAnnotation(GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO_TARGET); if (target != null) { final String curTarget = GrAnnotationUtil.inferStringAttribute(target, "value"); if (curTarget != null && curTarget.equals(targetName)) { return; //target is used } } } registerError(targetPair, GroovyBundle.message("target.0.does.not.exist", targetName != null ? targetName : "?"), LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); }
checkDelegatesTo
36,512
String (Object... args) { if (args[0] instanceof GrIfStatement) { return GroovyBundle.message("inspection.message.ref.statement.has.empty.branch"); } else { return GroovyBundle.message("inspection.message.ref.statement.has.empty.body"); } }
buildErrorString
36,513
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,514
void (@NotNull GrWhileStatement statement) { super.visitWhileStatement(statement); final GrStatement body = statement.getBody(); if (body == null) { return; } if (!isEmpty(body)) { return; } registerStatementError(statement, statement); }
visitWhileStatement
36,515
void (@NotNull GrForStatement statement) { super.visitForStatement(statement); final GrStatement body = statement.getBody(); if (body == null) { return; } if (!isEmpty(body)) { return; } registerStatementError(statement, statement); }
visitForStatement
36,516
void (@NotNull GrIfStatement statement) { super.visitIfStatement(statement); final GrStatement thenBranch = statement.getThenBranch(); if (thenBranch != null) { if (isEmpty(thenBranch)) { registerStatementError(statement, statement); return; } } final GrStatement elseBranch = statement.getElseBranch(); if (elseBranch != null) { if (isEmpty(elseBranch)) { registerStatementError(statement, statement); } } }
visitIfStatement
36,517
boolean (GroovyPsiElement body) { if (!(body instanceof GrBlockStatement block)) { return false; } final GrOpenBlock openBlock = block.getBlock(); final PsiElement brace = openBlock.getLBrace(); if (brace == null) return false; final PsiElement nextNonWhitespace = PsiUtil.skipWhitespaces(brace.getNextSibling(), true); return nextNonWhitespace == openBlock.getRBrace(); }
isEmpty
36,518
String (Object... args) { return GroovyBundle.message("getter.0.clashes.with.getter.1", args); }
buildErrorString
36,519
BaseInspectionVisitor () { return new BaseInspectionVisitor() { @Override public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) { super.visitTypeDefinition(typeDefinition); Map<String, PsiMethod> getters = new HashMap<>(); for (PsiMethod method : typeDefinition.getMethods()) { final String methodName = method.getName(); if (!GroovyPropertyUtils.isSimplePropertyGetter(method)) continue; final String propertyName = GroovyPropertyUtils.getPropertyNameByGetterName(methodName, true); final PsiMethod otherGetter = getters.get(propertyName); if (otherGetter != null && !methodName.equals(otherGetter.getName())) { final Pair<PsiElement, String> description = getGetterDescription(method); final Pair<PsiElement, String> otherDescription = getGetterDescription(otherGetter); if (description.first != null) { registerError(description.first, description.second, otherDescription.second); } if (otherDescription.first != null) { registerError(otherDescription.first, otherDescription.second, description.second); } } else { getters.put(propertyName, method); } } } }; }
buildVisitor
36,520
void (@NotNull GrTypeDefinition typeDefinition) { super.visitTypeDefinition(typeDefinition); Map<String, PsiMethod> getters = new HashMap<>(); for (PsiMethod method : typeDefinition.getMethods()) { final String methodName = method.getName(); if (!GroovyPropertyUtils.isSimplePropertyGetter(method)) continue; final String propertyName = GroovyPropertyUtils.getPropertyNameByGetterName(methodName, true); final PsiMethod otherGetter = getters.get(propertyName); if (otherGetter != null && !methodName.equals(otherGetter.getName())) { final Pair<PsiElement, String> description = getGetterDescription(method); final Pair<PsiElement, String> otherDescription = getGetterDescription(otherGetter); if (description.first != null) { registerError(description.first, description.second, otherDescription.second); } if (otherDescription.first != null) { registerError(otherDescription.first, otherDescription.second, description.second); } } else { getters.put(propertyName, method); } } }
visitTypeDefinition
36,521
String (Object... args) { return GroovyBundle.message("inspection.message.octal.integer.ref"); }
buildErrorString
36,522
BaseInspectionVisitor () { return new BaseInspectionVisitor() { @Override public void visitLiteralExpression(@NotNull GrLiteral literal) { super.visitLiteralExpression(literal); @NonNls final String text = literal.getText(); if (!text.startsWith("0")) return; if (text.replaceAll("0", "").isEmpty()) return; if ("0g".equals(text) || "0G".equals(text)) return; if ("0i".equals(text) || "0I".equals(text)) return; if ("0l".equals(text) || "0L".equals(text)) return; if (text.startsWith("0x") || text.startsWith("0X")) return; if (text.startsWith("0b") || text.startsWith("0B")) return; if (text.endsWith("d") || text.endsWith("D")) return; if (text.endsWith("f") || text.endsWith("F")) return; if (text.contains(".") || text.contains("e") || text.contains("E")) return; registerError(literal); } }; }
buildVisitor
36,523
void (@NotNull GrLiteral literal) { super.visitLiteralExpression(literal); @NonNls final String text = literal.getText(); if (!text.startsWith("0")) return; if (text.replaceAll("0", "").isEmpty()) return; if ("0g".equals(text) || "0G".equals(text)) return; if ("0i".equals(text) || "0I".equals(text)) return; if ("0l".equals(text) || "0L".equals(text)) return; if (text.startsWith("0x") || text.startsWith("0X")) return; if (text.startsWith("0b") || text.startsWith("0B")) return; if (text.endsWith("d") || text.endsWith("D")) return; if (text.endsWith("f") || text.endsWith("F")) return; if (text.contains(".") || text.contains("e") || text.contains("E")) return; registerError(literal); }
visitLiteralExpression
36,524
String (Object... args) { return GroovyBundle.message("inspection.message.result.increment.or.decrement.expression.used"); }
buildErrorString
36,525
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,526
void (@NotNull GrUnaryExpression grUnaryExpression) { super.visitUnaryExpression(grUnaryExpression); final IElementType tokenType = grUnaryExpression.getOperationTokenType(); if (!GroovyTokenTypes.mINC.equals(tokenType) && !GroovyTokenTypes.mDEC.equals(tokenType)) { return; } if (PsiUtil.isExpressionUsed(grUnaryExpression)) { registerError(grUnaryExpression); } }
visitUnaryExpression
36,527
String (Object... args) { return GroovyBundle.message("inspection.message.gstring.used.as.maps.key"); }
buildErrorString
36,528
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,529
void (@NotNull GrNamedArgument namedArgument) { PsiElement parent = namedArgument.getParent(); if (!(parent instanceof GrListOrMap) || !((GrListOrMap)parent).isMap()) return; final GrArgumentLabel argumentLabel = namedArgument.getLabel(); if (argumentLabel == null) return; final GrExpression labelExpression = argumentLabel.getExpression(); if (labelExpression == null) return; if (isGStringType(labelExpression)) { registerError(argumentLabel); } }
visitNamedArgument
36,530
void (@NotNull GrExpression grExpression) { final PsiElement gstringParent = grExpression.getParent(); if (!(gstringParent instanceof GrArgumentList)) return; GrExpression[] arguments = ((GrArgumentList)gstringParent).getExpressionArguments(); if (arguments.length != 2 || !arguments[0].equals(grExpression)) return; final PsiElement grandparent = gstringParent.getParent(); if (!(grandparent instanceof GrMethodCall)) { return; } if (!isGStringType(grExpression)) return; if (!isMapPutMethod((GrMethodCall)grandparent)) return; registerError(grExpression); }
visitExpression
36,531
boolean (@NotNull GrExpression expression) { PsiType expressionType = expression.getType(); return expressionType != null && expressionType.equalsToText(GROOVY_LANG_GSTRING); }
isGStringType
36,532
String (Object... args) { return GroovyBundle.message("inspection.message.package.name.mismatch"); }
buildErrorString
36,533
OptPane () { return pane( checkbox("myCheckScripts", GroovyBundle.message("gr.package.inspection.check.scripts"))); }
getGroovyOptionsPane
36,534
BaseInspectionVisitor () { return new BaseInspectionVisitor() { @Override public void visitFile(@NotNull GroovyFileBase file) { if (!(file instanceof GroovyFile)) return; if (!myCheckScripts && file.isScript()) return; String expectedPackage = ExpectedPackageNameProviderKt.inferExpectedPackageName((GroovyFile)file); String actual = file.getPackageName(); if (!expectedPackage.equals(actual)) { PsiElement toHighlight = getElementToHighlight((GroovyFile)file); if (toHighlight == null) return; registerError(toHighlight, GroovyBundle.message("inspection.message.package.name.mismatch.actual.0.expected.1", actual, expectedPackage), new LocalQuickFix[]{new ChangePackageQuickFix(expectedPackage), GroovyQuickFixFactory.getInstance().createGrMoveToDirFix(actual)}, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } } }; }
buildVisitor
36,535
void (@NotNull GroovyFileBase file) { if (!(file instanceof GroovyFile)) return; if (!myCheckScripts && file.isScript()) return; String expectedPackage = ExpectedPackageNameProviderKt.inferExpectedPackageName((GroovyFile)file); String actual = file.getPackageName(); if (!expectedPackage.equals(actual)) { PsiElement toHighlight = getElementToHighlight((GroovyFile)file); if (toHighlight == null) return; registerError(toHighlight, GroovyBundle.message("inspection.message.package.name.mismatch.actual.0.expected.1", actual, expectedPackage), new LocalQuickFix[]{new ChangePackageQuickFix(expectedPackage), GroovyQuickFixFactory.getInstance().createGrMoveToDirFix(actual)}, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } }
visitFile
36,536
PsiElement (GroovyFile file) { GrPackageDefinition packageDefinition = file.getPackageDefinition(); if (packageDefinition != null) return packageDefinition; PsiClass[] classes = file.getClasses(); for (PsiClass aClass : classes) { if (!(aClass instanceof SyntheticElement) && aClass instanceof GrTypeDefinition) { return ((GrTypeDefinition)aClass).getNameIdentifierGroovy(); } } GrTopStatement[] statements = file.getTopStatements(); if (statements.length > 0) { GrTopStatement first = statements[0]; if (first instanceof GrNamedElement) return ((GrNamedElement)first).getNameIdentifierGroovy(); return first; } return null; }
getElementToHighlight
36,537
String () { return GroovyBundle.message("fix.package.name"); }
getFamilyName
36,538
void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { PsiFile file = element.getContainingFile(); ((GroovyFile)file).setPackageName(myNewPackageName); }
applyFix
36,539
String (Object... infos) { return GroovyBundle.message("inspection.message.double.negation.ref"); }
buildErrorString
36,540
LocalQuickFix (@NotNull PsiElement location) { return new DoubleNegationFix(); }
buildFix
36,541
String () { return GroovyBundle.message("intention.family.name.remove.double.negation"); }
getFamilyName
36,542
void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { final GrUnaryExpression expression = (GrUnaryExpression)element; GrExpression operand = (GrExpression)PsiUtil.skipParentheses(expression.getOperand(), false); if (operand instanceof GrUnaryExpression prefixExpression) { final GrExpression innerOperand = prefixExpression.getOperand(); if (innerOperand == null) { return; } GrInspectionUtil.replaceExpression(expression, innerOperand.getText()); } else if (operand instanceof GrBinaryExpression binaryExpression) { final GrExpression lhs = binaryExpression.getLeftOperand(); final String lhsText = lhs.getText(); final StringBuilder builder = new StringBuilder(lhsText); builder.append("=="); final GrExpression rhs = binaryExpression.getRightOperand(); if (rhs != null) { final String rhsText = rhs.getText(); builder.append(rhsText); } GrInspectionUtil.replaceExpression(expression, builder.toString()); } }
applyFix
36,543
BaseInspectionVisitor () { return new DoubleNegationVisitor(); }
buildVisitor
36,544
void (@NotNull GrUnaryExpression expression) { final IElementType tokenType = expression.getOperationTokenType(); if (!T_NOT.equals(tokenType)) { return; } checkParent(expression); }
visitUnaryExpression
36,545
void (@NotNull GrBinaryExpression expression) { final IElementType tokenType = expression.getOperationTokenType(); if (!T_NEQ.equals(tokenType)) { return; } checkParent(expression); }
visitBinaryExpression
36,546
void (GrExpression expression) { PsiElement parent = expression.getParent(); while (parent instanceof GrParenthesizedExpression) { parent = parent.getParent(); } if (!(parent instanceof GrUnaryExpression prefixExpression)) { return; } final IElementType parentTokenType = prefixExpression.getOperationTokenType(); if (!T_NOT.equals(parentTokenType)) { return; } registerError(prefixExpression); }
checkParent
36,547
String () { // used to enable inspection in tests // remove when inspection class will match its short name return "GroovyUnusedIncOrDec"; }
getShortName
36,548
BaseInspectionVisitor () { return new GrUnusedIncDecInspectionVisitor(); }
buildVisitor
36,549
void (@NotNull GrUnaryExpression expression) { super.visitUnaryExpression(expression); IElementType opType = expression.getOperationTokenType(); if (opType != GroovyTokenTypes.mINC && opType != GroovyTokenTypes.mDEC) return; GrExpression operand = expression.getOperand(); if (!(operand instanceof GrReferenceExpression)) return; PsiElement resolved = ((GrReferenceExpression)operand).resolve(); if (!(resolved instanceof GrVariable) || resolved instanceof GrField) return; final GrControlFlowOwner owner = ControlFlowUtils.findControlFlowOwner(expression); assert owner != null; GrControlFlowOwner ownerOfDeclaration = ControlFlowUtils.findControlFlowOwner(resolved); if (ownerOfDeclaration != owner) return; GroovyControlFlow groovyFlow = ControlFlowUtils.getGroovyControlFlow(owner); final Instruction cur = ControlFlowUtils.findInstruction(operand, groovyFlow.getFlow()); if (cur == null) { LOG.error("no instruction found in flow." + "operand: " + operand.getText(), new Attachment("", owner.getText())); } //get write access for inc or dec Iterable<? extends Instruction> successors = cur.allSuccessors(); Iterator<? extends Instruction> iterator = successors.iterator(); LOG.assertTrue(iterator.hasNext()); Instruction writeAccess = iterator.next(); LOG.assertTrue(!iterator.hasNext()); int variableIndex = groovyFlow.getIndex(createDescriptor((GrVariable)resolved)); List<ReadWriteVariableInstruction> accesses = ControlFlowUtils.findAccess(variableIndex, true, false, writeAccess); boolean allAreWrite = true; for (ReadWriteVariableInstruction access : accesses) { if (!access.isWrite()) { allAreWrite = false; break; } } if (allAreWrite) { if (expression.isPostfix() && PsiUtil.isExpressionUsed(expression)) { registerError(expression.getOperationToken(), GroovyBundle.message("unused.0", expression.getOperationToken().getText()), new LocalQuickFix[]{new ReplacePostfixIncWithPrefixFix(expression), new RemoveIncOrDecFix(expression)}, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } else if (!PsiUtil.isExpressionUsed(expression)) { registerError(expression.getOperationToken(), GroovyBundle.message("unused.0", expression.getOperationToken().getText()), LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } } }
visitUnaryExpression
36,550
String () { return myMessage; }
getFamilyName
36,551
void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { GrUnaryExpression expr = findUnaryExpression(element); if (expr == null) return; expr.replaceWithExpression(expr.getOperand(), true); }
applyFix
36,552
String () { return myMessage; }
getFamilyName
36,553
void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { GrUnaryExpression expr = findUnaryExpression(element); if (expr == null) return; GrExpression prefix = GroovyPsiElementFactory.getInstance(project) .createExpressionFromText(expr.getOperationToken().getText() + expr.getOperand().getText()); expr.replaceWithExpression(prefix, true); }
applyFix
36,554
GrUnaryExpression (@NotNull PsiElement element) { PsiElement parent = element.getParent(); IElementType opType = element.getNode().getElementType(); if (opType != GroovyTokenTypes.mINC && opType != GroovyTokenTypes.mDEC) return null; return ObjectUtils.tryCast(parent, GrUnaryExpression.class); }
findUnaryExpression
36,555
String (Object... args) { return GroovyBundle.message("inspection.message.negated.if.condition.expression"); }
buildErrorString
36,556
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,557
void (@NotNull GrIfStatement grIfStatement) { super.visitIfStatement(grIfStatement); final GrExpression condition = grIfStatement.getCondition(); if (condition == null) { return; } if (!BoolUtils.isNegation(condition)) { return; } if (grIfStatement.getElseBranch() == null || grIfStatement.getThenBranch() == null) { return; } registerError(condition); }
visitIfStatement
36,558
int () { return m_limit; }
getLimit
36,559
String (Object... args) { return GroovyBundle.message("inspection.message.overly.complex.arithmetic.expression"); }
buildErrorString
36,560
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,561
void (@NotNull GrBinaryExpression expression) { super.visitBinaryExpression(expression); checkExpression(expression); }
visitBinaryExpression
36,562
void (@NotNull GrUnaryExpression expression) { super.visitUnaryExpression(expression); checkExpression(expression); }
visitUnaryExpression
36,563
void (@NotNull GrParenthesizedExpression expression) { super.visitParenthesizedExpression(expression); checkExpression(expression); }
visitParenthesizedExpression
36,564
void (GrExpression expression) { if (isParentArithmetic(expression)) { return; } if (!isArithmetic(expression)) { return; } if (containsStringConcatenation(expression)) { return; } final int numTerms = countTerms(expression); if (numTerms <= getLimit()) { return; } registerError(expression); }
checkExpression
36,565
int (GrExpression expression) { if (expression == null) { return 0; } if (!isArithmetic(expression)) { return 1; } if (expression instanceof GrBinaryExpression binaryExpression) { final GrExpression lhs = binaryExpression.getLeftOperand(); final GrExpression rhs = binaryExpression.getRightOperand(); return countTerms(lhs) + countTerms(rhs); } else if (expression instanceof GrUnaryExpression unaryExpression) { final GrExpression operand = unaryExpression.getOperand(); return countTerms(operand); } else if (expression instanceof GrParenthesizedExpression parenthesizedExpression) { final GrExpression contents = parenthesizedExpression.getOperand(); return countTerms(contents); } return 1; }
countTerms
36,566
boolean (GrExpression expression) { final PsiElement parent = expression.getParent(); if (!(parent instanceof GrExpression)) { return false; } return isArithmetic((GrExpression) parent); }
isParentArithmetic
36,567
boolean (GrExpression expression) { if (expression instanceof GrBinaryExpression binaryExpression) { final IElementType sign = binaryExpression.getOperationTokenType(); return arithmeticTokens.contains(sign); } else if (expression instanceof GrUnaryExpression unaryExpression) { final IElementType sign = unaryExpression.getOperationTokenType(); return arithmeticTokens.contains(sign); } else if (expression instanceof GrParenthesizedExpression parenthesizedExpression) { final GrExpression contents = parenthesizedExpression.getOperand(); return isArithmetic(contents); } return false; }
isArithmetic
36,568
boolean (GrExpression expression) { if (isString(expression)) { return true; } if (expression instanceof GrBinaryExpression binaryExpression) { final GrExpression lhs = binaryExpression.getLeftOperand(); if (containsStringConcatenation(lhs)) { return true; } final GrExpression rhs = binaryExpression.getRightOperand(); return containsStringConcatenation(rhs); } else if (expression instanceof GrUnaryExpression unaryExpression) { final GrExpression operand = unaryExpression.getOperand(); return containsStringConcatenation(operand); } else if (expression instanceof GrParenthesizedExpression parenthesizedExpression) { final GrExpression contents = parenthesizedExpression.getOperand(); return containsStringConcatenation(contents); } return false; }
containsStringConcatenation
36,569
boolean (GrExpression expression) { if (expression == null) { return false; } final PsiType type = expression.getType(); if (type == null) { return false; } return type.equalsToText(JAVA_LANG_STRING); }
isString
36,570
String (Object... args) { return GroovyBundle.message("inspection.message.nested.ref.statement"); }
buildErrorString
36,571
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,572
void (@NotNull GrSwitchStatement switchStatement) { super.visitSwitchStatement(switchStatement); final GrSwitchStatement containingSwitch = PsiTreeUtil.getParentOfType(switchStatement, GrSwitchStatement.class); if (containingSwitch == null) { return; } registerStatementError(switchStatement); }
visitSwitchStatement
36,573
BaseInspectionVisitor () { return new PointlessBooleanExpressionVisitor(); }
buildVisitor
36,574
String (Object... args) { return GroovyBundle.message("pointless.boolean.problem.descriptor"); }
buildErrorString
36,575
String (GrBinaryExpression expression) { final IElementType sign = expression.getOperationTokenType(); final GrExpression lhs = expression.getLeftOperand(); final GrExpression rhs = expression.getRightOperand(); if (rhs == null) { return null; } final String rhsText = rhs.getText(); final String lhsText = lhs.getText(); if (sign.equals(T_LAND)) { if (isTrue(lhs)) { return rhsText; } else { return lhsText; } } else if (sign.equals(T_LOR)) { if (isFalse(lhs)) { return rhsText; } else { return lhsText; } } else if (sign.equals(T_XOR) || sign.equals(T_NEQ)) { if (isFalse(lhs)) { return rhsText; } else if (isFalse(rhs)) { return lhsText; } else if (isTrue(lhs)) { return createStringForNegatedExpression(rhs); } else { return createStringForNegatedExpression(lhs); } } else if (sign.equals(T_EQ)) { if (isTrue(lhs)) { return rhsText; } else if (isTrue(rhs)) { return lhsText; } else if (isFalse(lhs)) { return createStringForNegatedExpression(rhs); } else { return createStringForNegatedExpression(lhs); } } else { return ""; } }
calculateSimplifiedBinaryExpression
36,576
String (GrExpression exp) { if (ComparisonUtils.isComparison(exp)) { final GrBinaryExpression binaryExpression = (GrBinaryExpression)exp; final IElementType sign = binaryExpression.getOperationTokenType(); final String negatedComparison = ComparisonUtils.getNegatedComparison(sign); final GrExpression lhs = binaryExpression.getLeftOperand(); final GrExpression rhs = binaryExpression.getRightOperand(); if (rhs == null) { return lhs.getText() + negatedComparison; } return lhs.getText() + negatedComparison + rhs.getText(); } else { final String baseText = exp.getText(); if (ParenthesesUtils.getPrecedence(exp) > ParenthesesUtils.PREFIX_PRECEDENCE) { return "!(" + baseText + ')'; } else { return '!' + baseText; } } }
createStringForNegatedExpression
36,577
String (GrUnaryExpression expression) { final GrExpression operand = expression.getOperand(); if (isUnaryNot(operand)) { return booleanLiteral(((GrUnaryExpression)operand).getOperand()); } else { return negateBooleanLiteral(operand); } }
calculateSimplifiedPrefixExpression
36,578
String (GrExpression operand) { if (isTrue(operand)) { return "false"; } else if (isFalse(operand)) { return "true"; } else { throw new IllegalStateException(operand.getText()); } }
negateBooleanLiteral
36,579
String (GrExpression operand) { if (isTrue(operand)) { return "true"; } else if (isFalse(operand)) { return "false"; } else { throw new IllegalStateException(operand.getText()); } }
booleanLiteral
36,580
LocalQuickFix (@NotNull PsiElement location) { return new BooleanLiteralComparisonFix(); }
buildFix
36,581
String () { return GroovyBundle.message("pointless.boolean.quickfix"); }
getFamilyName
36,582
void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { if (element instanceof GrBinaryExpression expression) { final String replacementString = calculateSimplifiedBinaryExpression(expression); GrInspectionUtil.replaceExpression(expression, replacementString); } else { final GrUnaryExpression expression = (GrUnaryExpression)element; final String replacementString = calculateSimplifiedPrefixExpression(expression); GrInspectionUtil.replaceExpression(expression, replacementString); } }
applyFix
36,583
void (@NotNull GrBinaryExpression expression) { if (isFake(expression)) return; final IElementType sign = expression.getOperationTokenType(); if (!booleanTokens.contains(sign)) { return; } final GrExpression rhs = expression.getRightOperand(); if (rhs == null) { return; } final GrExpression lhs = expression.getLeftOperand(); if (isPointless(sign, rhs, lhs)) { registerError(expression); } }
visitBinaryExpression
36,584
void (@NotNull GrUnaryExpression expression) { final IElementType sign = expression.getOperationTokenType(); if (!sign.equals(T_NOT)) { return; } final GrExpression operand = expression.getOperand(); if (isBooleanLiteral(operand)) { final PsiElement parent = expression.getParent(); if (parent instanceof GrExpression && isUnaryNot((GrExpression)parent)) { // don't highlight inner unary in double negation return; } registerError(expression); } else if (isUnaryNot(operand) && isBooleanLiteral(((GrUnaryExpression)operand).getOperand())) { registerError(expression); } }
visitUnaryExpression
36,585
boolean (IElementType sign, GrExpression rhs, GrExpression lhs) { if (sign.equals(T_EQ) || sign.equals(T_NEQ)) { return equalityExpressionIsPointless(lhs, rhs); } else if (sign.equals(T_LAND)) { return andExpressionIsPointless(lhs, rhs); } else if (sign.equals(T_LOR)) { return orExpressionIsPointless(lhs, rhs); } else if (sign.equals(T_XOR)) { return xorExpressionIsPointless(lhs, rhs); } else { return false; } }
isPointless
36,586
boolean (GrExpression lhs, GrExpression rhs) { return ((isTrue(lhs) || isFalse(lhs)) && isBoolean(rhs)) || ((isTrue(rhs) || isFalse(rhs)) && isBoolean(lhs)); }
equalityExpressionIsPointless
36,587
boolean (GrExpression expression) { final PsiType type = expression.getType(); return PsiTypes.booleanType().equals(type); }
isBoolean
36,588
boolean (GrExpression lhs, GrExpression rhs) { return isTrue(lhs) || isTrue(rhs); }
andExpressionIsPointless
36,589
boolean (GrExpression lhs, GrExpression rhs) { return isFalse(lhs) || isFalse(rhs); }
orExpressionIsPointless
36,590
boolean (GrExpression lhs, GrExpression rhs) { return isTrue(lhs) || isTrue(rhs) || isFalse(lhs) || isFalse(rhs); }
xorExpressionIsPointless
36,591
boolean (GrExpression arg) { return arg instanceof GrUnaryExpression && ((GrUnaryExpression)arg).getOperationTokenType() == T_NOT; }
isUnaryNot
36,592
boolean (GrExpression arg) { return isFalse(arg) || isTrue(arg); }
isBooleanLiteral
36,593
boolean (GrExpression expression) { if (expression == null) { return false; } if (!(expression instanceof GrLiteral)) { return false; } @NonNls final String text = expression.getText(); return "true".equals(text); }
isTrue
36,594
boolean (GrExpression expression) { if (expression == null) { return false; } if (!(expression instanceof GrLiteral)) { return false; } @NonNls final String text = expression.getText(); return "false".equals(text); }
isFalse
36,595
BaseInspectionVisitor () { return new BaseInspectionVisitor() { @Override public void visitReferenceExpression(@NotNull GrReferenceExpression referenceExpression) { super.visitReferenceExpression(referenceExpression); if (!PsiUtil.isLValue(referenceExpression)) return; final PsiElement resolved = referenceExpression.resolve(); if (!PsiUtil.isLocalVariable(resolved)) return; final PsiType checked = GrReassignedLocalVarsChecker.getReassignedVarType(referenceExpression, false); if (checked == null) return; final GrControlFlowOwner varFlowOwner = ControlFlowUtils.findControlFlowOwner(resolved); final GrControlFlowOwner refFlorOwner = ControlFlowUtils.findControlFlowOwner(referenceExpression); if (isOtherScopeAndType(referenceExpression, checked, varFlowOwner, refFlorOwner)) { String flowDescription = getFlowDescription(refFlorOwner); final String message = GroovyBundle.message("local.var.0.is.reassigned", ((GrNamedElement)resolved).getName(), flowDescription); registerError(referenceExpression, message, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } } }; }
buildVisitor
36,596
void (@NotNull GrReferenceExpression referenceExpression) { super.visitReferenceExpression(referenceExpression); if (!PsiUtil.isLValue(referenceExpression)) return; final PsiElement resolved = referenceExpression.resolve(); if (!PsiUtil.isLocalVariable(resolved)) return; final PsiType checked = GrReassignedLocalVarsChecker.getReassignedVarType(referenceExpression, false); if (checked == null) return; final GrControlFlowOwner varFlowOwner = ControlFlowUtils.findControlFlowOwner(resolved); final GrControlFlowOwner refFlorOwner = ControlFlowUtils.findControlFlowOwner(referenceExpression); if (isOtherScopeAndType(referenceExpression, checked, varFlowOwner, refFlorOwner)) { String flowDescription = getFlowDescription(refFlorOwner); final String message = GroovyBundle.message("local.var.0.is.reassigned", ((GrNamedElement)resolved).getName(), flowDescription); registerError(referenceExpression, message, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } }
visitReferenceExpression
36,597
boolean (GrReferenceExpression referenceExpression, PsiType checked, GrControlFlowOwner varFlowOwner, GrControlFlowOwner refFlorOwner) { return varFlowOwner != refFlorOwner && !TypesUtil.isAssignable(referenceExpression.getType(), checked, referenceExpression); }
isOtherScopeAndType
36,598
String (GrControlFlowOwner refFlorOwner) { String flowDescription; if (refFlorOwner instanceof GrClosableBlock) { flowDescription = GroovyBundle.message("closure"); } else if (refFlorOwner instanceof GrAnonymousClassDefinition) { flowDescription = GroovyBundle.message("anonymous.class"); } else { flowDescription = GroovyBundle.message("other.scope"); } return flowDescription; }
getFlowDescription
36,599
String (Object... args) { return GroovyBundle.message("inspection.message.call.to.ref.can.be.keyed.access"); }
buildErrorString