Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class InplaceIntroduceParameterPopup extends AbstractJavaInplaceIntroduce
final PsiExpression[] occurrences,
final IntList parametersToRemove,
final boolean mustBeFinal) {
super(project, editor, expr, localVar, occurrences, typeSelectorManager, IntroduceParameterHandler.REFACTORING_NAME
super(project, editor, expr, localVar, occurrences, typeSelectorManager, IntroduceParameterHandler.REFACTORING_NAME.get()
);
myMethod = method;
myMethodToSearchFor = methodToSearchFor;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.intellij.java.language.psi.javadoc.PsiDocTag;
import com.intellij.java.language.psi.util.PsiUtil;
import com.intellij.java.language.util.VisibilityUtil;
import consulo.annotation.access.RequiredReadAction;
import consulo.annotation.access.RequiredWriteAction;
import consulo.annotation.component.ExtensionImpl;
import consulo.language.Language;
import consulo.language.codeStyle.CodeStyleManager;
Expand All @@ -53,15 +55,20 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
Logger.getInstance(JavaIntroduceParameterMethodUsagesProcessor.class);
private static final JavaLanguage myLanguage = Language.findInstance(JavaLanguage.class);

@RequiredReadAction
private static boolean isJavaUsage(UsageInfo usage) {
PsiElement e = usage.getElement();
return e != null && e.getLanguage().is(myLanguage);
}

@Override
@RequiredReadAction
public boolean isMethodUsage(UsageInfo usage) {
return RefactoringUtil.isMethodUsage(usage.getElement()) && isJavaUsage(usage);
}

@Override
@RequiredWriteAction
public boolean processChangeMethodUsage(
IntroduceParameterData data,
UsageInfo usage,
Expand Down Expand Up @@ -108,13 +115,9 @@ public boolean processChangeMethodUsage(
PsiElement initializer =
ExpressionConverter.getExpression(data.getParameterInitializer().getExpression(), JavaLanguage.INSTANCE, data.getProject());
assert initializer instanceof PsiExpression;
if (initializer instanceof PsiNewExpression) {
if (!PsiDiamondTypeUtil.canChangeContextForDiamond(
(PsiNewExpression) initializer,
((PsiNewExpression) initializer).getType()
)) {
initializer = PsiDiamondTypeUtil.expandTopLevelDiamondsInside((PsiNewExpression) initializer);
}
if (initializer instanceof PsiNewExpression newExpression
&& !PsiDiamondTypeUtil.canChangeContextForDiamond(newExpression, newExpression.getType())) {
initializer = PsiDiamondTypeUtil.expandTopLevelDiamondsInside(newExpression);
}
substituteTypeParametersInInitializer(initializer, callExpression, argList, methodToSearchFor);
ChangeContextUtil.encodeContextInfo(initializer, true);
Expand All @@ -141,20 +144,23 @@ private static void substituteTypeParametersInInitializer(
PsiMethod method
) {
Project project = method.getProject();
PsiSubstitutor psiSubstitutor = JavaPsiFacade.getInstance(project).getResolveHelper()
.inferTypeArguments(
method.getTypeParameters(),
method.getParameterList().getParameters(),
argList.getExpressions(),
PsiSubstitutor.EMPTY,
callExpression,
DefaultParameterTypeInferencePolicy.INSTANCE
);
RefactoringUtil.replaceMovedMemberTypeParameters(initializer, PsiUtil.typeParametersIterable(method), psiSubstitutor,
PsiSubstitutor psiSubstitutor = JavaPsiFacade.getInstance(project).getResolveHelper().inferTypeArguments(
method.getTypeParameters(),
method.getParameterList().getParameters(),
argList.getExpressions(),
PsiSubstitutor.EMPTY,
callExpression,
DefaultParameterTypeInferencePolicy.INSTANCE
);
RefactoringUtil.replaceMovedMemberTypeParameters(
initializer,
PsiUtil.typeParametersIterable(method),
psiSubstitutor,
JavaPsiFacade.getElementFactory(project)
);
}

@RequiredWriteAction
private static void removeParametersFromCall(@Nonnull PsiExpressionList argList, IntList parametersToRemove) {
PsiExpression[] exprs = argList.getExpressions();

Expand Down Expand Up @@ -185,6 +191,7 @@ private static PsiExpression getLast(PsiExpression[] oldArgs) {
}

@Override
@RequiredReadAction
public void findConflicts(IntroduceParameterData data, UsageInfo[] usages, MultiMap<PsiElement, LocalizeValue> conflicts) {
PsiMethod method = data.getMethodToReplaceIn();
int parametersCount = method.getParameterList().getParametersCount();
Expand All @@ -197,8 +204,8 @@ public void findConflicts(IntroduceParameterData data, UsageInfo[] usages, Multi
PsiExpressionList argList = call.getArgumentList();
if (argList != null) {
int actualParamLength = argList.getExpressions().length;
if ((method.isVarArgs() && actualParamLength + 1 < parametersCount) ||
(!method.isVarArgs() && actualParamLength < parametersCount)) {
if ((method.isVarArgs() && actualParamLength + 1 < parametersCount)
|| (!method.isVarArgs() && actualParamLength < parametersCount)) {
conflicts.putValue(
call,
LocalizeValue.localizeTODO(
Expand All @@ -223,6 +230,7 @@ public void findConflicts(IntroduceParameterData data, UsageInfo[] usages, Multi
}

@Override
@RequiredWriteAction
public boolean processChangeMethodSignature(
IntroduceParameterData data,
UsageInfo usage,
Expand Down Expand Up @@ -288,11 +296,12 @@ public static PsiParameter getAnchorParameter(PsiMethod methodToReplaceIn) {
return anchorParameter;
}

@Override
@RequiredWriteAction
public boolean processAddDefaultConstructor(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) {
if (!(usage.getElement() instanceof PsiClass) || !isJavaUsage(usage)) {
if (!(usage.getElement() instanceof PsiClass aClass) || !isJavaUsage(usage)) {
return true;
}
PsiClass aClass = (PsiClass) usage.getElement();
if (!(aClass instanceof PsiAnonymousClass)) {
PsiElementFactory factory = JavaPsiFacade.getInstance(data.getProject()).getElementFactory();
PsiMethod constructor = factory.createMethodFromText(aClass.getName() + "(){}", aClass);
Expand All @@ -307,15 +316,13 @@ public boolean processAddDefaultConstructor(IntroduceParameterData data, UsageIn
return false;
}

public boolean processAddSuperCall(
IntroduceParameterData data,
UsageInfo usage,
UsageInfo[] usages
) throws IncorrectOperationException {
if (!(usage.getElement() instanceof PsiMethod) || !isJavaUsage(usage)) {
@Override
@RequiredWriteAction
public boolean processAddSuperCall(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages)
throws IncorrectOperationException {
if (!(usage.getElement() instanceof PsiMethod constructor) || !isJavaUsage(usage)) {
return true;
}
PsiMethod constructor = (PsiMethod) usage.getElement();

if (!constructor.isConstructor()) {
return true;
Expand Down
Loading
Loading