Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
16,400
T () {return t;}
get
16,401
void (T t) { this.t = t; }
set
16,402
T () {return t;}
get
16,403
void (T t) { this.t = t; }
set
16,404
List () { return new List<String>(); }
get
16,405
List () { return new List<String>(); }
get
16,406
T () {return null;}
get
16,407
Iterator<T> () { return null; }
iterator
16,408
T () {return null;}
get
16,409
Iterator<T> () { return null; }
iterator
16,410
T () {return t;}
get
16,411
void (T t) { this.t = t; }
set
16,412
T () {return t;}
get
16,413
void (T t) { this.t = t; }
set
16,414
T () {return t;}
get
16,415
void (T t) { this.t = t; }
set
16,416
T () {return t;}
get
16,417
void (T t) { this.t = t; }
set
16,418
void () { Set tenL = getNumberSet4(10); Set fiveL = getNumberSet4(5); tenL.removeAll(fiveL); }
testSet4
16,419
Set (int n) { Set result; for (int i = 0; i < n; i++) { result.add(i); } return result; }
getNumberSet4
16,420
void () { Set tenL = getNumberSet4(10); Set fiveL = getNumberSet4(5); tenL.removeAll(fiveL); }
testSet4
16,421
Set (int n) { Set result; for (int i = 0; i < n; i++) { result.add(i); } return result; }
getNumberSet4
16,422
Set<PsiMethod> (PsiField field) { final Set<PsiMethod> out = new HashSet<>(); final PsiClass containingClass = field.getContainingClass(); if (containingClass == null) { return out; } final PsiMethod[] methods = containingClass.getMethods(); for (PsiMethod method : methods) { if (isDelegation(field, method)) { out.add(method); } } return out; }
getDelegatingMethodsForField
16,423
boolean (PsiField field, PsiMethod method) { if (method.isConstructor()) { return false; } final PsiCodeBlock body = method.getBody(); if (body == null) { return false; } final PsiStatement[] statements = body.getStatements(); if (statements.length != 1) { return false; } final PsiStatement statement = statements[0]; if (statement instanceof PsiReturnStatement) { final PsiExpression returnValue = ((PsiReturnStatement)statement).getReturnValue(); if (!isDelegationCall(returnValue, field, method)) { return false; } } else if (statement instanceof PsiExpressionStatement) { final PsiExpression value = ((PsiExpressionStatement)statement).getExpression(); if (!isDelegationCall(value, field, method)) { return false; } } else { return false; } return true; }
isDelegation
16,424
boolean (PsiMethod method) { if (method.hasModifierProperty(PsiModifier.ABSTRACT)) { return true; } return method.getContainingClass().isInterface(); }
isAbstract
16,425
boolean (PsiExpression expression, PsiField field, PsiMethod method) { if (!(expression instanceof PsiMethodCallExpression call)) { return false; } final PsiReferenceExpression methodExpression = call.getMethodExpression(); final PsiExpression qualifier = methodExpression.getQualifierExpression(); if (!(qualifier instanceof PsiReferenceExpression)) { return false; } final PsiElement referent = ((PsiReference)qualifier).resolve(); if (referent == null || !referent.equals(field)) { return false; } final PsiExpressionList argumentList = call.getArgumentList(); final PsiExpression[] args = argumentList.getExpressions(); for (PsiExpression arg : args) { if (!isParameterReference(arg, method)) { return false; } } return true; }
isDelegationCall
16,426
boolean (PsiExpression arg, PsiMethod method) { if (!(arg instanceof PsiReferenceExpression)) { return false; } final PsiElement referent = ((PsiReference)arg).resolve(); if (!(referent instanceof PsiParameter)) { return false; } final PsiElement declarationScope = ((PsiParameter)referent).getDeclarationScope(); return method.equals(declarationScope); }
isParameterReference
16,427
int[] (PsiMethod method) { final PsiCodeBlock body = method.getBody(); assert body != null; final PsiStatement[] statements = body.getStatements(); final PsiStatement statement = statements[0]; final PsiParameterList parameterList = method.getParameterList(); if (statement instanceof PsiReturnStatement) { final PsiExpression returnValue = ((PsiReturnStatement)statement).getReturnValue(); final PsiMethodCallExpression call = (PsiMethodCallExpression)returnValue; return calculatePermutation(call, parameterList); } else { final PsiExpression value = ((PsiExpressionStatement)statement).getExpression(); final PsiMethodCallExpression call = (PsiMethodCallExpression)value; return calculatePermutation(call, parameterList); } }
getParameterPermutation
16,428
int[] (PsiMethodCallExpression call, PsiParameterList parameterList) { final PsiExpressionList argumentList = call.getArgumentList(); final PsiExpression[] args = argumentList.getExpressions(); final int[] out = ArrayUtil.newIntArray(args.length); for (int i = 0; i < args.length; i++) { final PsiExpression arg = args[i]; final PsiParameter parameter = (PsiParameter)((PsiReference)arg).resolve(); out[i] = parameterList.getParameterIndex(parameter); } return out; }
calculatePermutation
16,429
PsiMethod (PsiMethod method) { final PsiCodeBlock body = method.getBody(); assert body != null; final PsiStatement[] statements = body.getStatements(); final PsiStatement statement = statements[0]; if (statement instanceof PsiReturnStatement) { final PsiExpression returnValue = ((PsiReturnStatement)statement).getReturnValue(); final PsiMethodCallExpression call = (PsiMethodCallExpression)returnValue; assert call != null; return call.resolveMethod(); } else { final PsiExpression value = ((PsiExpressionStatement)statement).getExpression(); final PsiMethodCallExpression call = (PsiMethodCallExpression)value; return call.resolveMethod(); } }
getDelegatedMethod
16,430
String () { return "RefactorJ.RemoveMiddleman"; }
getDimensionServiceKey
16,431
JComponent () { final JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 5, 0)); final MemberSelectionPanel selectionPanel = new MemberSelectionPanel( JavaRareRefactoringsBundle.message("remove.middleman.methods.to.inline.title"), delegateMethods, JavaRareRefactoringsBundle.message("remove.middleman.column.header")); final MemberSelectionTable table = selectionPanel.getTable(); table.setMemberInfoModel(new DelegatingMemberInfoModel<>(table.getMemberInfoModel()) { @Override public int checkForProblems(@NotNull final MemberInfo member) { return hasSuperMethods(member) ? ERROR : OK; } @Override public String getTooltipText(final MemberInfo member) { if (hasSuperMethods(member)) return JavaRareRefactoringsBundle.message("remove.middleman.tooltip.warning"); return super.getTooltipText(member); } private static boolean hasSuperMethods(final MemberInfo member) { if (member.isChecked() && member.isToAbstract()) { final PsiMember psiMember = member.getMember(); if (psiMember instanceof PsiMethod && ((PsiMethod)psiMember).findDeepestSuperMethods().length > 0) { return true; } } return false; } }); panel.add(selectionPanel, BorderLayout.CENTER); return panel; }
createCenterPanel
16,432
int (@NotNull final MemberInfo member) { return hasSuperMethods(member) ? ERROR : OK; }
checkForProblems
16,433
String (final MemberInfo member) { if (hasSuperMethods(member)) return JavaRareRefactoringsBundle.message("remove.middleman.tooltip.warning"); return super.getTooltipText(member); }
getTooltipText
16,434
boolean (final MemberInfo member) { if (member.isChecked() && member.isToAbstract()) { final PsiMember psiMember = member.getMember(); if (psiMember instanceof PsiMethod && ((PsiMethod)psiMember).findDeepestSuperMethods().length > 0) { return true; } } return false; }
hasSuperMethods
16,435
JComponent () { fieldNameLabel.setEditable(false); final JPanel sourceClassPanel = new JPanel(new BorderLayout()); sourceClassPanel.add(new JLabel(JavaRareRefactoringsBundle.message("delegating.field")), BorderLayout.NORTH); sourceClassPanel.add(fieldNameLabel, BorderLayout.CENTER); return sourceClassPanel; }
createNorthPanel
16,436
String () { return HelpID.RemoveMiddleman; }
getHelpId
16,437
void () { invokeRefactoring(new RemoveMiddlemanProcessor(myField, delegateMethods)); }
doAction
16,438
UsageViewDescriptor (UsageInfo @NotNull [] usageInfos) { return new RemoveMiddlemanUsageViewDescriptor(field); }
createUsageViewDescriptor
16,439
void (@NotNull List<? super FixableUsageInfo> usages) { for (final MemberInfo memberInfo : myDelegateMethodInfos) { if (!memberInfo.isChecked()) continue; final PsiMethod method = (PsiMethod)memberInfo.getMember(); final String getterName = GenerateMembersUtil.suggestGetterName(field); final int[] paramPermutation = DelegationUtils.getParameterPermutation(method); final PsiMethod delegatedMethod = DelegationUtils.getDelegatedMethod(method); LOG.assertTrue(!DelegationUtils.isAbstract(method)); processUsagesForMethod(memberInfo.isToAbstract(), method, paramPermutation, getterName, delegatedMethod, usages); } }
findUsages
16,440
boolean (@NotNull final Ref<UsageInfo[]> refUsages) { final MultiMap<PsiElement, String> conflicts = new MultiMap<>(); for (MemberInfo memberInfo : myDelegateMethodInfos) { if (memberInfo.isChecked() && memberInfo.isToAbstract()) { final PsiMember psiMember = memberInfo.getMember(); if (psiMember instanceof PsiMethod && ((PsiMethod)psiMember).findDeepestSuperMethods().length > 0) { conflicts.putValue(psiMember, JavaRareRefactoringsBundle .message("remove.middleman.deleted.hierarchy.conflict", SymbolPresentationUtil.getSymbolPresentableText(psiMember))); } } } return showConflicts(conflicts, refUsages.get()); }
preprocessUsages
16,441
void (final boolean deleteMethodHierarchy, PsiMethod method, int[] paramPermutation, String getterName, PsiMethod delegatedMethod, List<? super FixableUsageInfo> usages) { for (PsiReference reference : ReferencesSearch.search(method)) { final PsiElement referenceElement = reference.getElement(); final PsiMethodCallExpression call = (PsiMethodCallExpression)referenceElement.getParent(); final String access; if (call.getMethodExpression().getQualifierExpression() == null) { access = field.getName(); } else { access = getterName + "()"; if (getter == null) { getter = GenerateMembersUtil.generateGetterPrototype(field); } } usages.add(new InlineDelegatingCall(call, paramPermutation, access, delegatedMethod.getName())); } if (deleteMethodHierarchy) { usages.add(new DeleteMethod(method)); } }
processUsagesForMethod
16,442
void (UsageInfo @NotNull [] usageInfos) { if (getter != null) { try { if (containingClass.findMethodBySignature(getter, false) == null) { containingClass.add(getter); } } catch (IncorrectOperationException e) { LOG.error(e); } } super.performRefactoring(usageInfos); }
performRefactoring
16,443
String () { return JavaRareRefactoringsBundle.message("exposed.delegation.command.name", StringUtil.getQualifiedName(containingClass.getName(), field.getName())); }
getCommandName
16,444
String () { return getRefactoringNameText(); }
getRefactoringName
16,445
String () { return HelpID.RemoveMiddleman; }
getHelpID
16,446
void (@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) { final ScrollingModel scrollingModel = editor.getScrollingModel(); scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE); final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext); if (!(element instanceof PsiField)) { CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + JavaRareRefactoringsBundle.message( "the.caret.should.be.positioned.at.the.name.of.the.field.to.be.refactored"), getRefactoringNameText(), getHelpID()); return; } invoke((PsiField)element, editor); }
invoke
16,447
void (@NotNull Project project, PsiElement @NotNull [] elements, DataContext dataContext) { if (elements.length != 1) { return; } if (elements[0] instanceof PsiField) { Editor editor = CommonDataKeys.EDITOR.getData(dataContext); invoke((PsiField)elements[0], editor); } }
invoke
16,448
void (final PsiField field, Editor editor) { final Project project = field.getProject(); final Set<PsiMethod> delegating = DelegationUtils.getDelegatingMethodsForField(field); if (delegating.isEmpty()) { final String message = RefactorJBundle.message("cannot.perform.the.refactoring") + JavaRareRefactoringsBundle.message("field.selected.is.not.used.as.a.delegate"); CommonRefactoringUtil.showErrorHint(project, editor, message, getRefactoringNameText(), getHelpID()); return; } MemberInfo[] infos = new MemberInfo[delegating.size()]; int i = 0; for (PsiMethod method : delegating) { final MemberInfo memberInfo = new MemberInfo(method); memberInfo.setChecked(true); memberInfo.setToAbstract(method.findDeepestSuperMethods().length == 0); infos[i++] = memberInfo; } new RemoveMiddlemanDialog(field, infos).show(); }
invoke
16,449
String (int usagesCount, int filesCount) { return JavaRareRefactoringsBundle .message("references.to.expose.usage.view", usagesCount, filesCount); }
getCodeReferencesText
16,450
String () { return JavaRareRefactoringsBundle.message("remove.middleman.field.header"); }
getProcessedElementsHeader
16,451
String () { return JavaRareRefactoringsBundle.message("method.whose.return.are.to.wrapped"); }
getProcessedElementsHeader
16,452
String (int usagesCount, int filesCount) { return JavaRareRefactoringsBundle.message("references.to.be.modified.usage.view", usagesCount, filesCount); }
getCodeReferencesText
16,453
RefactoringActionHandler (@NotNull DataContext context) { return new WrapReturnValueHandler(); }
getHandler
16,454
boolean () { return false; }
isAvailableInEditorOnly
16,455
boolean (@NotNull PsiElement element, @NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext context) { final PsiMethod psiMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class, false); if (psiMethod != null && !(psiMethod instanceof PsiCompiledElement)) { final PsiType returnType = psiMethod.getReturnType(); return returnType != null && !PsiTypes.voidType().equals(returnType); } return false; }
isAvailableOnElementInEditorAndFile
16,456
boolean (PsiElement @NotNull [] elements) { if (elements.length != 1) { return false; } final PsiElement element = elements[0]; final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class, false); return containingMethod != null; }
isEnabledOnElements
16,457
String () { final PsiClass existingClass = JavaPsiFacade.getInstance(myProject).findClass(myQualifiedName, GlobalSearchScope.allScope(myProject)); if (existingClass != null) { if (TypeConversionUtil.isPrimitiveWrapper(myQualifiedName)) { final PsiPrimitiveType unboxedType = PsiPrimitiveType.getUnboxedType(JavaPsiFacade.getElementFactory(myProject).createType(existingClass)); assert unboxedType != null; return unboxedType.getCanonicalText() + "Value()"; } final PsiMethod getter = PropertyUtilBase.findGetterForField(myDelegateField); return getter != null ? getter.getName() : ""; } return ""; }
calculateUnwrapMethodName
16,458
UsageViewDescriptor (UsageInfo @NotNull [] usageInfos) { return new WrapReturnValueUsageViewDescriptor(myMethod, usageInfos); }
createUsageViewDescriptor
16,459
void (@NotNull List<? super FixableUsageInfo> usages) { findUsagesForMethod(myMethod, usages); for (PsiMethod overridingMethod : OverridingMethodsSearch.search(myMethod)) { findUsagesForMethod(overridingMethod, usages); } }
findUsages
16,460
void (PsiMethod psiMethod, List<? super FixableUsageInfo> usages) { for (PsiReference reference : ReferencesSearch.search(psiMethod, psiMethod.getUseScope())) { final PsiElement referenceElement = reference.getElement(); final PsiElement parent = referenceElement.getParent(); if (parent instanceof PsiCallExpression) { usages.add(new UnwrapCall((PsiCallExpression)parent, myUnwrapMethodName)); } else if (referenceElement instanceof PsiMethodReferenceExpression) { usages.add(new UnwrapCall((PsiMethodReferenceExpression)referenceElement, myUnwrapMethodName)); } } final String returnType = calculateReturnTypeString(); usages.add(new ChangeReturnType(psiMethod, returnType)); psiMethod.accept(new ReturnSearchVisitor(usages, returnType)); }
findUsagesForMethod
16,461
String () { final String qualifiedName = StringUtil.getQualifiedName(myPackageName, myClassName); final StringBuilder returnTypeBuffer = new StringBuilder(qualifiedName); if (!myTypeParameters.isEmpty()) { returnTypeBuffer.append('<'); returnTypeBuffer.append(StringUtil.join(myTypeParameters, typeParameter -> { final String paramName = typeParameter.getName(); LOG.assertTrue(paramName != null); return paramName; }, ",")); returnTypeBuffer.append('>'); } else if (myDelegateField != null) { final PsiType type = myDelegateField.getType(); final PsiType returnType = myMethod.getReturnType(); final PsiClass containingClass = myDelegateField.getContainingClass(); final PsiType inferredType = getInferredType(type, returnType, containingClass, myMethod); if (inferredType != null) { returnTypeBuffer.append("<").append(inferredType.getCanonicalText()).append(">"); } } return returnTypeBuffer.toString(); }
calculateReturnTypeString
16,462
PsiType (PsiType type, PsiType returnType, PsiClass containingClass, PsiMethod method) { if (containingClass != null && containingClass.getTypeParameters().length == 1) { final PsiSubstitutor substitutor = PsiResolveHelper.getInstance(method.getProject()) .inferTypeArguments(containingClass.getTypeParameters(), new PsiType[]{type}, new PsiType[]{returnType}, PsiUtil.getLanguageLevel( method)); final PsiTypeParameter typeParameter = containingClass.getTypeParameters()[0]; final PsiType substituted = substitutor.substitute(typeParameter); if (substituted != null && !typeParameter.equals(PsiUtil.resolveClassInClassTypeOnly(substituted))) { return substituted; } } return null; }
getInferredType
16,463
boolean (@NotNull final Ref<UsageInfo[]> refUsages) { MultiMap<PsiElement, String> conflicts = new MultiMap<>(); PsiClass existingClass = JavaPsiFacade.getInstance(myProject).findClass(myQualifiedName, GlobalSearchScope.allScope(myProject)); if (myUseExistingClass) { if (existingClass == null) { conflicts.putValue(null, JavaRareRefactoringsBundle.message("could.not.find.selected.wrapping.class")); } else { PsiElement navigationElement = existingClass.getNavigationElement(); if (navigationElement instanceof PsiClass) { existingClass = (PsiClass)navigationElement; } boolean foundConstructor = false; final Set<PsiType> returnTypes = new HashSet<>(); returnTypes.add(myMethod.getReturnType()); final PsiCodeBlock methodBody = myMethod.getBody(); if (methodBody != null) { methodBody.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitReturnStatement(final @NotNull PsiReturnStatement statement) { super.visitReturnStatement(statement); final PsiExpression returnValue = statement.getReturnValue(); if (returnValue != null) { returnTypes.add(returnValue.getType()); } } @Override public void visitClass(@NotNull PsiClass aClass) {} @Override public void visitLambdaExpression(@NotNull PsiLambdaExpression expression) {} }); } final PsiMethod[] constructors = existingClass.getConstructors(); constr: for (PsiMethod constructor : constructors) { final PsiParameter[] parameters = constructor.getParameterList().getParameters(); if (parameters.length == 1) { final PsiParameter parameter = parameters[0]; final PsiType parameterType = parameter.getType(); for (PsiType returnType : returnTypes) { if (getInferredType(parameterType, returnType, existingClass, myMethod) == null && !TypeConversionUtil.isAssignable(parameterType, returnType)) { continue constr; } } if (!PsiUtil.isAccessible(constructor, myMethod, null)) { continue constr; } final PsiCodeBlock body = constructor.getBody(); if (body == null) continue constr; final boolean[] found = new boolean[1]; body.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitAssignmentExpression(final @NotNull PsiAssignmentExpression expression) { super.visitAssignmentExpression(expression); final PsiExpression lExpression = expression.getLExpression(); if (lExpression instanceof PsiReferenceExpression && myDelegateField.isEquivalentTo(((PsiReferenceExpression)lExpression).resolve())) { found[0] = true; } } }); if (found[0]) { foundConstructor = true; break; } } } if (!foundConstructor) { conflicts.putValue(existingClass, JavaBundle.message("wrap.return.value.existing.class.does.not.have.appropriate.constructor.conflict")); } } if (myUnwrapMethodName.length() == 0) { conflicts.putValue(existingClass, JavaBundle.message("wrap.return.value.existing.class.does.not.have.getter.conflict")); } } else { if (existingClass != null) { conflicts.putValue(existingClass, JavaRareRefactoringsBundle.message("there.already.exists.a.class.with.the.selected.name")); } if (myMoveDestination != null && !myMoveDestination.isTargetAccessible(myProject, myMethod.getContainingFile().getVirtualFile())) { conflicts.putValue(myMethod, JavaBundle.message("wrap.return.value.created.class.not.accessible.conflict")); } } return showConflicts(conflicts, refUsages.get()); }
preprocessUsages
16,464
void (final @NotNull PsiReturnStatement statement) { super.visitReturnStatement(statement); final PsiExpression returnValue = statement.getReturnValue(); if (returnValue != null) { returnTypes.add(returnValue.getType()); } }
visitReturnStatement
16,465
void (@NotNull PsiClass aClass) {}
visitClass
16,466
void (@NotNull PsiLambdaExpression expression) {}
visitLambdaExpression
16,467
void (final @NotNull PsiAssignmentExpression expression) { super.visitAssignmentExpression(expression); final PsiExpression lExpression = expression.getLExpression(); if (lExpression instanceof PsiReferenceExpression && myDelegateField.isEquivalentTo(((PsiReferenceExpression)lExpression).resolve())) { found[0] = true; } }
visitAssignmentExpression
16,468
void (UsageInfo @NotNull [] usageInfos) { if (!myUseExistingClass && !buildClass()) return; super.performRefactoring(usageInfos); }
performRefactoring
16,469
boolean () { final PsiManager manager = myMethod.getManager(); final Project project = myMethod.getProject(); final ReturnValueBeanBuilder beanClassBuilder = new ReturnValueBeanBuilder(); beanClassBuilder.setProject(project); beanClassBuilder.setFile(myMethod.getContainingFile()); beanClassBuilder.setTypeArguments(myTypeParameters); beanClassBuilder.setClassName(myClassName); beanClassBuilder.setPackageName(myPackageName); beanClassBuilder.setStatic(myCreateInnerClass && myMethod.hasModifierProperty(PsiModifier.STATIC)); final PsiType returnType = myMethod.getReturnType(); beanClassBuilder.setValueType(returnType); final String classString; try { classString = beanClassBuilder.buildBeanClass(); } catch (IOException e) { LOG.error(e); return false; } try { final PsiFileFactory factory = PsiFileFactory.getInstance(project); final PsiJavaFile psiFile = (PsiJavaFile)factory.createFileFromText(myClassName + ".java", JavaFileType.INSTANCE, classString); final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); if (myCreateInnerClass) { final PsiClass containingClass = myMethod.getContainingClass(); final PsiElement innerClass = containingClass.add(psiFile.getClasses()[0]); JavaCodeStyleManager.getInstance(project).shortenClassReferences(innerClass); } else { final PsiFile containingFile = myMethod.getContainingFile(); final PsiDirectory containingDirectory = containingFile.getContainingDirectory(); final PsiDirectory directory; if (myMoveDestination != null) { directory = myMoveDestination.getTargetDirectory(containingDirectory); } else { final Module module = ModuleUtilCore.findModuleForPsiElement(containingFile); directory = PackageUtil.findOrCreateDirectoryForPackage(module, myPackageName, containingDirectory, true, true); } if (directory != null) { final PsiElement shortenedFile = JavaCodeStyleManager.getInstance(project).shortenClassReferences(psiFile); final PsiElement reformattedFile = codeStyleManager.reformat(shortenedFile); directory.add(reformattedFile); } else { return false; } } } catch (IncorrectOperationException e) { LOG.info(e); return false; } return true; }
buildClass
16,470
String () { final PsiClass containingClass = myMethod.getContainingClass(); return JavaRareRefactoringsBundle.message("wrapped.return.command.name", myClassName, StringUtil.getQualifiedName(containingClass.getName(), myMethod.getName())); }
getCommandName
16,471
void (@NotNull PsiClass aClass) {}
visitClass
16,472
void (@NotNull PsiLambdaExpression expression) {}
visitLambdaExpression
16,473
void (@NotNull PsiReturnStatement statement) { super.visitReturnStatement(statement); final PsiExpression returnValue = statement.getReturnValue(); if (myUseExistingClass && returnValue instanceof PsiMethodCallExpression callExpression) { if (callExpression.getArgumentList().isEmpty()) { final PsiReferenceExpression callMethodExpression = callExpression.getMethodExpression(); final String methodName = callMethodExpression.getReferenceName(); if (Comparing.strEqual(myUnwrapMethodName, methodName)) { final PsiExpression qualifier = callMethodExpression.getQualifierExpression(); if (qualifier != null) { final PsiType qualifierType = qualifier.getType(); if (qualifierType != null && qualifierType.getCanonicalText().equals(myQualifiedName)) { usages.add(new ReturnWrappedValue(statement)); return; } } } } } usages.add(new WrapReturnValue(statement, type)); }
visitReturnStatement
16,474
void (@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) { final ScrollingModel scrollingModel = editor.getScrollingModel(); scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE); PsiMethod selectedMethod = getSelectedMethod(editor, file); if(selectedMethod == null){ CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message( "the.caret.should.be.positioned.within.a.method.declaration.to.be.refactored"), getRefactoringNameText(), this.getHelpID()); return; } invoke(project, selectedMethod, editor); }
invoke
16,475
boolean (@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) { return getSelectedMethod(editor, file) != null; }
isAvailableForQuickList
16,476
PsiMethod (Editor editor, PsiFile file) { final int caret = editor.getCaretModel().getOffset(); final PsiElement elementAt = file.findElementAt(caret); return MethodUtils.getJavaMethodFromHeader(elementAt); }
getSelectedMethod
16,477
String () { return getRefactoringNameText(); }
getRefactoringName
16,478
String () { return HelpID.WrapReturnValue; }
getHelpID
16,479
void (@NotNull Project project, PsiElement @NotNull [] elements, DataContext dataContext) { if(elements.length != 1){ return; } PsiMethod method = PsiTreeUtil.getParentOfType(elements[0], PsiMethod.class, false); if(method == null){ return; } Editor editor = CommonDataKeys.EDITOR.getData(dataContext); invoke(project, method, editor); }
invoke
16,480
void (final Project project, PsiMethod method, Editor editor) { if(method.isConstructor()){ CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + JavaRareRefactoringsBundle.message("constructor.returns.can.not.be.wrapped"), getRefactoringNameText(), this.getHelpID()); return; } final PsiType returnType = method.getReturnType(); if(PsiTypes.voidType().equals(returnType)){ CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + JavaRareRefactoringsBundle.message("method.selected.returns.void"), getRefactoringNameText(), this.getHelpID()); return; } method = SuperMethodWarningUtil.checkSuperMethod(method); if (method == null) return; if(method instanceof PsiCompiledElement){ CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message( "the.selected.method.cannot.be.wrapped.because.it.is.defined.in.a.non.project.class"), getRefactoringNameText(), this.getHelpID()); return; } new WrapReturnValueDialog(method).show(); }
invoke
16,481
void (String className) { myClassName = className; }
setClassName
16,482
void (String packageName) { myPackageName = packageName; }
setPackageName
16,483
void (List<? extends PsiTypeParameter> typeParams) { myTypeParams.clear(); myTypeParams.addAll(typeParams); }
setTypeArguments
16,484
void (Project project) { myProject = project; }
setProject
16,485
void (@NotNull PsiFile file) { myFile = file; }
setFile
16,486
void (PsiType valueType) { myValueType = valueType; }
setValueType
16,487
void (boolean isStatic) { myStatic = isStatic; }
setStatic
16,488
void (@NonNls StringBuilder out) { final String typeText = myValueType.getCanonicalText(false); out.append('\t' + "private final ").append(typeText).append(' ').append(getFieldName("value")).append(";"); }
outputField
16,489
void (@NonNls StringBuilder out) { final String typeText = myValueType.getCanonicalText(true); final String name = "value"; final String parameterName = JavaCodeStyleManager.getInstance(myProject).propertyNameToVariableName(name, VariableKind.PARAMETER); final String fieldName = getFieldName(name); out.append("\tpublic ").append(myClassName).append('('); out.append( getSettings().getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS ? "final " : ""); out.append(typeText).append(' ').append(parameterName); out.append(") {\n"); if (fieldName.equals(parameterName)) { out.append("\t\tthis.").append(fieldName).append(" = ").append(parameterName).append(";\n"); } else { out.append("\t\t").append(fieldName).append(" = ").append(parameterName).append(";\n"); } out.append("\t}"); }
outputConstructor
16,490
CodeStyleSettings () { return myFile != null ? CodeStyle.getSettings(myFile) : CodeStyle.getProjectOrDefaultSettings(myProject); }
getSettings
16,491
void (@NonNls StringBuilder out) { final String typeText = myValueType.getCanonicalText(true); final String name = "value"; final String capitalizedName = StringUtil.capitalize(name); final String fieldName = getFieldName(name); out.append("\tpublic ").append(typeText).append(" get").append(capitalizedName).append("() {\n"); out.append("\t\treturn ").append(fieldName).append(";\n"); out.append("\t}"); }
outputGetter
16,492
String (final String name) { return JavaCodeStyleManager.getInstance(myProject).propertyNameToVariableName(name, VariableKind.FIELD); }
getFieldName
16,493
String () { return "RefactorJ.WrapReturnValue"; }
getDimensionServiceKey
16,494
void () { final boolean useExistingClass = useExistingClassButton.isSelected(); final boolean createInnerClass = myCreateInnerClassButton.isSelected(); final String existingClassName = existingClassField.getText().trim(); final String className; final String packageName; if (useExistingClass) { className = StringUtil.getShortName(existingClassName); packageName = StringUtil.getPackageName(existingClassName); } else if (createInnerClass) { className = getInnerClassName(); packageName = ""; } else { className = getClassName(); packageName = getPackageName(); } invokeRefactoring( new WrapReturnValueProcessor(className, packageName, ((DestinationFolderComboBox)myDestinationCb).selectDirectory(new PackageWrapper(sourceMethod.getManager(), packageName), false), sourceMethod, useExistingClass, createInnerClass, (PsiField)myFieldsCombo.getSelectedItem())); }
doAction
16,495
String () { return myInnerClassNameTextField.getText().trim(); }
getInnerClassName
16,496
String () { return packageTextField.getText().trim(); }
getPackageName
16,497
String () { return classNameField.getText().trim(); }
getClassName
16,498
JComponent () { sourceMethodTextField.setEditable(false); final DocumentListener docListener = new DocumentAdapter() { @Override protected void textChanged(@NotNull final DocumentEvent e) { validateButtons(); } }; classNameField.getDocument().addDocumentListener(docListener); myFieldsCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { validateButtons(); } }); myInnerClassNameTextField.getDocument().addDocumentListener(docListener); final PsiFile file = sourceMethod.getContainingFile(); if (file instanceof PsiJavaFile) { final String packageName = ((PsiJavaFile)file).getPackageName(); packageTextField.setText(packageName); } final PsiClass containingClass = sourceMethod.getContainingClass(); assert containingClass != null : sourceMethod; final String containingClassName = containingClass instanceof PsiAnonymousClass ? JavaBundle.message("wrap.return.value.anonymous.class.presentation", ((PsiAnonymousClass)containingClass).getBaseClassType().getClassName()) : containingClass.getName(); final String sourceMethodName = sourceMethod.getName(); sourceMethodTextField.setText(containingClassName + '.' + sourceMethodName); final ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(useExistingClassButton); buttonGroup.add(createNewClassButton); buttonGroup.add(myCreateInnerClassButton); createNewClassButton.setSelected(true); final ActionListener enableListener = new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { toggleRadioEnablement(); } }; useExistingClassButton.addActionListener(enableListener); createNewClassButton.addActionListener(enableListener); myCreateInnerClassButton.addActionListener(enableListener); toggleRadioEnablement(); final DefaultComboBoxModel<PsiField> model = new DefaultComboBoxModel<>(); myFieldsCombo.setModel(model); myFieldsCombo.setRenderer(SimpleListCellRenderer.create((label, field, index) -> { if (field != null) { label.setText(field.getName()); label.setIcon(field.getIcon(Iconable.ICON_FLAG_VISIBILITY)); } })); existingClassField.getChildComponent().getDocument().addDocumentListener(new com.intellij.openapi.editor.event.DocumentListener() { @Override public void documentChanged(@NotNull com.intellij.openapi.editor.event.DocumentEvent e) { final JavaPsiFacade facade = JavaPsiFacade.getInstance(myProject); final PsiClass currentClass = facade.findClass(existingClassField.getText(), GlobalSearchScope.allScope(myProject)); if (currentClass != null) { model.removeAllElements(); final PsiType returnType = sourceMethod.getReturnType(); assert returnType != null; for (PsiField field : currentClass.getFields()) { final PsiType fieldType = field.getType(); if (TypeConversionUtil.isAssignable(fieldType, returnType)) { model.addElement(field); } else { if (WrapReturnValueProcessor.getInferredType(fieldType, returnType, currentClass, sourceMethod) != null) { model.addElement(field); } } } } } }); return myWholePanel; }
createCenterPanel
16,499
void (@NotNull final DocumentEvent e) { validateButtons(); }
textChanged