Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
30,900
void () { final GrVariable var = mySettings.getVar(); if (var != null && mySettings.removeLocalVariable()) { var.delete(); } }
processVar
30,901
void () { final StringPartInfo stringPartInfo = mySettings.getStringPartInfo(); if (stringPartInfo != null) { final GrExpression expr = mySettings.getStringPartInfo().replaceLiteralWithConcatenation(mySettings.getName()); final Editor editor = PsiEditorUtil.findEditor(expr); if (editor != null) { editor.getSelectionModel().removeSelection(); editor.getCaretModel().moveToOffset(expr.getTextRange().getEndOffset()); } } }
processStringPart
30,902
void (UsageInfo[] usages, GroovyPsiElementFactory factory) { // Replacing expression occurrences for (UsageInfo usage : usages) { if (usage instanceof ChangedMethodCallInfo) { PsiElement element = usage.getElement(); GroovyIntroduceParameterUtil.processChangedMethodCall(element, mySettings, myProject); } else if (usage instanceof InternalUsageInfo) { PsiElement element = usage.getElement(); if (element == null) continue; GrExpression newExpr = factory.createExpressionFromText(mySettings.getName()); if (element instanceof GrExpression) { ((GrExpression)element).replaceWithExpression(newExpr, true); } else { element.replace(newExpr); } } } }
processUsages
30,903
void (UsageInfo[] usages, GrMethod toReplaceIn, PsiMethod toSearchFor, boolean methodsToProcessAreDifferent) { IntroduceParameterUtil.changeMethodSignatureAndResolveFieldConflicts(new UsageInfo(toReplaceIn), usages, this); if (methodsToProcessAreDifferent) { IntroduceParameterUtil.changeMethodSignatureAndResolveFieldConflicts(new UsageInfo(toSearchFor), usages, this); } }
processMethodSignature
30,904
void (GrMethod toReplaceIn, PsiMethod toSearchFor, boolean methodsToProcessAreDifferent) { GroovyIntroduceParameterUtil.generateDelegate(toReplaceIn, myParameterInitializer, myProject); if (methodsToProcessAreDifferent) { final GrMethod method = GroovyIntroduceParameterUtil.generateDelegate(toSearchFor, myParameterInitializer, myProject); final PsiClass containingClass = method.getContainingClass(); if (containingClass != null && containingClass.isInterface()) { final GrOpenBlock block = method.getBlock(); if (block != null) { block.delete(); } } } }
generateDelegate
30,905
String () { return JavaRefactoringBundle.message("introduce.parameter.command", DescriptiveNameUtil.getDescriptiveName(mySettings.getToReplaceIn())); }
getCommandName
30,906
Project () { return mySettings.getProject(); }
getProject
30,907
PsiMethod () { return (PsiMethod)mySettings.getToReplaceIn(); }
getMethodToReplaceIn
30,908
PsiMethod () { return (PsiMethod)mySettings.getToSearchFor(); }
getMethodToSearchFor
30,909
String () { return mySettings.getName(); }
getParameterName
30,910
int () { return mySettings.replaceFieldsWithGetters(); }
getReplaceFieldsWithGetters
30,911
boolean () { return mySettings.declareFinal(); }
isDeclareFinal
30,912
boolean () { return mySettings.generateDelegate(); }
isGenerateDelegate
30,913
PsiType () { final PsiType selectedType = mySettings.getSelectedType(); if (selectedType != null) return selectedType; final PsiManager manager = PsiManager.getInstance(myProject); final GlobalSearchScope resolveScope = mySettings.getToReplaceIn().getResolveScope(); return PsiType.getJavaLangObject(manager, resolveScope); }
getForcedType
30,914
IntList () { return mySettings.parametersToRemove(); }
getParameterListToRemove
30,915
String () { return "IntroduceParameter"; }
getActionName
30,916
JComponent () { JPanel previewPanel = new JPanel(new BorderLayout()); previewPanel.add(getPreviewEditor().getComponent(), BorderLayout.CENTER); previewPanel.setBorder(new EmptyBorder(2, 2, 6, 2)); myDelegateCB = new JBCheckBox(GroovyBundle.message("checkbox.delegate.via.overloading.method")); myDelegateCB.setMnemonic(KeyEvent.VK_L); myDelegateCB.setFocusable(false); JPanel panel = new JPanel(new BorderLayout()); panel.add(previewPanel, BorderLayout.CENTER); panel.add(myDelegateCB, BorderLayout.SOUTH); return panel; }
getComponent
30,917
void (@NotNull GrVariable variable) { }
saveSettings
30,918
void (@Nullable GrVariable variable) { if (variable == null) return; updateTitle(variable, variable.getName()); }
updateTitle
30,919
void (@Nullable GrVariable variable, String value) { if (getPreviewEditor() == null || variable == null) return; final PsiElement declarationScope = ((PsiParameter)variable).getDeclarationScope(); if (declarationScope instanceof PsiMethod psiMethod) { final StringBuilder buf = new StringBuilder(); buf.append(psiMethod.getName()).append(" ("); boolean frst = true; final List<TextRange> ranges2Remove = new ArrayList<>(); TextRange addedRange = null; int i = 0; for (PsiParameter parameter : psiMethod.getParameterList().getParameters()) { if (frst) { frst = false; } else { buf.append(", "); } int startOffset = buf.length(); /*if (myMustBeFinal || myPanel.isGenerateFinal()) { buf.append("final "); }*/ buf.append(parameter.getType().getPresentableText()).append(" ").append(variable == parameter ? value : parameter.getName()); int endOffset = buf.length(); if (variable == parameter) { addedRange = new TextRange(startOffset, endOffset); } else if (myParametersToRemove.contains(i)) { ranges2Remove.add(new TextRange(startOffset, endOffset)); } i++; } assert addedRange != null; buf.append(")"); setPreviewText(buf.toString()); final MarkupModel markupModel = DocumentMarkupModel.forDocument(getPreviewEditor().getDocument(), myProject, true); markupModel.removeAllHighlighters(); for (TextRange textRange : ranges2Remove) { markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(), 0, getTestAttributesForRemoval(), HighlighterTargetArea.EXACT_RANGE); } markupModel.addRangeHighlighter(addedRange.getStartOffset(), addedRange.getEndOffset(), 0, getTextAttributesForAdd(), HighlighterTargetArea.EXACT_RANGE); //revalidate(); } }
updateTitle
30,920
TextAttributes () { final TextAttributes textAttributes = new TextAttributes(); textAttributes.setEffectType(EffectType.ROUNDED_BOX); textAttributes.setEffectColor(JBColor.RED); return textAttributes; }
getTextAttributesForAdd
30,921
TextAttributes () { final TextAttributes textAttributes = new TextAttributes(); textAttributes.setEffectType(EffectType.STRIKEOUT); textAttributes.setEffectColor(JBColor.BLACK); return textAttributes; }
getTestAttributesForRemoval
30,922
GrVariable (GrIntroduceContext context, GrIntroduceParameterSettings settings, boolean processUsages) { GrExpressionWrapper wrapper = createExpressionWrapper(context); if (processUsages) { GrIntroduceExpressionSettingsImpl patchedSettings = new GrIntroduceExpressionSettingsImpl(settings, settings.getName(), settings.declareFinal(), settings.parametersToRemove(), settings.generateDelegate(), settings.replaceFieldsWithGetters(), context.getExpression(), context.getVar(), settings.getSelectedType(), context.getVar() != null || settings.replaceAllOccurrences(), context.getVar() != null, settings.isForceReturn()); GrIntroduceParameterProcessor processor = new GrIntroduceParameterProcessor(patchedSettings, wrapper); processor.run(); } else { WriteAction.run(() -> new GrIntroduceParameterProcessor(settings, wrapper).performRefactoring(UsageInfo.EMPTY_ARRAY)); } GrParameterListOwner owner = settings.getToReplaceIn(); return ArrayUtil.getLastElement(owner.getParameters()); }
runRefactoring
30,923
GrExpressionWrapper (@NotNull GrIntroduceContext context) { GrExpression expression = context.getExpression(); GrVariable var = context.getVar(); assert expression != null || var != null ; GrExpression initializer = expression != null ? expression : var.getInitializerGroovy(); return new GrExpressionWrapper(initializer); }
createExpressionWrapper
30,924
GrIntroduceParameterSettings (@NotNull GrIntroduceContext context, @NotNull OccurrencesChooser.ReplaceChoice choice, String[] names) { GrExpression expression = context.getExpression(); GrVariable var = context.getVar(); PsiType type = var != null ? var.getDeclaredType() : expression != null ? expression.getType() : null; return new GrIntroduceExpressionSettingsImpl(myInfo, names[0], false, new IntArrayList(), false, IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, expression, var, type, false, false, false); }
getInitialSettingsForInplace
30,925
GrIntroduceParameterSettings () { return new GrIntroduceExpressionSettingsImpl(myInfo, getInputName(), false, myParametersToRemove, myDelegateCB.isSelected(), IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, null, null, getSelectedType(), isReplaceAllOccurrences(), false, false); }
getSettings
30,926
GrVariable () { return myVar; }
getVar
30,927
GrExpression () { return myExpr; }
getExpression
30,928
PsiType () { return mySelectedType; }
getSelectedType
30,929
boolean () { return myRemoveLocalVar; }
removeLocalVariable
30,930
UsageViewDescriptor (final UsageInfo @NotNull [] usages) { return new UsageViewDescriptorAdapter() { @Override public PsiElement @NotNull [] getElements() { return new PsiElement[]{toSearchFor != null ? toSearchFor : toReplaceIn}; } @Override public String getProcessedElementsHeader() { return GroovyRefactoringBundle.message("introduce.closure.parameter.elements.header"); } }; }
createUsageViewDescriptor
30,931
String () { return GroovyRefactoringBundle.message("introduce.closure.parameter.elements.header"); }
getProcessedElementsHeader
30,932
boolean (@NotNull Ref<UsageInfo[]> refUsages) { UsageInfo[] usagesIn = refUsages.get(); MultiMap<PsiElement, String> conflicts = new MultiMap<>(); if (!mySettings.generateDelegate()) { detectAccessibilityConflicts(usagesIn, conflicts); } final GrExpression expression = mySettings.getExpression(); if (expression != null && toSearchFor instanceof PsiMember) { final AnySupers anySupers = new AnySupers(); expression.accept(anySupers); if (anySupers.containsSupers()) { final PsiElement containingClass = PsiUtil.getFileOrClassContext(toReplaceIn); for (UsageInfo usageInfo : usagesIn) { if (!(usageInfo.getElement() instanceof PsiMethod) && !(usageInfo instanceof InternalUsageInfo)) { if (!PsiTreeUtil.isAncestor(containingClass, usageInfo.getElement(), false)) { conflicts.putValue(expression, JavaRefactoringBundle .message("parameter.initializer.contains.0.but.not.all.calls.to.method.are.in.its.class", CommonRefactoringUtil.htmlEmphasize(PsiKeyword.SUPER))); break; } } } } } //todo //for (IntroduceParameterMethodUsagesProcessor processor : IntroduceParameterMethodUsagesProcessor.EP_NAME.getExtensions()) { //processor.findConflicts(this, refUsages.get(), conflicts); //} return showConflicts(conflicts, usagesIn); }
preprocessUsages
30,933
void (final UsageInfo[] usageArray, MultiMap<PsiElement, String> conflicts) { //todo whole method final GrExpression expression = mySettings.getExpression(); if (expression == null) return; GroovyIntroduceParameterUtil.detectAccessibilityConflicts(expression, usageArray, conflicts, mySettings.replaceFieldsWithGetters() != IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, myProject); }
detectAccessibilityConflicts
30,934
Collection<PsiReference> (GrClosableBlock initializer, final GrVariable var) { GrControlFlowOwner owner = ControlFlowUtils.findControlFlowOwner(initializer); if (owner == null) return Collections.emptyList(); final GroovyControlFlow flow = ControlFlowUtils.getGroovyControlFlow(owner); final List<BitSet> writes = ControlFlowUtils.inferWriteAccessMap(flow, var); Instruction writeInstr = null; final PsiElement parent = initializer.getParent(); if (parent instanceof GrVariable) { writeInstr = ContainerUtil.find(flow.getFlow(), instruction -> instruction.getElement() == var); } else if (parent instanceof GrAssignmentExpression) { final GrReferenceExpression refExpr = (GrReferenceExpression)((GrAssignmentExpression)parent).getLValue(); final Instruction instruction = ContainerUtil.find(flow.getFlow(), instruction1 -> instruction1.getElement() == refExpr); LOG.assertTrue(instruction != null); final BitSet prev = writes.get(instruction.num()); if (prev.cardinality() == 1) { writeInstr = flow.getFlow()[prev.nextSetBit(0)]; } } LOG.assertTrue(writeInstr != null); Collection<PsiReference> result = new ArrayList<>(); for (Instruction instruction : flow.getFlow()) { if (!(instruction instanceof ReadWriteVariableInstruction)) continue; if (((ReadWriteVariableInstruction)instruction).isWrite()) continue; final PsiElement element = instruction.getElement(); if (element instanceof GrVariable && element != var) continue; if (!(element instanceof GrReferenceExpression ref)) continue; if (ref.isQualified() || ref.resolve() != var) continue; final BitSet prev = writes.get(instruction.num()); if (prev.cardinality() == 1 && prev.get(writeInstr.num())) { result.add(ref); } } return result; }
findUsagesForLocal
30,935
void (UsageInfo @NotNull [] usages) { processExternalUsages(usages, mySettings, myParameterInitializer.getExpression()); processClosure(usages, mySettings); final GrVariable var = mySettings.getVar(); if (var != null && mySettings.removeLocalVariable()) { var.delete(); } }
performRefactoring
30,936
void (UsageInfo[] usages, GrIntroduceParameterSettings settings) { changeSignature((GrClosableBlock)settings.getToReplaceIn(), settings); processInternalUsages(usages, settings); }
processClosure
30,937
void (UsageInfo[] usages, GrIntroduceParameterSettings settings) { final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(settings.getProject()); // Replacing expression occurrences for (UsageInfo usage : usages) { if (usage instanceof ChangedMethodCallInfo) { PsiElement element = usage.getElement(); processChangedMethodCall(element, settings); } else if (usage instanceof InternalUsageInfo) { PsiElement element = usage.getElement(); if (element == null) continue; GrExpression newExpr = factory.createExpressionFromText(settings.getName()); if (element instanceof GrExpression) { ((GrExpression)element).replaceWithExpression(newExpr, true); } else { element.replace(newExpr); } } } final StringPartInfo info = settings.getStringPartInfo(); if (info != null) { final GrExpression expr = info.replaceLiteralWithConcatenation(settings.getName()); final Editor editor = PsiEditorUtil.findEditor(expr); if (editor != null) { editor.getSelectionModel().removeSelection(); editor.getCaretModel().moveToOffset(expr.getTextRange().getEndOffset()); } } }
processInternalUsages
30,938
void (UsageInfo[] usages, GrIntroduceParameterSettings settings, PsiElement expression) { for (UsageInfo usage : usages) { if (usage instanceof ExternalUsageInfo) { processExternalUsage(usage, settings, expression); } } }
processExternalUsages
30,939
void (GrClosableBlock block, GrIntroduceParameterSettings settings) { final String name = settings.getName(); final FieldConflictsResolver fieldConflictsResolver = new FieldConflictsResolver(name, block); final GrParameter[] parameters = block.getParameters(); for (int i = settings.parametersToRemove().size() - 1; i >= 0; i--) { try { PsiParameter param = parameters[settings.parametersToRemove().getInt(i)]; param.delete(); } catch (IncorrectOperationException e) { LOG.error(e); } } final PsiType type = settings.getSelectedType(); final String typeText = type == null ? null : type.getCanonicalText(); final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(settings.getProject()); GrParameter parameter = factory.createParameter(name, typeText, block); parameter.getModifierList().setModifierProperty(PsiModifier.FINAL, settings.declareFinal()); final GrParameterList parameterList = block.getParameterList(); final PsiParameter anchorParameter = GroovyIntroduceParameterUtil.getAnchorParameter(parameterList, block.isVarArgs()); parameter = (GrParameter)parameterList.addAfter(parameter, anchorParameter); if (block.getArrow() == null) { final PsiElement arrow = block.addAfter(factory.createClosureFromText("{->}").getArrow().copy(), parameterList); final PsiElement child = block.getFirstChild().getNextSibling(); if (PsiImplUtil.isWhiteSpaceOrNls(child)) { final String text = child.getText(); child.delete(); block.addAfter(factory.createLineTerminator(text), arrow); } } JavaCodeStyleManager.getInstance(parameter.getProject()).shortenClassReferences(parameter); fieldConflictsResolver.fix(); }
changeSignature
30,940
void (UsageInfo usage, GrIntroduceParameterSettings settings, PsiElement expression) { final PsiElement element = usage.getElement(); GrCall callExpression = GroovyRefactoringUtil.getCallExpressionByMethodReference(element); if (callExpression == null) { final PsiElement parent = element.getParent(); if (parent instanceof GrReferenceExpression && element == ((GrReferenceExpression)parent).getQualifier() && "call".equals( ((GrReferenceExpression)parent).getReferenceName())) { callExpression = GroovyRefactoringUtil.getCallExpressionByMethodReference(parent); } } if (callExpression == null) return; //LOG.assertTrue(callExpression != null); //check for x.getFoo()(args) if (callExpression instanceof GrMethodCall) { final GrExpression invoked = ((GrMethodCall)callExpression).getInvokedExpression(); if (invoked instanceof GrReferenceExpression) { final GroovyResolveResult result = ((GrReferenceExpression)invoked).advancedResolve(); final PsiElement resolved = result.getElement(); if (resolved instanceof GrAccessorMethod && !result.isInvokedOnProperty()) { PsiElement actualCallExpression = callExpression.getParent(); if (actualCallExpression instanceof GrCall) { callExpression = (GrCall)actualCallExpression; } } } } GrArgumentList argList = callExpression.getArgumentList(); LOG.assertTrue(argList != null); GrExpression[] oldArgs = argList.getExpressionArguments(); GrClosableBlock toReplaceIn = (GrClosableBlock)settings.getToReplaceIn(); GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(settings.getProject()); final GrExpression anchor = getAnchorForArgument(oldArgs, toReplaceIn.isVarArgs(), toReplaceIn.getParameterList()); GrSignature signature = GrClosureSignatureUtil.createSignature(callExpression); if (signature == null) signature = GrClosureSignatureUtil.createSignature(toReplaceIn); final GrClosureSignatureUtil.ArgInfo<PsiElement>[] actualArgs = GrClosureSignatureUtil .mapParametersToArguments(signature, callExpression.getNamedArguments(), callExpression.getExpressionArguments(), callExpression.getClosureArguments(), callExpression, true, true); if (PsiTreeUtil.isAncestor(toReplaceIn, callExpression, false)) { argList.addAfter(factory.createExpressionFromText(settings.getName()), anchor); } else { PsiElement initializer = ExpressionConverter.getExpression(expression, GroovyLanguage.INSTANCE, settings.getProject()); LOG.assertTrue(initializer instanceof GrExpression); GrExpression newArg = GroovyIntroduceParameterUtil.addClosureToCall(initializer, argList); if (newArg == null) { final PsiElement dummy = argList.addAfter(factory.createExpressionFromText("1"), anchor); newArg = ((GrExpression)dummy).replaceWithExpression((GrExpression)initializer, true); } new OldReferencesResolver(callExpression, newArg, toReplaceIn, settings.replaceFieldsWithGetters(), initializer, signature, actualArgs, toReplaceIn.getParameters()).resolve(); ChangeContextUtil.clearContextInfo(initializer); //newarg can be replaced by OldReferenceResolve if (newArg.isValid()) { JavaCodeStyleManager.getInstance(newArg.getProject()).shortenClassReferences(newArg); CodeStyleManager.getInstance(settings.getProject()).reformat(newArg); } } if (actualArgs == null) { GroovyIntroduceParameterUtil .removeParamsFromUnresolvedCall(callExpression, toReplaceIn.getParameters(), settings.parametersToRemove()); } else { GroovyIntroduceParameterUtil.removeParametersFromCall(actualArgs, settings.parametersToRemove()); } if (argList.getAllArguments().length == 0 && callExpression.hasClosureArguments()) { final GrArgumentList emptyArgList = ((GrMethodCallExpression)factory.createExpressionFromText("foo{}")).getArgumentList(); argList.replace(emptyArgList); } }
processExternalUsage
30,941
GrExpression (GrExpression[] oldArgs, boolean isVarArg, PsiParameterList parameterList) { if (!isVarArg) return ArrayUtil.getLastElement(oldArgs); final PsiParameter[] parameters = parameterList.getParameters(); if (parameters.length > oldArgs.length) return ArrayUtil.getLastElement(oldArgs); final int lastNonVararg = parameters.length - 2; return lastNonVararg >= 0 ? oldArgs[lastNonVararg] : null; }
getAnchorForArgument
30,942
GrClosableBlock (GrClosableBlock originalClosure, GrVariable anchor, String newName) { GrClosableBlock result; if (originalClosure.hasParametersSection()) { result = myFactory.createClosureFromText("{->}", anchor); final GrParameterList parameterList = (GrParameterList)originalClosure.getParameterList().copy(); result.getParameterList().replace(parameterList); } else { result = myFactory.createClosureFromText("{}", anchor); } StringBuilder call = new StringBuilder(); call.append(newName).append('('); final GrParameter[] parameters = result.getParameters(); for (int i = 0; i < parameters.length; i++) { if (!mySettings.parametersToRemove().contains(i)) { call.append(parameters[i].getName()).append(", "); } } call.append(myParameterInitializer.getText()); call.append(")"); final GrStatement statement = myFactory.createStatementFromText(call.toString()); result.addStatementBefore(statement, null); return result; }
generateDelegateClosure
30,943
GrVariableDeclaration (GrVariable original, GrVariableDeclaration declaration) { if (original instanceof GrField) { final PsiClass containingClass = ((GrField)original).getContainingClass(); LOG.assertTrue(containingClass != null); return (GrVariableDeclaration)containingClass.addBefore(declaration, original.getParent()); } final GrStatementOwner block; if (original instanceof PsiParameter) { final PsiElement container = original.getParent().getParent(); if (container instanceof GrMethod) { block = ((GrMethod)container).getBlock(); } else if (container instanceof GrClosableBlock) { block = (GrCodeBlock)container; } else if (container instanceof GrForStatement) { final GrStatement body = ((GrForStatement)container).getBody(); if (body instanceof GrBlockStatement) { block = ((GrBlockStatement)body).getBlock(); } else { GrBlockStatement blockStatement = myFactory.createBlockStatement(); LOG.assertTrue(blockStatement != null); if (body != null) { blockStatement.getBlock().addStatementBefore((GrStatement)body.copy(), null); blockStatement = (GrBlockStatement)body.replace(blockStatement); } else { blockStatement = (GrBlockStatement)container.add(blockStatement); } block = blockStatement.getBlock(); } } else { throw new IncorrectOperationException(); } LOG.assertTrue(block != null); return (GrVariableDeclaration)block.addStatementBefore(declaration, null); } PsiElement parent = original.getParent(); LOG.assertTrue(parent instanceof GrVariableDeclaration); final PsiElement pparent = parent.getParent(); if (pparent instanceof GrIfStatement) { if (((GrIfStatement)pparent).getThenBranch() == parent) { block = ((GrIfStatement)pparent).replaceThenBranch(myFactory.createBlockStatement()).getBlock(); } else { block = ((GrIfStatement)pparent).replaceElseBranch(myFactory.createBlockStatement()).getBlock(); } parent = block.addStatementBefore(((GrVariableDeclaration)parent), null); } else if (pparent instanceof GrLoopStatement) { block = ((GrLoopStatement)pparent).replaceBody(myFactory.createBlockStatement()).getBlock(); parent = block.addStatementBefore(((GrVariableDeclaration)parent), null); } else { LOG.assertTrue(pparent instanceof GrStatementOwner); block = (GrStatementOwner)pparent; } return (GrVariableDeclaration)block.addStatementBefore(declaration, (GrStatement)parent); }
insertDeclaration
30,944
void (PsiElement element, GrIntroduceParameterSettings settings) { if (element.getParent() instanceof GrMethodCallExpression methodCall) { final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(settings.getProject()); GrExpression expression = factory.createExpressionFromText(settings.getName(), null); final GrArgumentList argList = methodCall.getArgumentList(); final PsiElement[] exprs = argList.getAllArguments(); if (exprs.length > 0) { argList.addAfter(expression, exprs[exprs.length - 1]); } else { argList.add(expression); } removeParametersFromCall(methodCall, settings); } else { LOG.error("Unexpected parent type " + element.getParent()); } }
processChangedMethodCall
30,945
void (GrMethodCallExpression methodCall, GrIntroduceParameterSettings settings) { final GroovyResolveResult resolveResult = methodCall.advancedResolve(); final PsiElement resolved = resolveResult.getElement(); LOG.assertTrue(resolved instanceof PsiMethod); final GrSignature signature = GrClosureSignatureUtil.createSignature((PsiMethod)resolved, resolveResult.getSubstitutor()); final GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos = GrClosureSignatureUtil.mapParametersToArguments(signature, methodCall); LOG.assertTrue(argInfos != null); settings.parametersToRemove().forEach((IntConsumer)value -> { final List<PsiElement> args = argInfos[value].args; for (PsiElement arg : args) { arg.delete(); } }); }
removeParametersFromCall
30,946
String () { return JavaRefactoringBundle.message("introduce.parameter.command", DescriptiveNameUtil.getDescriptiveName(mySettings.getToReplaceIn())); }
getCommandName
30,947
PsiField[] (GrStatement[] statements, PsiClass containingClass) { if (containingClass == null) return PsiField.EMPTY_ARRAY; final FieldSearcher searcher = new FieldSearcher(containingClass); for (GrStatement statement : statements) { statement.accept(searcher); } return searcher.getResult(); }
findUsedFieldsWithGetters
30,948
PsiParameter (PsiParameterList parameterList, boolean isVarArgs) { final PsiParameter[] parameters = parameterList.getParameters(); final int length = parameters.length; if (isVarArgs) { return length > 1 ? parameters[length - 2] : null; } else { return length > 0 ? parameters[length - 1] : null; } }
getAnchorParameter
30,949
void (final GrClosureSignatureUtil.ArgInfo<PsiElement>[] actualArgs, final IntList parametersToRemove) { parametersToRemove.forEach((IntConsumer)paramNum -> { try { final GrClosureSignatureUtil.ArgInfo<PsiElement> actualArg = actualArgs[paramNum]; for (PsiElement arg : actualArg.args) { arg.delete(); } } catch (IncorrectOperationException e) { LOG.error(e); } }); }
removeParametersFromCall
30,950
void (GrCall callExpression, PsiParameter[] parameters, IntList parametersToRemove) { final GrExpression[] arguments = callExpression.getExpressionArguments(); final GrClosableBlock[] closureArguments = callExpression.getClosureArguments(); final GrNamedArgument[] namedArguments = callExpression.getNamedArguments(); final boolean hasNamedArgs; if (namedArguments.length > 0) { if (parameters.length > 0) { final PsiType type = parameters[0].getType(); hasNamedArgs = InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_MAP); } else { hasNamedArgs = false; } } else { hasNamedArgs = false; } for (int i = parametersToRemove.size() - 1; i >= 0; i--) { int paramNum = parametersToRemove.getInt(i); try { if (paramNum == 0 && hasNamedArgs) { for (GrNamedArgument namedArgument : namedArguments) { namedArgument.delete(); } } else { if (hasNamedArgs) paramNum--; if (paramNum < arguments.length) { arguments[paramNum].delete(); } else if (paramNum < arguments.length + closureArguments.length) { closureArguments[paramNum - arguments.length].delete(); } } } catch (IncorrectOperationException e) { LOG.error(e); } } }
removeParamsFromUnresolvedCall
30,951
void (@Nullable GroovyPsiElement elementToProcess, final UsageInfo[] usages, MultiMap<PsiElement, String> conflicts, boolean replaceFieldsWithGetters, Project project) { if (elementToProcess == null) return; final ReferencedElementsCollector collector = new ReferencedElementsCollector(); elementToProcess.accept(collector); final List<PsiElement> result = collector.getResult(); if (result.isEmpty()) return; for (final UsageInfo usageInfo : usages) { if (!(usageInfo instanceof ExternalUsageInfo) || !IntroduceParameterUtil.isMethodUsage(usageInfo)) continue; final PsiElement place = usageInfo.getElement(); for (PsiElement element : result) { if (element instanceof PsiField && replaceFieldsWithGetters) { //check getter access instead final PsiClass psiClass = ((PsiField)element).getContainingClass(); LOG.assertTrue(psiClass != null); final PsiMethod method = GroovyPropertyUtils.findGetterForField((PsiField)element); if (method != null) { element = method; } } if (element instanceof PsiMember && !JavaPsiFacade.getInstance(project).getResolveHelper().isAccessible((PsiMember)element, place, null)) { String message = JavaRefactoringBundle.message( "0.is.not.accessible.from.1.value.for.introduced.parameter.in.that.method.call.will.be.incorrect", RefactoringUIUtil.getDescription(element, true), RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(place), true)); conflicts.putValue(element, message); } } } }
detectAccessibilityConflicts
30,952
void (PsiElement element, GrIntroduceParameterSettings settings, Project project) { if (!(element.getParent() instanceof GrMethodCallExpression methodCall)) { LOG.error("Unexpected parent type: " + element.getParent()); return; } GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project); final String name = settings.getName(); LOG.assertTrue(name != null); GrExpression expression = factory.createExpressionFromText(name, null); final GrArgumentList argList = methodCall.getArgumentList(); final PsiElement[] exprs = argList.getAllArguments(); if (exprs.length > 0) { argList.addAfter(expression, exprs[exprs.length - 1]); } else { argList.add(expression); } removeParametersFromCall(methodCall, settings); }
processChangedMethodCall
30,953
void (GrMethodCallExpression methodCall, GrIntroduceParameterSettings settings) { final GroovyResolveResult resolveResult = methodCall.advancedResolve(); final PsiElement resolved = resolveResult.getElement(); LOG.assertTrue(resolved instanceof PsiMethod); final GrSignature signature = GrClosureSignatureUtil.createSignature((PsiMethod)resolved, resolveResult.getSubstitutor()); final GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos = GrClosureSignatureUtil.mapParametersToArguments(signature, methodCall); LOG.assertTrue(argInfos != null); settings.parametersToRemove().forEach((IntConsumer)value -> { final List<PsiElement> args = argInfos[value].args; for (PsiElement arg : args) { arg.delete(); } }); }
removeParametersFromCall
30,954
GrMethod (PsiMethod prototype, IntroduceParameterData.ExpressionWrapper initializer, Project project) { final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project); GrMethod result; if (prototype instanceof GrMethod) { result = (GrMethod)prototype.copy(); } else { StringBuilder builder = new StringBuilder(); builder.append(prototype.getModifierList().getText()).append(' '); if (prototype.getReturnTypeElement() != null ) { builder.append(prototype.getReturnTypeElement().getText()); } builder.append(' ').append(prototype.getName()); builder.append(prototype.getParameterList().getText()); builder.append("{}"); result = factory.createMethodFromText(builder.toString()); } StringBuilder call = new StringBuilder(); call.append("def foo(){\n"); final GrParameter[] parameters = result.getParameters(); call.append(prototype.getName()); if (initializer.getExpression() instanceof GrClosableBlock) { if (parameters.length > 0) { call.append('('); for (GrParameter parameter : parameters) { call.append(parameter.getName()).append(", "); } call.replace(call.length()-2, call.length(), ")"); } call.append(initializer.getText()); } else { call.append('('); for (GrParameter parameter : parameters) { call.append(parameter.getName()).append(", "); } call.append(initializer.getText()); call.append(")"); } call.append("\n}"); final GrOpenBlock block = factory.createMethodFromText(call.toString()).getBlock(); result.getBlock().replace(block); final PsiElement parent = prototype.getParent(); final GrMethod method = (GrMethod)parent.addBefore(result, prototype); JavaCodeStyleManager.getInstance(method.getProject()).shortenClassReferences(method); return method; }
generateDelegate
30,955
Object2IntMap<GrParameter> (IntroduceParameterInfo helper) { final Object2IntMap<GrParameter> result = new Object2IntOpenHashMap<>(); final TextRange range = ExtractUtil.getRangeOfRefactoring(helper); GrParameter[] parameters = helper.getToReplaceIn().getParameters(); for (int i = 0; i < parameters.length; i++) { GrParameter parameter = parameters[i]; if (shouldRemove(parameter, range.getStartOffset(), range.getEndOffset())) { result.put(parameter, i); } } return result; }
findParametersToRemove
30,956
boolean (GrParameter parameter, int start, int end) { for (PsiReference reference : ReferencesSearch.search(parameter)) { final PsiElement element = reference.getElement(); final int offset = element.getTextRange().getStartOffset(); if (offset < start || end <= offset) { return false; } } return true; }
shouldRemove
30,957
PsiElement[] (GrIntroduceParameterSettings settings) { final GrParameterListOwner scope = settings.getToReplaceIn(); final GrExpression expression = settings.getExpression(); if (expression != null) { final PsiElement expr = PsiUtil.skipParentheses(expression, false); if (expr == null) return PsiElement.EMPTY_ARRAY; final PsiElement[] occurrences = GroovyRefactoringUtil.getExpressionOccurrences(expr, scope); if (occurrences.length == 0) { throw new GrRefactoringError(GroovyRefactoringBundle.message("no.occurrences.found")); } return occurrences; } else { final GrVariable var = settings.getVar(); LOG.assertTrue(var != null); final List<PsiElement> list = Collections.synchronizedList(new ArrayList<>()); ReferencesSearch.search(var, new LocalSearchScope(scope)).forEach(psiReference -> { list.add(psiReference.getElement()); return true; }); return list.toArray(PsiElement.EMPTY_ARRAY); } }
getOccurrences
30,958
GrExpression (PsiElement initializer, GrArgumentList list) { if (!(initializer instanceof GrClosableBlock)) return null; final PsiElement parent = list.getParent(); if (!(parent instanceof GrMethodCallExpression)) return null; PsiElement anchor; final GrClosableBlock[] cls = ((GrMethodCallExpression)parent).getClosureArguments(); if (cls.length > 0) { anchor = cls[cls.length - 1]; } else { anchor = list; } return (GrExpression)parent.addAfter(initializer, anchor); }
addClosureToCall
30,959
GrVariable (IntroduceParameterInfo info) { GrVariable variable = info.getVar(); if (variable != null) return variable; final GrStatement[] statements = info.getStatements(); if (statements.length != 1) return null; return GrIntroduceHandlerBase.findVariable(statements[0]); }
findVar
30,960
GrExpression (IntroduceParameterInfo info) { final GrStatement[] statements = info.getStatements(); if (statements.length != 1) return null; return GrIntroduceHandlerBase.findExpression(statements[0]); }
findExpr
30,961
LinkedHashSet<String> (GrVariable var, GrExpression expr, StringPartInfo stringPart, GrParameterListOwner scope, Project project) { if (expr != null) { final GrIntroduceContext introduceContext = new GrIntroduceContextImpl(project, null, expr, var, stringPart, PsiElement.EMPTY_ARRAY, scope); final GroovyFieldValidator validator = new GroovyFieldValidator(introduceContext); return new LinkedHashSet<>(Arrays.asList(GroovyNameSuggestionUtil.suggestVariableNames(expr, validator, true))); } else if (var != null) { final GrIntroduceContext introduceContext = new GrIntroduceContextImpl(project, null, expr, var, stringPart, PsiElement.EMPTY_ARRAY, scope); final GroovyFieldValidator validator = new GroovyFieldValidator(introduceContext); LinkedHashSet<String> names = new LinkedHashSet<>(); names.add(var.getName()); ContainerUtil.addAll(names, GroovyNameSuggestionUtil.suggestVariableNameByType(var.getType(), validator)); return names; } else { LinkedHashSet<String> names = new LinkedHashSet<>(); names.add("closure"); return names; } }
suggestNames
30,962
PsiField[] () { return result.toArray(PsiField.EMPTY_ARRAY); }
getResult
30,963
void (@NotNull GrReferenceExpression ref) { super.visitReferenceExpression(ref); final GrExpression qualifier = ref.getQualifier(); if (!PsiUtil.isThisReference(qualifier)) return; final PsiElement resolved = ref.resolve(); if (!(resolved instanceof PsiField)) return; final PsiMethod getter = GroovyPropertyUtils.findGetterForField((PsiField)resolved); if (getter != null) { result.add((PsiField)resolved); } }
visitReferenceExpression
30,964
void (@NotNull GrReferenceExpression referenceExpression) { add(referenceExpression); }
visitReferenceExpression
30,965
void (GrReferenceElement referenceExpression) { final PsiElement resolved = referenceExpression.resolve(); if (resolved != null) { myResult.add(resolved); } }
add
30,966
void (@NotNull GrCodeReferenceElement refElement) { add(refElement); }
visitCodeReferenceElement
30,967
List<PsiElement> () { return myResult; }
getResult
30,968
boolean (UsageInfo usage) { final PsiElement el = usage.getElement(); return el != null && GroovyLanguage.INSTANCE.equals(el.getLanguage()); }
isGroovyUsage
30,969
boolean (UsageInfo usage) { return GroovyRefactoringUtil.isMethodUsage(usage.getElement()) && isGroovyUsage(usage); }
isMethodUsage
30,970
void (IntroduceParameterData data, UsageInfo[] usages, MultiMap<PsiElement, String> conflicts) { }
findConflicts
30,971
GrExpression (GrExpression[] oldArgs) { GrExpression anchor; if (oldArgs.length > 0) { anchor = oldArgs[oldArgs.length - 1]; } else { anchor = null; } return anchor; }
getLast
30,972
void (final GrClosureSignatureUtil.ArgInfo<PsiElement>[] actualArgs, IntList parametersToRemove) { parametersToRemove.forEach((IntConsumer)paramNum -> { try { final GrClosureSignatureUtil.ArgInfo<PsiElement> actualArg = actualArgs[paramNum]; if (actualArg == null) { return; } for (PsiElement arg : actualArg.args) { arg.delete(); } } catch (IncorrectOperationException e) { LOG.error(e); } }); }
removeParametersFromCall
30,973
void (GrCall callExpression, IntroduceParameterData data) { final GrExpression[] arguments = callExpression.getExpressionArguments(); final GrClosableBlock[] closureArguments = callExpression.getClosureArguments(); final GrNamedArgument[] namedArguments = callExpression.getNamedArguments(); final boolean hasNamedArgs; if (namedArguments.length > 0) { final PsiMethod method = data.getMethodToSearchFor(); final PsiParameter[] parameters = method.getParameterList().getParameters(); if (parameters.length > 0) { final PsiType type = parameters[0].getType(); hasNamedArgs = InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_MAP); } else { hasNamedArgs = false; } } else { hasNamedArgs = false; } IntList parameterListToRemove = data.getParameterListToRemove(); for (int i = parameterListToRemove.size() - 1; i >= 0; i--) { int paramNum = parameterListToRemove.getInt(i); try { if (paramNum == 0 && hasNamedArgs) { for (GrNamedArgument namedArgument : namedArguments) { namedArgument.delete(); } } else { if (hasNamedArgs) paramNum--; if (paramNum < arguments.length) { arguments[paramNum].delete(); } else if (paramNum < arguments.length + closureArguments.length) { closureArguments[paramNum - arguments.length].delete(); } } } catch (IncorrectOperationException e) { LOG.error(e); } } }
removeParamsFromUnresolvedCall
30,974
GrParameter (@NotNull GrParameterListOwner parametersOwner, @Nullable MethodJavaDocHelper javaDocHelper, @NotNull PsiType forcedType, @NotNull String parameterName, boolean isFinal, @NotNull Project project) { GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project); final String typeText = forcedType.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) || forcedType == PsiTypes.nullType() || PsiTypes.voidType().equals(forcedType) ? null : forcedType.getCanonicalText(); GrParameter parameter = factory.createParameter(parameterName, typeText, parametersOwner); parameter.getModifierList().setModifierProperty(PsiModifier.FINAL, isFinal); final PsiParameter anchorParameter = getAnchorParameter(parametersOwner); final GrParameterList parameterList = parametersOwner.getParameterList(); parameter = (GrParameter)parameterList.addAfter(parameter, anchorParameter); JavaCodeStyleManager.getInstance(project).shortenClassReferences(parameter); if (javaDocHelper != null) { final PsiDocTag tagForAnchorParameter = javaDocHelper.getTagForParameter(anchorParameter); javaDocHelper.addParameterAfter(parameterName, tagForAnchorParameter); } return parameter; }
addParameter
30,975
PsiParameter (GrParameterListOwner parametersOwner) { PsiParameterList parameterList = parametersOwner.getParameterList(); final PsiParameter anchorParameter; final PsiParameter[] parameters = parameterList.getParameters(); final int length = parameters.length; if (!parametersOwner.isVarArgs()) { anchorParameter = length > 0 ? parameters[length - 1] : null; } else { anchorParameter = length > 1 ? parameters[length - 2] : null; } return anchorParameter; }
getAnchorParameter
30,976
boolean (IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) { if (!(usage.getElement() instanceof PsiClass aClass) || !isGroovyUsage(usage)) return true; final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(data.getProject()); GrMethod constructor = factory.createConstructorFromText(aClass.getName(), ArrayUtilRt.EMPTY_STRING_ARRAY, ArrayUtilRt.EMPTY_STRING_ARRAY, "{}"); constructor = (GrMethod)aClass.add(constructor); constructor.getModifierList().setModifierProperty(VisibilityUtil.getVisibilityModifier(aClass.getModifierList()), true); processAddSuperCall(data, new UsageInfo(constructor), usages); return false; }
processAddDefaultConstructor
30,977
GrExpression (GrMethodCall methodExpression) { final GroovyResolveResult result = methodExpression.advancedResolve(); if (!(result.getElement() instanceof GrAccessorMethod) || result.isInvokedOnProperty()) return null; final GrExpression invoked = methodExpression.getInvokedExpression(); if (invoked instanceof GrReferenceExpression) return ((GrReferenceExpression)invoked).getQualifier(); return null; }
getQualifierFromGetterCall
30,978
PsiElement (PsiElement newExpr, GrExpression actualArg, PsiParameter parameter) { if (myParamsToNotInline.contains(parameter)) return newExpr; GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(myProject); if (myExpr instanceof GrClosableBlock) { int count = 0; for (PsiReference reference : ReferencesSearch.search(parameter, new LocalSearchScope(myParameterInitializer))) { count++; if (count > 1) break; } if (count > 1) { myParamsToNotInline.add(parameter); final PsiType type; if (parameter instanceof GrParameter) { type = ((GrParameter)parameter).getDeclaredType(); } else { type = parameter.getType(); } final GrVariableDeclaration declaration = factory.createVariableDeclaration(ArrayUtilRt.EMPTY_STRING_ARRAY, actualArg, type, parameter.getName()); final GrStatement[] statements = ((GrClosableBlock)myExpr).getStatements(); GrStatement anchor = statements.length > 0 ? statements[0] : null; return ((GrClosableBlock)myExpr).addStatementBefore(declaration, anchor); } } int copyingSafetyLevel = GroovyRefactoringUtil.verifySafeCopyExpression(actualArg); if (copyingSafetyLevel == RefactoringUtil.EXPR_COPY_PROHIBITED) { actualArg = factory.createExpressionFromText(getTempVar(actualArg)); } newExpr = newExpr.replace(actualArg); return newExpr; }
inlineParam
30,979
boolean (PsiElement oldExpr) { if (oldExpr instanceof GrReferenceExpression ref) { if (ref.getQualifier() == null) { PsiElement nameElement = ref.getReferenceNameElement(); if (nameElement != null) { return nameElement.getNode().getElementType() == GroovyTokenTypes.kSUPER; } } } return false; }
isSimpleSuperReference
30,980
boolean (PsiElement oldExpr) { if (!(oldExpr instanceof GrReferenceExpression && PsiUtil.isThisReference(oldExpr))) return false; final GrReferenceExpression qualifier = (GrReferenceExpression)((GrReferenceExpression)oldExpr).getQualifier(); if (qualifier == null) return true; final PsiClass contextClass = PsiUtil.getContextClass(myToReplaceIn); final PsiElement resolved = qualifier.resolve(); return myManager.areElementsEquivalent(resolved, contextClass); }
isThisReferenceToContainingClass
30,981
GrExpression (int index) { if (myActualArgs == null || myActualArgs[index] == null) { final GrExpression[] arguments = myContext.getArgumentList().getExpressionArguments(); if (index < arguments.length) return arguments[index]; index -= arguments.length; final GrClosableBlock[] closureArguments = myContext.getClosureArguments(); if (index < closureArguments.length) return closureArguments[index]; throw new IncorrectOperationException("fail :("); } final GrClosureSignatureUtil.ArgInfo<PsiElement> argInfo = myActualArgs[index]; final List<PsiElement> args = argInfo.args; if (argInfo.isMultiArg) { return GroovyRefactoringUtil.generateArgFromMultiArg(mySignature.getSubstitutor(), args, myParameters[index].getType(), myContext.getProject()); } else if (args.isEmpty()) { final PsiParameter parameter = myParameters[index]; LOG.assertTrue(parameter instanceof GrParameter); final GrExpression initializer = ((GrParameter)parameter).getInitializerGroovy(); LOG.assertTrue(initializer != null); return (GrExpression)initializer.copy(); } else { return (GrExpression)args.get(0); } }
getActualArg
30,982
PsiElement (final GroovyResolveResult result) { final PsiElement elem = result.getElement(); if (elem != null) { if (elem instanceof PsiMember) { return ((PsiMember)elem).getContainingClass(); } else { return PsiUtil.getContextClass(elem); } } return null; }
getClassContainingResolve
30,983
boolean (GrReferenceExpression refExpr) { try { GrExpression qualifier = refExpr.getQualifier(); if (!(qualifier instanceof GrReferenceExpression)) return false; PsiElement qualifierRefElement = ((GrReferenceExpression)qualifier).resolve(); if (!(qualifierRefElement instanceof PsiClass)) return false; PsiElement refElement = refExpr.resolve(); if (refElement == null) return false; final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(refExpr.getProject()); if (refExpr.getParent() instanceof GrMethodCallExpression methodCall) { GrMethodCallExpression newMethodCall = (GrMethodCallExpression)factory.createExpressionFromText(refExpr.getReferenceName() + "()", refExpr); newMethodCall.getArgumentList().replace(methodCall.getArgumentList()); PsiElement newRefElement = ((GrReferenceExpression)newMethodCall.getInvokedExpression()).resolve(); return refElement.equals(newRefElement); } else { GrReferenceExpression newRefExpr = (GrReferenceExpression)factory.createExpressionFromText(refExpr.getReferenceName(), refExpr); PsiElement newRefElement = newRefExpr.resolve(); return refElement.equals(newRefElement); } } catch (IncorrectOperationException e) { return false; } }
canRemoveQualifier
30,984
void (@NotNull GrExpression selectedExpr) { // Cannot perform refactoring in parameter default values PsiElement parent = selectedExpr.getParent(); while (!(parent == null || parent instanceof GroovyFileBase || parent instanceof GrParameter)) { parent = parent.getParent(); } if (checkInFieldInitializer(selectedExpr)) { throw new GrRefactoringError(GroovyRefactoringBundle.message("refactoring.is.not.supported.in.the.current.context")); } if (parent instanceof GrParameter) { throw new GrRefactoringError(GroovyRefactoringBundle.message("refactoring.is.not.supported.in.method.parameters")); } }
checkExpression
30,985
void (PsiElement @NotNull [] occurrences) { //nothing to do }
checkOccurrences
30,986
boolean (@NotNull GrExpression expr) { PsiElement parent = expr.getParent(); if (parent instanceof GrClosableBlock) { return false; } if (parent instanceof GrField && expr == ((GrField)parent).getInitializerGroovy()) { return true; } if (parent instanceof GrExpression) { return checkInFieldInitializer(((GrExpression)parent)); } return false; }
checkInFieldInitializer
30,987
GrVariable (@NotNull final GrIntroduceContext context, @NotNull final GroovyIntroduceVariableSettings settings) { // Generating variable declaration GrVariable insertedVar = processExpression(context, settings); moveOffsetToPositionMarker(context.getEditor()); return insertedVar; }
runRefactoring
30,988
void (Editor editor) { if (editor != null && getPositionMarker() != null) { editor.getSelectionModel().removeSelection(); editor.getCaretModel().moveToOffset(getPositionMarker().getEndOffset()); } }
moveOffsetToPositionMarker
30,989
GrInplaceVariableIntroducer (@NotNull GrIntroduceContext context, @NotNull OccurrencesChooser.ReplaceChoice choice) { final Ref<GrIntroduceContext> contextRef = Ref.create(context); if (context.getStringPart() != null) { extractStringPart(contextRef); } context = contextRef.get(); final GrStatement anchor = findAnchor(context, choice == OccurrencesChooser.ReplaceChoice.ALL); if (anchor.getParent() instanceof GrControlStatement) { addBraces(anchor, contextRef); } return new GrInplaceVariableIntroducer(getRefactoringName(), choice, contextRef.get()) { @Override protected GrVariable runRefactoring(GrIntroduceContext context, GroovyIntroduceVariableSettings settings, boolean processUsages) { return refactorInWriteAction(() -> processUsages ? processExpression(context, settings) : addVariable(context, settings)); } @Override protected void performPostIntroduceTasks() { super.performPostIntroduceTasks(); moveOffsetToPositionMarker(contextRef.get().getEditor()); } }; }
getIntroducer
30,990
GrVariable (GrIntroduceContext context, GroovyIntroduceVariableSettings settings, boolean processUsages) { return refactorInWriteAction(() -> processUsages ? processExpression(context, settings) : addVariable(context, settings)); }
runRefactoring
30,991
void () { super.performPostIntroduceTasks(); moveOffsetToPositionMarker(contextRef.get().getEditor()); }
performPostIntroduceTasks
30,992
GrVariable (@NotNull GrIntroduceContext context, @NotNull GroovyIntroduceVariableSettings settings) { GrStatement anchor = findAnchor(context, settings.replaceAllOccurrences()); PsiElement parent = anchor.getParent(); assert parent instanceof GrStatementOwner; GrVariableDeclaration generated = generateDeclaration(context, settings); GrStatement declaration = ((GrStatementOwner)parent).addStatementBefore(generated, anchor); declaration = (GrStatement)JavaCodeStyleManager.getInstance(context.getProject()).shortenClassReferences(declaration); PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(context.getEditor().getDocument()); return ((GrVariableDeclaration)declaration).getVariables()[0]; }
addVariable
30,993
void (GrControlFlowOwner[] scopes, Consumer<? super GrControlFlowOwner> callback, Editor editor) { //todo do nothing right now }
showScopeChooser
30,994
GrVariableDeclaration (@NotNull GrIntroduceContext context, @NotNull GroovyIntroduceVariableSettings settings) { final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(context.getProject()); final String[] modifiers = settings.isDeclareFinal() ? new String[]{PsiModifier.FINAL} : null; final GrVariableDeclaration declaration = factory.createVariableDeclaration(modifiers, "foo", settings.getSelectedType(), settings.getName()); generateInitializer(context, declaration.getVariables()[0]); return declaration; }
generateDeclaration
30,995
GrVariable (@NotNull GrIntroduceContext context, @NotNull GroovyIntroduceVariableSettings settings) { GrVariableDeclaration varDecl = generateDeclaration(context, settings); if (context.getStringPart() != null) { final GrExpression ref = context.getStringPart().replaceLiteralWithConcatenation(DUMMY_NAME); return doProcessExpression(context, settings, varDecl, new PsiElement[]{ref}, ref, true); } else { final GrExpression expression = context.getExpression(); assert expression != null; return doProcessExpression(context, settings, varDecl, context.getOccurrences(), expression, true); } }
processExpression
30,996
GrVariable (@NotNull final GrIntroduceContext context, @NotNull GroovyIntroduceVariableSettings settings, @NotNull GrVariableDeclaration varDecl, PsiElement @NotNull [] elements, @NotNull GrExpression expression, boolean processUsages) { return new GrIntroduceLocalVariableProcessor(context, settings, elements, expression, processUsages) { @Override protected void refreshPositionMarker(PsiElement e) { GrIntroduceVariableHandler.this.refreshPositionMarker(context.getEditor().getDocument().createRangeMarker(e.getTextRange())); } }.processExpression(varDecl); }
doProcessExpression
30,997
void (PsiElement e) { GrIntroduceVariableHandler.this.refreshPositionMarker(context.getEditor().getDocument().createRangeMarker(e.getTextRange())); }
refreshPositionMarker
30,998
GrExpression (@NotNull GrIntroduceContext context, @NotNull GrVariable variable) { final GrExpression initializer = context.getStringPart() != null ? context.getStringPart().createLiteralFromSelected() : context.getExpression(); final GrExpression dummyInitializer = variable.getInitializerGroovy(); assert dummyInitializer != null; return dummyInitializer.replaceWithExpression(initializer, true); }
generateInitializer
30,999
RangeMarker () { return myPosition; }
getPositionMarker