use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class RemoveMiddlemanProcessor method findUsages.
public void findUsages(@NotNull List<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);
}
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class MoveMembersDialog method getSelectedMembers.
public PsiMember[] getSelectedMembers() {
final Collection<MemberInfo> selectedMemberInfos = myTable.getSelectedMemberInfos();
ArrayList<PsiMember> list = new ArrayList<>();
for (MemberInfo selectedMemberInfo : selectedMemberInfos) {
list.add(selectedMemberInfo.getMember());
}
return list.toArray(new PsiMember[list.size()]);
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class ExtractMethodObjectProcessor method moveUsedMethodsToInner.
void moveUsedMethodsToInner() {
if (!myUsages.isEmpty()) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
WriteAction.run(() -> {
for (MethodToMoveUsageInfo usage : myUsages) {
final PsiMember member = (PsiMember) usage.getElement();
LOG.assertTrue(member != null);
myInnerClass.add(member.copy());
member.delete();
}
});
return;
}
final List<MemberInfo> memberInfos = new ArrayList<>();
for (MethodToMoveUsageInfo usage : myUsages) {
memberInfos.add(new MemberInfo((PsiMethod) usage.getElement()));
}
final MemberSelectionPanel panel = new MemberSelectionPanel("&Methods to move to the extracted class", memberInfos, null);
DialogWrapper dlg = new DialogWrapper(myProject, false) {
{
init();
setTitle("Move Methods Used in Extracted Block Only");
}
@Override
protected JComponent createCenterPanel() {
return panel;
}
};
if (dlg.showAndGet()) {
WriteAction.run(() -> {
for (MemberInfoBase<PsiMember> memberInfo : panel.getTable().getSelectedMemberInfos()) {
if (memberInfo.isChecked()) {
myInnerClass.add(memberInfo.getMember().copy());
memberInfo.getMember().delete();
}
}
});
}
}
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class ExtractSuperClassUtil method createExtendingReference.
public static PsiJavaCodeReferenceElement createExtendingReference(final PsiClass superClass, final PsiClass derivedClass, final MemberInfo[] selectedMembers) throws IncorrectOperationException {
final PsiManager manager = derivedClass.getManager();
Set<PsiElement> movedElements = new com.intellij.util.containers.HashSet<>();
for (final MemberInfo info : selectedMembers) {
movedElements.add(info.getMember());
}
final Condition<PsiTypeParameter> filter = parameter -> findTypeParameterInDerived(derivedClass, parameter.getName()) == parameter;
final PsiTypeParameterList typeParameterList = RefactoringUtil.createTypeParameterListWithUsedTypeParameters(null, filter, PsiUtilCore.toPsiElementArray(movedElements));
final PsiTypeParameterList originalTypeParameterList = superClass.getTypeParameterList();
assert originalTypeParameterList != null;
final PsiTypeParameterList newList = typeParameterList != null ? (PsiTypeParameterList) originalTypeParameterList.replace(typeParameterList) : originalTypeParameterList;
final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
Map<PsiTypeParameter, PsiType> substitutionMap = new HashMap<>();
for (final PsiTypeParameter parameter : newList.getTypeParameters()) {
final PsiTypeParameter parameterInDerived = findTypeParameterInDerived(derivedClass, parameter.getName());
if (parameterInDerived != null) {
substitutionMap.put(parameter, factory.createType(parameterInDerived));
}
}
final PsiClassType type = factory.createType(superClass, factory.createSubstitutor(substitutionMap));
return factory.createReferenceElementByType(type);
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class ExtractSuperclassDialog method createCenterPanel.
protected JComponent createCenterPanel() {
JPanel panel = new JPanel(new BorderLayout());
final MemberSelectionPanel memberSelectionPanel = new MemberSelectionPanel(RefactoringBundle.message("members.to.form.superclass"), myMemberInfos, RefactoringBundle.message("make.abstract"));
panel.add(memberSelectionPanel, BorderLayout.CENTER);
final MemberInfoModel<PsiMember, MemberInfo> memberInfoModel = new UsesAndInterfacesDependencyMemberInfoModel<PsiMember, MemberInfo>(mySourceClass, null, false, myContainmentVerifier) {
@Override
public Boolean isFixedAbstract(MemberInfo member) {
return Boolean.TRUE;
}
};
memberInfoModel.memberInfoChanged(new MemberInfoChange<>(myMemberInfos));
memberSelectionPanel.getTable().setMemberInfoModel(memberInfoModel);
memberSelectionPanel.getTable().addMemberInfoChangeListener(memberInfoModel);
panel.add(myDocCommentPanel, BorderLayout.EAST);
return panel;
}
Aggregations