Search in sources :

Example 6 with PsiImmediateClassType

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)));
                }
            }
        }
    }
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) PsiImmediateClassType(com.intellij.psi.impl.source.PsiImmediateClassType) Pair(com.intellij.openapi.util.Pair)

Example 7 with PsiImmediateClassType

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);
}
Also used : LightClassReference(com.intellij.psi.impl.light.LightClassReference) PsiImmediateClassType(com.intellij.psi.impl.source.PsiImmediateClassType) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClassReferenceType(com.intellij.psi.impl.source.PsiClassReferenceType) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with PsiImmediateClassType

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;
}
Also used : PsiImmediateClassType(com.intellij.psi.impl.source.PsiImmediateClassType)

Example 9 with PsiImmediateClassType

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));
    }
}
Also used : PsiImmediateClassType(com.intellij.psi.impl.source.PsiImmediateClassType) GrClassReferenceType(org.jetbrains.plugins.groovy.lang.psi.impl.GrClassReferenceType) GrLightVariable(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightVariable)

Aggregations

PsiImmediateClassType (com.intellij.psi.impl.source.PsiImmediateClassType)9 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 com.intellij.codeInsight.completion (com.intellij.codeInsight.completion)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 ClassFilesIndexFeature (com.intellij.compiler.classFilesIndex.api.index.ClassFilesIndexFeature)1 ClassFilesIndexFeaturesHolder (com.intellij.compiler.classFilesIndex.api.index.ClassFilesIndexFeaturesHolder)1 com.intellij.compiler.classFilesIndex.chainsSearch (com.intellij.compiler.classFilesIndex.chainsSearch)1 CompletionContributorPatternUtil (com.intellij.compiler.classFilesIndex.chainsSearch.completion.CompletionContributorPatternUtil)1 ChainCompletionContext (com.intellij.compiler.classFilesIndex.chainsSearch.context.ChainCompletionContext)1 ContextUtil (com.intellij.compiler.classFilesIndex.chainsSearch.context.ContextUtil)1 TargetType (com.intellij.compiler.classFilesIndex.chainsSearch.context.TargetType)1 MethodsUsageIndexReader (com.intellij.compiler.classFilesIndex.impl.MethodsUsageIndexReader)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ModuleUtilCore (com.intellij.openapi.module.ModuleUtilCore)1 Project (com.intellij.openapi.project.Project)1 Pair (com.intellij.openapi.util.Pair)1 ElementPattern (com.intellij.patterns.ElementPattern)1 PsiJavaPatterns.or (com.intellij.patterns.PsiJavaPatterns.or)1 com.intellij.psi (com.intellij.psi)1