use of com.intellij.psi.impl.source.PsiImmediateClassType in project intellij-community by JetBrains.
the class DelegateTransformationSupport method applyTransformation.
@Override
public void applyTransformation(@NotNull TransformationContext context) {
for (GrField field : context.getFields()) {
final PsiAnnotation annotation = PsiImplUtil.getAnnotation(field, GroovyCommonClassNames.GROOVY_LANG_DELEGATE);
if (annotation == null)
continue;
final PsiType type = field.getDeclaredType();
if (!(type instanceof PsiClassType))
continue;
final PsiClassType.ClassResolveResult delegateResult = ((PsiClassType) type).resolveGenerics();
final PsiClass delegate = delegateResult.getElement();
if (delegate == null)
continue;
DelegateProcessor processor = new DelegateProcessor(context, delegate, annotation);
delegate.processDeclarations(processor, ResolveState.initial().put(PsiSubstitutor.KEY, delegateResult.getSubstitutor()), null, context.getCodeClass());
if (!processor.myInterfaces)
continue;
Set<PsiClass> visited = ContainerUtil.newHashSet();
Queue<Pair<PsiClass, PsiSubstitutor>> queue = ContainerUtil.newLinkedList(Pair.create(delegate, delegateResult.getSubstitutor()));
while (!queue.isEmpty()) {
Pair<PsiClass, PsiSubstitutor> pair = queue.poll();
PsiClass currentClass = pair.first;
PsiSubstitutor substitutor = pair.second;
if (visited.add(currentClass) && currentClass.isInterface()) {
context.addInterface(new PsiImmediateClassType(currentClass, substitutor));
continue;
}
for (PsiClassType superType : currentClass.getSuperTypes()) {
PsiClassType.ClassResolveResult resolveResult = superType.resolveGenerics();
PsiClass superClass = resolveResult.getElement();
if (superClass != null) {
queue.offer(Pair.create(superClass, TypeConversionUtil.getSuperClassSubstitutor(superClass, currentClass, substitutor)));
}
}
}
}
}
use of com.intellij.psi.impl.source.PsiImmediateClassType in project intellij-community by JetBrains.
the class PsiImplUtil method getType.
@NotNull
public static PsiType getType(@NotNull PsiClassObjectAccessExpression classAccessExpression) {
GlobalSearchScope resolveScope = classAccessExpression.getResolveScope();
PsiManager manager = classAccessExpression.getManager();
final PsiClass classClass = JavaPsiFacade.getInstance(manager.getProject()).findClass("java.lang.Class", resolveScope);
if (classClass == null) {
return new PsiClassReferenceType(new LightClassReference(manager, "Class", "java.lang.Class", resolveScope), null);
}
if (!PsiUtil.isLanguageLevel5OrHigher(classAccessExpression)) {
//Raw java.lang.Class
return JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createType(classClass);
}
PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
PsiType operandType = classAccessExpression.getOperand().getType();
if (operandType instanceof PsiPrimitiveType && !PsiType.NULL.equals(operandType)) {
if (PsiType.VOID.equals(operandType)) {
operandType = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createTypeByFQClassName("java.lang.Void", classAccessExpression.getResolveScope());
} else {
operandType = ((PsiPrimitiveType) operandType).getBoxedType(classAccessExpression);
}
}
final PsiTypeParameter[] typeParameters = classClass.getTypeParameters();
if (typeParameters.length == 1) {
substitutor = substitutor.put(typeParameters[0], operandType);
}
return new PsiImmediateClassType(classClass, substitutor);
}
use of com.intellij.psi.impl.source.PsiImmediateClassType in project intellij-community by JetBrains.
the class PsiClassImplUtil method getEnumSuperType.
private static PsiClassType getEnumSuperType(@NotNull PsiClass psiClass, @NotNull PsiElementFactory factory) {
PsiClassType superType;
final PsiClass enumClass = findSpecialSuperClass(psiClass, CommonClassNames.JAVA_LANG_ENUM);
if (enumClass == null) {
try {
superType = (PsiClassType) factory.createTypeFromText(CommonClassNames.JAVA_LANG_ENUM, null);
} catch (IncorrectOperationException e) {
superType = null;
}
} else {
final PsiTypeParameter[] typeParameters = enumClass.getTypeParameters();
PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
if (typeParameters.length == 1) {
substitutor = substitutor.put(typeParameters[0], factory.createType(psiClass));
}
superType = new PsiImmediateClassType(enumClass, substitutor);
}
return superType;
}
use of com.intellij.psi.impl.source.PsiImmediateClassType in project intellij-community by JetBrains.
the class GroovyShellCodeFragment method addVariable.
public void addVariable(String name, GrExpression expr) {
PsiType type = expr.getType();
if (type instanceof GrClassReferenceType) {
final PsiClassType.ClassResolveResult resolveResult = ((GrClassReferenceType) type).resolveGenerics();
final PsiClass psiClass = resolveResult.getElement();
type = psiClass == null ? null : new PsiImmediateClassType(psiClass, resolveResult.getSubstitutor());
}
if (type != null) {
myVariables.put(name, new GrLightVariable(getManager(), name, type, this));
}
}
Aggregations