use of com.intellij.psi.impl.light.LightClassReference in project intellij-community by JetBrains.
the class PsiImplUtil method buildTypeFromTypeString.
public static PsiType buildTypeFromTypeString(@NotNull final String typeName, @NotNull final PsiElement context, @NotNull final PsiFile psiFile) {
final PsiManager psiManager = psiFile.getManager();
if (typeName.indexOf('<') != -1 || typeName.indexOf('[') != -1 || typeName.indexOf('.') == -1) {
try {
return JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory().createTypeFromText(typeName, context);
}// invalid syntax will produce unresolved class type
catch (Exception ignored) {
}
}
PsiClass aClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(typeName, context.getResolveScope());
PsiType resultType;
if (aClass == null) {
final LightClassReference ref = new LightClassReference(psiManager, PsiNameHelper.getShortClassName(typeName), typeName, PsiSubstitutor.EMPTY, psiFile);
resultType = new PsiClassReferenceType(ref, null);
} else {
PsiElementFactory factory = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory();
PsiSubstitutor substitutor = factory.createRawSubstitutor(aClass);
resultType = factory.createType(aClass, substitutor);
}
return resultType;
}
Aggregations