Search in sources :

Example 1 with LightClassReference

use of com.intellij.psi.impl.light.LightClassReference in project intellij-community by JetBrains.

the class PsiClassReferenceType method rawType.

@Override
@NotNull
public PsiClassType rawType() {
    PsiJavaCodeReferenceElement reference = getReference();
    PsiElement resolved = reference.resolve();
    if (resolved instanceof PsiClass) {
        PsiClass aClass = (PsiClass) resolved;
        if (!PsiUtil.typeParametersIterable(aClass).iterator().hasNext())
            return this;
        PsiManager manager = reference.getManager();
        final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
        final PsiSubstitutor rawSubstitutor = factory.createRawSubstitutor(aClass);
        return new PsiImmediateClassType(aClass, rawSubstitutor, getLanguageLevel(), getAnnotationProvider());
    }
    String qualifiedName = reference.getQualifiedName();
    String name = reference.getReferenceName();
    if (name == null)
        name = "";
    LightClassReference lightReference = new LightClassReference(reference.getManager(), name, qualifiedName, reference.getResolveScope());
    return new PsiClassReferenceType(lightReference, null, getAnnotationProvider());
}
Also used : LightClassReference(com.intellij.psi.impl.light.LightClassReference) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with LightClassReference

use of com.intellij.psi.impl.light.LightClassReference in project intellij-community by JetBrains.

the class GrThrowsClauseImpl method getReferenceElements.

@Override
@NotNull
public PsiJavaCodeReferenceElement[] getReferenceElements() {
    PsiClassType[] types = getReferencedTypes();
    if (types.length == 0)
        return PsiJavaCodeReferenceElement.EMPTY_ARRAY;
    PsiManagerEx manager = getManager();
    List<PsiJavaCodeReferenceElement> result = ContainerUtil.newArrayList();
    for (PsiClassType type : types) {
        PsiClassType.ClassResolveResult resolveResult = type.resolveGenerics();
        PsiClass resolved = resolveResult.getElement();
        if (resolved != null) {
            result.add(new LightClassReference(manager, type.getCanonicalText(), resolved, resolveResult.getSubstitutor()));
        }
    }
    return result.toArray(new PsiJavaCodeReferenceElement[result.size()]);
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) LightClassReference(com.intellij.psi.impl.light.LightClassReference) PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) PsiClass(com.intellij.psi.PsiClass) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with LightClassReference

use of com.intellij.psi.impl.light.LightClassReference in project intellij-community by JetBrains.

the class GrAnnotationImpl method getNameReferenceElement.

@Override
@Nullable
public PsiJavaCodeReferenceElement getNameReferenceElement() {
    final GroovyResolveResult resolveResult = getClassReference().advancedResolve();
    final PsiElement resolved = resolveResult.getElement();
    if (!(resolved instanceof PsiClass))
        return null;
    return new LightClassReference(getManager(), getClassReference().getText(), (PsiClass) resolved, resolveResult.getSubstitutor());
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) LightClassReference(com.intellij.psi.impl.light.LightClassReference) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with LightClassReference

use of com.intellij.psi.impl.light.LightClassReference in project intellij-community by JetBrains.

the class GrLightAnnotation method getNameReferenceElement.

@Override
public PsiJavaCodeReferenceElement getNameReferenceElement() {
    final GroovyResolveResult resolveResult = myRef.advancedResolve();
    final PsiElement resolved = resolveResult.getElement();
    if (resolved instanceof PsiClass) {
        return new LightClassReference(getManager(), getClassReference().getText(), (PsiClass) resolved, resolveResult.getSubstitutor());
    } else {
        return null;
    }
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) LightClassReference(com.intellij.psi.impl.light.LightClassReference)

Example 5 with LightClassReference

use of com.intellij.psi.impl.light.LightClassReference 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)

Aggregations

LightClassReference (com.intellij.psi.impl.light.LightClassReference)6 NotNull (org.jetbrains.annotations.NotNull)3 PsiClassReferenceType (com.intellij.psi.impl.source.PsiClassReferenceType)2 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)2 PsiClass (com.intellij.psi.PsiClass)1 PsiClassType (com.intellij.psi.PsiClassType)1 PsiJavaCodeReferenceElement (com.intellij.psi.PsiJavaCodeReferenceElement)1 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)1 PsiImmediateClassType (com.intellij.psi.impl.source.PsiImmediateClassType)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 Nullable (org.jetbrains.annotations.Nullable)1