Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
36,400
boolean (GrSafeCastExpression expression1, GrSafeCastExpression expression2) { final GrExpression operand1 = expression1.getOperand(); final GrExpression operand2 = expression2.getOperand(); if (!expressionsAreEquivalent(operand1, operand2)) { return false; } final GrTypeElement typeElement1 = expression1.getCastTypeElement(); final GrTypeElement typeElement2 = expression2.getCastTypeElement(); final PsiType safe1 = typeElement1 == null ? null : typeElement1.getType(); final PsiType safe2 = typeElement2 == null ? null : typeElement2.getType(); return typesAreEquivalent(safe1, safe2); }
safeCastExpressionsAreEquivalent
36,401
boolean (@NotNull GrMethodCall methodExp1, @NotNull GrMethodCall methodExp2) { final GrExpression methodExpression1 = methodExp1.getInvokedExpression(); final GrExpression methodExpression2 = methodExp2.getInvokedExpression(); if (!expressionsAreEquivalent(methodExpression1, methodExpression2)) { return false; } final GrClosableBlock[] closures1 = methodExp1.getClosureArguments(); final GrClosableBlock[] closures2 = methodExp2.getClosureArguments(); if (!expressionListsAreEquivalent(closures1, closures2)) { return false; } return argumentListsAreEquivalent(methodExp1.getArgumentList(), methodExp2.getArgumentList()); }
methodCallExpressionsAreEquivalent
36,402
boolean (@Nullable GrArgumentList list1, @Nullable GrArgumentList list2) { if (list1 == null && list2 == null) { return true; } if (list1 == null || list2 == null) { return false; } final GrExpression[] args1 = list1.getExpressionArguments(); final GrExpression[] args2 = list2.getExpressionArguments(); if (!expressionListsAreEquivalent(args1, args2)) { return false; } final GrNamedArgument[] namedArgs1 = list1.getNamedArguments(); final GrNamedArgument[] namedArgs2 = list2.getNamedArguments(); if (!namedArgumentListsAreEquivalent(namedArgs1, namedArgs2)) { return false; } return true; }
argumentListsAreEquivalent
36,403
boolean (GrNamedArgument[] namedArgs1, GrNamedArgument[] namedArgs2) { if (namedArgs1.length != namedArgs2.length) { return false; } for (GrNamedArgument arg1 : namedArgs1) { final GrArgumentLabel label1 = arg1.getLabel(); if (label1 == null) { return false; } final String name1 = label1.getName(); boolean found = false; final GrExpression expression1 = arg1.getExpression(); for (GrNamedArgument arg2 : namedArgs2) { final GrArgumentLabel label2 = arg2.getLabel(); if (label2 == null) { return false; } final String name2 = label2.getName(); final GrExpression expression2 = arg2.getExpression(); if (name1 == null) { if (name2 == null && expressionsAreEquivalent(((GrExpression)label1.getNameElement()), (GrExpression)label2.getNameElement()) && expressionsAreEquivalent(expression1, expression2)) { found = true; break; } } else if (name1.equals(name2) && expressionsAreEquivalent(expression1, expression2)) { found = true; break; } } if (!found) { return false; } } return true; }
namedArgumentListsAreEquivalent
36,404
boolean (@NotNull GrNewExpression newExp1, @NotNull GrNewExpression newExp2) { if (newExp1.getArrayCount() == newExp2.getArrayCount() && newExp1.getArrayCount() != 0) { GrCodeReferenceElement referenceElement1 = newExp1.getReferenceElement(); GrCodeReferenceElement referenceElement2 = newExp2.getReferenceElement(); if (referenceElement1 == null || referenceElement2 == null) { return referenceElement1 == referenceElement2; } if (referenceElement1.resolve() != referenceElement2.resolve()) { return false; } GrArrayDeclaration arrayDeclaration1 = newExp1.getArrayDeclaration(); GrArrayDeclaration arrayDeclaration2 = newExp2.getArrayDeclaration(); if (arrayDeclaration1 == null || arrayDeclaration2 == null) { return arrayDeclaration1 == arrayDeclaration2; } return arrayDeclarationsAreEquivalent(arrayDeclaration1, arrayDeclaration2); } else { final PsiMethod constructor1 = newExp1.resolveMethod(); final PsiMethod constructor2 = newExp2.resolveMethod(); if (constructor1 == null || constructor2 == null || !constructor1.equals(constructor2)) { return false; } return argumentListsAreEquivalent(newExp1.getArgumentList(), newExp2.getArgumentList()); } }
newExpressionsAreEquivalent
36,405
boolean (@NotNull GrUnaryExpression prefixExp1, @NotNull GrUnaryExpression prefixExp2) { final IElementType sign1 = prefixExp1.getOperationTokenType(); final IElementType sign2 = prefixExp2.getOperationTokenType(); if (sign1 != sign2) { return false; } final GrExpression operand1 = prefixExp1.getOperand(); final GrExpression operand2 = prefixExp2.getOperand(); return expressionsAreEquivalent(operand1, operand2); }
prefixExpressionsAreEquivalent
36,406
boolean (@NotNull GrUnaryExpression postfixExp1, @NotNull GrUnaryExpression postfixExp2) { final IElementType sign1 = postfixExp1.getOperationTokenType(); final IElementType sign2 = postfixExp2.getOperationTokenType(); if (sign1 != sign2) { return false; } final GrExpression operand1 = postfixExp1.getOperand(); final GrExpression operand2 = postfixExp2.getOperand(); return expressionsAreEquivalent(operand1, operand2); }
postfixExpressionsAreEquivalent
36,407
boolean (@NotNull GrBinaryExpression binaryExp1, @NotNull GrBinaryExpression binaryExp2) { final IElementType sign1 = binaryExp1.getOperationTokenType(); final IElementType sign2 = binaryExp2.getOperationTokenType(); if (sign1 != sign2) { return false; } final GrExpression lhs1 = binaryExp1.getLeftOperand(); final GrExpression lhs2 = binaryExp2.getLeftOperand(); final GrExpression rhs1 = binaryExp1.getRightOperand(); final GrExpression rhs2 = binaryExp2.getRightOperand(); return expressionsAreEquivalent(lhs1, lhs2) && expressionsAreEquivalent(rhs1, rhs2); }
binaryExpressionsAreEquivalent
36,408
boolean (@NotNull GrRangeExpression rangeExp1, @NotNull GrRangeExpression rangeExp2) { return expressionsAreEquivalent(rangeExp1.getFrom(), rangeExp2.getFrom()) && expressionsAreEquivalent(rangeExp1.getTo(), rangeExp2.getTo()) && rangeExp1.getBoundaryType() == rangeExp2.getBoundaryType(); }
rangeExpressionsAreEquivalent
36,409
boolean (@NotNull GrAssignmentExpression assignExp1, @NotNull GrAssignmentExpression assignExp2) { final IElementType sign1 = assignExp1.getOperationTokenType(); final IElementType sign2 = assignExp2.getOperationTokenType(); if (sign1 != sign2) { return false; } final GrExpression lhs1 = assignExp1.getLValue(); final GrExpression lhs2 = assignExp2.getLValue(); final GrExpression rhs1 = assignExp1.getRValue(); final GrExpression rhs2 = assignExp2.getRValue(); return expressionsAreEquivalent(lhs1, lhs2) && expressionsAreEquivalent(rhs1, rhs2); }
assignmentExpressionsAreEquivalent
36,410
boolean (@NotNull GrConditionalExpression condExp1, @NotNull GrConditionalExpression condExp2) { final GrExpression condition1 = condExp1.getCondition(); final GrExpression condition2 = condExp2.getCondition(); final GrExpression thenExpression1 = condExp1.getThenBranch(); final GrExpression thenExpression2 = condExp2.getThenBranch(); final GrExpression elseExpression1 = condExp1.getElseBranch(); final GrExpression elseExpression2 = condExp2.getElseBranch(); return expressionsAreEquivalent(condition1, condition2) && expressionsAreEquivalent(thenExpression1, thenExpression2) && expressionsAreEquivalent(elseExpression1, elseExpression2); }
conditionalExpressionsAreEquivalent
36,411
boolean (@NotNull GrElvisExpression condExp1, @NotNull GrElvisExpression condExp2) { final GrExpression condition1 = condExp1.getCondition(); final GrExpression condition2 = condExp2.getCondition(); final GrExpression elseExpression1 = condExp1.getElseBranch(); final GrExpression elseExpression2 = condExp2.getElseBranch(); return expressionsAreEquivalent(condition1, condition2) && expressionsAreEquivalent(elseExpression1, elseExpression2); }
elvisExpressionsAreEquivalent
36,412
boolean (GrExpression @Nullable [] expressions1, GrExpression @Nullable [] expressions2) { if (expressions1 == null && expressions2 == null) { return true; } if (expressions1 == null || expressions2 == null) { return false; } return ArrayUtil.areEqual(expressions1, expressions2, (e1, e2) -> expressionsAreEquivalent(e1, e2)); }
expressionListsAreEquivalent
36,413
int (@Nullable GrExpression exp) { if (exp instanceof GrLiteral) { return LITERAL_EXPRESSION; } if (exp instanceof GrReferenceExpression) { return REFERENCE_EXPRESSION; } if (exp instanceof GrTypeCastExpression) { return TYPE_CAST_EXPRESSION; } if (exp instanceof GrSafeCastExpression) { return SAFE_CAST_EXPRESSION; } if (exp instanceof GrInstanceOfExpression) { return INSTANCEOF_EXPRESSION; } if (exp instanceof GrNewExpression) { return NEW_EXPRESSION; } if (exp instanceof GrMethodCall) { return CALL_EXPRESSION; } if (exp instanceof GrUnaryExpression) { return ((GrUnaryExpression)exp).isPostfix() ? POSTFIX_EXPRESSION : PREFIX_EXPRESSION; } if (exp instanceof GrAssignmentExpression) { return ASSIGNMENT_EXPRESSION; } if (exp instanceof GrRangeExpression) { return RANGE_EXPRESSION; } if (exp instanceof GrBinaryExpression) { return BINARY_EXPRESSION; } if (exp instanceof GrElvisExpression) { return ELVIS_EXPRESSION; } if (exp instanceof GrConditionalExpression) { return CONDITIONAL_EXPRESSION; } if (exp instanceof GrIndexProperty) { return INDEX_EXPRESSION; } if (exp instanceof GrListOrMap) { return LIST_OR_MAP_EXPRESSION; } if (exp instanceof GrClosableBlock) { return CLOSABLE_BLOCK_EXPRESSION; } return -1; // Type of expression can be defined in third party plugins. See issue #IDEA-59846 }
getExpressionType
36,414
int (@Nullable GrStatement statement) { if (statement instanceof GrBlockStatement) { return BLOCK_STATEMENT; } if (statement instanceof GrBreakStatement) { return BREAK_STATEMENT; } if (statement instanceof GrContinueStatement) { return CONTINUE_STATEMENT; } if (statement instanceof GrVariableDeclaration) { return VAR_STATEMENT; } if (statement instanceof GrApplicationStatement) { return APPLICATION_STATEMENT; } if (statement instanceof GrExpression) { return EXPRESSION_STATEMENT; } if (statement instanceof GrForStatement) { return FOR_STATEMENT; } if (statement instanceof GrIfStatement) { return IF_STATEMENT; } if (statement instanceof GrReturnStatement) { return RETURN_STATEMENT; } if (statement instanceof GrSwitchStatement) { return SWITCH_STATEMENT; } if (statement instanceof GrThrowStatement) { return THROW_STATEMENT; } if (statement instanceof GrTryCatchStatement) { return TRY_STATEMENT; } if (statement instanceof GrWhileStatement) { return WHILE_STATEMENT; } if (statement instanceof GrSynchronizedStatement) { return SYNCHRONIZED_STATEMENT; } if (statement instanceof GrAssertStatement) { return ASSERT_STATEMENT; } return -1; // Type of expression can be defined in third party plugins. See issue #IDEA-59846 }
getStatementType
36,415
void (GrMethodCall call) { GrExpression invoked = call.getInvokedExpression(); String accessorName = ((GrReferenceExpression)invoked).getReferenceName(); if (isGetterInvocation(call)) { final GrExpression newCall = genRefForGetter(call, accessorName); call.replaceWithExpression(newCall, true); } else if (isSetterInvocation(call)) { final GrStatement newCall = genRefForSetter(call, accessorName); if(newCall != null) { call.replaceWithStatement(newCall); } } }
fixJavaStyleProperty
36,416
boolean (GrMethodCall call) { return !isInvokedOnMap(call) && (isGetterInvocation(call) || isSetterInvocation(call)); }
isPropertyAccessor
36,417
GrAssignmentExpression (GrMethodCall call, String accessorName) { String name = GroovyPropertyUtils.getPropertyNameBySetterName(accessorName); if(name == null) return null; GrExpression value = call.getExpressionArguments()[0]; GrReferenceExpression refExpr = (GrReferenceExpression)call.getInvokedExpression(); final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(call.getProject()); final GrAssignmentExpression assignment = (GrAssignmentExpression)factory.createStatementFromText("yyy = xxx", call); GrReferenceExpression lvalueRef = (GrReferenceExpression)assignment.getLValue(); lvalueRef.setQualifier(refExpr.getQualifier()); lvalueRef.handleElementRename(name); assignment.getRValue().replaceWithExpression(value, true); return assignment; }
genRefForSetter
36,418
GrExpression (GrMethodCall call, String accessorName) { String name = GroovyPropertyUtils.getPropertyNameByGetterName(accessorName, true); GrReferenceExpression refExpr = (GrReferenceExpression)call.getInvokedExpression(); String oldNameStr = refExpr.getReferenceNameElement().getText(); String newRefExpr = StringUtil.trimEnd(refExpr.getText(), oldNameStr) + name; final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(call.getProject()); return factory.createExpressionFromText(newRefExpr, call); }
genRefForGetter
36,419
boolean (GrMethodCall call) { GrExpression expr = call.getInvokedExpression(); return expr instanceof GrReferenceExpression && ResolveUtil.isKeyOfMap((GrReferenceExpression)expr); }
isInvokedOnMap
36,420
boolean (GrMethodCall call) { GrExpression expr = call.getInvokedExpression(); if (!(expr instanceof GrReferenceExpression refExpr)) return false; PsiMethod method; if (call instanceof GrApplicationStatement) { PsiElement element = refExpr.resolve(); if (!(element instanceof PsiMethod) || !GroovyPropertyUtils.isSimplePropertySetter(((PsiMethod)element))) return false; method = (PsiMethod)element; } else { method = call.resolveMethod(); if (!GroovyPropertyUtils.isSimplePropertySetter(method)) return false; } if (!GroovyNamesUtil.isValidReference(GroovyPropertyUtils.getPropertyNameBySetterName(method.getName()), ((GrReferenceExpression)expr).getQualifier() != null, call.getProject())) { return false; } GrArgumentList args = call.getArgumentList(); if (args.getExpressionArguments().length != 1 || PsiImplUtil.hasNamedArguments(args)) { return false; } GrAssignmentExpression assignment = genRefForSetter(call, refExpr.getReferenceName()); if(assignment != null) { GrExpression value = assignment.getLValue(); if (value instanceof GrReferenceExpression && call.getManager().areElementsEquivalent(((GrReferenceExpression)value).resolve(), method)) { return true; } } return false; }
isSetterInvocation
36,421
boolean (@NotNull GrMethodCall call) { GrExpression expr = call.getInvokedExpression(); if (!(expr instanceof GrReferenceExpression)) return false; PsiMethod method = call.resolveMethod(); if (!GroovyPropertyUtils.isSimplePropertyGetter(method)) return false; if (!GroovyNamesUtil.isValidReference(GroovyPropertyUtils.getPropertyNameByGetterName(method.getName(), true), ((GrReferenceExpression)expr).getQualifier() != null, call.getProject())) { return false; } GrArgumentList args = call.getArgumentList(); if (args.getAllArguments().length != 0) { return false; } GrExpression ref = genRefForGetter(call, ((GrReferenceExpression)expr).getReferenceName()); if (ref instanceof GrReferenceExpression) { PsiElement resolved = ((GrReferenceExpression)ref).resolve(); PsiManager manager = call.getManager(); if (manager.areElementsEquivalent(resolved, method) || areEquivalentAccessors(method, resolved, manager)) { return true; } } return false; }
isGetterInvocation
36,422
boolean (PsiMethod method, PsiElement resolved, PsiManager manager) { if (!(resolved instanceof GrAccessorMethod) || !(method instanceof GrAccessorMethod)) { return false; } if (((GrAccessorMethod)resolved).isSetter() != ((GrAccessorMethod)method).isSetter()) return false; GrField p1 = ((GrAccessorMethod)resolved).getProperty(); GrField p2 = ((GrAccessorMethod)method).getProperty(); return manager.areElementsEquivalent(p1, p2); }
areEquivalentAccessors
36,423
String (Object... args) { return GroovyBundle.message("inspection.message.empty.ref.block"); }
buildErrorString
36,424
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,425
void (@NotNull GrFinallyClause finallyClause) { super.visitFinallyClause(finallyClause); final GrOpenBlock body = finallyClause.getBody(); if (body == null || !isEmpty(body)) { return; } registerError(finallyClause.getFirstChild()); }
visitFinallyClause
36,426
boolean (GrOpenBlock body) { final GrStatement[] statements = body.getStatements(); return statements.length == 0; }
isEmpty
36,427
boolean (@NotNull GrParameter parameter) { final String name = StringUtil.toLowerCase(parameter.getName()); return IGNORE.equals(name) || IGNORED.equals(name); }
ignore
36,428
String (Object... args) { return GroovyBundle.message("inspection.message.ref.inside.finally.block"); }
buildErrorString
36,429
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,430
void (@NotNull GrThrowStatement throwStatement) { super.visitThrowStatement(throwStatement); if (!ControlFlowUtils.isInFinallyBlock(throwStatement)) { return; } registerStatementError(throwStatement); }
visitThrowStatement
36,431
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,432
void (@NotNull GrCatchClause catchClause) { super.visitCatchClause(catchClause); final GrOpenBlock block = catchClause.getBody(); if (block == null) { return; } final GrParameter parameter = catchClause.getParameter(); if (parameter == null) { return; } if (GrExceptionUtil.ignore(parameter)) return; final CatchParameterUsedVisitor visitor = new CatchParameterUsedVisitor(parameter); block.accept(visitor); if (!visitor.isUsed()) { final PsiElement nameIdentifier = parameter.getNameIdentifierGroovy(); registerError(nameIdentifier, GroovyBundle.message("inspection.message.unused.catch.parameter.ref"), new LocalQuickFix[]{QuickFixFactory.getInstance().createRenameElementFix(parameter, IGNORED)}, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } }
visitCatchClause
36,433
String (Object... args) { return GroovyBundle.message("inspection.message.ref.inside.finally.block"); }
buildErrorString
36,434
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,435
void (@NotNull GrContinueStatement continueStatement) { super.visitContinueStatement(continueStatement); if (!ControlFlowUtils.isInFinallyBlock(continueStatement)) { return; } final GrStatement continuedStatement = continueStatement.findTargetStatement(); if (continuedStatement == null) { return; } if (ControlFlowUtils.isInFinallyBlock(continuedStatement)) { return; } registerStatementError(continueStatement); }
visitContinueStatement
36,436
void (@NotNull GrBreakStatement breakStatement) { super.visitBreakStatement(breakStatement); if (!ControlFlowUtils.isInFinallyBlock(breakStatement)) { return; } final GrStatement target = breakStatement.findTargetStatement(); if (target == null) { return; } if (ControlFlowUtils.isInFinallyBlock(target)) { return; } registerStatementError(breakStatement); }
visitBreakStatement
36,437
String (Object... args) { return GroovyBundle.message("inspection.message.empty.ref.block"); }
buildErrorString
36,438
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,439
void (@NotNull GrTryCatchStatement tryCatchStatement) { super.visitTryStatement(tryCatchStatement); final GrOpenBlock body = tryCatchStatement.getTryBlock(); if (body == null || !isEmpty(body)) { return; } registerError(tryCatchStatement.getFirstChild()); }
visitTryStatement
36,440
boolean (GrOpenBlock body) { final GrStatement[] statements = body.getStatements(); return statements.length == 0; }
isEmpty
36,441
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,442
OptPane () { return pane( checkbox("myCountCommentsAsContent", GroovyBundle.message("comments.count.as.content")), checkbox("myIgnore", GroovyBundle.message("ignore.when.catch.parameter.is.named.ignore.or.ignored"))); }
getGroovyOptionsPane
36,443
void (@NotNull GrCatchClause catchClause) { super.visitCatchClause(catchClause); final GrOpenBlock body = catchClause.getBody(); if (body == null || !isEmpty(body)) { return; } final GrParameter parameter = catchClause.getParameter(); if (parameter == null) return; if (myIgnore && GrExceptionUtil.ignore(parameter)) return; LocalQuickFix fix = QuickFixFactory.getInstance().createRenameElementFix(parameter, NEW_NAME); final LocalQuickFix[] fixes = myIgnore ? new LocalQuickFix[]{fix} : LocalQuickFix.EMPTY_ARRAY; registerError(catchClause.getFirstChild(), GroovyBundle.message("inspection.message.empty.ref.block"), fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); }
visitCatchClause
36,444
boolean (@NotNull GrOpenBlock body) { final GrStatement[] statements = body.getStatements(); if (statements.length != 0) return false; if (myCountCommentsAsContent) { final PsiElement brace = body.getLBrace(); if (brace != null) { final PsiElement next = PsiUtil.skipWhitespaces(brace.getNextSibling(), true); if (next instanceof PsiComment) { return false; } } } return true; }
isEmpty
36,445
String (Object... args) { return GroovyBundle.message("inspection.message.ref.inside.finally.block"); }
buildErrorString
36,446
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,447
void (@NotNull GrReturnStatement returnStatement) { super.visitReturnStatement(returnStatement); if (!ControlFlowUtils.isInFinallyBlock(returnStatement)) { return; } registerStatementError(returnStatement); }
visitReturnStatement
36,448
void (@NotNull GroovyPsiElement element) { if (!used) { super.visitElement(element); } }
visitElement
36,449
void (@NotNull GrReferenceExpression referenceExpression) { if (used) { return; } super.visitReferenceExpression(referenceExpression); final PsiElement element = referenceExpression.resolve(); if (parameter.equals(element)) { used = true; } }
visitReferenceExpression
36,450
void (@NotNull GrReferenceExpression reference) { if (used) { return; } super.visitReferenceExpression(reference); final PsiElement element = reference.resolve(); if (parameter.equals(element)) { used = true; } }
visitJSReferenceExpression
36,451
boolean () { return used; }
isUsed
36,452
BaseInspectionVisitor () { return new BaseInspectionVisitor() { @Override public void visitCodeReferenceElement(@NotNull GrCodeReferenceElement refElement) { super.visitCodeReferenceElement(refElement); if (canBeSimplified(refElement)) { registerError(refElement); } } @Override public void visitReferenceExpression(@NotNull GrReferenceExpression referenceExpression) { super.visitReferenceExpression(referenceExpression); if (canBeSimplified(referenceExpression) || isQualifiedStaticMethodWithUnnecessaryQualifier(referenceExpression)) { registerError(referenceExpression); } } }; }
buildVisitor
36,453
void (@NotNull GrCodeReferenceElement refElement) { super.visitCodeReferenceElement(refElement); if (canBeSimplified(refElement)) { registerError(refElement); } }
visitCodeReferenceElement
36,454
void (@NotNull GrReferenceExpression referenceExpression) { super.visitReferenceExpression(referenceExpression); if (canBeSimplified(referenceExpression) || isQualifiedStaticMethodWithUnnecessaryQualifier(referenceExpression)) { registerError(referenceExpression); } }
visitReferenceExpression
36,455
boolean (GrReferenceExpression ref) { if (ref.getQualifier() == null) return false; if (ref.hasAt()) return false; final PsiElement resolved = ref.resolve(); if (!(resolved instanceof PsiMember)) return false; if (!((PsiMember)resolved).hasModifierProperty(PsiModifier.STATIC)) return false; if (GroovyConfigUtils.isAtLeastGroovy40(ref)) { PsiClass container = ((PsiMember)resolved).getContainingClass(); if (container != null && container.isInterface()) { return false; } } PsiElement copyResolved; final PsiElement parent = ref.getParent(); if (parent instanceof GrMethodCall) { final GrMethodCall copy = (GrMethodCall)parent.copy(); GrReferenceExpression invoked = (GrReferenceExpression)copy.getInvokedExpression(); assert invoked != null; invoked.setQualifier(null); copyResolved = ((GrReferenceExpression)copy.getInvokedExpression()).resolve(); } else { final GrReferenceExpression copy = (GrReferenceExpression)ref.copy(); copy.setQualifier(null); copyResolved = copy.resolve(); } return ref.getManager().areElementsEquivalent(copyResolved, resolved); }
isQualifiedStaticMethodWithUnnecessaryQualifier
36,456
String (Object... args) { return GroovyBundle.message("inspection.display.name.unnecessary.qualified.reference"); }
buildErrorString
36,457
LocalQuickFix (@NotNull PsiElement location) { return GroovyQuickFixFactory.getInstance().createReplaceWithImportFix(); }
buildFix
36,458
boolean (PsiElement element) { if (PsiTreeUtil.getParentOfType(element, PsiComment.class) != null) return false; if (element instanceof GrCodeReferenceElement) { if (PsiTreeUtil.getParentOfType(element, GrImportStatement.class, GrPackageDefinition.class) != null) return false; } else if (element instanceof GrReferenceExpression) { if (!PsiImplUtil.seemsToBeQualifiedClassName((GrReferenceExpression)element)) return false; } else { return false; } final GrReferenceElement<?> ref = (GrReferenceElement<?>)element; if (ref.getQualifier() == null) return false; if (!(ref.getContainingFile() instanceof GroovyFileBase)) return false; final PsiElement resolved = ref.resolve(); if (!(resolved instanceof PsiClass)) return false; final String name = ((PsiClass)resolved).getName(); if (name == null) return false; final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(element.getProject()); final GrReferenceExpression shortedRef = factory.createReferenceExpressionFromText(name, element); final GroovyResolveResult resolveResult = shortedRef.advancedResolve(); if (element.getManager().areElementsEquivalent(resolved, resolveResult.getElement())) { return true; } final PsiClass containingClass = ((PsiClass)resolved).getContainingClass(); if (containingClass != null && !GroovyCodeStyleSettingsFacade.getInstance(containingClass.getProject()).insertInnerClassImports()) { return false; } return resolveResult.getElement() == null || !resolveResult.isAccessible() || !resolveResult.isStaticsOK(); }
canBeSimplified
36,459
BaseInspectionVisitor () { return new BaseInspectionVisitor() { @Override public void visitReferenceExpression(@NotNull GrReferenceExpression ref) { super.visitReferenceExpression(ref); PsiElement resolveResult = getResolveElement(ref); checkRef(resolveResult, ref.getReferenceNameElement(), ref.getReferenceName()); } @Override public void visitCodeReferenceElement(@NotNull GrCodeReferenceElement ref) { super.visitCodeReferenceElement(ref); PsiElement resolveResult = getResolveElement(ref); checkRef(resolveResult, ref.getReferenceNameElement(), ref.getReferenceName()); } @Override public void visitArgumentLabel(@NotNull GrArgumentLabel argumentLabel) { super.visitArgumentLabel(argumentLabel); PsiElement resolveResult = getResolveElement(argumentLabel); if (resolveResult instanceof GrAccessorMethod) { resolveResult = ((GrAccessorMethod)resolveResult).getProperty(); } checkRef(resolveResult, argumentLabel.getNameElement(), argumentLabel.getName()); } @Override public void visitNewExpression(@NotNull GrNewExpression ref) { super.visitNewExpression(ref); var resolvedCall = ref.resolveMethod(); if (resolvedCall == null || isDeprecated(resolvedCall.getContainingClass())) { return; } var referenceElement = ref.getReferenceElement(); if (referenceElement != null) { checkRef(resolvedCall, ref.getReferenceElement(), referenceElement.getReferenceName()); } else { checkRef(resolvedCall, ref, resolvedCall.getName()); } } private void checkRef(PsiElement resolved, PsiElement elementToHighlight, String elementName) { if (isDeprecated(resolved)) { registerError(elementToHighlight, GroovyBundle.message("0.is.deprecated", elementName), LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.LIKE_DEPRECATED); } } private static @Nullable PsiElement getResolveElement(GroovyReference reference) { GroovyResolveResult[] results = reference.multiResolve(false); for (GroovyResolveResult result : results) { PsiElement element = result.getElement(); if (element != null) { return element; } } return null; } private static boolean isDeprecated(PsiElement resolved) { if (resolved instanceof PsiDocCommentOwner) { return ((PsiDocCommentOwner)resolved).isDeprecated(); } if (resolved instanceof PsiModifierListOwner && PsiImplUtil.isDeprecatedByAnnotation((PsiModifierListOwner)resolved)) { return true; } return false; } }; }
buildVisitor
36,460
void (@NotNull GrReferenceExpression ref) { super.visitReferenceExpression(ref); PsiElement resolveResult = getResolveElement(ref); checkRef(resolveResult, ref.getReferenceNameElement(), ref.getReferenceName()); }
visitReferenceExpression
36,461
void (@NotNull GrCodeReferenceElement ref) { super.visitCodeReferenceElement(ref); PsiElement resolveResult = getResolveElement(ref); checkRef(resolveResult, ref.getReferenceNameElement(), ref.getReferenceName()); }
visitCodeReferenceElement
36,462
void (@NotNull GrArgumentLabel argumentLabel) { super.visitArgumentLabel(argumentLabel); PsiElement resolveResult = getResolveElement(argumentLabel); if (resolveResult instanceof GrAccessorMethod) { resolveResult = ((GrAccessorMethod)resolveResult).getProperty(); } checkRef(resolveResult, argumentLabel.getNameElement(), argumentLabel.getName()); }
visitArgumentLabel
36,463
void (@NotNull GrNewExpression ref) { super.visitNewExpression(ref); var resolvedCall = ref.resolveMethod(); if (resolvedCall == null || isDeprecated(resolvedCall.getContainingClass())) { return; } var referenceElement = ref.getReferenceElement(); if (referenceElement != null) { checkRef(resolvedCall, ref.getReferenceElement(), referenceElement.getReferenceName()); } else { checkRef(resolvedCall, ref, resolvedCall.getName()); } }
visitNewExpression
36,464
void (PsiElement resolved, PsiElement elementToHighlight, String elementName) { if (isDeprecated(resolved)) { registerError(elementToHighlight, GroovyBundle.message("0.is.deprecated", elementName), LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.LIKE_DEPRECATED); } }
checkRef
36,465
boolean (PsiElement resolved) { if (resolved instanceof PsiDocCommentOwner) { return ((PsiDocCommentOwner)resolved).isDeprecated(); } if (resolved instanceof PsiModifierListOwner && PsiImplUtil.isDeprecatedByAnnotation((PsiModifierListOwner)resolved)) { return true; } return false; }
isDeprecated
36,466
String (Object... args) { return GroovyBundle.message("inspection.message.negated.conditional.expression"); }
buildErrorString
36,467
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,468
void (@NotNull GrConditionalExpression grConditionalExpression) { super.visitConditionalExpression(grConditionalExpression); final GrExpression condition = grConditionalExpression.getCondition(); if (!BoolUtils.isNegation(condition)) { return; } registerError(grConditionalExpression); }
visitConditionalExpression
36,469
String (Object... args) { return GroovyBundle.message("inspection.message.nested.conditional.expression"); }
buildErrorString
36,470
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,471
void (@NotNull GrConditionalExpression grConditionalExpression) { super.visitConditionalExpression(grConditionalExpression); final GrConditionalExpression containingConditional = PsiTreeUtil.getParentOfType(grConditionalExpression, GrConditionalExpression.class); if (containingConditional == null) { return; } registerError(grConditionalExpression); }
visitConditionalExpression
36,472
int () { return m_limit; }
getLimit
36,473
String (Object... args) { return GroovyBundle.message("inspection.message.overly.complex.boolean.expression"); }
buildErrorString
36,474
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,475
void (@NotNull GrBinaryExpression expression) { super.visitBinaryExpression(expression); checkExpression(expression); }
visitBinaryExpression
36,476
void (@NotNull GrUnaryExpression expression) { super.visitUnaryExpression(expression); checkExpression(expression); }
visitUnaryExpression
36,477
void (@NotNull GrParenthesizedExpression expression) { super.visitParenthesizedExpression(expression); checkExpression(expression); }
visitParenthesizedExpression
36,478
void (GrExpression expression) { if (!isBoolean(expression)) { return; } if (isParentBoolean(expression)) { return; } final int numTerms = countTerms(expression); if (numTerms <= getLimit()) { return; } registerError(expression); }
checkExpression
36,479
int (GrExpression expression) { if (expression == null) { return 0; } if (!isBoolean(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 prefixExpression) { final GrExpression operand = prefixExpression.getOperand(); return countTerms(operand); } else if (expression instanceof GrParenthesizedExpression parenthesizedExpression) { final GrExpression contents = parenthesizedExpression.getOperand(); return countTerms(contents); } return 1; }
countTerms
36,480
boolean (GrExpression expression) { final PsiElement parent = expression.getParent(); if (!(parent instanceof GrExpression)) { return false; } return isBoolean((GrExpression) parent); }
isParentBoolean
36,481
boolean (GrExpression expression) { if (expression instanceof GrBinaryExpression binaryExpression) { final IElementType sign = binaryExpression.getOperationTokenType(); return GroovyTokenTypes.mLAND.equals(sign) || GroovyTokenTypes.mLOR.equals(sign); } else if (expression instanceof GrUnaryExpression prefixExpression) { final IElementType sign = prefixExpression.getOperationTokenType(); return GroovyTokenTypes.mLNOT.equals(sign); } else if (expression instanceof GrParenthesizedExpression parenthesizedExpression) { final GrExpression contents = parenthesizedExpression.getOperand(); return isBoolean(contents); } return false; }
isBoolean
36,482
List<ClashingMethod> (@NotNull GrTypeDefinition typeDefinition) { Collection<HierarchicalMethodSignature> visibleSignatures = typeDefinition.getVisibleSignatures(); List<ClashingMethod> clashingMethods = new ArrayList<>(); for (HierarchicalMethodSignature signature : visibleSignatures) { PsiMethod method = signature.getMethod(); if (method instanceof GrTraitMethod && method.getContainingClass() == typeDefinition) { List<HierarchicalMethodSignature> superSignatures = signature.getSuperSignatures(); if (superSignatures.size() > 1) { List<GrTypeDefinition> traits = new ArrayList<>(); for (HierarchicalMethodSignature superSignature : superSignatures) { PsiMethod superMethod = superSignature.getMethod(); PsiClass superClass = superMethod.getContainingClass(); if (GrTraitUtil.isTrait(superClass) && !superMethod.getModifierList().hasExplicitModifier(PsiModifier.ABSTRACT)) { traits.add((GrTypeDefinition)superClass); } } if (traits.size() > 1) { clashingMethods.add(new ClashingMethod(signature, traits)); } } } } return clashingMethods; }
collectClassingMethods
36,483
List<PsiClass> (@NotNull GrTypeDefinition typeDefinition) { return ContainerUtil.findAll(typeDefinition.getSupers(), aClass -> GrTraitUtil.isTrait(aClass)); }
collectImplementedTraits
36,484
BaseInspectionVisitor () { return new BaseInspectionVisitor() { @Override public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) { super.visitTypeDefinition(typeDefinition); List<PsiClass> superTraits = collectImplementedTraits(typeDefinition); if (superTraits.size() < 2) return; List<ClashingMethod> clashingMethods = collectClassingMethods(typeDefinition); for (ClashingMethod clashing : clashingMethods) { registerError(typeDefinition.getNameIdentifierGroovy(), buildWarning(clashing), new LocalQuickFix[]{getFix()}, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } } @NotNull @InspectionMessage private String buildWarning(@NotNull ClashingMethod entry) { return GroovyBundle.message("inspection.message.traits.0.contain.clashing.methods.with.signature.1", buildTraitString(entry), buildSignatureString(entry)); } @NotNull @NlsSafe private static String buildSignatureString(@NotNull ClashingMethod entry) { HierarchicalMethodSignature signature = entry.getSignature(); return PsiFormatUtil.formatMethod(signature.getMethod(), signature.getSubstitutor(), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE); } @NotNull @NlsSafe private static String buildTraitString(@NotNull ClashingMethod entry) { return StringUtil.join(entry.getSuperTraits(), tr -> tr.getName(), ", "); } }; }
buildVisitor
36,485
void (@NotNull GrTypeDefinition typeDefinition) { super.visitTypeDefinition(typeDefinition); List<PsiClass> superTraits = collectImplementedTraits(typeDefinition); if (superTraits.size() < 2) return; List<ClashingMethod> clashingMethods = collectClassingMethods(typeDefinition); for (ClashingMethod clashing : clashingMethods) { registerError(typeDefinition.getNameIdentifierGroovy(), buildWarning(clashing), new LocalQuickFix[]{getFix()}, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } }
visitTypeDefinition
36,486
String (@NotNull ClashingMethod entry) { return GroovyBundle.message("inspection.message.traits.0.contain.clashing.methods.with.signature.1", buildTraitString(entry), buildSignatureString(entry)); }
buildWarning
36,487
String (@NotNull ClashingMethod entry) { HierarchicalMethodSignature signature = entry.getSignature(); return PsiFormatUtil.formatMethod(signature.getMethod(), signature.getSubstitutor(), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE); }
buildSignatureString
36,488
String (@NotNull ClashingMethod entry) { return StringUtil.join(entry.getSuperTraits(), tr -> tr.getName(), ", "); }
buildTraitString
36,489
LocalQuickFix () { return GroovyFix.EMPTY_FIX; }
getFix
36,490
HierarchicalMethodSignature () { return mySignature; }
getSignature
36,491
List<GrTypeDefinition> () { return mySuperTraits; }
getSuperTraits
36,492
String (Object... args) { return GroovyBundle.message("inspection.message.conditional.expression"); }
buildErrorString
36,493
BaseInspectionVisitor () { return new Visitor(); }
buildVisitor
36,494
void (@NotNull GrConditionalExpression grConditionalExpression) { super.visitConditionalExpression(grConditionalExpression); registerError(grConditionalExpression); }
visitConditionalExpression
36,495
BaseInspectionVisitor () { return new PointlessArithmeticVisitor(); }
buildVisitor
36,496
String (Object... args) { return GroovyBundle.message("pointless.arithmetic.error.message", calculateReplacementExpression((GrExpression) args[0])); }
buildErrorString
36,497
String (GrExpression expression) { final GrBinaryExpression exp = (GrBinaryExpression)expression; final IElementType sign = exp.getOperationTokenType(); final GrExpression lhs = exp.getLeftOperand(); final GrExpression rhs = exp.getRightOperand(); assert rhs != null; if (GroovyTokenTypes.mPLUS == sign) { if (isZero(lhs)) { return rhs.getText(); } else { return lhs.getText(); } } if (GroovyTokenTypes.mMINUS == sign) { return lhs.getText(); } if (GroovyTokenTypes.mSTAR == sign) { if (isOne(lhs)) { return rhs.getText(); } else if (isOne(rhs)) { return lhs.getText(); } else { return "0"; } } if (GroovyTokenTypes.mDIV == sign) { return lhs.getText(); } return ""; }
calculateReplacementExpression
36,498
LocalQuickFix (@NotNull PsiElement location) { return new PointlessArithmeticFix(); }
buildFix
36,499
String () { return GroovyBundle.message("intention.family.name.simplify"); }
getFamilyName