PsiReferenceExpression (PsiElement place, @NotNull PsiType qualifierType, LookupElement qualifierItem, String separator) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(place.getProject()); if (qualifierItem.getObject() instanceof PsiClass) { final String qname = ((PsiClass)qualifierItem.getObject()).getQualifiedName(); if (qname == null) return null; String text = qname + separator + "xxx"; try { final PsiExpression expr = factory.createExpressionFromText(text, place); if (expr instanceof PsiReferenceExpression) { return (PsiReferenceExpression)expr; } return null; // ignore ill-formed qualified names like "org.spark-project.jetty" that can't be used from Java code anyway } catch (IncorrectOperationException e) { LOG.info(e); return null; } } return (PsiReferenceExpression) factory.createExpressionFromText("xxx" + separator + "xxx", JavaCompletionUtil .createContextWithXxxVariable(place, qualifierType)); }