Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
31,900
void (@NotNull GrMethod method) { GrOpenBlock block = method.getBlock(); if (block != null) { GroovyControlFlow flow = ControlFlowUtils.getGroovyControlFlow(block); collectRefs(variable, flow.getFlow(), ControlFlowUtils.inferWriteAccessMap(flow, variable), -1, toInline); } }
visitMethod
31,901
void (@NotNull GrClassInitializer initializer) { GrOpenBlock block = initializer.getBlock(); GroovyControlFlow flow = ControlFlowUtils.getGroovyControlFlow(block); collectRefs(variable, flow.getFlow(), ControlFlowUtils.inferWriteAccessMap(flow, variable), -1, toInline); }
visitClassInitializer
31,902
void (UsageInfo @NotNull [] usages) { CommonRefactoringUtil.sortDepthFirstRightLeftOrder(usages); final GrExpression initializer = mySettings.getInitializer(); GrExpression initializerToUse = GrIntroduceHandlerBase.insertExplicitCastIfNeeded(myLocal, mySettings.getInitializer()); for (UsageInfo usage : usages) { GrVariableInliner.inlineReference(usage, myLocal, initializerToUse); } final PsiElement initializerParent = initializer.getParent(); if (initializerParent instanceof GrAssignmentExpression) { initializerParent.delete(); return; } if (initializerParent instanceof GrVariable) { final Collection<PsiReference> all = ReferencesSearch.search(myLocal).findAll(); if (!all.isEmpty()) { initializer.delete(); return; } } final PsiElement owner = myLocal.getParent().getParent(); if (owner instanceof GrVariableDeclarationOwner) { ((GrVariableDeclarationOwner)owner).removeVariable(myLocal); } else { myLocal.delete(); } }
performRefactoring
31,903
String () { return RefactoringBundle.message("inline.command", myLocal.getName()); }
getCommandName
31,904
boolean (GrCallExpression call) { GrStatement stmt = call; PsiElement parent = call.getParent(); // return statement if (parent instanceof GrReturnStatement) { stmt = ((GrReturnStatement) parent); parent = parent.getParent(); } // method body result if (parent instanceof GrOpenBlock) { if (parent.getParent() instanceof GrMethod) { GrStatement[] statements = ((GrOpenBlock) parent).getStatements(); return statements.length > 0 && stmt == statements[statements.length - 1]; } } // closure result if (parent instanceof GrClosableBlock) { GrStatement[] statements = ((GrClosableBlock) parent).getStatements(); return statements.length > 0 && stmt == statements[statements.length - 1]; } // todo add for inner method block statements // todo test me! if (stmt instanceof GrReturnStatement) { GrMethod method = PsiTreeUtil.getParentOfType(stmt, GrMethod.class); if (method != null) { Collection<GrStatement> returnStatements = ControlFlowUtils.collectReturns(method.getBlock()); return returnStatements.contains(stmt) && !hasBadReturns(method); } } return false; }
isTailMethodCall
31,905
boolean () { return dialog.isInlineThisOnly(); }
isOnlyOneReferenceToInline
31,906
boolean () { return true; }
isOnlyOneReferenceToInline
31,907
boolean (GrMethod method) { Collection<GrStatement> returnStatements = ControlFlowUtils.collectReturns(method.getBlock()); GrOpenBlock block = method.getBlock(); if (block == null || returnStatements.isEmpty()) return false; boolean checked = checkTailOpenBlock(block, returnStatements); return !(checked && returnStatements.isEmpty()); }
hasBadReturns
31,908
boolean (GrIfStatement ifStatement, Collection<GrStatement> returnStatements) { GrStatement thenBranch = ifStatement.getThenBranch(); GrStatement elseBranch = ifStatement.getElseBranch(); if (elseBranch == null) return false; boolean tb = false; boolean eb = false; if (thenBranch instanceof GrReturnStatement) { tb = returnStatements.remove(thenBranch); } else if (thenBranch instanceof GrBlockStatement) { tb = checkTailOpenBlock(((GrBlockStatement) thenBranch).getBlock(), returnStatements); } if (elseBranch instanceof GrReturnStatement) { eb = returnStatements.remove(elseBranch); } else if (elseBranch instanceof GrBlockStatement) { eb = checkTailOpenBlock(((GrBlockStatement) elseBranch).getBlock(), returnStatements); } return tb && eb; }
checkTailIfStatement
31,909
boolean (GrOpenBlock block, Collection<GrStatement> returnStatements) { if (block == null) return false; GrStatement[] statements = block.getStatements(); if (statements.length == 0) return false; GrStatement last = statements[statements.length - 1]; if (returnStatements.contains(last)) { returnStatements.remove(last); return true; } if (last instanceof GrIfStatement) { return checkTailIfStatement(((GrIfStatement) last), returnStatements); } return false; }
checkTailOpenBlock
31,910
void (@DialogMessage String message, final Project project, Editor editor) { CommonRefactoringUtil.showErrorHint(project, editor, message, getRefactoringName(), HelpID.INLINE_METHOD); }
showErrorMessage
31,911
Collection<ReferenceExpressionInfo> (GrMethod method) { ArrayList<ReferenceExpressionInfo> list = new ArrayList<>(); collectReferenceInfoImpl(list, method, method); return list; }
collectReferenceInfo
31,912
void (Collection<ReferenceExpressionInfo> infos, PsiElement elem, GrMethod method) { if (elem instanceof GrReferenceExpression expr) { PsiReference ref = expr.getReference(); if (ref != null) { PsiElement declaration = ref.resolve(); if (declaration instanceof GrMember member) { int offsetInMethod = expr.getTextRange().getStartOffset() - method.getTextRange().getStartOffset(); infos.add(new ReferenceExpressionInfo(expr, offsetInMethod, member, member.getContainingClass())); } } } for (PsiElement element : elem.getChildren()) { collectReferenceInfoImpl(infos, element, method); } }
collectReferenceInfoImpl
31,913
boolean (GrExpression qualifier) { if (!(qualifier instanceof GrReferenceExpression)) return false; GrExpression qual = ((GrReferenceExpression) qualifier).getQualifierExpression(); return qual == null || isSimpleReference(qual); }
isSimpleReference
31,914
boolean () { return declaration.hasModifierProperty(PsiModifier.STATIC); }
isStatic
31,915
boolean (GrMethod method) { return checkCalls(method.getBlock(), method); }
checkMethodForRecursion
31,916
boolean (PsiElement scope, PsiMethod method) { if (scope instanceof GrMethodCall) { PsiMethod refMethod = ((GrMethodCall)scope).resolveMethod(); if (method.equals(refMethod)) return true; } for (PsiElement child = scope.getFirstChild(); child != null; child = child.getNextSibling()) { if (checkCalls(child, method)) return true; } return false; }
checkCalls
31,917
String () { return GroovyRefactoringBundle.message("inline.method.border.title"); }
getBorderTitle
31,918
String () { return GroovyRefactoringBundle.message("inline.method.label", GroovyRefactoringUtil.getMethodSignature(myMethod)); }
getNameLabelText
31,919
String () { return myMethod.isWritable() ? GroovyRefactoringBundle.message("all.invocations.and.remove.the.method") : GroovyRefactoringBundle.message("all.invocations.in.project"); }
getInlineAllText
31,920
String () { return GroovyRefactoringBundle.message("this.invocation.only.and.keep.the.method"); }
getInlineThisText
31,921
boolean () { return false; }
isInlineThis
31,922
void () { if (getOKAction().isEnabled()) { close(OK_EXIT_CODE); } }
doAction
31,923
String () { return HelpID.INLINE_METHOD; }
getHelpId
31,924
boolean () { return myAllowInlineThisOnly; }
canInlineThisOnly
31,925
GrExpression (GrSignature signature, GrParameter[] parameters, GrParameter parameter, GrClosureSignatureUtil.ArgInfo<PsiElement> argInfo, Project project) { if (argInfo == null) return null; List<PsiElement> arguments = argInfo.args; if (argInfo.isMultiArg) { //arguments for Map and varArg final PsiType type = parameter.getDeclaredType(); return GroovyRefactoringUtil.generateArgFromMultiArg(signature.getSubstitutor(), arguments, type, project); } else { //arguments for simple parameters if (arguments.size() == 1) { //arg exists PsiElement arg = arguments.iterator().next(); if (isVararg(parameter, parameters)) { if (arg instanceof GrSafeCastExpression) { PsiElement expr = ((GrSafeCastExpression)arg).getOperand(); if (expr instanceof GrListOrMap && !((GrListOrMap)expr).isMap()) { return ((GrListOrMap)expr); } } } return (GrExpression)arg; } else { //arg is skipped. Parameter is optional return parameter.getInitializerGroovy(); } } }
inferArg
31,926
boolean (GrParameter p, GrParameter[] parameters) { return parameters[parameters.length - 1] == p && p.getType() instanceof PsiArrayType; }
isVararg
31,927
void (GrMethod method, GrCallExpression call, GrExpression oldExpression, GrParameter parameter) { Collection<PsiReference> refs = ReferencesSearch.search(parameter, new LocalSearchScope(method), false).findAll(); final GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(call.getProject()); GrExpression expression = elementFactory.createExpressionFromText(oldExpression.getText()); if (GroovyRefactoringUtil.hasSideEffect(expression) && refs.size() > 1 || !hasUnresolvableWriteAccess(refs, oldExpression)) { final String oldName = parameter.getName(); final String newName = InlineMethodConflictSolver.suggestNewName(oldName, method, call); expression = elementFactory.createExpressionFromText(newName); final GrOpenBlock body = method.getBlock(); final GrStatement[] statements = body.getStatements(); GrStatement anchor = null; if (statements.length > 0) { anchor = statements[0]; } body.addStatementBefore(elementFactory.createStatementFromText(createVariableDefinitionText(parameter, oldExpression, newName)), anchor); } for (PsiReference ref : refs) { PsiElement element = ref.getElement(); if (element instanceof GrReferenceExpression) { ((GrReferenceExpression)element).replaceWithExpression(expression, true); } } }
replaceAllOccurrencesWithExpression
31,928
String (GrParameter parameter, GrExpression expression, String varName) { StringBuilder buffer = new StringBuilder(); final PsiModifierList modifierList = parameter.getModifierList(); buffer.append(modifierList.getText().trim()); if (buffer.length() > 0) buffer.append(' '); final GrTypeElement typeElement = parameter.getTypeElementGroovy(); if (typeElement != null) { buffer.append(typeElement.getText()).append(' '); } if (buffer.length() == 0) { buffer.append("def "); } buffer.append(varName).append(" = ").append(expression.getText()); return buffer.toString(); }
createVariableDefinitionText
31,929
boolean (Collection<PsiReference> refs) { for (PsiReference ref : refs) { final PsiElement element = ref.getElement(); final PsiElement parent = element.getParent(); if (parent instanceof GrAssignmentExpression && ((GrAssignmentExpression)parent).getLValue() == element) return true; if (parent instanceof GrUnaryExpression) return true; } return false; }
containsWriteAccess
31,930
boolean (Collection<PsiReference> refs, GrExpression expression) { if (containsWriteAccess(refs)) { if (expression instanceof GrReferenceExpression) { final PsiElement resolved = ((GrReferenceExpression)expression).resolve(); if (resolved instanceof GrVariable && !(resolved instanceof PsiField)) { final boolean isFinal = ((GrVariable)resolved).hasModifierProperty(PsiModifier.FINAL); if (!isFinal) { final PsiReference lastRef = Collections.max(ReferencesSearch.search(resolved).findAll(), Comparator.comparingInt(o -> o.getElement().getTextRange().getStartOffset())); return lastRef.getElement() == expression; } } } return false; } return true; }
hasUnresolvableWriteAccess
31,931
boolean () { return invokedOnReference; }
isOnlyOneReferenceToInline
31,932
boolean () { return dialog.isInlineThisOnly(); }
isOnlyOneReferenceToInline
31,933
String (@NotNull String startName, @Nullable GrMethod method, @NotNull PsiElement call, String... otherNames) { String newName; int i = 1; PsiElement parent = call.getParent(); while (!(parent instanceof GrVariableDeclarationOwner) && parent != null) { parent = parent.getParent(); } if (parent == null || isValidName(startName, parent, call) && isValid(startName, otherNames)) { return startName; } do { newName = startName + i; i++; } while (!((method == null || isValidNameInMethod(newName, method)) && isValidName(newName, parent, call) && isValid(newName, otherNames))); return newName; }
suggestNewName
31,934
boolean (@Nullable String name, String ... otherNames) { for (String otherName : otherNames) { if (otherName.equals(name)) { return false; } } return true; }
isValid
31,935
boolean (@NotNull String name, @NotNull GrMethod method) { for (GrParameter parameter : method.getParameters()) { if (name.equals(parameter.getName())) return false; } final GrOpenBlock block = method.getBlock(); if (block != null) { return isValidNameDown(name, block, null); } return true; }
isValidNameInMethod
31,936
boolean (@NotNull String name, @NotNull PsiElement scopeElement, PsiElement call) { if (isValidNameDown(name, scopeElement, call)) { if (!(scopeElement instanceof GroovyFileBase)) { return isValidNameUp(name, scopeElement, call); } else { return true; } } else { return false; } }
isValidName
31,937
boolean (@NotNull String name, @NotNull PsiElement startElement, @Nullable PsiElement call) { PsiElement child = startElement.getFirstChild(); while (child != null) { // Do not check defined classes, methods, closures and blocks before if (child instanceof GrTypeDefinition || child instanceof GrMethod || call != null && GroovyRefactoringUtil.isAppropriateContainerForIntroduceVariable(child) && child.getTextRange().getEndOffset() < call.getTextRange().getStartOffset()) { child = child.getNextSibling(); continue; } if (child instanceof GrAssignmentExpression) { GrExpression lValue = ((GrAssignmentExpression) child).getLValue(); if (lValue instanceof GrReferenceExpression expr) { if (expr.getQualifierExpression() == null && name.equals(expr.getReferenceName())) { return false; } } } if (child instanceof GrVariable && name.equals(((GrVariable) child).getName())) { return false; } else { boolean inner = isValidNameDown(name, child, call); if (!inner) return false; } child = child.getNextSibling(); } return true; }
isValidNameDown
31,938
boolean (@NotNull String name, @NotNull PsiElement startElement, @Nullable PsiElement call) { if (startElement instanceof PsiFile) { return true; } PsiElement prevSibling = startElement.getPrevSibling(); while (prevSibling != null) { if (!isValidNameDown(name, prevSibling, call)) { return false; } prevSibling = prevSibling.getPrevSibling(); } PsiElement parent = startElement.getParent(); return parent == null || parent instanceof PsiDirectory || isValidNameUp(name, parent, call); }
isValidNameUp
31,939
void (@NotNull final UsageInfo usage, @NotNull final PsiElement referenced) { inlineReference(usage, referenced, myTempExpr); }
inlineUsage
31,940
void (UsageInfo usage, PsiElement referenced, GrExpression initializer) { if (initializer == null) return; GrExpression exprToBeReplaced = (GrExpression)usage.getElement(); if (exprToBeReplaced == null) return; if ((referenced instanceof GrAccessorMethod || referenced instanceof GrField) && exprToBeReplaced instanceof GrReferenceExpression) { final GroovyResolveResult resolveResult = ((GrReferenceExpression)exprToBeReplaced).advancedResolve(); if (resolveResult.getElement() instanceof GrAccessorMethod && !resolveResult.isInvokedOnProperty()) { final PsiElement parent = exprToBeReplaced.getParent(); if (parent instanceof GrCall && parent instanceof GrExpression) { exprToBeReplaced = (GrExpression)parent; } else { return; } } } GrExpression newExpr = exprToBeReplaced.replaceWithExpression((GrExpression)initializer.copy(), true); final Project project = usage.getProject(); JavaCodeStyleManager.getInstance(project).shortenClassReferences(newExpr); Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); GroovyRefactoringUtil.highlightOccurrences(project, editor, new PsiElement[]{newExpr}); WindowManager.getInstance().getStatusBar(project).setInfo(GroovyRefactoringBundle.message("press.escape.to.remove.the.highlighting")); }
inlineReference
31,941
GrExpression () { return myInitializer; }
getInitializer
31,942
int () { return myWriteInstructionNumber; }
getWriteInstructionNumber
31,943
GroovyControlFlow () { return myFlow; }
getFlow
31,944
String () { @SuppressWarnings("StaticFieldReferencedViaSubclass") String fieldText = PsiFormatUtil.formatVariable(myField, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE, PsiSubstitutor.EMPTY); return JavaRefactoringBundle.message("inline.field.field.name.label", fieldText, ""); }
getNameLabelText
31,945
String () { return RefactoringBundle.message("inline.field.border.title"); }
getBorderTitle
31,946
String () { return JavaRefactoringBundle.message("this.reference.only.and.keep.the.field"); }
getInlineThisText
31,947
String () { return JavaRefactoringBundle.message("all.references.and.remove.the.field"); }
getInlineAllText
31,948
boolean () { return JavaRefactoringSettings.getInstance().INLINE_FIELD_THIS; }
isInlineThis
31,949
void () { if (getOKAction().isEnabled()) { JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance(); if (myRbInlineThisOnly.isEnabled() && myRbInlineAll.isEnabled()) { settings.INLINE_FIELD_THIS = isInlineThisOnly(); } close(OK_EXIT_CODE); } }
doAction
31,950
String () { return HelpID.INLINE_FIELD; }
getHelpId
31,951
void (@NotNull UsageInfo usage, @NotNull PsiElement referenced) { PsiElement element=usage.getElement(); if (!(element instanceof GrExpression && element.getParent() instanceof GrCallExpression call)) return; final Editor editor = getCurrentEditorIfApplicable(element); RangeMarker marker = inlineReferenceImpl(call, myMethod, isOnExpressionOrReturnPlace(call), GroovyInlineMethodUtil.isTailMethodCall(call), editor); // highlight replaced result if (marker != null) { Project project = referenced.getProject(); TextRange range = marker.getTextRange(); GroovyRefactoringUtil.highlightOccurrencesByRanges(project, editor, new TextRange[]{range}); WindowManager.getInstance().getStatusBar(project).setInfo(GroovyRefactoringBundle.message("press.escape.to.remove.the.highlighting")); if (editor != null) { editor.getCaretModel().moveToOffset(marker.getEndOffset()); } } }
inlineUsage
31,952
Editor (@NotNull PsiElement element) { final Project project = element.getProject(); final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); if (editor != null && editor.getDocument() == PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile())) { return editor; } return null; }
getCurrentEditorIfApplicable
31,953
RangeMarker (@NotNull GrCallExpression call, @NotNull GrMethod method, boolean resultOfCallExplicitlyUsed, boolean isTailMethodCall, @Nullable Editor editor) { try { GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(call.getProject()); final Project project = call.getProject(); // Variable declaration for qualifier expression GrVariableDeclaration qualifierDeclaration = null; GrReferenceExpression innerQualifier = null; GrExpression qualifier = null; if (call instanceof GrMethodCallExpression methodCall) { GrExpression invoked = methodCall.getInvokedExpression(); if (invoked instanceof GrReferenceExpression ref && ref.getQualifierExpression() != null) { qualifier = ref.getQualifierExpression(); if (PsiUtil.isSuperReference(qualifier)) { qualifier = null; } else if (!GroovyInlineMethodUtil.isSimpleReference(qualifier)) { String qualName = generateQualifierName(call, method, project, qualifier); qualifier = (GrExpression)PsiUtil.skipParentheses(qualifier, false); qualifierDeclaration = factory.createVariableDeclaration(ArrayUtilRt.EMPTY_STRING_ARRAY, qualifier, null, qualName); innerQualifier = (GrReferenceExpression)factory.createExpressionFromText(qualName); } else { innerQualifier = (GrReferenceExpression)qualifier; } } } GrMethod _method = prepareNewMethod(call, method, qualifier); GrExpression result = getAloneResultExpression(_method); if (result != null) { GrExpression expression = call.replaceWithExpression(result, false); TextRange range = expression.getTextRange(); return editor != null ? editor.getDocument().createRangeMarker(range.getStartOffset(), range.getEndOffset(), true) : null; } GrMethod newMethod = prepareNewMethod(call, method, innerQualifier); String resultName = InlineMethodConflictSolver.suggestNewName("result", newMethod, call); // Add variable for method result Collection<GrStatement> returnStatements = ControlFlowUtils.collectReturns(newMethod.getBlock()); final int returnCount = returnStatements.size(); PsiType methodType = method.getInferredReturnType(); GrOpenBlock body = newMethod.getBlock(); assert body != null; GrExpression replaced; if (resultOfCallExplicitlyUsed && !isTailMethodCall) { GrExpression resultExpr = null; if (PsiTypes.voidType().equals(methodType)) { resultExpr = factory.createExpressionFromText("null"); } else if (returnCount == 1) { final GrExpression returnExpression = ControlFlowUtils.extractReturnExpression(returnStatements.iterator().next()); if (returnExpression != null) { resultExpr = factory.createExpressionFromText(returnExpression.getText()); } } else if (returnCount > 1) { resultExpr = factory.createExpressionFromText(resultName); } if (resultExpr == null) { resultExpr = factory.createExpressionFromText("null"); } replaced = call.replaceWithExpression(resultExpr, false); } else { replaced = call; } // Calculate anchor to insert before GrExpression enclosingExpr = GroovyRefactoringUtil.addBlockIntoParent(replaced); GrVariableDeclarationOwner owner = PsiTreeUtil.getParentOfType(enclosingExpr, GrVariableDeclarationOwner.class); assert owner != null; PsiElement element = enclosingExpr; while (element != null && element.getParent() != owner) { element = element.getParent(); } assert element instanceof GrStatement; GrStatement anchor = (GrStatement) element; if (!resultOfCallExplicitlyUsed) { assert anchor == enclosingExpr; } // add qualifier reference declaration if (qualifierDeclaration != null) { owner.addVariableDeclarationBefore(qualifierDeclaration, anchor); } // Process method return statements if (returnCount > 1 && !PsiTypes.voidType().equals(methodType) && !isTailMethodCall) { PsiType type = methodType != null && methodType.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) ? null : methodType; GrVariableDeclaration resultDecl = factory.createVariableDeclaration(ArrayUtilRt.EMPTY_STRING_ARRAY, "", type, resultName); GrStatement statement = ((GrStatementOwner) owner).addStatementBefore(resultDecl, anchor); JavaCodeStyleManager.getInstance(statement.getProject()).shortenClassReferences(statement); // Replace all return statements with assignments to 'result' variable for (GrStatement returnStatement : returnStatements) { GrExpression value = ControlFlowUtils.extractReturnExpression(returnStatement); if (value != null) { GrExpression assignment = factory.createExpressionFromText(resultName + " = " + value.getText()); returnStatement.replaceWithStatement(assignment); } else { returnStatement.replaceWithStatement(factory.createExpressionFromText(resultName + " = null")); } } } if (!isTailMethodCall && resultOfCallExplicitlyUsed && returnCount == 1) { returnStatements.iterator().next().removeStatement(); } else if (!isTailMethodCall && (PsiTypes.voidType().equals(methodType) || returnCount == 1)) { for (GrStatement returnStatement : returnStatements) { if (returnStatement instanceof GrReturnStatement) { final GrExpression returnValue = ((GrReturnStatement)returnStatement).getReturnValue(); if (returnValue != null && GroovyRefactoringUtil.hasSideEffect(returnValue)) { returnStatement.replaceWithStatement(returnValue); continue; } } else if (GroovyRefactoringUtil.hasSideEffect(returnStatement)) { continue; } returnStatement.removeStatement(); } } // Add all method statements GrStatement[] statements = body.getStatements(); for (GrStatement statement : statements) { ((GrStatementOwner) owner).addStatementBefore(statement, anchor); } if (resultOfCallExplicitlyUsed && !isTailMethodCall) { TextRange range = replaced.getTextRange(); RangeMarker marker = editor != null ? editor.getDocument().createRangeMarker(range.getStartOffset(), range.getEndOffset(), true) : null; reformatOwner(owner); return marker; } else { GrStatement stmt; if (isTailMethodCall && enclosingExpr.getParent() instanceof GrReturnStatement) { stmt = (GrReturnStatement) enclosingExpr.getParent(); } else { stmt = enclosingExpr; } stmt.removeStatement(); reformatOwner(owner); return null; } } catch (IncorrectOperationException e) { LOG.error(e); } return null; }
inlineReferenceImpl
31,954
String (@NotNull GrCallExpression call, @Nullable GrMethod method, @NotNull final Project project, @NotNull GrExpression qualifier) { String[] possibleNames = GroovyNameSuggestionUtil.suggestVariableNames(qualifier, new NameValidator() { @Override public String validateName(String name, boolean increaseNumber) { return name; } @Override public Project getProject() { return project; } }); String qualName = possibleNames[0]; qualName = InlineMethodConflictSolver.suggestNewName(qualName, method, call); return qualName; }
generateQualifierName
31,955
String (String name, boolean increaseNumber) { return name; }
validateName
31,956
Project () { return project; }
getProject
31,957
void (@Nullable PsiElement element, ArrayList<PsiNamedElement> defintions) { if (element == null) return; for (PsiElement child : element.getChildren()) { if (child instanceof GrVariable && !(child instanceof GrParameter)) { defintions.add((GrVariable) child); } if (!(child instanceof GrClosableBlock)) { collectInnerDefinitions(child, defintions); } } }
collectInnerDefinitions
31,958
GrExpression (@NotNull GrMethod method) { GrOpenBlock body = method.getBlock(); assert body != null; GrStatement[] statements = body.getStatements(); if (statements.length == 1) { if (statements[0] instanceof GrExpression) return (GrExpression) statements[0]; if (statements[0] instanceof GrReturnStatement) { GrExpression value = ((GrReturnStatement) statements[0]).getReturnValue(); if (value == null && !PsiTypes.voidType().equals(PsiUtil.getSmartReturnType(method))) { return GroovyPsiElementFactory.getInstance(method.getProject()).createExpressionFromText("null"); } return value; } } return null; }
getAloneResultExpression
31,959
boolean (@NotNull GrCallExpression call) { PsiElement parent = call.getParent(); if (!(parent instanceof GrVariableDeclarationOwner owner)) { return true; } // tail calls in methods and closures if (owner instanceof GrClosableBlock || owner instanceof GrOpenBlock && owner.getParent() instanceof GrMethod) { GrStatement[] statements = ((GrCodeBlock) owner).getStatements(); assert statements.length > 0; GrStatement last = statements[statements.length - 1]; if (last == call) return true; if (last instanceof GrReturnStatement && call == ((GrReturnStatement) last).getReturnValue()) { return true; } } return false; }
isOnExpressionOrReturnPlace
31,960
Template (PsiField f, Object expectedTypes, PsiClass targetClass, Editor editor, PsiElement context, boolean createConstantField, @NotNull PsiSubstitutor substitutor) { GrVariableDeclaration fieldDecl = (GrVariableDeclaration)f.getParent(); GrField field = (GrField)fieldDecl.getVariables()[0]; Project project = field.getProject(); fieldDecl = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(fieldDecl); TemplateBuilderImpl builder = new TemplateBuilderImpl(fieldDecl); GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project); if (expectedTypes instanceof TypeConstraint[]) { GrTypeElement typeElement = fieldDecl.getTypeElementGroovy(); assert typeElement != null; ChooseTypeExpression expr = new ChooseTypeExpression((TypeConstraint[])expectedTypes, PsiManager.getInstance(project), typeElement.getResolveScope()); builder.replaceElement(typeElement, expr); } else if (expectedTypes instanceof ExpectedTypeInfo[]) { new GuessTypeParameters(project, factory, builder, substitutor) .setupTypeElement(field.getTypeElement(), (ExpectedTypeInfo[])expectedTypes, context, targetClass); } GrExpression initializer = field.getInitializerGroovy(); if (createConstantField && initializer != null) { builder.replaceElement(initializer, new EmptyExpression()); PsiElement identifier = field.getNameIdentifierGroovy(); builder.setEndVariableAfter(identifier); } fieldDecl = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(fieldDecl); Template template = builder.buildTemplate(); TextRange range = fieldDecl.getTextRange(); editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset()); if (expectedTypes instanceof ExpectedTypeInfo[]) { if (!Registry.is("ide.create.field.enable.shortening") && ((ExpectedTypeInfo[])expectedTypes).length > 1) { template.setToShortenLongNames(false); } } return template; }
setupTemplateImpl
31,961
GrField (@NotNull PsiClass targetClass, @NotNull PsiField field, @Nullable PsiElement place) { if (targetClass instanceof GroovyScriptClass) { PsiElement added = targetClass.getContainingFile().add(field.getParent()); return (GrField)((GrVariableDeclaration)added).getVariables()[0]; } else { return (GrField)targetClass.add(field); } }
insertFieldImpl
31,962
IntentionPreviewInfo (@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { final List<PsiClass> classes = getTargetClasses(); if (classes.size() == 0) { return IntentionPreviewInfo.EMPTY; } PsiClass targetClass = classes.get(0); final CreateFieldFix fix = new CreateFieldFix(targetClass); PsiField representation = fix.getFieldRepresentation(targetClass.getProject(), generateModifiers(targetClass), myReferenceName, getRefExpr(), true); PsiElement parent = representation == null ? null : representation.getParent(); if (parent == null) { return IntentionPreviewInfo.EMPTY; } return new IntentionPreviewInfo.CustomDiff(GroovyFileType.GROOVY_FILE_TYPE, "", parent.getText()); }
generatePreview
31,963
String[] (@NotNull PsiClass targetClass) { final GrReferenceExpression myRefExpression = getRefExpr(); if (myRefExpression != null && GrStaticChecker.isInStaticContext(myRefExpression, targetClass)) { return new String[]{PsiModifier.STATIC}; } return ArrayUtilRt.EMPTY_STRING_ARRAY; }
generateModifiers
31,964
TypeConstraint[] () { return GroovyExpectedTypesProvider.calculateTypeConstraints(getRefExpr()); }
calculateTypeConstrains
31,965
String () { return GroovyBundle.message("create.field.from.usage.family.name"); }
getFamilyName
31,966
String () { return GroovyBundle.message("create.field.from.usage", myReferenceName); }
getText
31,967
void (Project project, @NotNull PsiClass targetClass) { final CreateFieldFix fix = new CreateFieldFix(targetClass); fix.doFix(targetClass.getProject(), generateModifiers(targetClass), myReferenceName, calculateTypeConstrains(), getRefExpr()); }
invokeImpl
31,968
boolean (PsiClass psiClass) { return super.canBeTargetClass(psiClass) && !psiClass.isInterface() && !psiClass.isAnnotationType(); }
canBeTargetClass
31,969
PsiType[] () { return PsiType.EMPTY_ARRAY; }
getArgumentTypes
31,970
String () { return GroovyPropertyUtils.getGetterNameNonBoolean(getRefExpr().getReferenceName()); }
getMethodName
31,971
void (ActionEvent event) { PackageChooserDialog chooser = new PackageChooserDialog(GroovyBundle.message("dialog.create.class.package.chooser.title"), myProject); chooser.selectPackage(myPackageTextField.getText()); chooser.show(); PsiPackage aPackage = chooser.getSelectedPackage(); if (aPackage != null) { myPackageTextField.setText(aPackage.getQualifiedName()); } }
actionPerformed
31,972
void () { myPackageTextField = new EditorTextField(); myPackageChooseButton = new FixedSizeButton(myPackageTextField); }
createUIComponents
31,973
JComponent () { myPackageTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void documentChanged(@NotNull DocumentEvent e) { PsiNameHelper nameHelper = PsiNameHelper.getInstance(myProject); String packageName = getPackageName(); getOKAction().setEnabled(nameHelper.isQualifiedName(packageName) || packageName.isEmpty()); } }); new AnAction() { @Override public void actionPerformed(@NotNull AnActionEvent e) { myPackageChooseButton.doClick(); } }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK)), myPackageTextField); return myContentPane; }
createCenterPanel
31,974
void (@NotNull DocumentEvent e) { PsiNameHelper nameHelper = PsiNameHelper.getInstance(myProject); String packageName = getPackageName(); getOKAction().setEnabled(nameHelper.isQualifiedName(packageName) || packageName.isEmpty()); }
documentChanged
31,975
void (@NotNull AnActionEvent e) { myPackageChooseButton.doClick(); }
actionPerformed
31,976
JComponent () { return myContentPane; }
getContentPane
31,977
PsiDirectory () { return myTargetDirectory; }
getTargetDirectory
31,978
JComponent () { return myPackageTextField; }
getPreferredFocusedComponent
31,979
String () { return myPackageTextField.getText().trim(); }
getPackageName
31,980
void () { final String packageName = getPackageName(); final Ref<@DialogMessage String> errorStringRef = new Ref<>(); CommandProcessor.getInstance().executeCommand(myProject, () -> { try { final PsiDirectory baseDir = myModule == null ? null : PackageUtil.findPossiblePackageDirectoryInModule(myModule, packageName); myTargetDirectory = myModule == null ? null : PackageUtil.findOrCreateDirectoryForPackage(myModule, packageName, baseDir, true); if (myTargetDirectory == null) { errorStringRef.set(""); return; } errorStringRef.set(RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getClassName())); } catch (IncorrectOperationException e) { errorStringRef.set(e.getMessage()); } }, GroovyBundle.message("create.directory.command"), null); if (errorStringRef.get() != null) { if (!errorStringRef.get().isEmpty()) { Messages.showMessageDialog(myProject, errorStringRef.get(), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); } return; } super.doOKAction(); }
doOKAction
31,981
String () { return myClassName; }
getClassName
31,982
GrReferenceExpression () { return myRefExpression.getElement(); }
getRefExpr
31,983
boolean (@NotNull Project project, Editor editor, PsiFile file) { final GrReferenceExpression element = myRefExpression.getElement(); if (element == null || !element.isValid()) { return false; } List<PsiClass> targetClasses = getTargetClasses(); return !targetClasses.isEmpty(); }
isAvailable
31,984
PsiElementPredicate () { return new PsiElementPredicate() { @Override public boolean satisfiedBy(@NotNull PsiElement element) { return element instanceof GrReferenceExpression; } }; }
getElementPredicate
31,985
boolean (@NotNull PsiElement element) { return element instanceof GrReferenceExpression; }
satisfiedBy
31,986
void (List<PsiClass> classes, Editor editor) { final Project project = classes.get(0).getProject(); PsiClassListCellRenderer renderer = new PsiClassListCellRenderer(); final IPopupChooserBuilder<PsiClass> builder = JBPopupFactory.getInstance() .createPopupChooserBuilder(classes) .setRenderer(renderer) .setSelectionMode(ListSelectionModel.SINGLE_SELECTION) .setItemChosenCallback((aClass) -> CommandProcessor.getInstance() .executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> invokeImpl(project, aClass)), getText(), null)) .setTitle(QuickFixBundle.message("target.class.chooser.title")); renderer.installSpeedSearch(builder); builder.createPopup().showInBestPositionFor(editor); }
chooseClass
31,987
List<PsiClass> () { final GrReferenceExpression ref = getRefExpr(); final PsiClass targetClass = QuickfixUtil.findTargetClass(ref); if (targetClass == null || !canBeTargetClass(targetClass)) return Collections.emptyList(); final ArrayList<PsiClass> classes = new ArrayList<>(); collectSupers(targetClass, classes); return classes; }
getTargetClasses
31,988
void (PsiClass psiClass, ArrayList<PsiClass> classes) { classes.add(psiClass); final PsiClass[] supers = psiClass.getSupers(); for (PsiClass aSuper : supers) { if (classes.contains(aSuper)) continue; if (canBeTargetClass(aSuper)) { collectSupers(aSuper, classes); } } }
collectSupers
31,989
boolean (PsiClass psiClass) { return psiClass.getManager().isInProject(psiClass); }
canBeTargetClass
31,990
String () { return GroovyBundle.message("create.method.from.usage.family.name"); }
getFamilyName
31,991
String () { return GroovyBundle.message("create.method.from.usage", getMethodName()); }
getText
31,992
IntentionPreviewInfo (@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { final List<PsiClass> classes = getTargetClasses(); if (classes.size() == 0) { return IntentionPreviewInfo.EMPTY; } Data data = generateMethod(classes.get(0), true); return new IntentionPreviewInfo.CustomDiff(GroovyFileType.GROOVY_FILE_TYPE, "", data.method.getText()); }
generatePreview
31,993
void (Project project, @NotNull PsiClass targetClass) { Data data = generateMethod(targetClass, false); final PsiElement context = PsiTreeUtil.getParentOfType(getRefExpr(), PsiClass.class, PsiMethod.class, PsiFile.class); IntentionUtils.createTemplateForMethod(data.paramTypesExpressions, data.method, targetClass, data.constraints, false, context); }
invokeImpl
31,994
Data (@NotNull PsiClass targetClass, boolean readOnly) { final JVMElementFactory factory = JVMElementFactories.getFactory(targetClass.getLanguage(), targetClass.getProject()); assert factory != null; PsiMethod method = factory.createMethod(getMethodName(), PsiTypes.voidType()); final GrReferenceExpression ref = getRefExpr(); if (GrStaticChecker.isInStaticContext(ref, targetClass)) { method.getModifierList().setModifierProperty(PsiModifier.STATIC, true); } PsiType[] argTypes = getArgumentTypes(); assert argTypes != null; ChooseTypeExpression[] paramTypesExpressions = setupParams(method, argTypes, factory); TypeConstraint[] constraints = getReturnTypeConstraints(); final PsiGenerationInfo<PsiMethod> info = OverrideImplementUtil.createGenerationInfo(method); if (!readOnly) { info.insert(targetClass, findInsertionAnchor(info, targetClass), false); } method = info.getPsiMember(); if (shouldBeAbstract(targetClass)) { method.getBody().delete(); if (!targetClass.isInterface()) { method.getModifierList().setModifierProperty(PsiModifier.ABSTRACT, true); } } return new Data(paramTypesExpressions, method, constraints); }
generateMethod
31,995
PsiType[] () { return PsiUtil.getArgumentTypes(getRefExpr(), false); }
getArgumentTypes
31,996
String () { return getRefExpr().getReferenceName(); }
getMethodName
31,997
boolean (PsiClass aClass) { return aClass.isInterface() && !GrTraitUtil.isTrait(aClass); }
shouldBeAbstract
31,998
PsiElement (PsiGenerationInfo<PsiMethod> info, PsiClass targetClass) { PsiElement parent = targetClass instanceof GroovyScriptClass ? ((GroovyScriptClass)targetClass).getContainingFile() : targetClass; if (PsiTreeUtil.isAncestor(parent, getRefExpr(), false)) { return info.findInsertionAnchor(targetClass, getRefExpr()); } else { return null; } }
findInsertionAnchor
31,999
String () { return getText(); }
getFamilyName