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 @@ -329,7 +329,7 @@ private void showUsageView(
SimpleReference<Usage[]> convertUsagesRef = new SimpleReference<>();
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(
() -> project.getApplication().runReadAction(() -> convertUsagesRef.set(UsageInfo2UsageAdapter.convert(usageInfos))),
"Preprocess Usages",
LocalizeValue.localizeTODO("Preprocess Usages"),
true,
project
)) {
Expand All @@ -342,27 +342,30 @@ private void showUsageView(
Usage[] usages = convertUsagesRef.get();

UsageViewPresentation presentation = new UsageViewPresentation();
presentation.setTabText("Infer Nullity Preview");
presentation.setTabText(LocalizeValue.localizeTODO("Infer Nullity Preview"));
presentation.setShowReadOnlyStatusAsRed(true);
presentation.setShowCancelButton(true);
presentation.setUsagesString(RefactoringLocalize.usageviewUsagestext());

UsageView usageView =
UsageViewManager.getInstance(project).showUsages(targets, usages, presentation, rerunFactory(annotateLocalVars, project, scope));
UsageViewManager.getInstance(project)
.showUsages(targets, usages, presentation, rerunFactory(annotateLocalVars, project, scope));

Runnable refactoringRunnable = applyRunnable(project, () ->
{
Set<UsageInfo> infos = UsageViewUtil.getNotExcludedUsageInfos(usageView);
return infos.toArray(new UsageInfo[infos.size()]);
});

String canNotMakeString = "Cannot perform operation.\n" +
"There were changes in code after usages have been found.\n" +
"Please perform operation search again.";
LocalizeValue canNotMakeString = LocalizeValue.localizeTODO(
"Cannot perform operation.\n" +
"There were changes in code after usages have been found.\n" +
"Please perform operation search again."
);

usageView.addPerformOperationAction(
refactoringRunnable,
INFER_NULLITY_ANNOTATIONS.get(),
INFER_NULLITY_ANNOTATIONS,
canNotMakeString,
INFER_NULLITY_ANNOTATIONS,
false
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected void refreshElements(PsiElement[] elements) {

@Nonnull
@Override
protected String getCommandName() {
protected LocalizeValue getCommandName() {
return ChangeClassSignatureDialog.REFACTORING_NAME;
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,26 @@
import consulo.localize.LocalizeValue;

/**
* @author dsl
* @author dsl
*/
public class NewParameterCollidesWithLocalUsageInfo extends UnresolvableCollisionUsageInfo {
private final PsiElement myConflictingElement;
private final PsiMethod myMethod;
private final PsiElement myConflictingElement;
private final PsiMethod myMethod;

public NewParameterCollidesWithLocalUsageInfo(PsiElement element, PsiElement referencedElement,
PsiMethod method) {
super(element, referencedElement);
myConflictingElement = referencedElement;
myMethod = method;
}
public NewParameterCollidesWithLocalUsageInfo(
PsiElement element, PsiElement referencedElement,
PsiMethod method
) {
super(element, referencedElement);
myConflictingElement = referencedElement;
myMethod = method;
}

public String getDescription() {
LocalizeValue buffer = RefactoringLocalize.thereIsAlreadyA0In1ItWillConflictWithTheNewParameter(
RefactoringUIUtil.getDescription(myConflictingElement, true),
RefactoringUIUtil.getDescription(myMethod, true)
);

return CommonRefactoringUtil.capitalize(buffer.get());
}
@Override
public LocalizeValue getDescription() {
return RefactoringLocalize.thereIsAlreadyA0In1ItWillConflictWithTheNewParameter(
RefactoringUIUtil.getDescription(myConflictingElement, true),
RefactoringUIUtil.getDescription(myMethod, true)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import consulo.codeEditor.Editor;
import consulo.codeEditor.ScrollType;
import consulo.dataContext.DataContext;
import consulo.language.editor.refactoring.RefactoringBundle;
import consulo.language.editor.refactoring.action.RefactoringActionHandler;
import consulo.language.editor.refactoring.localize.RefactoringLocalize;
import consulo.language.editor.refactoring.util.CommonRefactoringUtil;
Expand All @@ -39,90 +38,99 @@
* @author dsl
*/
public class ConvertToInstanceMethodHandler implements RefactoringActionHandler {
private static final Logger LOG = Logger.getInstance(ConvertToInstanceMethodHandler.class);
static final String REFACTORING_NAME = RefactoringBundle.message("convert.to.instance.method.title");
private static final Logger LOG = Logger.getInstance(ConvertToInstanceMethodHandler.class);
static final LocalizeValue REFACTORING_NAME = RefactoringLocalize.convertToInstanceMethodTitle();

@RequiredUIAccess
public void invoke(@Nonnull Project project, Editor editor, PsiFile file, DataContext dataContext) {
PsiElement element = dataContext.getData(PsiElement.KEY);
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
if (element == null) {
element = file.findElementAt(editor.getCaretModel().getOffset());
}
@Override
@RequiredUIAccess
public void invoke(@Nonnull Project project, Editor editor, PsiFile file, DataContext dataContext) {
PsiElement element = dataContext.getData(PsiElement.KEY);
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
if (element == null) {
element = file.findElementAt(editor.getCaretModel().getOffset());
}

if (element == null) return;
if (element instanceof PsiIdentifier) element = element.getParent();
if (element == null) {
return;
}
if (element instanceof PsiIdentifier) {
element = element.getParent();
}

if (!(element instanceof PsiMethod)) {
LocalizeValue message = RefactoringLocalize.cannotPerformRefactoringWithReason(RefactoringLocalize.errorWrongCaretPositionMethod());
CommonRefactoringUtil.showErrorHint(project, editor, message.get(), REFACTORING_NAME, HelpID.CONVERT_TO_INSTANCE_METHOD);
return;
}
if (LOG.isDebugEnabled()) {
LOG.debug("MakeMethodStaticHandler invoked");
if (!(element instanceof PsiMethod)) {
LocalizeValue message =
RefactoringLocalize.cannotPerformRefactoringWithReason(RefactoringLocalize.errorWrongCaretPositionMethod());
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.CONVERT_TO_INSTANCE_METHOD);
return;
}
if (LOG.isDebugEnabled()) {
LOG.debug("MakeMethodStaticHandler invoked");
}
invoke(project, new PsiElement[]{element}, dataContext);
}
invoke(project, new PsiElement[]{element}, dataContext);
}

@RequiredUIAccess
public void invoke(@Nonnull Project project, @Nonnull PsiElement[] elements, DataContext dataContext) {
if (elements.length != 1 || !(elements[0] instanceof PsiMethod)) return;
PsiMethod method = (PsiMethod)elements[0];
if (!method.hasModifierProperty(PsiModifier.STATIC)) {
LocalizeValue message = RefactoringLocalize.converttoinstancemethodMethodIsNotStatic(method.getName());
Editor editor = dataContext.getData(Editor.KEY);
CommonRefactoringUtil.showErrorHint(project, editor, message.get(), REFACTORING_NAME, HelpID.CONVERT_TO_INSTANCE_METHOD);
return;
}
PsiParameter[] parameters = method.getParameterList().getParameters();
List<PsiParameter> suitableParameters = new ArrayList<>();
boolean classTypesFound = false;
boolean resolvableClassesFound = false;
boolean classesInProjectFound = false;
for (PsiParameter parameter : parameters) {
PsiType type = parameter.getType();
if (type instanceof PsiClassType classType) {
classTypesFound = true;
PsiClass psiClass = classType.resolve();
if (psiClass != null && !(psiClass instanceof PsiTypeParameter)) {
resolvableClassesFound = true;
boolean inProject = method.getManager().isInProject(psiClass);
if (inProject) {
classesInProjectFound = true;
suitableParameters.add(parameter);
}
@Override
@RequiredUIAccess
public void invoke(@Nonnull Project project, @Nonnull PsiElement[] elements, DataContext dataContext) {
if (elements.length != 1 || !(elements[0] instanceof PsiMethod)) {
return;
}
PsiMethod method = (PsiMethod) elements[0];
if (!method.isStatic()) {
LocalizeValue message = RefactoringLocalize.converttoinstancemethodMethodIsNotStatic(method.getName());
Editor editor = dataContext.getData(Editor.KEY);
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.CONVERT_TO_INSTANCE_METHOD);
return;
}
PsiParameter[] parameters = method.getParameterList().getParameters();
List<PsiParameter> suitableParameters = new ArrayList<>();
boolean classTypesFound = false;
boolean resolvableClassesFound = false;
boolean classesInProjectFound = false;
for (PsiParameter parameter : parameters) {
PsiType type = parameter.getType();
if (type instanceof PsiClassType classType) {
classTypesFound = true;
PsiClass psiClass = classType.resolve();
if (psiClass != null && !(psiClass instanceof PsiTypeParameter)) {
resolvableClassesFound = true;
boolean inProject = method.getManager().isInProject(psiClass);
if (inProject) {
classesInProjectFound = true;
suitableParameters.add(parameter);
}
}
}
}
if (suitableParameters.isEmpty()) {
LocalizeValue message;
if (!classTypesFound) {
message = RefactoringLocalize.converttoinstancemethodNoParametersWithReferenceType();
}
else if (!resolvableClassesFound) {
message = RefactoringLocalize.converttoinstancemethodAllReferenceTypeParametresHaveUnknownTypes();
}
else if (!classesInProjectFound) {
message = RefactoringLocalize.converttoinstancemethodAllReferenceTypeParametersAreNotInProject();
}
else {
LOG.assertTrue(false);
return;
}
Editor editor = dataContext.getData(Editor.KEY);
CommonRefactoringUtil.showErrorHint(
project,
editor,
RefactoringLocalize.cannotPerformRefactoringWithReason(message),
REFACTORING_NAME,
HelpID.CONVERT_TO_INSTANCE_METHOD
);
return;
}
}
}
if (suitableParameters.isEmpty()) {
LocalizeValue message;
if (!classTypesFound) {
message = RefactoringLocalize.converttoinstancemethodNoParametersWithReferenceType();
}
else if (!resolvableClassesFound) {
message = RefactoringLocalize.converttoinstancemethodAllReferenceTypeParametresHaveUnknownTypes();
}
else if (!classesInProjectFound) {
message = RefactoringLocalize.converttoinstancemethodAllReferenceTypeParametersAreNotInProject();
}
else {
LOG.assertTrue(false);
return;
}
Editor editor = dataContext.getData(Editor.KEY);
CommonRefactoringUtil.showErrorHint(
project,
editor,
RefactoringLocalize.cannotPerformRefactoringWithReason(message).get(),
REFACTORING_NAME,
HelpID.CONVERT_TO_INSTANCE_METHOD
);
return;
}

new ConvertToInstanceMethodDialog(
method,
suitableParameters.toArray(new PsiParameter[suitableParameters.size()])
).show();
}
new ConvertToInstanceMethodDialog(
method,
suitableParameters.toArray(new PsiParameter[suitableParameters.size()])
).show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected boolean preprocessUsages(@Nonnull SimpleReference<UsageInfo[]> refUsag
}

@Override
@RequiredUIAccess
@RequiredWriteAction
protected void performRefactoring(@Nonnull UsageInfo[] usages) {
if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, myTargetClass)) {
return;
Expand Down Expand Up @@ -240,7 +240,8 @@ else if (usage instanceof ImplementingClassUsageInfo implementingClassUsageInfo)
PsiMethod newMethod = addMethodToClass(psiClass);
PsiUtil.setModifierProperty(
newMethod,
myNewVisibility != null && !myNewVisibility.equals(VisibilityUtil.ESCALATE_VISIBILITY) ? myNewVisibility
myNewVisibility != null && !myNewVisibility.equals(VisibilityUtil.ESCALATE_VISIBILITY)
? myNewVisibility
: PsiModifier.PUBLIC,
true
);
Expand Down Expand Up @@ -381,7 +382,7 @@ private void processMethodCall(MethodCallUsageInfo usageInfo) throws IncorrectOp

@Nonnull
@Override
protected String getCommandName() {
protected LocalizeValue getCommandName() {
return ConvertToInstanceMethodHandler.REFACTORING_NAME;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ protected UsageViewDescriptor createUsageViewDescriptor(@Nonnull UsageInfo[] usa
@Nonnull
@Override
@RequiredReadAction
protected String getCommandName() {
return RefactoringLocalize.encapsulateFieldsCommandName(DescriptiveNameUtil.getDescriptiveName(myClass)).get();
protected LocalizeValue getCommandName() {
return RefactoringLocalize.encapsulateFieldsCommandName(DescriptiveNameUtil.getDescriptiveName(myClass));
}

@Override
Expand Down
Loading
Loading