public static LookupElementBuilder forMethod(@NotNull PsiMethod method, @NotNull String lookupString, final @NotNull PsiSubstitutor substitutor, @Nullable PsiClass qualifierClass) { LookupElementBuilder builder = LookupElementBuilder.create(method, lookupString) .withIcon(method.getIcon(Iconable.ICON_FLAG_VISIBILITY)) .withPresentableText(method.getName()) .withTailText(PsiFormatUtil.formatMethod(method, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE)); final PsiType returnType = method.getReturnType(); if (returnType != null) { builder = builder.withTypeText(substitutor.substitute(returnType).getPresentableText()); } builder = setBoldIfInClass(method, qualifierClass, builder); return builder; }
private void generateVariableJavaDoc(@NonNls StringBuilder buffer, PsiVariable variable, boolean generatePrologueAndEpilogue) { if (generatePrologueAndEpilogue) generatePrologue(buffer); buffer.append("<PRE>"); String modifiers = PsiFormatUtil.formatModifiers(variable, PsiFormatUtilBase.JAVADOC_MODIFIERS_ONLY); if (!modifiers.isEmpty()) { buffer.append(modifiers); buffer.append(" "); } generateType(buffer, variable.getType(), variable); buffer.append(" "); buffer.append("<b>"); buffer.append(variable.getName()); appendInitializer(buffer, variable); buffer.append("</b>"); buffer.append("</PRE>"); //buffer.append("<br>"); ColorUtil.appendColorPreview(variable, buffer); if (generatePrologueAndEpilogue) generateEpilogue(buffer); }
private static String formatMethodSignature(PsiMethod method, boolean raw, boolean java8Format) { int options = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS; int parameterOptions = PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_FQ_CLASS_NAMES; if (raw) { options |= PsiFormatUtilBase.SHOW_RAW_NON_TOP_TYPE; parameterOptions |= PsiFormatUtilBase.SHOW_RAW_NON_TOP_TYPE; } String signature = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, options, parameterOptions, 999); if (java8Format) { signature = signature.replaceAll("\\(|\\)|, ", "-").replaceAll("\\[\\]", ":A"); } return signature; }
@Override public void updateImpl(PresentationData data) { String name = PsiFormatUtil.formatMethod( (PsiMethod)getPsiElement(), PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE ); int c = name.indexOf('\n'); if (c > -1) { name = name.substring(0, c - 1); } data.setPresentableText(name); }
@Override public void updateImpl(PresentationData data) { String name = PsiFormatUtil.formatMethod( getValue(), PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE ); int c = name.indexOf('\n'); if (c > -1) { name = name.substring(0, c - 1); } data.setPresentableText(name); }
public OverridingMethodsDialog(Project project, List<UsageInfo> overridingMethods) { super(project, true); myOverridingMethods = overridingMethods; myChecked = new boolean[myOverridingMethods.size()]; for (int i = 0; i < myChecked.length; i++) { myChecked[i] = true; } myMethodText = new String[myOverridingMethods.size()]; for (int i = 0; i < myMethodText.length; i++) { myMethodText[i] = PsiFormatUtil.formatMethod( ((SafeDeleteOverridingMethodUsageInfo) myOverridingMethods.get(i)).getOverridingMethod(), PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_CONTAINING_CLASS | PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS | PsiFormatUtilBase.SHOW_TYPE, PsiFormatUtilBase.SHOW_TYPE ); } myUsagePreviewPanel = new UsagePreviewPanel(project, new UsageViewPresentation()); setTitle(RefactoringBundle.message("unused.overriding.methods.title")); init(); }
private static String getMethodCandidateInfo(GrReferenceExpression expr) { final GroovyResolveResult[] candidates = expr.multiResolve(false); final String text = expr.getText(); if (candidates.length > 0) { @NonNls final StringBuilder sb = new StringBuilder(); for (final GroovyResolveResult candidate : candidates) { final PsiElement element = candidate.getElement(); if (!(element instanceof PsiMethod)) { continue; } final String str = PsiFormatUtil .formatMethod((PsiMethod)element, candidate.getSubstitutor(), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE); createElementLink(sb, element, str); } return CodeInsightBundle.message("javadoc.candidates", text, sb); } return CodeInsightBundle.message("javadoc.candidates.not.found", text); }
private static void generateVariableJavaDoc(@NonNls StringBuilder buffer, PsiVariable variable, boolean generatePrologueAndEpilogue) { if (generatePrologueAndEpilogue) generatePrologue(buffer); buffer.append("<PRE>"); String modifiers = PsiFormatUtil.formatModifiers(variable, PsiFormatUtilBase.JAVADOC_MODIFIERS_ONLY); if (modifiers.length() > 0) { buffer.append(modifiers); buffer.append(" "); } generateType(buffer, variable.getType(), variable); buffer.append(" "); buffer.append("<b>"); buffer.append(variable.getName()); appendInitializer(buffer, variable); buffer.append("</b>"); buffer.append("</PRE>"); //buffer.append("<br>"); ColorUtil.appendColorPreview(variable, buffer); if (generatePrologueAndEpilogue) generateEpilogue(buffer); }
private static LookupElementBuilder createGenerateMethodElement(PsiMethod prototype, PsiSubstitutor substitutor, Icon icon, String typeText, InsertHandler<LookupElement> insertHandler) { String methodName = prototype.getName(); String visibility = VisibilityUtil.getVisibilityModifier(prototype.getModifierList()); String modifiers = (visibility == PsiModifier.PACKAGE_LOCAL ? "" : visibility + " "); PsiType type = substitutor.substitute(prototype.getReturnType()); String signature = modifiers + (type == null ? "" : type.getPresentableText() + " ") + methodName; String parameters = PsiFormatUtil.formatMethod(prototype, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_NAME); LookupElementBuilder element = LookupElementBuilder.create(prototype, signature).withLookupString(methodName). withLookupString(signature).withInsertHandler(insertHandler). appendTailText(parameters, false).appendTailText(" {...}", true).withTypeText(typeText).withIcon(icon); element.putUserData(GENERATE_ELEMENT, true); return element; }
public MethodList(PsiClass psiClass) { super(new BorderLayout()); model = new SortedListModel<PsiMethod>(comparator); list = new JBList(model); this.psiClass = psiClass; evaluate(psiClass.getAllMethods(), new TestMethodFilter()); add(ScrollPaneFactory.createScrollPane(list)); list.setCellRenderer(new ColoredListCellRenderer() { @Override protected void customizeCellRenderer(JList jlist, Object obj, int i, boolean flag, boolean flag1) { PsiMethod psimethod = (PsiMethod)obj; append(PsiFormatUtil.formatMethod(psimethod, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME, 0), StructureNodeRenderer.applyDeprecation(psimethod, SimpleTextAttributes.REGULAR_ATTRIBUTES)); PsiClass psiclass1 = psimethod.getContainingClass(); if(!MethodList.this.psiClass.equals(psiclass1)) { append(" (" + psiclass1.getQualifiedName() + ')', StructureNodeRenderer.applyDeprecation(psiclass1, SimpleTextAttributes.GRAY_ATTRIBUTES)); } } }); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ListScrollingUtil.ensureSelectionExists(list); }
private static String getMethodCandidateInfo(GrReferenceExpression expr) { final GroovyResolveResult[] candidates = expr.multiResolve(false); final String text = expr.getText(); if (candidates.length > 0) { @NonNls final StringBuilder sb = new StringBuilder(); for (final GroovyResolveResult candidate : candidates) { final PsiElement element = candidate.getElement(); if (!(element instanceof PsiMethod)) { continue; } final String str = PsiFormatUtil .formatMethod((PsiMethod)element, candidate.getSubstitutor(), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE); createElementLink(sb, element, str); } return CodeInsightBundle.message("javadoc.candiates", text, sb); } return CodeInsightBundle.message("javadoc.candidates.not.found", text); }
private static LookupElementBuilder createGenerateMethodElement(PsiMethod prototype, PsiSubstitutor substitutor, Icon icon, String typeText, InsertHandler<LookupElement> insertHandler) { String methodName = prototype.getName(); String visibility = VisibilityUtil.getVisibilityModifier(prototype.getModifierList()); String modifiers = (visibility == PsiModifier.PACKAGE_LOCAL ? "" : visibility + " "); PsiType type = substitutor.substitute(prototype.getReturnType()); String signature = modifiers + (type == null ? "" : type.getPresentableText() + " ") + methodName; String parameters = PsiFormatUtil.formatMethod(prototype, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_NAME); String overrideSignature = " @Override " + signature; // leading space to make it a middle match, under all annotation suggestions LookupElementBuilder element = LookupElementBuilder.create(prototype, signature).withLookupString(methodName). withLookupString(signature).withLookupString(overrideSignature).withInsertHandler(insertHandler). appendTailText(parameters, false).appendTailText(" {...}", true).withTypeText(typeText).withIcon(icon); element.putUserData(GENERATE_ELEMENT, true); return element; }
public static LookupElementBuilder forMethod(@NotNull PsiMethod method, @NotNull String lookupString, final @NotNull PsiSubstitutor substitutor, @Nullable PsiClass qualifierClass) { LookupElementBuilder builder = LookupElementBuilder.create(method, lookupString) .withIcon(IconDescriptorUpdaters.getIcon(method, Iconable.ICON_FLAG_VISIBILITY)) .withPresentableText(method.getName()) .withTailText(PsiFormatUtil.formatMethod(method, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE)); final PsiType returnType = method.getReturnType(); if (returnType != null) { builder = builder.withTypeText(substitutor.substitute(returnType).getPresentableText()); } builder = setBoldIfInClass(method, qualifierClass, builder); return builder; }
private static void generateFieldSignature(StringBuilder buffer, PsiField field, boolean generateLink) { generateAnnotations(buffer, field, generateLink, true, false); String modifiers = PsiFormatUtil.formatModifiers(field, PsiFormatUtilBase.JAVADOC_MODIFIERS_ONLY); if(!modifiers.isEmpty()) { buffer.append(modifiers); buffer.append(" "); } generateType(buffer, field.getType(), field, generateLink); buffer.append(" "); buffer.append("<b>"); buffer.append(field.getName()); appendInitializer(buffer, field); enumConstantOrdinal(buffer, field, field.getContainingClass(), "\n"); buffer.append("</b>"); }
public static String formatMethodSignature(PsiMethod method, boolean raw, boolean java8Format) { int options = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS; int parameterOptions = PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_FQ_CLASS_NAMES; if(raw) { options |= PsiFormatUtilBase.SHOW_RAW_NON_TOP_TYPE; parameterOptions |= PsiFormatUtilBase.SHOW_RAW_NON_TOP_TYPE; } String signature = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, options, parameterOptions, 999); if(java8Format) { signature = signature.replaceAll("\\(|\\)|, ", "-").replaceAll("\\[\\]", ":A"); } return signature; }
@Override public void updateImpl(PresentationData data) { final PsiClass aClass = getValue(); if(aClass != null) { if(aClass.hasTypeParameters()) { StringBuilder builder = new StringBuilder(); builder.append(aClass.getName()); PsiFormatUtil.formatTypeParameters(aClass, builder, PsiFormatUtilBase.SHOW_TYPE_PARAMETER_EXTENDS); data.setPresentableText(builder.toString()); } else { data.setPresentableText(aClass.getName()); } } }
@Override public void updateImpl(PresentationData data) { String name = PsiFormatUtil.formatMethod( getValue(), PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE_PARAMETERS | PsiFormatUtilBase.SHOW_TYPE_PARAMETER_EXTENDS | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE ); int c = name.indexOf('\n'); if (c > -1) { name = name.substring(0, c - 1); } data.setPresentableText(name); }
public OverridingMethodsDialog(Project project, List<UsageInfo> overridingMethods) { super(project, true); myOverridingMethods = overridingMethods; myChecked = new boolean[myOverridingMethods.size()]; for(int i = 0; i < myChecked.length; i++) { myChecked[i] = true; } myMethodText = new String[myOverridingMethods.size()]; for(int i = 0; i < myMethodText.length; i++) { myMethodText[i] = PsiFormatUtil.formatMethod(((SafeDeleteOverridingMethodUsageInfo) myOverridingMethods.get(i)).getOverridingMethod(), PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_CONTAINING_CLASS | PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS | PsiFormatUtilBase.SHOW_TYPE, PsiFormatUtilBase.SHOW_TYPE); } myUsagePreviewPanel = new UsagePreviewPanel(project, new UsageViewPresentation()); setTitle(RefactoringBundle.message("unused.overriding.methods.title")); init(); }
@Nullable public static String getSymbolName(@NotNull PsiElement symbol, PsiSubstitutor substitutor) { String symbolName = null; if (symbol instanceof PsiClass) { if (symbol instanceof PsiAnonymousClass) { symbolName = LangBundle.message("java.terms.anonymous.class"); } else { symbolName = ((PsiClass)symbol).getQualifiedName(); if (symbolName == null) { symbolName = ((PsiClass)symbol).getName(); } } } else if (symbol instanceof PsiMethod) { symbolName = PsiFormatUtil.formatMethod((PsiMethod)symbol, substitutor, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_FQ_CLASS_NAMES | PsiFormatUtilBase.USE_INTERNAL_CANONICAL_TEXT); } else if (symbol instanceof PsiVariable) { symbolName = ((PsiVariable)symbol).getName(); } else if (symbol instanceof PsiPackage) { symbolName = ((PsiPackage)symbol).getQualifiedName(); } else if (symbol instanceof PsiFile) { PsiDirectory directory = ((PsiFile)symbol).getContainingDirectory(); PsiPackage aPackage = directory == null ? null : JavaDirectoryService.getInstance().getPackage(directory); symbolName = aPackage == null ? null : aPackage.getQualifiedName(); } else if (symbol instanceof PsiDirectory) { symbolName = ((PsiDirectory)symbol).getName(); } return symbolName; }
@NotNull public static ColoredItemPresentation getMethodPresentation(@NotNull final PsiMethod psiMethod) { return new ColoredItemPresentation() { @Override public String getPresentableText() { return PsiFormatUtil.formatMethod( psiMethod, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE ); } @Override public TextAttributesKey getTextAttributesKey() { if (psiMethod.isDeprecated()) { return CodeInsightColors.DEPRECATED_ATTRIBUTES; } return null; } @Override public String getLocationString() { return getJavaSymbolContainerText(psiMethod); } @Override public Icon getIcon(boolean open) { return psiMethod.getIcon(Iconable.ICON_FLAG_VISIBILITY); } }; }
@NotNull @Override public String getPresentation() { String label = getLabel(); String formatted = PsiFormatUtil.formatMethod( myMethod, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE, 999 ); return label != null? label + formatted : formatted; }
public MethodThrowsFix(@NotNull PsiMethod method, @NotNull PsiClassType exceptionType, boolean shouldThrow, boolean showContainingClass) { super(method); myThrowsCanonicalText = exceptionType.getCanonicalText(); myShouldThrow = shouldThrow; myMethodName = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | (showContainingClass ? PsiFormatUtilBase.SHOW_CONTAINING_CLASS : 0), 0); }
public static String getSearchableTypeName(final PsiElement e) { if (e instanceof PsiThrowStatement) { final PsiThrowStatement aThrow = (PsiThrowStatement)e; final PsiType type = aThrow.getException().getType(); return PsiFormatUtil.formatType(type, PsiFormatUtilBase.SHOW_FQ_CLASS_NAMES, PsiSubstitutor.EMPTY); } if (e instanceof PsiKeyword && PsiKeyword.THROWS.equals(e.getText())) { return e.getParent().getText(); } LOG.error("invalid searchable element"); return e.getText(); }
public void renderElement(LookupElementPresentation presentation, boolean showClass, boolean showPackage, PsiSubstitutor substitutor) { final String className = myContainingClass == null ? "???" : myContainingClass.getName(); final String memberName = myMember.getName(); if (showClass && StringUtil.isNotEmpty(className)) { presentation.setItemText(className + "." + memberName); } else { presentation.setItemText(memberName); } final String qname = myContainingClass == null ? "" : myContainingClass.getQualifiedName(); String pkg = qname == null ? "" : StringUtil.getPackageName(qname); String location = showPackage && StringUtil.isNotEmpty(pkg) ? " (" + pkg + ")" : ""; final String params = myMergedOverloads ? "(...)" : myMember instanceof PsiMethod ? PsiFormatUtil.formatMethod((PsiMethod)myMember, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE) : ""; presentation.clearTail(); presentation.appendTailText(params, false); if (myShouldImport && StringUtil.isNotEmpty(className)) { presentation.appendTailText(" in " + className + location, true); } else { presentation.appendTailText(location, true); } final PsiType type = myMember instanceof PsiMethod ? ((PsiMethod)myMember).getReturnType() : ((PsiField) myMember).getType(); if (type != null) { presentation.setTypeText(substitutor.substitute(type).getPresentableText()); } }
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); Icon icon = null; if (value instanceof PsiField) { PsiField field = (PsiField)value; icon = field.getIcon(0); final String text = PsiFormatUtil.formatVariable(field, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE, PsiSubstitutor.EMPTY); setText(text); } super.setIcon(icon); return this; }
private String format(PsiVariable variable, PsiModifierList modifierList) { String name = null; PsiElement parent = variable == null ? modifierList == null ? null : modifierList.getParent() : variable; if (parent instanceof PsiClass) { name = ((PsiClass)parent).getName(); } else { int options = PsiFormatUtilBase.SHOW_NAME | (myShowContainingClass ? PsiFormatUtilBase.SHOW_CONTAINING_CLASS : 0); if (parent instanceof PsiMethod) { name = PsiFormatUtil.formatMethod((PsiMethod)parent, PsiSubstitutor.EMPTY, options, 0); } else if (parent instanceof PsiVariable) { name = PsiFormatUtil.formatVariable((PsiVariable)parent, options, PsiSubstitutor.EMPTY); } else if (parent instanceof PsiClassInitializer) { PsiClass containingClass = ((PsiClassInitializer)parent).getContainingClass(); String className = containingClass instanceof PsiAnonymousClass ? QuickFixBundle.message("anonymous.class.presentation", ((PsiAnonymousClass)containingClass).getBaseClassType().getPresentableText()) : containingClass != null ? containingClass.getName() : "unknown"; name = QuickFixBundle.message("class.initializer.presentation", className); } } String modifierText = VisibilityUtil.toPresentableText(myModifier); return QuickFixBundle.message(myShouldHave ? "add.modifier.fix" : "remove.modifier.fix", name, modifierText); }
@Override @NotNull public String getText() { String name = PsiFormatUtil.formatMethod( mySuperMethod, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_CONTAINING_CLASS, 0 ); return QuickFixBundle.message("fix.super.method.return.type.text", name, JavaHighlightUtil.formatType(mySuperMethodType)); }
@Override @NotNull public String getText() { PsiClass myTargetClass = (PsiClass)getStartElement(); String signature = myTargetClass == null ? "" : PsiFormatUtil.formatMethod(createMethod(myTargetClass), PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_PARAMETERS | PsiFormatUtilBase.SHOW_RAW_TYPE, PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_RAW_TYPE, 2); return QuickFixBundle.message("create.method.from.usage.text", signature); }
private static void generateFieldSignature(StringBuilder buffer, PsiField field, boolean generateLink) { generateAnnotations(buffer, field, generateLink, true, false); String modifiers = PsiFormatUtil.formatModifiers(field, PsiFormatUtilBase.JAVADOC_MODIFIERS_ONLY); if (!modifiers.isEmpty()) { buffer.append(modifiers); buffer.append(" "); } generateType(buffer, field.getType(), field, generateLink); buffer.append(" "); buffer.append("<b>"); buffer.append(field.getName()); appendInitializer(buffer, field); enumConstantOrdinal(buffer, field, field.getContainingClass(), "\n"); buffer.append("</b>"); }
public MethodUsageGroup(PsiMethod psiMethod) { myName = PsiFormatUtil.formatMethod( psiMethod, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE ); myProject = psiMethod.getProject(); myMethodPointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(psiMethod); myIcon = getIconImpl(psiMethod); }
@Override public String getElementDescription(@NotNull final PsiElement element, @NotNull final ElementDescriptionLocation location) { if (location instanceof UsageViewShortNameLocation) { if (element instanceof PsiThrowStatement) { return UsageViewBundle.message("usage.target.exception"); } } if (location instanceof UsageViewLongNameLocation) { if (element instanceof PsiPackage) { return ((PsiPackage)element).getQualifiedName(); } else if (element instanceof PsiClass) { if (element instanceof PsiAnonymousClass) { return LangBundle.message("java.terms.anonymous.class"); } else { String ret = ((PsiClass)element).getQualifiedName(); // It happens for local classes if (ret == null) { ret = ((PsiClass)element).getName(); } return ret; } } else if (element instanceof PsiVariable) { return ((PsiVariable)element).getName(); } else if (element instanceof PsiMethod) { PsiMethod psiMethod = (PsiMethod)element; return PsiFormatUtil.formatMethod(psiMethod, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE); } } return null; }
private static void generateModifiers(StringBuilder buffer, PsiElement element) { String modifiers = PsiFormatUtil.formatModifiers(element, PsiFormatUtilBase.JAVADOC_MODIFIERS_ONLY); if (modifiers.length() > 0) { buffer.append(modifiers); buffer.append(" "); } }
@Override public void updateImpl(PresentationData data) { String name = PsiFormatUtil.formatVariable( (PsiField)getPsiElement(), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_INITIALIZER, PsiSubstitutor.EMPTY); int c = name.indexOf('\n'); if (c > -1) { name = name.substring(0, c - 1); } data.setPresentableText(name); }
@Override public void updateImpl(PresentationData data) { String name = PsiFormatUtil.formatVariable(getValue(), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_INITIALIZER, PsiSubstitutor.EMPTY); int c = name.indexOf('\n'); if (c > -1) { name = name.substring(0, c - 1); } data.setPresentableText(name); }
public String getElementText(PsiMethod element) { final PsiNamedElement container = fetchContainer(element); String text = container instanceof PsiClass ? myClassListCellRenderer.getElementText((PsiClass)container) : container.getName(); if (myShowMethodNames) { text += "."+PsiFormatUtil.formatMethod(element, PsiSubstitutor.EMPTY, myOptions, PsiFormatUtilBase.SHOW_TYPE); } return text; }
public EncapsulateFieldsDialog(Project project, PsiClass aClass, final Set preselectedFields, EncapsulateFieldHelper helper) { super(project, true); myProject = project; myClass = aClass; myHelper = helper; String title = REFACTORING_NAME; String qName = myClass.getQualifiedName(); if (qName != null) { title += " - " + qName; } setTitle(title); myFields = myHelper.getApplicableFields(myClass); myFieldNames = new String[myFields.length]; myCheckedMarks = new boolean[myFields.length]; myFinalMarks = new boolean[myFields.length]; myGetterNames = new String[myFields.length]; mySetterNames = new String[myFields.length]; myGetterPrototypes = new PsiMethod[myFields.length]; mySetterPrototypes = new PsiMethod[myFields.length]; for (int idx = 0; idx < myFields.length; idx++) { PsiField field = myFields[idx]; myCheckedMarks[idx] = preselectedFields.contains(field); myFinalMarks[idx] = field.hasModifierProperty(PsiModifier.FINAL); myFieldNames[idx] = PsiFormatUtil.formatVariable(field, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER, PsiSubstitutor.EMPTY ); myGetterNames[idx] = myHelper.suggestGetterName(field); mySetterNames[idx] = myHelper.suggestSetterName(field); myGetterPrototypes[idx] = myHelper.generateMethodPrototype(field, myGetterNames[idx], true); mySetterPrototypes[idx] = myHelper.generateMethodPrototype(field, mySetterNames[idx], false); } init(); }