Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
31,100
boolean () { if (myPanel.isMoveToAnotherClass()) { try { myEditor.putUserData(INTRODUCE_RESTART, true); myEditor.putUserData(ACTIVE_INTRODUCE, this); final GrIntroduceConstantHandler constantHandler = new GrIntroduceConstantHandler(); final GrVariable localVariable = getLocalVariable(); constantHandler.getContextAndInvoke(myProject, myEditor, ((GrExpression)myExpr), localVariable, null); } finally { myEditor.putUserData(INTRODUCE_RESTART, false); myEditor.putUserData(ACTIVE_INTRODUCE, null); releaseResources(); if (myLocalMarker != null) { myLocalMarker.dispose(); } if (myExprMarker != null) { myExprMarker.dispose(); } } return false; } return super.performRefactoring(); }
performRefactoring
31,101
boolean () { return myMoveToAnotherClassJBCheckBox.isSelected(); }
isMoveToAnotherClass
31,102
JComponent () { return myRootPane; }
getRootPane
31,103
void () { myPreview = getPreviewComponent(); }
createUIComponents
31,104
String () { return HelpID.INTRODUCE_CONSTANT; }
getHelpID
31,105
void (@NotNull GrExpression selectedExpr) { GrVariable variable = GrIntroduceHandlerBase.resolveLocalVar(selectedExpr); if (variable != null) { checkVariable(variable); } else { selectedExpr.accept(new ConstantChecker(selectedExpr, selectedExpr)); } }
checkExpression
31,106
void (PsiElement @NotNull [] occurrences) { if (hasLhs(occurrences)) { throw new GrRefactoringError(GroovyRefactoringBundle.message("selected.variable.is.used.for.write")); } }
checkOccurrences
31,107
PsiClass (GrIntroduceContext context) { return (PsiClass)context.getScope(); }
findContainingClass
31,108
GrIntroduceDialog<GrIntroduceConstantSettings> (@NotNull GrIntroduceContext context) { return new GrIntroduceConstantDialog(context, findContainingClass(context)); }
getDialog
31,109
GrField (@NotNull GrIntroduceContext context, @NotNull GrIntroduceConstantSettings settings) { return new GrIntroduceConstantProcessor(context, settings).run(); }
runRefactoring
31,110
GrAbstractInplaceIntroducer<GrIntroduceConstantSettings> (@NotNull GrIntroduceContext context, @NotNull OccurrencesChooser.ReplaceChoice choice) { final Ref<GrIntroduceContext> contextRef = Ref.create(context); if (context.getStringPart() != null) { extractStringPart(contextRef); } return new GrInplaceConstantIntroducer(contextRef.get(), choice); }
getIntroducer
31,111
void (@NotNull GrReferenceExpression referenceExpression) { final PsiElement resolved = referenceExpression.resolve(); if (resolved instanceof PsiVariable) { if (!isStaticFinalField((PsiVariable)resolved)) { if (expr instanceof GrClosableBlock) { if (!PsiTreeUtil.isContextAncestor(scope, resolved, true)) { throw new GrRefactoringError(GroovyRefactoringBundle.message("closure.uses.external.variables")); } } else { throw new GrRefactoringError(JavaRefactoringBundle.message("selected.expression.cannot.be.a.constant.initializer")); } } } else if (resolved instanceof PsiMethod && ((PsiMethod)resolved).getContainingClass() != null) { final GrExpression qualifier = referenceExpression.getQualifierExpression(); if (qualifier == null || (qualifier instanceof GrReferenceExpression && ((GrReferenceExpression)qualifier).resolve() instanceof PsiClass)) { if (!((PsiMethod)resolved).hasModifierProperty(PsiModifier.STATIC)) { throw new GrRefactoringError(JavaRefactoringBundle.message("selected.expression.cannot.be.a.constant.initializer")); } } } }
visitReferenceExpression
31,112
boolean (PsiVariable var) { return var instanceof PsiField && var.hasModifierProperty(PsiModifier.FINAL) && var.hasModifierProperty(PsiModifier.STATIC); }
isStaticFinalField
31,113
void (@NotNull GrClosableBlock closure) { if (closure == expr) { super.visitClosure(closure); } else { closure.accept(new ConstantChecker(closure, scope)); } }
visitClosure
31,114
LinkedHashSet<String> () { final GrExpression expression = myContext.getExpression(); final GrVariable var = myContext.getVar(); final StringPartInfo stringPart = myContext.getStringPart(); if (expression != null) { return new LinkedHashSet<>(Arrays.asList(GroovyNameSuggestionUtil.suggestVariableNames(expression, myValidator, myForStatic))); } else if (stringPart != null) { return new LinkedHashSet<>( Arrays.asList(GroovyNameSuggestionUtil.suggestVariableNames(stringPart.getLiteral(), myValidator, myForStatic))); } else { assert var != null; return new LinkedHashSet<>(Arrays.asList(GroovyNameSuggestionUtil.suggestVariableNameByType(var.getType(), myValidator))); } }
suggestNames
31,115
JComponent () { return myNameField; }
getPreferredFocusedComponent
31,116
void (ItemEvent e) { myNameField.requestFocusInWindow(); checkErrors(); if (myReplaceAllOccurrencesCheckBox.isSelected()) { PsiElement anchor = GrIntroduceHandlerBase.findAnchor(myContext.getOccurrences(), myContext.getScope()); if (anchor != null && anchor != myContext.getScope() && anchor != ((GrTypeDefinition)myContext.getScope()).getBody()) { myCurrentMethodRadioButton.setEnabled(true); } else if (myCurrentMethodRadioButton.isEnabled()) { myCurrentMethodRadioButton.setEnabled(false); myFieldDeclarationRadioButton.setSelected(true); } } else if (!myCurrentMethodRadioButton.isEnabled()) { myCurrentMethodRadioButton.setEnabled(true); } }
itemStateChanged
31,117
void () { List<String> errors = new ArrayList<>(); if (myCurrentMethodRadioButton.isSelected() && myDeclareFinalCheckBox.isSelected() && !isInvokedInAlwaysInvokedConstructor) { errors.add(GroovyRefactoringBundle.message("final.field.cant.be.initialized.in.cur.method")); } if (myDeclareFinalCheckBox.isSelected() && myReplaceAllOccurrencesCheckBox.isSelected() && myInvokedOnLocalVar != null && hasLHSUsages) { errors.add(GroovyRefactoringBundle.message("Field.cannot.be.final.because.replaced.variable.has.lhs.usages")); } if (!myCanBeInitializedOutsideBlock) { if (myFieldDeclarationRadioButton.isSelected()) { errors.add(GroovyRefactoringBundle.message("field.cannot.be.initialized.in.field.declaration")); } else if (myClassConstructorSRadioButton.isSelected()) { errors.add(GroovyRefactoringBundle.message("field.cannot.be.initialized.in.constructor(s)")); } } if (errors.isEmpty()) { setErrorText(null); } else { setErrorText(errorString(errors)); } }
checkErrors
31,118
boolean (@NotNull GrIntroduceContext context) { if (context.getVar() == null && !(context.getExpression() instanceof GrReferenceExpression)) return false; if (GrIntroduceHandlerBase.hasLhs(context.getOccurrences())) return true; return false; }
hasLhsUsages
31,119
void () { ButtonGroup visibility = new ButtonGroup(); visibility.add(myPrivateRadioButton); visibility.add(myProtectedRadioButton); visibility.add(myPublicRadioButton); visibility.add(myPropertyRadioButton); if (myContext.getScope() instanceof GroovyScriptClass) { myPropertyRadioButton.setSelected(true); myPrivateRadioButton.setEnabled(false); myProtectedRadioButton.setEnabled(false); myPublicRadioButton.setEnabled(false); myPropertyRadioButton.setEnabled(false); } else { myPrivateRadioButton.setSelected(true); } RadioUpDownListener.installOn(myPrivateRadioButton, myProtectedRadioButton, myPublicRadioButton, myPropertyRadioButton); }
initVisibility
31,120
boolean (@Nullable PsiMethod method, @NotNull PsiClass clazz) { if (method == null) return false; if (!method.isConstructor()) return false; final PsiMethod[] constructors = clazz.getConstructors(); if (constructors.length == 1) return true; final GrConstructorInvocation invocation = PsiImplUtil.getChainingConstructorInvocation((GrMethod)method); if (invocation != null && invocation.isThisCall()) return false; for (PsiMethod constructor : constructors) { if (constructor == method) continue; final GrConstructorInvocation inv = PsiImplUtil.getChainingConstructorInvocation((GrMethod)constructor); if (inv == null || inv.isSuperCall()) return false; } return true; }
isAlwaysInvokedConstructor
31,121
boolean (PsiElement @NotNull [] occurrences, PsiElement scope) { if (occurrences.length == 0) return true; GrMember container = GrIntroduceFieldHandler.getContainer(occurrences[0], scope); if (container == null) return false; for (int i = 1; i < occurrences.length; i++) { GrMember other = GrIntroduceFieldHandler.getContainer(occurrences[i], scope); if (other != container) return false; } return true; }
allOccurrencesInOneMethod
31,122
JComponent () { myNameLabel.setLabelFor(myNameField); myTypeLabel.setLabelFor(myTypeComboBox); return myContentPane; }
createCenterPanel
31,123
GrIntroduceFieldSettings () { return this; }
getSettings
31,124
LinkedHashSet<String> () { return new GrFieldNameSuggester(myContext, new GroovyFieldValidator(myContext), false).suggestNames(); }
suggestNames
31,125
void () { final GrExpression expression = myContext.getExpression(); final GrVariable var = myContext.getVar(); final StringPartInfo stringPart = myContext.getStringPart(); List<String> list = new ArrayList<>(); if (var != null) { list.add(var.getName()); } list.addAll(suggestNames()); myNameField = new NameSuggestionsField(ArrayUtilRt.toStringArray(list), myContext.getProject(), GroovyFileType.GROOVY_FILE_TYPE); if (expression != null) { myTypeComboBox = GrTypeComboBox.createTypeComboBoxFromExpression(expression); } else if (stringPart != null) { myTypeComboBox = GrTypeComboBox.createTypeComboBoxFromExpression(stringPart.getLiteral()); } else { myTypeComboBox = GrTypeComboBox.createTypeComboBoxWithDefType(var.getDeclaredType(), var); } GrTypeComboBox.registerUpDownHint(myNameField, myTypeComboBox); }
createUIComponents
31,126
boolean () { return myDeclareFinalCheckBox.isSelected(); }
declareFinal
31,127
Init () { if (myCurrentMethodRadioButton.isSelected()) return Init.CUR_METHOD; if (myFieldDeclarationRadioButton.isSelected()) return Init.FIELD_DECLARATION; if (myClassConstructorSRadioButton.isSelected()) return Init.CONSTRUCTOR; if (mySetUpMethodRadioButton.isSelected()) return Init.SETUP_METHOD; throw new IncorrectOperationException("no initialization place is selected"); }
initializeIn
31,128
String () { if (myPrivateRadioButton.isSelected()) return PsiModifier.PRIVATE; if (myProtectedRadioButton.isSelected()) return PsiModifier.PROTECTED; if (myPublicRadioButton.isSelected()) return PsiModifier.PUBLIC; if (myPropertyRadioButton.isSelected()) return PsiModifier.PACKAGE_LOCAL; throw new IncorrectOperationException("no visibility selected"); }
getVisibilityModifier
31,129
boolean () { return myIsStatic; }
isStatic
31,130
boolean () { return myInvokedOnLocalVar != null && myReplaceAllOccurrencesCheckBox.isSelected(); }
removeLocalVar
31,131
String () { return myNameField.getEnteredName(); }
getName
31,132
boolean () { return myReplaceAllOccurrencesCheckBox.isSelected(); }
replaceAllOccurrences
31,133
PsiType () { return myTypeComboBox.getSelectedType(); }
getSelectedType
31,134
String (GrExpression expression) { if (expression instanceof GrReferenceExpression) { final PsiElement resolved = ((GrReferenceExpression)expression).resolve(); if (PsiUtil.isLocalVariable(resolved)) { return ((GrVariable)resolved).getName(); } } return null; }
getInvokedOnLocalVar
31,135
boolean (@NotNull GrIntroduceContext context, @NotNull PsiClass clazz) { final StringPartInfo part = context.getStringPart(); GrExpression expression = context.getExpression(); if (expression != null) { expression = (GrExpression)PsiUtil.skipParentheses(expression, false); if (expression == null) return false; if (expression instanceof GrReferenceExpression) { final PsiElement resolved = ((GrReferenceExpression)expression).resolve(); if (PsiUtil.isLocalVariable(resolved)) { expression = ((GrVariable)resolved).getInitializerGroovy(); if (expression == null) return false; } } ExpressionChecker visitor = new ExpressionChecker(clazz, expression); expression.accept(visitor); return visitor.isResult(); } if (part != null) { for (GrStringInjection injection : part.getInjections()) { GroovyPsiElement scope = injection.getExpression() != null ? injection.getExpression() : injection.getClosableBlock(); assert scope != null; ExpressionChecker visitor = new ExpressionChecker(clazz, scope); scope.accept(visitor); if (!visitor.isResult()) { return visitor.isResult(); } } return true; } else { return false; } }
canBeInitializedOutsideBlock
31,136
void (@NotNull GrReferenceExpression refExpr) { super.visitReferenceExpression(refExpr); final PsiElement resolved = refExpr.resolve(); if (!(resolved instanceof GrVariable)) return; if (resolved instanceof GrField && myClass.getManager().areElementsEquivalent(myClass, ((GrField)resolved).getContainingClass())) { return; } if (resolved instanceof PsiParameter && PsiTreeUtil.isAncestor(myScope, ((PsiParameter)resolved).getDeclarationScope(), false)) { return; } result = false; }
visitReferenceExpression
31,137
boolean () { return result; }
isResult
31,138
void () { setOKActionEnabled(GroovyNamesUtil.isIdentifier(getName())); }
validateOKAction
31,139
void () { final PsiClass clazz = (PsiClass)myContext.getScope(); final String name = getName(); String message = RefactoringBundle.message("field.exists", name, clazz.getQualifiedName()); if (clazz.findFieldByName(name, true) != null && Messages.showYesNoDialog(myContext.getProject(), message, IntroduceFieldHandler.getRefactoringNameText(), Messages.getWarningIcon()) != Messages.YES) { return; } super.doOKAction(); }
doOKAction
31,140
String () { return myName; }
toString
31,141
GrVariable () { PsiElement scope = myContext.getScope(); final PsiClass targetClass = scope instanceof GroovyFileBase ? ((GroovyFileBase)scope).getScriptClass() : (PsiClass)scope; if (targetClass == null) return null; final GrVariableDeclaration declaration = insertField(targetClass); final GrVariable field = declaration.getVariables()[0]; if (mySettings.removeLocalVar()) { myLocalVariable = GrIntroduceHandlerBase.resolveLocalVar(myContext); assert myLocalVariable != null : myContext.getExpression() + ", " + myContext.getVar() + ", " + myContext.getStringPart(); } GrExpression originalInitializer = getInitializer(); myInitializer = originalInitializer == null ? null : (GrExpression)originalInitializer.copy(); List<PsiElement> replaced = processOccurrences(targetClass, field); switch (mySettings.initializeIn()) { case CUR_METHOD -> initializeInMethod(field, replaced); case FIELD_DECLARATION -> field.setInitializerGroovy(myInitializer); case CONSTRUCTOR -> initializeInConstructor(field, replaced); case SETUP_METHOD -> initializeInSetup(field, replaced); } JavaCodeStyleManager.getInstance(declaration.getProject()).shortenClassReferences(declaration); if (mySettings.removeLocalVar()) { GrIntroduceHandlerBase.deleteLocalVar(myLocalVariable); } return field; }
run
31,142
List<PsiElement> (@NotNull PsiClass targetClass, @NotNull GrVariable field) { if (myContext.getStringPart() != null) { final GrExpression expr = myContext.getStringPart().replaceLiteralWithConcatenation(field.getName()); final PsiElement occurrence = replaceOccurrence(field, expr, targetClass); updateCaretPosition(occurrence); return Collections.singletonList(occurrence); } if (mySettings.replaceAllOccurrences()) { GroovyRefactoringUtil.sortOccurrences(myContext.getOccurrences()); ArrayList<PsiElement> result = new ArrayList<>(); for (PsiElement occurrence : myContext.getOccurrences()) { result.add(replaceOccurrence(field, occurrence, targetClass)); } return result; } GrVariable var = myContext.getVar(); if (var != null) { GrExpression initializer = var.getInitializerGroovy(); if (initializer != null) { return Collections.singletonList(replaceOccurrence(field, initializer, targetClass)); } else { return Collections.emptyList(); } } final GrExpression expression = myContext.getExpression(); assert expression != null; return Collections.singletonList(replaceOccurrence(field, expression, targetClass)); }
processOccurrences
31,143
void (@NotNull PsiElement occurrence) { myContext.getEditor().getCaretModel().moveToOffset(occurrence.getTextRange().getEndOffset()); myContext.getEditor().getSelectionModel().removeSelection(); }
updateCaretPosition
31,144
GrVariableDeclaration (@NotNull PsiClass targetClass) { GrVariableDeclaration declaration = createField(targetClass); if (targetClass instanceof GrEnumTypeDefinition) { final GrEnumConstantList enumConstants = ((GrEnumTypeDefinition)targetClass).getEnumConstantList(); return (GrVariableDeclaration)targetClass.addAfter(declaration, enumConstants); } if (targetClass instanceof GroovyScriptClass) { final GroovyFile file = ((GroovyScriptClass)targetClass).getContainingFile(); PsiElement[] elements = file.getMethods(); if (elements.length == 0) elements = file.getStatements(); final PsiElement anchor = ArrayUtil.getFirstElement(elements); return (GrVariableDeclaration)file.addBefore(declaration, anchor); } if (targetClass instanceof GrTypeDefinition) { PsiElement anchor = getAnchorForDeclaration((GrTypeDefinition)targetClass); return (GrVariableDeclaration)targetClass.addAfter(declaration, anchor); } throw new IllegalArgumentException("Unexpected targetClass: " + targetClass.getClass()); }
insertField
31,145
PsiElement (@NotNull GrTypeDefinition targetClass) { final GrTypeDefinitionBody body = targetClass.getBody(); if (body == null) return null; PsiElement anchor = body.getLBrace(); final GrMembersDeclaration[] declarations = targetClass.getMemberDeclarations(); for (GrMembersDeclaration declaration : declarations) { if (declaration instanceof GrVariableDeclaration) anchor = declaration; if (!(declaration instanceof GrVariableDeclaration)) return anchor; } return anchor; }
getAnchorForDeclaration
31,146
void (@NotNull GrVariable field, @Nullable GrStatementOwner container, @Nullable GrStatement anchor, @Nullable PsiElement occurence) { if (!mySettings.replaceAllOccurrences() && PsiUtil.isExpressionStatement(occurence) && Comparing.equal(anchor, occurence)) { generateAssignment(field, anchor, container, occurence); } else { generateAssignment(field, anchor, container, null); } }
initializeInMethodInner
31,147
void (@NotNull GrVariable field, @NotNull PsiClass scope, @NotNull Collection<PsiElement> replaced) { PsiMethod[] constructors = scope.getConstructors(); if (constructors.length == 0) { constructors = new PsiMethod[]{generateConstructor(scope)}; } for (PsiMethod constructor : constructors) { final GrConstructorInvocation invocation = PsiImplUtil.getChainingConstructorInvocation((GrMethod)constructor); if (invocation != null && invocation.isThisCall()) continue; final GrOpenBlock body = ((GrMethod)constructor).getBlock(); final GrStatement anchor = findAnchorForAssignment(body, replaced); initializeInMethodInner(field, body, anchor, ContainerUtil.getFirstItem(replaced)); } }
initializeInConstructor
31,148
PsiMethod (@NotNull PsiClass scope) { final String name = scope.getName(); LOG.assertTrue(name != null, scope.getText()); GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(myContext.getProject()); final GrMethod constructor = factory.createConstructorFromText(name, ArrayUtilRt.EMPTY_STRING_ARRAY, ArrayUtilRt.EMPTY_STRING_ARRAY, "{}", scope); if (scope instanceof GroovyScriptClass) constructor.getModifierList().setModifierProperty(GrModifier.DEF, true); return (PsiMethod)scope.add(constructor); }
generateConstructor
31,149
void (@NotNull GrVariable field, @NotNull GrAnonymousClassDefinition scope, @NotNull Collection<PsiElement> replaced) { final GrClassInitializer[] initializers = scope.getInitializers(); GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(myContext.getProject()); final GrClassInitializer initializer = initializers.length == 0 ? (GrClassInitializer)scope.add(factory.createClassInitializer()) : initializers[0]; final GrStatement anchor = findAnchorForAssignment(initializer.getBlock(), replaced); initializeInMethodInner(field, initializer.getBlock(), anchor, ContainerUtil.getFirstItem(replaced)); }
initializeInAnonymousClassInitializer
31,150
void (@NotNull GrVariable field, @Nullable GrStatement anchor, @Nullable GrStatementOwner defaultContainer, @Nullable PsiElement occurrenceToDelete) { if (myInitializer == null || defaultContainer == null) return; GrAssignmentExpression init = (GrAssignmentExpression)GroovyPsiElementFactory.getInstance(myContext.getProject()) .createExpressionFromText(mySettings.getName() + " = " + myInitializer.getText()); GrStatementOwner block; if (anchor != null) { anchor = GroovyRefactoringUtil.addBlockIntoParent(anchor); LOG.assertTrue(anchor.getParent() instanceof GrStatementOwner); block = (GrStatementOwner)anchor.getParent(); } else { block = defaultContainer; } init = (GrAssignmentExpression)block.addStatementBefore(init, anchor); replaceOccurrence(field, init.getLValue(), (PsiClass)myContext.getScope()); if (occurrenceToDelete != null) { occurrenceToDelete.delete(); } }
generateAssignment
31,151
GrExpression () { assert myLocalVariable != null; return myLocalVariable.getInitializerGroovy(); }
extractVarInitializer
31,152
GrStatement (@Nullable final GrCodeBlock block, @NotNull Collection<PsiElement> replaced) { if (block == null) return null; final List<PsiElement> elements = ContainerUtil.findAll(replaced, element -> PsiTreeUtil.isAncestor(block, element, true)); if (elements.isEmpty()) return null; return (GrStatement)GrIntroduceHandlerBase.findAnchor(elements.toArray(PsiElement.EMPTY_ARRAY), block); }
findAnchorForAssignment
31,153
PsiElement (@NotNull GrVariable field, @NotNull PsiElement occurrence, @NotNull PsiClass containingClass) { boolean isOriginal = occurrence == myContext.getExpression(); final GrReferenceExpression newExpr = createRefExpression(field, occurrence, containingClass); final PsiElement replaced; if (occurrence instanceof GrExpression) { replaced = ((GrExpression)occurrence).replaceWithExpression(newExpr, false); } else { replaced = occurrence.replace(newExpr); } if (replaced instanceof GrQualifiedReference<?>) { GrReferenceAdjuster.shortenReference((GrQualifiedReference<?>)replaced); } if (isOriginal) { updateCaretPosition(replaced); } return replaced; }
replaceOccurrence
31,154
GrReferenceExpression (@NotNull GrVariable field, @NotNull PsiElement place, @NotNull PsiClass containingClass) { final String qname = containingClass instanceof GroovyScriptClass ? null : containingClass.getQualifiedName(); final String prefix = qname != null ? qname + "." : ""; final String refText; if (field.hasModifierProperty(PsiModifier.STATIC)) { refText = prefix + field.getName(); } else { refText = prefix + "this." + field.getName(); } return GroovyPsiElementFactory.getInstance(place.getProject()).createReferenceExpressionFromText(refText, place); }
createRefExpression
31,155
GrVariableDeclaration (@NotNull PsiClass targetClass) { final String name = mySettings.getName(); final PsiType type = mySettings.getSelectedType(); final String modifier = mySettings.getVisibilityModifier(); List<String> modifiers = new ArrayList<>(); if (targetClass instanceof GroovyScriptClass) { modifiers.add("@" + GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD); } if (mySettings.isStatic()) modifiers.add(PsiModifier.STATIC); if (!PsiModifier.PACKAGE_LOCAL.equals(modifier)) modifiers.add(modifier); if (mySettings.declareFinal()) modifiers.add(PsiModifier.FINAL); final String[] arr_modifiers = ArrayUtilRt.toStringArray(modifiers); final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(myContext.getProject()); if (targetClass instanceof GroovyScriptClass) { return factory.createVariableDeclaration(arr_modifiers, ((GrExpression)null), type, name); } else { return factory.createFieldDeclaration(arr_modifiers, name, null, type); } }
createField
31,156
GrExpression () { if (mySettings.removeLocalVar()) { return extractVarInitializer(); } GrExpression expression = myContext.getExpression(); StringPartInfo stringPart = myContext.getStringPart(); if (expression != null) { return expression; } else if (stringPart != null) { return stringPart.createLiteralFromSelected(); } throw new IncorrectOperationException("cannot be here!"); }
getInitializer
31,157
String () { return HelpID.INTRODUCE_FIELD; }
getHelpID
31,158
void (@NotNull GrExpression selectedExpr) { checkContainingClass(selectedExpr); }
checkExpression
31,159
void (PsiElement place) { final PsiClass containingClass = PsiUtil.getContextClass(place); if (containingClass == null) throw new GrRefactoringError(GroovyRefactoringBundle.message("cannot.introduce.field.in.script")); if (containingClass.isInterface()) { throw new GrRefactoringError(GroovyRefactoringBundle.message("cannot.introduce.field.in.interface")); } if (PsiUtil.skipParentheses(place, false) == null) { throw new GrRefactoringError(GroovyRefactoringBundle.message("expression.contains.errors")); } }
checkContainingClass
31,160
void (PsiElement @NotNull [] occurrences) { //nothing to do }
checkOccurrences
31,161
GrIntroduceDialog<GrIntroduceFieldSettings> (@NotNull GrIntroduceContext context) { return new GrIntroduceFieldDialog(context); }
getDialog
31,162
GrVariable (@NotNull GrIntroduceContext context, @NotNull GrIntroduceFieldSettings settings) { return new GrIntroduceFieldProcessor(context, settings).run(); }
runRefactoring
31,163
GrAbstractInplaceIntroducer<GrIntroduceFieldSettings> (@NotNull GrIntroduceContext context, @NotNull OccurrencesChooser.ReplaceChoice choice) { final Ref<GrIntroduceContext> contextRef = Ref.create(context); if (context.getStringPart() != null) { extractStringPart(contextRef); } return new GrInplaceFieldIntroducer(contextRef.get(), choice); }
getIntroducer
31,164
GrMember (@Nullable PsiElement place, @Nullable PsiElement scope) { while (place != null && place != scope) { place = place.getParent(); if (place instanceof GrMember) return (GrMember)place; } return null; }
getContainer
31,165
boolean (PsiElement expr, PsiElement clazz) { final GrMember method = getContainer(expr, clazz); if (method == null) return false; return method.hasModifierProperty(PsiModifier.STATIC); }
shouldBeStatic
31,166
PsiElement () { final GrVariable variable = getVariable(); if (variable instanceof PsiField) { return ((PsiField)getVariable()).getContainingClass(); } else { final PsiFile file = variable.getContainingFile(); if (file instanceof GroovyFile) { return ((GroovyFile)file).getScriptClass(); } else { return null; } } }
checkLocalScope
31,167
GrVariable (GrIntroduceContext context, GrIntroduceFieldSettings settings, boolean processUsages) { return refactorInWriteAction(() -> { GrIntroduceFieldProcessor processor = new GrIntroduceFieldProcessor(context, settings); return processUsages ? processor.run() : processor.insertField((PsiClass)context.getScope()).getVariables()[0]; }); }
runRefactoring
31,168
GrIntroduceFieldSettings (@NotNull final GrIntroduceContext context, @NotNull final OccurrencesChooser.ReplaceChoice choice, final String[] names) { return new GrIntroduceFieldSettings() { @Override public boolean declareFinal() { return false; } @Override public Init initializeIn() { return Init.FIELD_DECLARATION; } @Override public String getVisibilityModifier() { return PsiModifier.PRIVATE; } @Override public boolean isStatic() { boolean hasInstanceInScope = true; PsiClass clazz = (PsiClass)context.getScope(); if (replaceAllOccurrences()) { for (PsiElement occurrence : context.getOccurrences()) { if (!PsiUtil.hasEnclosingInstanceInScope(clazz, occurrence, false)) { hasInstanceInScope = false; break; } } } else if (context.getExpression() != null) { hasInstanceInScope = PsiUtil.hasEnclosingInstanceInScope(clazz, context.getExpression(), false); } else if (context.getStringPart() != null) { hasInstanceInScope = PsiUtil.hasEnclosingInstanceInScope(clazz, context.getStringPart().getLiteral(), false); } return !hasInstanceInScope; } @Override public boolean removeLocalVar() { return myLocalVar != null; } @Nullable @Override public String getName() { return names[0]; } @Override public boolean replaceAllOccurrences() { return context.getVar() != null || choice == OccurrencesChooser.ReplaceChoice.ALL; } @Nullable @Override public PsiType getSelectedType() { GrExpression expression = context.getExpression(); GrVariable var = context.getVar(); StringPartInfo stringPart = context.getStringPart(); return var != null ? var.getDeclaredType() : expression != null ? expression.getType() : stringPart != null ? stringPart.getLiteral().getType() : null; } }; }
getInitialSettingsForInplace
31,169
boolean () { return false; }
declareFinal
31,170
Init () { return Init.FIELD_DECLARATION; }
initializeIn
31,171
String () { return PsiModifier.PRIVATE; }
getVisibilityModifier
31,172
boolean () { boolean hasInstanceInScope = true; PsiClass clazz = (PsiClass)context.getScope(); if (replaceAllOccurrences()) { for (PsiElement occurrence : context.getOccurrences()) { if (!PsiUtil.hasEnclosingInstanceInScope(clazz, occurrence, false)) { hasInstanceInScope = false; break; } } } else if (context.getExpression() != null) { hasInstanceInScope = PsiUtil.hasEnclosingInstanceInScope(clazz, context.getExpression(), false); } else if (context.getStringPart() != null) { hasInstanceInScope = PsiUtil.hasEnclosingInstanceInScope(clazz, context.getStringPart().getLiteral(), false); } return !hasInstanceInScope; }
isStatic
31,173
boolean () { return myLocalVar != null; }
removeLocalVar
31,174
String () { return names[0]; }
getName
31,175
boolean () { return context.getVar() != null || choice == OccurrencesChooser.ReplaceChoice.ALL; }
replaceAllOccurrences
31,176
PsiType () { GrExpression expression = context.getExpression(); GrVariable var = context.getVar(); StringPartInfo stringPart = context.getStringPart(); return var != null ? var.getDeclaredType() : expression != null ? expression.getType() : stringPart != null ? stringPart.getLiteral().getType() : null; }
getSelectedType
31,177
GrIntroduceFieldSettings () { return new GrIntroduceFieldSettings() { @Override public boolean declareFinal() { return myPanel.isFinal(); } @Override public Init initializeIn() { return myPanel.getInitPlace(); } @Override public String getVisibilityModifier() { return PsiModifier.PRIVATE; } @Override public boolean isStatic() { return myIsStatic; } @Override public boolean removeLocalVar() { return myLocalVar != null; } @Nullable @Override public String getName() { return getInputName(); } @Override public boolean replaceAllOccurrences() { return isReplaceAllOccurrences(); } @Nullable @Override public PsiType getSelectedType() { return GrInplaceFieldIntroducer.this.getSelectedType(); } }; }
getSettings
31,178
boolean () { return myPanel.isFinal(); }
declareFinal
31,179
Init () { return myPanel.getInitPlace(); }
initializeIn
31,180
String () { return PsiModifier.PRIVATE; }
getVisibilityModifier
31,181
boolean () { return myIsStatic; }
isStatic
31,182
boolean () { return myLocalVar != null; }
removeLocalVar
31,183
String () { return getInputName(); }
getName
31,184
boolean () { return isReplaceAllOccurrences(); }
replaceAllOccurrences
31,185
PsiType () { return GrInplaceFieldIntroducer.this.getSelectedType(); }
getSelectedType
31,186
String () { return IntroduceFieldHandler.getRefactoringNameText(); }
getActionName
31,187
void (@NotNull GrVariable variable) { }
saveSettings
31,188
void (@NotNull GrVariable psiField) { myIsStatic = psiField.hasModifierProperty(PsiModifier.STATIC); super.restoreState(psiField); }
restoreState
31,189
JComponent () { myPanel = new GrInplaceIntroduceFieldPanel(); return myPanel.getRootPane(); }
getComponent
31,190
void (ActionEvent e) { WriteCommandAction.writeCommandAction(myProject).withName(getCommandName()).withGroupId(getCommandName()).run(() -> { PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument()); final GrVariable variable = getVariable(); if (variable != null) { finalListener.perform(myDeclareFinalCB.isSelected(), variable); } }); }
actionPerformed
31,191
JPanel () { return myRootPane; }
getRootPane
31,192
boolean () { return myDeclareFinalCB.isSelected(); }
isFinal
31,193
void () { myPreview = getPreviewComponent(); }
createUIComponents
31,194
void (PsiElement toCheck, MultiMap<PsiElement, String> conflicts, String varName) { if (toCheck instanceof GrField && varName.equals(((GrField)toCheck).getName())) { conflicts.putValue(toCheck, GroovyRefactoringBundle.message("field.0.is.already.defined", CommonRefactoringUtil.htmlEmphasize(varName))); } if (toCheck instanceof GrMethod) { if (GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)toCheck) && varName.equals(GroovyPropertyUtils.getPropertyNameByAccessorName(((PsiMethod)toCheck).getName()))) { conflicts.putValue(toCheck, GroovyRefactoringBundle .message("access.to.created.field.0.will.be.overridden.by.method.1", CommonRefactoringUtil.htmlEmphasize(varName), CommonRefactoringUtil.htmlEmphasize(DescriptiveNameUtil.getDescriptiveName(toCheck)))); } } }
check
31,195
void (PsiElement toCheck, MultiMap<PsiElement, String> conflicts, String varName) { if (toCheck instanceof GrVariable && varName.equals(((GrVariable)toCheck).getName())) { conflicts.putValue(toCheck, GroovyRefactoringBundle.message("field.0.is.already.defined", CommonRefactoringUtil.htmlEmphasize(varName))); } if (toCheck instanceof GrMethod) { if (GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)toCheck) && varName.equals(GroovyPropertyUtils.getPropertyNameByAccessorName(((PsiMethod)toCheck).getName()))) { conflicts.putValue(toCheck, GroovyRefactoringBundle .message("access.to.created.field.0.will.be.overridden.by.method.1", CommonRefactoringUtil.htmlEmphasize(varName), CommonRefactoringUtil.htmlEmphasize(DescriptiveNameUtil.getDescriptiveName(toCheck)))); } } }
check
31,196
boolean () { return myChangeInfo.isNameChanged() || myChangeInfo.isParameterSetOrOrderChanged() || myChangeInfo.isExceptionSetOrOrderChanged(); }
needToChangeCalls
31,197
void (MultiMap<PsiElement, String> conflicts) { try { GrMethod prototype; final PsiMethod method = myChangeInfo.getMethod(); if (!(method instanceof GrMethod)) return; PsiManager manager = method.getManager(); GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(manager.getProject()); final CanonicalTypes.Type returnType = myChangeInfo.getNewReturnType(); String newMethodName = myChangeInfo.getNewName(); if (method.isConstructor()) { prototype = factory.createConstructorFromText("foo", ArrayUtilRt.EMPTY_STRING_ARRAY, ArrayUtilRt.EMPTY_STRING_ARRAY, "{}", method); } else { prototype = factory.createMethodFromText("", "foo", returnType != null ? returnType.getTypeText() : null, ArrayUtilRt.EMPTY_STRING_ARRAY, method); } prototype.setName(newMethodName); JavaParameterInfo[] parameters = myChangeInfo.getNewParameters(); for (JavaParameterInfo info : parameters) { GrParameter param; if (info instanceof GrParameterInfo) { param = factory.createParameter(info.getName(), info.getTypeText(), ((GrParameterInfo)info).getDefaultInitializer(), (GroovyPsiElement)method); } else { param = factory.createParameter(info.getName(), info.getTypeText(), (GroovyPsiElement)method); } prototype.getParameterList().add(param); } ConflictsUtil.checkMethodConflicts(method.getContainingClass(), method, prototype, conflicts); GrMethodConflictUtil.checkMethodConflicts(method.getContainingClass(), prototype, ((GrMethod)method), conflicts, true); } catch (IncorrectOperationException e) { LOG.error(e); } }
addMethodConflicts
31,198
String () { return myMethod.getName(); }
getName
31,199
List<GrParameterInfo> () { final ArrayList<GrParameterInfo> result = new ArrayList<>(); final GrParameter[] parameters = myMethod.getParameters(); for (int i = 0; i < parameters.length; i++) { GrParameter parameter = parameters[i]; GrParameterInfo info = new GrParameterInfo(parameter, i); result.add(info); } return result; }
getParameters