@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 String toString() { final PsiMethod method = (PsiMethod)getPsiElement(); if (method == null || !method.isValid()) return ""; if (DumbService.isDumb(myProject)) return method.getName(); String name = PsiFormatUtil.formatMethod( method, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE | PsiFormatUtil.TYPE_AFTER | PsiFormatUtil.SHOW_PARAMETERS, PsiFormatUtil.SHOW_TYPE ); int c = name.indexOf('\n'); if (c > -1) { name = name.substring(0, c - 1); } return name; }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); PsiMethod method = (PsiMethod) value; final String text = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_CONTAINING_CLASS | PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS, PsiFormatUtil.SHOW_TYPE); setText(text); Icon icon = method.getIcon(Iconable.ICON_FLAG_VISIBILITY); if(icon != null) setIcon(icon); return this; }
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(); }
@Override public void processQuery(@NotNull MethodReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) { final PsiMethod method = queryParameters.getMethod(); final String propertyName; if (GdkMethodUtil.isCategoryMethod(method, null, null, PsiSubstitutor.EMPTY)) { final GrGdkMethod cat = GrGdkMethodImpl.createGdkMethod(method, false, null); propertyName = GroovyPropertyUtils.getPropertyName((PsiMethod)cat); } else { propertyName = GroovyPropertyUtils.getPropertyName(method); } if (propertyName == null) return; final SearchScope onlyGroovyFiles = GroovyScopeUtil.restrictScopeToGroovyFiles(queryParameters.getEffectiveSearchScope(), GroovyScopeUtil.getEffectiveScope(method)); queryParameters.getOptimizer().searchWord(propertyName, onlyGroovyFiles, UsageSearchContext.IN_CODE, true, method); if (!GroovyPropertyUtils.isPropertyName(propertyName)) { queryParameters.getOptimizer().searchWord(StringUtil.decapitalize(propertyName), onlyGroovyFiles, UsageSearchContext.IN_CODE, true, method); } }
@NotNull @Override public List<PsiType[]> inferExpectedSignatures(@NotNull final PsiMethod method, @NotNull PsiSubstitutor substitutor, @NotNull String[] options) { return Collections.singletonList(ContainerUtil.map(options, new Function<String, PsiType>() { @Override public PsiType fun(String value) { try { PsiType type = JavaPsiFacade.getElementFactory(method.getProject()).createTypeFromText(value, method); return DefaultGroovyMethods.asBoolean(type) ? type : PsiType.NULL; } catch (IncorrectOperationException e) { return PsiType.NULL; } } }, new PsiType[options.length])); }
@NotNull @Override public List<PsiType[]> inferExpectedSignatures(@NotNull PsiMethod method, @NotNull PsiSubstitutor substitutor, @NotNull String[] options) { List<PsiType[]> signatures = new SecondParamHintProcessor().inferExpectedSignatures(method, substitutor, options); if (signatures.size() == 1) { PsiType[] signature = signatures.get(0); if (signature.length == 1) { PsiType type = signature[0]; if (type instanceof PsiArrayType) { return produceResult(((PsiArrayType)type).getComponentType()); } } } return Collections.emptyList(); }
@NotNull @Override public List<PsiType[]> inferExpectedSignatures(@NotNull PsiMethod method, @NotNull PsiSubstitutor substitutor, @NotNull String[] options) { List<PsiType[]> signatures = new ThirdParamHintProcessor().inferExpectedSignatures(method, substitutor, options); if (signatures.size() == 1) { PsiType[] signature = signatures.get(0); if (signature.length == 1) { PsiType type = signature[0]; if (type instanceof PsiArrayType) { return produceResult(((PsiArrayType)type).getComponentType()); } } } return Collections.emptyList(); }
@NotNull @Override public List<PsiType[]> inferExpectedSignatures(@NotNull PsiMethod method, @NotNull PsiSubstitutor substitutor, @NotNull String[] options) { List<PsiType[]> signatures = new FirstParamHintProcessor().inferExpectedSignatures(method, substitutor, options); if (signatures.size() == 1) { PsiType[] signature = signatures.get(0); if (signature.length == 1) { PsiType type = signature[0]; if (type instanceof PsiArrayType) { return produceResult(((PsiArrayType)type).getComponentType()); } } } return Collections.emptyList(); }
public GroovyResolveResultImpl(@NotNull PsiElement element, @Nullable PsiElement resolveContext, @Nullable SpreadState spreadState, @NotNull PsiSubstitutor substitutor, boolean isAccessible, boolean staticsOK, boolean isInvokedOnProperty, boolean isApplicable) { myCurrentFileResolveContext = resolveContext; myElement = element; myIsAccessible = isAccessible; mySubstitutor = substitutor; myIsStaticsOK = staticsOK; myIsInvokedOnProperty = isInvokedOnProperty; mySpreadState = spreadState; myIsApplicable = isApplicable; }
@Nullable("null if ref is not actually 'this' reference") public static GroovyResolveResult[] resolveThisExpression(@NotNull GrReferenceExpression ref) { GrExpression qualifier = ref.getQualifier(); if (qualifier == null) { final PsiElement parent = ref.getParent(); if (parent instanceof GrConstructorInvocation) { return ((GrConstructorInvocation)parent).multiResolve(false); } else { PsiClass aClass = PsiUtil.getContextClass(ref); if (aClass != null) { return new GroovyResolveResultImpl[]{new GroovyResolveResultImpl(aClass, null, null, PsiSubstitutor.EMPTY, true, true)}; } } } else if (qualifier instanceof GrReferenceExpression) { GroovyResolveResult result = ((GrReferenceExpression)qualifier).advancedResolve(); PsiElement resolved = result.getElement(); if (resolved instanceof PsiClass && PsiUtil.hasEnclosingInstanceInScope((PsiClass)resolved, ref, false)) { return new GroovyResolveResult[]{result}; } } return null; }
public static boolean invokeMethodOn(@NotNull ExpressionGenerator generator, @NotNull GrGdkMethod method, @Nullable GrExpression caller, @NotNull GrExpression[] exprs, @NotNull GrNamedArgument[] namedArgs, @NotNull GrClosableBlock[] closures, @NotNull PsiSubstitutor substitutor, @NotNull GroovyPsiElement context) { final PsiMethod staticMethod = method.getStaticMethod(); for (CustomMethodInvocator invocator : EP_NAME.getExtensions()) { if (invocator.invoke(generator, staticMethod, caller, exprs, namedArgs, closures, substitutor, context)) { return true; } } return false; }
private static boolean canImplementOverride(final MethodHierarchyNodeDescriptor descriptor, final MethodHierarchyBrowser methodHierarchyBrowser, final boolean toImplement) { final PsiClass psiClass = descriptor.getPsiClass(); if (psiClass == null || psiClass instanceof JspClass) return false; final PsiMethod baseMethod = methodHierarchyBrowser.getBaseMethod(); if (baseMethod == null) return false; final MethodSignature signature = baseMethod.getSignature(PsiSubstitutor.EMPTY); Collection<MethodSignature> allOriginalSignatures = toImplement ? OverrideImplementUtil.getMethodSignaturesToImplement(psiClass) : OverrideImplementUtil.getMethodSignaturesToOverride(psiClass); for (final MethodSignature originalSignature : allOriginalSignatures) { if (originalSignature.equals(signature)) { return true; } } return false; }
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, PsiFormatUtil.SHOW_CONTAINING_CLASS | PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS | PsiFormatUtil.SHOW_TYPE, PsiFormatUtil.SHOW_TYPE ); } myUsagePreviewPanel = new UsagePreviewPanel(project); setTitle(RefactoringBundle.message("unused.overriding.methods.title")); init(); }
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); }
@Override public void processQuery(@NotNull MethodReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) { final PsiMethod method = queryParameters.getMethod(); final String propertyName; if (GdkMethodUtil.isCategoryMethod(method, null, null, PsiSubstitutor.EMPTY)) { final GrGdkMethod cat = GrGdkMethodImpl.createGdkMethod(method, false, null); propertyName = GroovyPropertyUtils.getPropertyName((PsiMethod)cat); } else { propertyName = GroovyPropertyUtils.getPropertyName(method); } if (propertyName == null) return; final SearchScope onlyGroovyFiles = GroovyScopeUtil.restrictScopeToGroovyFiles(queryParameters.getScope(), GroovyScopeUtil.getEffectiveScope(method)); queryParameters.getOptimizer().searchWord(propertyName, onlyGroovyFiles, UsageSearchContext.IN_CODE, true, method); if (!GroovyPropertyUtils.isPropertyName(propertyName)) { queryParameters.getOptimizer().searchWord(StringUtil.decapitalize(propertyName), onlyGroovyFiles, UsageSearchContext.IN_CODE, true, method); } }
public void addBuilderField(@NotNull List<PsiField> fields, @NotNull PsiVariable psiVariable, @NotNull PsiClass innerClass, @NotNull AccessorsInfo accessorsInfo, @NotNull PsiSubstitutor substitutor) { final String fieldName = accessorsInfo.removePrefix(psiVariable.getName()); final Project project = psiVariable.getProject(); final PsiManager psiManager = psiVariable.getManager(); final PsiType psiFieldType = psiVariable.getType(); final PsiType keyType = PsiTypeUtil.extractOneElementType(psiFieldType, psiManager, CommonClassNames.JAVA_UTIL_MAP, 0); final PsiType valueType = PsiTypeUtil.extractOneElementType(psiFieldType, psiManager, CommonClassNames.JAVA_UTIL_MAP, 1); final PsiType builderFieldKeyType = getBuilderFieldType(keyType, project); fields.add(new LombokLightFieldBuilder(psiManager, fieldName + LOMBOK_KEY, builderFieldKeyType) .withModifier(PsiModifier.PRIVATE) .withNavigationElement(psiVariable) .withContainingClass(innerClass)); final PsiType builderFieldValueType = getBuilderFieldType(valueType, project); fields.add(new LombokLightFieldBuilder(psiManager, fieldName + LOMBOK_VALUE, builderFieldValueType) .withModifier(PsiModifier.PRIVATE) .withNavigationElement(psiVariable) .withContainingClass(innerClass)); }
public <T extends PsiMember & PsiNamedElement> void generateElements(@NotNull T psiElement, @NotNull PsiType psiElementType, @NotNull PsiAnnotation psiAnnotation, @NotNull List<? super PsiElement> target) { final Project project = psiElement.getProject(); final PsiManager manager = psiElement.getContainingFile().getManager(); final Collection<Pair<PsiMethod, PsiSubstitutor>> includesMethods = new HashSet<Pair<PsiMethod, PsiSubstitutor>>(); final Collection<PsiType> types = collectDelegateTypes(psiAnnotation, psiElementType); addMethodsOfTypes(types, includesMethods); final Collection<Pair<PsiMethod, PsiSubstitutor>> excludeMethods = new HashSet<Pair<PsiMethod, PsiSubstitutor>>(); PsiClassType javaLangObjectType = PsiType.getJavaLangObject(manager, GlobalSearchScope.allScope(project)); addMethodsOfType(javaLangObjectType, excludeMethods); final Collection<PsiType> excludes = collectExcludeTypes(psiAnnotation); addMethodsOfTypes(excludes, excludeMethods); final Collection<Pair<PsiMethod, PsiSubstitutor>> methodsToDelegate = findMethodsToDelegate(includesMethods, excludeMethods); if (!methodsToDelegate.isEmpty()) { final PsiClass psiClass = psiElement.getContainingClass(); if (null != psiClass) { for (Pair<PsiMethod, PsiSubstitutor> pair : methodsToDelegate) { target.add(generateDelegateMethod(psiClass, psiElement, psiAnnotation, pair.getFirst(), pair.getSecond())); } } } }
private Collection<Pair<PsiMethod, PsiSubstitutor>> findMethodsToDelegate(Collection<Pair<PsiMethod, PsiSubstitutor>> includesMethods, Collection<Pair<PsiMethod, PsiSubstitutor>> excludeMethods) { final Collection<Pair<PsiMethod, PsiSubstitutor>> result = new ArrayList<Pair<PsiMethod, PsiSubstitutor>>(); for (Pair<PsiMethod, PsiSubstitutor> includesMethodPair : includesMethods) { boolean acceptMethod = true; for (Pair<PsiMethod, PsiSubstitutor> excludeMethodPair : excludeMethods) { if (PsiElementUtil.methodMatches(includesMethodPair, excludeMethodPair)) { acceptMethod = false; break; } } if (acceptMethod) { result.add(includesMethodPair); } } return result; }
@Override @NotNull public String getTextFor(SmartStepTarget value) { final String label = value.getLabel(); final String formatted; if(value instanceof MethodSmartStepTarget) { final PsiMethod method = ((MethodSmartStepTarget) value).getMethod(); formatted = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS, PsiFormatUtil.SHOW_TYPE, 999); } else if(value instanceof LambdaSmartStepTarget) { final PsiLambdaExpression lambda = ((LambdaSmartStepTarget) value).getLambda(); formatted = PsiFormatUtil.formatType(lambda.getType(), 0, PsiSubstitutor.EMPTY); } else { formatted = ""; } return label != null ? label + formatted : formatted; }
@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 Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); PsiMethod method = (PsiMethod) value; final String text = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_CONTAINING_CLASS | PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS, PsiFormatUtil.SHOW_TYPE); setText(text); Icon icon = IconDescriptorUpdaters.getIcon(method, Iconable.ICON_FLAG_VISIBILITY); if(icon != null) setIcon(icon); return this; }
@Nullable private static PsiSubstitutor getSuperSubstitutorWithCaching(@NotNull PsiClass superClass, @NotNull PsiClass derivedClass, @NotNull GlobalSearchScope resolveScope, @NotNull PsiSubstitutor derivedSubstitutor) { PsiSubstitutor substitutor = ScopedClassHierarchy.getSuperClassSubstitutor(derivedClass, resolveScope, superClass); if(substitutor == null) { return null; } if(PsiUtil.isRawSubstitutor(derivedClass, derivedSubstitutor)) { return createRawSubstitutor(superClass); } return composeSubstitutors(derivedSubstitutor, substitutor, superClass); }
@Nullable private static PsiExpression[] findRedundantArgument(@NotNull PsiExpression[] arguments, @NotNull PsiParameter[] parameters, @NotNull PsiSubstitutor substitutor) { if (arguments.length <= parameters.length) return null; for (int i = 0; i < parameters.length; i++) { final PsiExpression argument = arguments[i]; final PsiParameter parameter = parameters[i]; final PsiType argumentType = argument.getType(); if (argumentType == null) return null; final PsiType parameterType = substitutor.substitute(parameter.getType()); if (!TypeConversionUtil.isAssignable(parameterType, argumentType)) { return null; } } return Arrays.copyOfRange(arguments, parameters.length, arguments.length); }
private static void registerSwapFixes(final PsiExpression[] expressions, final PsiCall callExpression, final List<PsiCall> permutations, MethodCandidateInfo candidate, final int incompatibilitiesCount, final int minIncompatibleIndex, final int maxIncompatibleIndex) throws IncorrectOperationException { PsiMethod method = candidate.getElement(); PsiSubstitutor substitutor = candidate.getSubstitutor(); if (incompatibilitiesCount >= 3) return; // no way we can fix it by swapping for (int i = minIncompatibleIndex; i < maxIncompatibleIndex; i++) { for (int j = i+1; j <= maxIncompatibleIndex; j++) { ArrayUtil.swap(expressions, i, j); if (PsiUtil.isApplicable(method, substitutor, expressions)) { PsiCall copy = (PsiCall)callExpression.copy(); PsiExpression[] copyExpressions = copy.getArgumentList().getExpressions(); copyExpressions[i].replace(expressions[i]); copyExpressions[j].replace(expressions[j]); JavaResolveResult result = copy.resolveMethodGenerics(); if (result.getElement() != null && result.isValidResult()) { permutations.add(copy); if (permutations.size() > 1) return; } } ArrayUtil.swap(expressions, i, j); } } }
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 private static String calculateOverridingMethodTooltip(@NotNull PsiMethod method, boolean acceptSelf) { PsiMethod[] superMethods = composeSuperMethods(method, acceptSelf); if(superMethods.length == 0) { return null; } PsiMethod superMethod = superMethods[0]; boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT); boolean isSuperAbstract = superMethod.hasModifierProperty(PsiModifier.ABSTRACT); final boolean sameSignature = superMethod.getSignature(PsiSubstitutor.EMPTY).equals(method.getSignature(PsiSubstitutor.EMPTY)); @NonNls final String key; if(isSuperAbstract && !isAbstract) { key = sameSignature ? "method.implements" : "method.implements.in"; } else { key = sameSignature ? "method.overrides" : "method.overrides.in"; } return composeText(superMethods, "", DaemonBundle.message(key), IdeActions.ACTION_GOTO_SUPER); }
public static boolean isStructurallyAssignable_Laxed( PsiClass toType, PsiClass fromType, TypeVarToTypeMap inferenceMap, boolean structural ) { if( fromType == PsiType.NULL ) { return true; } List<Pair<PsiMethod, PsiSubstitutor>> toMethods = toType.getAllMethodsAndTheirSubstitutors(); inferenceMap.setStructural( true ); for( Pair<PsiMethod, PsiSubstitutor> pair : toMethods ) { PsiMethod toMi = pair.getFirst(); if( isObjectMethod( toMi ) ) { continue; } if( toMi.getContainingClass().getModifierList().findAnnotation( "manifold.ext.ExtensionMethod" ) != null ) { continue; } if( toMi.hasModifierProperty( PsiModifier.DEFAULT ) || toMi.hasModifierProperty( PsiModifier.STATIC ) ) { continue; } PsiMethod fromMi = findAssignableMethod( structural, fromType, toMi, inferenceMap ); if( fromMi == null ) { return false; } } return true; }
@Override public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) { if (myFilter.isAcceptable(element, myCurrentDeclarationHolder)) { if (myProcessor != null) { return myProcessor.execute(element, state); } add(element, state.get(PsiSubstitutor.KEY)); } return true; }
@NotNull @Override public String getPresentation() { String typeText = PsiFormatUtil.formatType(myLambda.getType(), 0, PsiSubstitutor.EMPTY); String label = getLabel(); return label != null ? label + typeText : typeText; }
@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; }
@Override public String getPresentableText() { final PsiField field = getElement(); if (field == null) return ""; final boolean dumb = DumbService.isDumb(field.getProject()); return StringUtil.replace(formatVariable( field, SHOW_NAME | (dumb ? 0 : SHOW_TYPE) | TYPE_AFTER | (dumb ? 0 : SHOW_INITIALIZER), PsiSubstitutor.EMPTY ), ":", ": "); }
@Override public void renderElement(LookupElementPresentation presentation) { presentation.setIcon(myMethod.getIcon(Iconable.ICON_FLAG_VISIBILITY)); presentation.setItemText(myMethod.getName()); presentation.setTailText(PsiFormatUtil.formatMethod(myMethod, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_PARAMETERS, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE)); final PsiType returnType = myMethod.getReturnType(); if (returnType != null) { presentation.setTypeText(returnType.getCanonicalText()); } }
public MethodListDlg(final PsiClass psiClass, final Condition<PsiMethod> filter, final JComponent parent) { super(parent, false); myClass = psiClass; createList(psiClass.getAllMethods(), filter); myWholePanel.add(ScrollPaneFactory.createScrollPane(myList)); myList.setCellRenderer(new ColoredListCellRenderer() { protected void customizeCellRenderer(final JList list, final Object value, final int index, final boolean selected, final boolean hasFocus) { final PsiMethod psiMethod = (PsiMethod)value; append(PsiFormatUtil.formatMethod(psiMethod, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME, 0), StructureNodeRenderer.applyDeprecation(psiMethod, SimpleTextAttributes.REGULAR_ATTRIBUTES)); final PsiClass containingClass = psiMethod.getContainingClass(); if (!myClass.equals(containingClass)) append(" (" + containingClass.getQualifiedName() + ")", StructureNodeRenderer.applyDeprecation(containingClass, SimpleTextAttributes.GRAY_ATTRIBUTES)); } }); myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { MethodListDlg.this.close(OK_EXIT_CODE); return true; } }.installOn(myList); ScrollingUtil.ensureSelectionExists(myList); setTitle(ExecutionBundle.message("choose.test.method.dialog.title")); init(); }