public static PsiMethod checkSuperMethod(@NotNull PsiMethod method, @NotNull String actionString) { PsiClass aClass = method.getContainingClass(); if (aClass == null) return method; PsiMethod superMethod = method.findDeepestSuperMethod(); if (superMethod == null) return method; if (ApplicationManager.getApplication().isUnitTestMode()) return superMethod; PsiClass containingClass = superMethod.getContainingClass(); SuperMethodWarningDialog dialog = new SuperMethodWarningDialog( method.getProject(), DescriptiveNameUtil.getDescriptiveName(method), actionString, containingClass.isInterface() || superMethod.hasModifierProperty(PsiModifier.ABSTRACT), containingClass.isInterface(), aClass.isInterface(), containingClass.getQualifiedName() ); dialog.show(); if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) return superMethod; if (dialog.getExitCode() == SuperMethodWarningDialog.NO_EXIT_CODE) return method; return null; }
public void setup(final PsiClass innerClass, final String className, final boolean passOuterClass, final String parameterName, boolean searchInComments, boolean searchInNonJava, @NotNull final PsiElement targetContainer) { myNewClassName = className; myInnerClass = innerClass; myDescriptiveName = DescriptiveNameUtil.getDescriptiveName(myInnerClass); myOuterClass = myInnerClass.getContainingClass(); myTargetContainer = targetContainer; JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(myProject); myParameterNameOuterClass = passOuterClass ? parameterName : null; if (myParameterNameOuterClass != null) { myFieldNameOuterClass = codeStyleManager.variableNameToPropertyName(myParameterNameOuterClass, VariableKind.PARAMETER); myFieldNameOuterClass = codeStyleManager.propertyNameToVariableName(myFieldNameOuterClass, VariableKind.FIELD); } mySearchInComments = searchInComments; mySearchInNonJavaFiles = searchInNonJava; }
@SuppressWarnings({"HardCodedStringLiteral"}) public TypeCookDialog(Project project, PsiElement[] elements) { super(project, true); setTitle(REFACTORING_NAME); init(); StringBuffer name = new StringBuffer(); myElements = elements; for (int i = 0; i < elements.length; i++) { PsiElement element = elements[i]; name.append(StringUtil.capitalize(UsageViewUtil.getType(element))); name.append(" "); name.append(DescriptiveNameUtil.getDescriptiveName(element)); if (i < elements.length - 1) { name.append("<br>"); } } myClassNameLabel.setText(XmlStringUtil.wrapInHtml(name)); }
public InlineMethodProcessor(@NotNull Project project, @NotNull PsiMethod method, @Nullable PsiJavaCodeReferenceElement reference, Editor editor, boolean isInlineThisOnly, boolean searchInComments, boolean searchForTextOccurrences) { super(project); myMethod = method; myReference = reference; myEditor = editor; myInlineThisOnly = isInlineThisOnly; mySearchInComments = searchInComments; mySearchForTextOccurrences = searchForTextOccurrences; myManager = PsiManager.getInstance(myProject); myFactory = JavaPsiFacade.getInstance(myManager.getProject()).getElementFactory(); myCodeStyleManager = CodeStyleManager.getInstance(myProject); myJavaCodeStyle = JavaCodeStyleManager.getInstance(myProject); myDescriptiveName = DescriptiveNameUtil.getDescriptiveName(myMethod); }
@Override @NotNull public String getNodeText(@NotNull PsiElement element, boolean useFullName) { if (element instanceof XmlTag) { final XmlTag xmlTag = (XmlTag)element; final PsiMetaData metaData = xmlTag.getMetaData(); final String name = metaData != null ? DescriptiveNameUtil.getMetaDataName(metaData) : xmlTag.getName(); String presentableName = metaData == null ? "<" + name + ">" : name; return presentableName+" of file "+xmlTag.getContainingFile().getName(); } if (element instanceof XmlAttributeValue) { return ((XmlAttributeValue)element).getValue(); } if (element instanceof PsiNamedElement) { return ((PsiNamedElement)element).getName(); } return element.getText(); }
public GroovyFieldValidator(GrIntroduceContext context) { super(context, new ConflictReporter() { @Override public void check(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.overriden.by.method.1", CommonRefactoringUtil.htmlEmphasize(varName), CommonRefactoringUtil.htmlEmphasize(DescriptiveNameUtil.getDescriptiveName(toCheck)))); } } } }); }
public GroovyInplaceFieldValidator(GrIntroduceContext context) { super(context, new ConflictReporter() { @Override public void check(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.overriden.by.method.1", CommonRefactoringUtil.htmlEmphasize(varName), CommonRefactoringUtil.htmlEmphasize(DescriptiveNameUtil.getDescriptiveName(toCheck)))); } } } }); }
public static PsiMethod checkSuperMethod(final PsiMethod method, String actionString) { PsiClass aClass = method.getContainingClass(); if (aClass == null) return method; PsiMethod superMethod = method.findDeepestSuperMethod(); if (superMethod == null) return method; if (ApplicationManager.getApplication().isUnitTestMode()) return superMethod; PsiClass containingClass = superMethod.getContainingClass(); SuperMethodWarningDialog dialog = new SuperMethodWarningDialog( method.getProject(), DescriptiveNameUtil.getDescriptiveName(method), actionString, containingClass.isInterface() || superMethod.hasModifierProperty(PsiModifier.ABSTRACT), containingClass.isInterface(), aClass.isInterface(), containingClass.getQualifiedName() ); dialog.show(); if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) return superMethod; if (dialog.getExitCode() == SuperMethodWarningDialog.NO_EXIT_CODE) return method; return null; }
@NotNull public String getNodeText(@NotNull PsiElement element, boolean useFullName) { if (element instanceof XmlTag) { final XmlTag xmlTag = (XmlTag)element; final PsiMetaData metaData = xmlTag.getMetaData(); final String name = metaData != null ? DescriptiveNameUtil.getMetaDataName(metaData) : xmlTag.getName(); return UsageViewBundle.message("usage.target.xml.tag.of.file", metaData == null ? "<" + name + ">" : name, xmlTag.getContainingFile().getName()); } else if (element instanceof XmlAttributeValue) { return ((XmlAttributeValue)element).getValue(); } if (element instanceof PsiNamedElement) { return ((PsiNamedElement)element).getName(); } else { return element.getText(); } }
public GroovyFieldValidator(GrIntroduceContext context) { super(context, new ConflictReporter() { @Override public void check(PsiElement toCheck, MultiMap<PsiElement, String> conflicts, String varName) { if (toCheck instanceof GrField && varName.equals(((GrField)toCheck).getName())) { conflicts.putValue(toCheck, message("field.0.is.already.defined", htmlEmphasize(varName))); } if (toCheck instanceof GrMethod) { if (GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)toCheck) && varName.equals(GroovyPropertyUtils.getPropertyNameByAccessorName(((PsiMethod)toCheck).getName()))) { conflicts.putValue(toCheck, message("access.to.created.field.0.will.be.overriden.by.method.1", htmlEmphasize(varName), htmlEmphasize(DescriptiveNameUtil.getDescriptiveName(toCheck)))); } } } }); }
public GroovyInplaceFieldValidator(GrIntroduceContext context) { super(context, new ConflictReporter() { @Override public void check(PsiElement toCheck, MultiMap<PsiElement, String> conflicts, String varName) { if (toCheck instanceof GrVariable && varName.equals(((GrVariable)toCheck).getName())) { conflicts.putValue(toCheck, message("field.0.is.already.defined", htmlEmphasize(varName))); } if (toCheck instanceof GrMethod) { if (GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)toCheck) && varName.equals(GroovyPropertyUtils.getPropertyNameByAccessorName(((PsiMethod)toCheck).getName()))) { conflicts.putValue(toCheck, message("access.to.created.field.0.will.be.overriden.by.method.1", htmlEmphasize(varName), htmlEmphasize(DescriptiveNameUtil.getDescriptiveName(toCheck)))); } } } }); }
@Override @NotNull public String getNodeText(@NotNull PsiElement element, boolean useFullName) { if(element instanceof XmlTag) { final XmlTag xmlTag = (XmlTag) element; final PsiMetaData metaData = xmlTag.getMetaData(); final String name = metaData != null ? DescriptiveNameUtil.getMetaDataName(metaData) : xmlTag.getName(); String presentableName = metaData == null ? "<" + name + ">" : name; return presentableName + " of file " + xmlTag.getContainingFile().getName(); } if(element instanceof XmlAttributeValue) { return ((XmlAttributeValue) element).getValue(); } if(element instanceof PsiNamedElement) { return ((PsiNamedElement) element).getName(); } return element.getText(); }
protected String getCommandName() { if (myConstructor != null) { return RefactoringBundle.message("replace.constructor.0.with.a.factory.method", DescriptiveNameUtil.getDescriptiveName(myConstructor)); } else { return RefactoringBundle.message("replace.default.constructor.of.0.with.a.factory.method", DescriptiveNameUtil.getDescriptiveName(myOriginalClass)); } }
@Override public String getElementDescription(@NotNull final PsiElement element, @NotNull final ElementDescriptionLocation location) { if (!(location instanceof UsageViewShortNameLocation)) return null; if (element instanceof PsiMetaOwner) { PsiMetaData metaData = ((PsiMetaOwner)element).getMetaData(); if (metaData!=null) return DescriptiveNameUtil.getMetaDataName(metaData); } if (element instanceof PsiNamedElement) { return ((PsiNamedElement)element).getName(); } return ""; }
@NotNull @Override public String getLongDescriptiveName() { SearchScope searchScope = myOptions.searchScope; String scopeString = searchScope.getDisplayName(); PsiElement psiElement = getElement(); return psiElement == null ? UsageViewBundle.message("node.invalid") : FindBundle.message("recent.find.usages.action.popup", StringUtil.capitalize(UsageViewUtil.getType(psiElement)), DescriptiveNameUtil.getDescriptiveName(psiElement), scopeString ); }
@Override protected void performRefactoringRename(final String newName, final StartMarkAction markAction) { try { final PsiNamedElement variable = getVariable(); if (variable != null && !newName.equals(myOldName)) { if (isIdentifier(newName, variable.getLanguage())) { final PsiElement substituted = getSubstituted(); if (substituted == null) { return; } final String commandName = RefactoringBundle .message("renaming.0.1.to.2", UsageViewUtil.getType(variable), DescriptiveNameUtil.getDescriptiveName(variable), newName); CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { @Override public void run() { performRenameInner(substituted, newName); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); } }, commandName, null); } } } finally { try { ((EditorImpl)InjectedLanguageUtil.getTopLevelEditor(myEditor)).stopDumbLater(); } finally { FinishMarkAction.finish(myProject, myEditor, markAction); } } }
private void setNewName(@NotNull String newName) { if (myPrimaryElement == null) { myCommandName = RefactoringBundle.message("renaming.something"); return; } myNewName = newName; myAllRenames.put(myPrimaryElement, newName); myCommandName = RefactoringBundle .message("renaming.0.1.to.2", UsageViewUtil.getType(myPrimaryElement), DescriptiveNameUtil.getDescriptiveName(myPrimaryElement), newName); }
public InvertBooleanDialog(final PsiElement element) { super(element.getProject(), false); myElement = element; final String name = myElement instanceof PsiNamedElement ? ((PsiNamedElement)myElement).getName() : myElement.getText(); myNameField.setText(name); myLabel.setLabelFor(myNameField); final String typeString = UsageViewUtil.getType(myElement); myLabel.setText(RefactoringBundle.message("invert.boolean.name.of.inverted.element", typeString)); myCaptionLabel.setText(RefactoringBundle.message("invert.0.1", typeString, DescriptiveNameUtil.getDescriptiveName(myElement))); setTitle(InvertBooleanHandler.REFACTORING_NAME); init(); }
public static String calculatePsiElementDescriptionList(PsiElement[] elements) { StringBuilder buffer = new StringBuilder(); for (int i = 0; i < elements.length; i++) { if (i > 0) buffer.append(", "); buffer.append(UsageViewUtil.getType(elements[i])); buffer.append(" "); buffer.append(DescriptiveNameUtil.getDescriptiveName(elements[i])); } return buffer.toString(); }
private static String buildPropertyName(PsiElement e, boolean property) { if (property) return DescriptiveNameUtil.getDescriptiveName(e); List<String> path = new ArrayList<String>(); do { path.add(DescriptiveNameUtil.getDescriptiveName(e)); } while ((e = PsiTreeUtil.getParentOfType(e, XmlTag.class)) != null); Collections.reverse(path); return StringUtil.join(path, "."); }
@NotNull public static PsiMethod[] checkSuperMethods(final PsiMethod method, String actionString, Collection<PsiElement> ignore) { PsiClass aClass = method.getContainingClass(); if (aClass == null) return new PsiMethod[]{method}; final Collection<PsiMethod> superMethods = DeepestSuperMethodsSearch.search(method).findAll(); if (ignore != null) { superMethods.removeAll(ignore); } if (superMethods.isEmpty()) return new PsiMethod[]{method}; Set<String> superClasses = new HashSet<String>(); boolean superAbstract = false; boolean parentInterface = false; for (final PsiMethod superMethod : superMethods) { final PsiClass containingClass = superMethod.getContainingClass(); superClasses.add(containingClass.getQualifiedName()); final boolean isInterface = containingClass.isInterface(); superAbstract |= isInterface || superMethod.hasModifierProperty(PsiModifier.ABSTRACT); parentInterface |= isInterface; } SuperMethodWarningDialog dialog = new SuperMethodWarningDialog(method.getProject(), DescriptiveNameUtil.getDescriptiveName(method), actionString, superAbstract, parentInterface, aClass.isInterface(), ArrayUtil.toStringArray(superClasses)); dialog.show(); if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) { return superMethods.toArray(new PsiMethod[superMethods.size()]); } if (dialog.getExitCode() == SuperMethodWarningDialog.NO_EXIT_CODE) { return new PsiMethod[]{method}; } return PsiMethod.EMPTY_ARRAY; }
public InvertBooleanDialog(final PsiNamedElement element) { super(element.getProject(), false); myElement = element; final String name = myElement.getName(); myNameField.setText(name); myLabel.setLabelFor(myNameField); final String typeString = UsageViewUtil.getType(myElement); myLabel.setText(RefactoringBundle.message("invert.boolean.name.of.inverted.element", typeString)); myCaptionLabel.setText(RefactoringBundle.message("invert.0.1", typeString, DescriptiveNameUtil.getDescriptiveName(myElement))); setTitle(InvertBooleanHandler.REFACTORING_NAME); init(); }
@Override public String getElementDescription(@Nonnull final PsiElement element, @Nonnull final ElementDescriptionLocation location) { if (!(location instanceof UsageViewShortNameLocation)) return null; if (element instanceof PsiMetaOwner) { PsiMetaData metaData = ((PsiMetaOwner)element).getMetaData(); if (metaData!=null) return DescriptiveNameUtil.getMetaDataName(metaData); } if (element instanceof PsiNamedElement) { return ((PsiNamedElement)element).getName(); } return ""; }
@Nonnull @Override public String getLongDescriptiveName() { SearchScope searchScope = myOptions.searchScope; String scopeString = searchScope.getDisplayName(); PsiElement psiElement = getElement(); return psiElement == null ? UsageViewBundle.message("node.invalid") : FindBundle.message("recent.find.usages.action.popup", StringUtil.capitalize(UsageViewUtil.getType(psiElement)), DescriptiveNameUtil.getDescriptiveName(psiElement), scopeString); }
public InplaceChangeSignature(Project project, Editor editor, @Nonnull PsiElement element) { myDocumentManager = PsiDocumentManager.getInstance(project); myProject = project; try { myMarkAction = StartMarkAction.start(editor, project, ChangeSignatureHandler.REFACTORING_NAME); } catch (StartMarkAction.AlreadyStartedException e) { final int exitCode = Messages.showYesNoDialog(myProject, e.getMessage(), ChangeSignatureHandler.REFACTORING_NAME, "Navigate to Started", "Cancel", Messages.getErrorIcon()); if (exitCode == Messages.CANCEL) return; PsiElement method = myStableChange.getMethod(); VirtualFile virtualFile = PsiUtilCore.getVirtualFile(method); new OpenFileDescriptor(project, virtualFile, method.getTextOffset()).navigate(true); return; } myEditor = editor; myDetector = LanguageChangeSignatureDetectors.INSTANCE.forLanguage(element.getLanguage()); myStableChange = myDetector.createInitialChangeInfo(element); myInitialSignature = myDetector.extractSignature(myStableChange); myInitialName = DescriptiveNameUtil.getDescriptiveName(myStableChange.getMethod()); TextRange highlightingRange = myDetector.getHighlightingRange(myStableChange); HighlightManager highlightManager = HighlightManager.getInstance(myProject); TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.LIVE_TEMPLATE_ATTRIBUTES); highlightManager.addRangeHighlight(editor, highlightingRange.getStartOffset(), highlightingRange.getEndOffset(), attributes, false, myHighlighters); for (RangeHighlighter highlighter : myHighlighters) { highlighter.setGreedyToRight(true); highlighter.setGreedyToLeft(true); } myEditor.getDocument().addDocumentListener(this); myEditor.putUserData(INPLACE_CHANGE_SIGNATURE, this); myPreview = InplaceRefactoring.createPreviewComponent(project, myDetector.getFileType()); showBalloon(); }