@Nullable private static String calculateOverridingSiblingMethodTooltip(@NotNull PsiMethod method) { Pair<PsiMethod, PsiClass> pair = FindSuperElementsHelper.getSiblingInheritedViaSubClass(method, FindSuperElementsHelper.createSubClassCache()); if (pair == null) return null; PsiMethod superMethod = pair.getFirst(); PsiClass subClass = pair.getSecond(); boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT); boolean isSuperAbstract = superMethod.hasModifierProperty(PsiModifier.ABSTRACT); String postfix = MessageFormat.format(" via sub-class <a href=\"#javaClass/{0}\">{0}</a>", ClassPresentationUtil.getNameForClass(subClass, true)); @NonNls String pattern = DaemonBundle.message(isSuperAbstract && !isAbstract ? "method.implements" : "method.overrides") + postfix; return composeText(new PsiElement[]{superMethod}, "", pattern, IdeActions.ACTION_GOTO_SUPER); }
@Override protected void customizeRendererText(ColoredTreeCellRenderer renderer) { final StringBuilder buffer = new StringBuilder(128); final PsiClass containingClass = myMethod.getContainingClass(); if (containingClass != null) { buffer.append(ClassPresentationUtil.getNameForClass(containingClass, false)); buffer.append('.'); } final String methodText = PsiFormatUtil.formatMethod( myMethod, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS, PsiFormatUtil.SHOW_TYPE ); buffer.append(methodText); final SimpleTextAttributes attributes = isEnabled() ? new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, UIUtil.getTreeForeground()) : SimpleTextAttributes.EXCLUDED_ATTRIBUTES; renderer.append(buffer.toString(), attributes); if (containingClass != null) { final String packageName = getPackageName(containingClass); renderer.append(" (" + packageName + ")", new SimpleTextAttributes(SimpleTextAttributes.STYLE_ITALIC, JBColor.GRAY)); } }
private static StringBuilder composeText(@NotNull PsiElement[] elements, final String pattern, StringBuilder result) { Set<String> names = new LinkedHashSet<String>(); for (PsiElement element : elements) { String methodName = ((PsiMethod)element).getName(); PsiClass aClass = ((PsiMethod)element).getContainingClass(); String className = aClass == null ? "" : ClassPresentationUtil.getNameForClass(aClass, true); names.add(MessageFormat.format(pattern, methodName, className)); } @NonNls String sep = ""; for (String name : names) { result.append(sep); sep = "<br>"; result.append(name); } return result; }
@Nullable public SearchScope getScope() { if (myCachedScope == null) { TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createAllProjectScopeChooser(IdeBundle.message("prompt.choose.base.class.of.the.hierarchy")); chooser.showDialog(); PsiClass aClass = chooser.getSelected(); if (aClass == null) return null; List<PsiElement> classesToSearch = new LinkedList<PsiElement>(); classesToSearch.add(aClass); classesToSearch.addAll(ClassInheritorsSearch.search(aClass, true).findAll()); myCachedScope = new LocalSearchScope(PsiUtilCore.toPsiElementArray(classesToSearch), IdeBundle.message("scope.hierarchy", ClassPresentationUtil.getNameForClass(aClass, true))); } return myCachedScope; }
@Override protected void customizeRendererText(ColoredTreeCellRenderer renderer) { final StringBuffer buffer = new StringBuffer(128); final PsiClass containingClass = myMethod.getContainingClass(); if (containingClass != null) { buffer.append(ClassPresentationUtil.getNameForClass(containingClass, false)); buffer.append('.'); } final String methodText = PsiFormatUtil.formatMethod( myMethod, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS, PsiFormatUtil.SHOW_TYPE ); buffer.append(methodText); final SimpleTextAttributes attributes = isEnabled() ? new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, UIUtil.getTreeForeground()) : SimpleTextAttributes.EXCLUDED_ATTRIBUTES; renderer.append(buffer.toString(), attributes); if (containingClass != null) { final String packageName = getPackageName(containingClass); renderer.append(" (" + packageName + ")", new SimpleTextAttributes(SimpleTextAttributes.STYLE_ITALIC, JBColor.GRAY)); } }
@Nullable private static String calculateOverridingSiblingMethodTooltip(@NotNull PsiMethod method) { FindSuperElementsHelper.SiblingInfo pair = FindSuperElementsHelper.getSiblingInfoInheritedViaSubClass(method); if(pair == null) { return null; } PsiMethod superMethod = pair.superMethod; PsiClass subClass = pair.subClass; boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT); boolean isSuperAbstract = superMethod.hasModifierProperty(PsiModifier.ABSTRACT); String postfix = MessageFormat.format(" via sub-class <a href=\"#javaClass/{0}\">{0}</a>", ClassPresentationUtil.getNameForClass(subClass, true)); @NonNls String pattern = DaemonBundle.message(isSuperAbstract && !isAbstract ? "method.implements" : "method.overrides") + postfix; return composeText(new PsiElement[]{superMethod}, "", pattern, IdeActions.ACTION_GOTO_SUPER); }
@Nullable public SearchScope getScope() { if (myCachedScope == null) { TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createAllProjectScopeChooser(IdeBundle.message("prompt.choose.base.class.of.the.hierarchy")); chooser.showDialog(); PsiClass aClass = chooser.getSelected(); if (aClass == null) return null; List<PsiElement> classesToSearch = new LinkedList<PsiElement>(); classesToSearch.add(aClass); classesToSearch.addAll(ClassInheritorsSearch.search(aClass, true).findAll()); myCachedScope = new LocalSearchScope(PsiUtilBase.toPsiElementArray(classesToSearch), IdeBundle.message("scope.hierarchy", ClassPresentationUtil.getNameForClass(aClass, true))); } return myCachedScope; }
@Override public String getElementLocation(final Object element) { if (element instanceof PsiField) { final PsiClass psiClass = ((PsiField)element).getContainingClass(); if (psiClass != null) { return ClassPresentationUtil.getNameForClass(psiClass, true); } } return null; }
@Override public String getElementLocation(final Object element) { if (element instanceof PsiClass) { return ClassPresentationUtil.getNameForClass((PsiClass)element, true); } return null; }
@Override public String getElementLocation(final Object element) { if (element instanceof PsiMethod) { final PsiClass parent = ((PsiMethod)element).getContainingClass(); if (parent != null) { return ClassPresentationUtil.getNameForClass(parent, true); } } return null; }
@Override public String getPresentableText(final Object object) { if (object instanceof PsiClass) { return ClassPresentationUtil.getNameForClass((PsiClass)object, false); } else if (object instanceof PsiPackage) { final String name = ((PsiPackage)object).getName(); return name != null ? name : AnalysisScopeBundle.message("dependencies.tree.node.default.package.abbreviation"); } else if (object instanceof PsiDirectory && JrtFileSystem.isRoot(((PsiDirectory)object).getVirtualFile())) { return LangBundle.message("jrt.node.short"); } return null; }
private static void addListenerRef(final DefaultActionGroup actionGroup, final String eventName, final PsiExpression listenerArg) { final PsiType type = listenerArg.getType(); if (type instanceof PsiClassType) { PsiClass listenerClass = ((PsiClassType) type).resolve(); if (listenerClass != null) { if (!isAbstractOrInterface(listenerClass)) { actionGroup.add(new MyNavigateAction(eventName + ": " + ClassPresentationUtil.getNameForClass(listenerClass, false), listenerClass)); return; } else if (listenerArg instanceof PsiReferenceExpression) { final PsiElement psiElement = ((PsiReferenceExpression)listenerArg).resolve(); if (psiElement instanceof PsiVariable) { PsiCodeBlock codeBlock = PsiTreeUtil.getParentOfType(listenerArg, PsiCodeBlock.class); final PsiElement[] defs = DefUseUtil.getDefs(codeBlock, (PsiVariable)psiElement, listenerArg); if (defs.length == 1) { final PsiElement def = defs[0]; if (def instanceof PsiVariable) { PsiVariable var = (PsiVariable) def; if (var.getInitializer() != listenerArg) { addListenerRef(actionGroup, eventName, var.getInitializer()); return; } } else if (def.getParent() instanceof PsiAssignmentExpression) { final PsiAssignmentExpression assignmentExpr = (PsiAssignmentExpression)def.getParent(); if (def.equals(assignmentExpr.getLExpression())) { addListenerRef(actionGroup, eventName, assignmentExpr.getRExpression()); return; } } } } } } } actionGroup.add(new MyNavigateAction(eventName + ": " + listenerArg.getText(), listenerArg)); }
public String getPresentableText(final Object object) { if (object instanceof PsiClass) { return ClassPresentationUtil.getNameForClass((PsiClass)object, false); } else if (object instanceof PsiPackage) { final String name = ((PsiPackage)object).getName(); return name != null ? name : AnalysisScopeBundle.message("dependencies.tree.node.default.package.abbreviation"); } return null; }
@Override public String getElementLocation(final Object element) { if(element instanceof PsiField) { final PsiClass psiClass = ((PsiField) element).getContainingClass(); if(psiClass != null) { return ClassPresentationUtil.getNameForClass(psiClass, true); } } return null; }
@Override public String getElementLocation(final Object element) { if(element instanceof PsiMethod) { final PsiClass parent = ((PsiMethod) element).getContainingClass(); if(parent != null) { return ClassPresentationUtil.getNameForClass(parent, true); } } return null; }
public String getPresentableText(final Object object) { if (object instanceof PsiClass) { return ClassPresentationUtil.getNameForClass((PsiClass)object, false); } else if (object instanceof PsiJavaPackage) { final String name = ((PsiJavaPackage)object).getName(); return name != null ? name : AnalysisScopeBundle.message("dependencies.tree.node.default.package.abbreviation"); } return null; }
@Override protected String getContentDisplayName(@NotNull String typeName, @NotNull PsiElement element) { return MessageFormat.format(typeName, ClassPresentationUtil.getNameForClass((PsiClass)element, false)); }
@Override public String getElementText(PsiClass element) { return ClassPresentationUtil.getNameForClass(element, false); }
@Override public String getElementText(NavigatablePsiElement element) { return element instanceof PsiClass ? ClassPresentationUtil.getNameForClass((PsiClass)element, false) : PsiExpressionTrimRenderer.render((PsiExpression)element); }
public String toString() { final PsiClass aClass = (PsiClass)getPsiElement(); return aClass != null && aClass.isValid() ? ClassPresentationUtil.getNameForClass(aClass, false) : ""; }
@Override protected void processIntention(@NotNull PsiElement element) throws IncorrectOperationException { final PsiClass anInterface = (PsiClass)element.getParent(); final SearchScope searchScope = anInterface.getUseScope(); final Query<PsiClass> query = ClassInheritorsSearch.search(anInterface, searchScope, false); final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>(); query.forEach(new Processor<PsiClass>() { @Override public boolean process(PsiClass aClass) { final PsiReferenceList extendsList = aClass.getExtendsList(); if (extendsList == null) { return true; } final PsiJavaCodeReferenceElement[] referenceElements = extendsList.getReferenceElements(); if (referenceElements.length > 0) { final PsiElement target = referenceElements[0].resolve(); if (target != null) { conflicts.putValue(aClass, IntentionPowerPackBundle.message( "0.already.extends.1.and.will.not.compile.after.converting.2.to.a.class", RefactoringUIUtil.getDescription(aClass, true), RefactoringUIUtil.getDescription(target, true), RefactoringUIUtil.getDescription(anInterface, false))); } } return true; } }); final PsiFunctionalExpression functionalExpression = FunctionalExpressionSearch.search(anInterface, searchScope).findFirst(); if (functionalExpression != null) { final String conflictMessage = ClassPresentationUtil.getFunctionalExpressionPresentation(functionalExpression, true) + " will not compile after converting " + RefactoringUIUtil.getDescription(anInterface, false) + " to a class"; conflicts.putValue(functionalExpression, conflictMessage); } final boolean conflictsDialogOK; if (conflicts.isEmpty()) { conflictsDialogOK = true; } else { if (getApplication().isUnitTestMode()) { throw new BaseRefactoringProcessor.ConflictsInTestsException(conflicts.values()); } final ConflictsDialog conflictsDialog = new ConflictsDialog(anInterface.getProject(), conflicts, new Runnable() { @Override public void run() { final AccessToken token = start(); try { convertInterfaceToClass(anInterface); } finally { token.finish(); } } }); conflictsDialogOK = conflictsDialog.showAndGet(); } if (conflictsDialogOK) { convertInterfaceToClass(anInterface); } }
private String getElementPresentableName(T element) { final PsiClass aClass = element.getContainingClass(); LOG.assertTrue(aClass != null); return ClassPresentationUtil.getNameForClass(aClass, false) + "." + element.getName(); }
@Override protected String getContentDisplayName(@NotNull String typeName, @NotNull PsiElement element) { return MessageFormat.format(typeName, ClassPresentationUtil.getNameForClass((PsiClass) element, false)); }
@Override public String getElementText(NavigatablePsiElement element) { return element instanceof PsiClass ? ClassPresentationUtil.getNameForClass((PsiClass) element, false) : PsiExpressionTrimRenderer.render((PsiExpression) element); }