void () { String text = "void method(final int i) {" + " Runnable runnable = new Runnable() {" + " public void run() {" + " System.out.println(i);" + " }" + " };" + " System.out.println(i);" + "}"; PsiManager psiManager = PsiManager.getInstance(getProject()); PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(psiManager.getProject()); PsiMethod methodFromText = elementFactory.createMethodFromText(text, null); PsiParameter[] parameters = methodFromText.getParameterList().getParameters(); PsiReference[] references = ReferencesSearch.search(parameters[0], new LocalSearchScope(methodFromText), false).toArray(PsiReference.EMPTY_ARRAY); assertEquals(2, references.length); }