void () { PsiClass jpanelClass = myJavaFacade.findClass("javax.swing.JPanel", GlobalSearchScope.allScope(myProject)); PsiClass[] inheritors = ClassInheritorsSearch.search(jpanelClass, GlobalSearchScope.projectScope(myProject), true).toArray(PsiClass.EMPTY_ARRAY); assertEquals(2, inheritors.length); assertTrue(inheritors[0] instanceof PsiAnonymousClass || inheritors[1] instanceof PsiAnonymousClass); PsiClass nonAnonClass = inheritors[0] instanceof PsiAnonymousClass ? inheritors[1] : inheritors[0]; PsiMethod[] methods = nonAnonClass.getMethods(); assertEquals(1, methods.length); PsiTypeElement newType = myJavaFacade.getElementFactory().createTypeElement(PsiTypes.floatType()); ApplicationManager.getApplication().runWriteAction(() -> { methods[0].getReturnTypeElement().replace(newType); }); }