private PsiMethod getSyntheticMethod(String text) { PsiElementFactory factory = JavaPsiFacade.getInstance(myClass.getProject()).getElementFactory(); PsiMethod method = factory.createMethodFromText(text, myClass); return new LightMethod(myClass.getManager(), method, myClass) { @Override public int getTextOffset() { return myClass.getTextOffset(); } }; }
@Nullable public PsiMethod getValuesMethod() { return !myClass.isEnum() || myClass.getName() == null ? null : CachedValuesManager.getCachedValue( myClass, new CachedValueProvider<PsiMethod>() { @Nullable @Override public Result<PsiMethod> compute() { String text = "public static " + myClass.getName() + "[] values() { }"; return new Result<PsiMethod>( getSyntheticMethod(text), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker); } }); }
@Nullable public PsiMethod getValueOfMethod() { return !myClass.isEnum() || myClass.getName() == null ? null : CachedValuesManager.getCachedValue( myClass, new CachedValueProvider<PsiMethod>() { @Nullable @Override public Result<PsiMethod> compute() { String text = "public static " + myClass.getName() + " valueOf(java.lang.String name) throws java.lang.IllegalArgumentException { }"; return new Result<PsiMethod>( getSyntheticMethod(text), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker); } }); }
@NotNull private PsiClass[] getAllInnerClasses() { List<PsiClass> own = myClass.getOwnInnerClasses(); List<PsiClass> ext = PsiAugmentProvider.collectAugments(myClass, PsiClass.class); return ArrayUtil.mergeCollections(own, ext, PsiClass.ARRAY_FACTORY); }
@NotNull private PsiMethod[] getAllMethods() { List<PsiMethod> own = myClass.getOwnMethods(); List<PsiMethod> ext = PsiAugmentProvider.collectAugments(myClass, PsiMethod.class); return ArrayUtil.mergeCollections(own, ext, PsiMethod.ARRAY_FACTORY); }