void () { PsiElement physical = findReferenceAtCaret("codeFragment/LocalVariable.java").getElement(); JavaCodeFragment fragment = JavaCodeFragmentFactory.getInstance(getProject()) .createExpressionCodeFragment("ref", physical, null, true); fragment.forceResolveScope(new JavaSourceFilterScope(physical.getResolveScope())); assertNotSame(fragment.getResolveScope(), physical.getResolveScope()); PsiExpression lightExpr = JavaPsiFacade.getElementFactory(getProject()).createExpressionFromText("xxx.xxx", fragment); assertEquals(lightExpr.getResolveScope(), fragment.getResolveScope()); }