@Override @NotNull public PsiClassType rawType() { PsiElement resolved = myReference.resolve(); if (resolved instanceof PsiClass) { PsiClass aClass = (PsiClass)resolved; if (!PsiUtil.typeParametersIterable(aClass).iterator().hasNext()) return this; PsiManager manager = myReference.getManager(); final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); final PsiSubstitutor rawSubstitutor = factory.createRawSubstitutor(aClass); return factory.createType(aClass, rawSubstitutor, getLanguageLevel(), getAnnotations()); } String qualifiedName = myReference.getQualifiedName(); String name = myReference.getReferenceName(); if (name == null) name = ""; LightClassReference reference = new LightClassReference(myReference.getManager(), name, qualifiedName, myReference.getResolveScope()); return new PsiClassReferenceType(reference, null, getAnnotations()); }
@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()]); }
@Nullable @Override public PsiJavaCodeReferenceElement getImportReference() { if(myErrorElement != null) { return null; } if(isOnDemand()) { return new LightPackageReference(getManager(), myQName); } else { return new LightClassReference(getManager(), myQName, myQName, getResolveScope()); } }
@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); }
@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; } }
@Override @Nullable public PsiJavaCodeReferenceElement getNameReferenceElement() { final GroovyResolveResult resolveResult = resolveWithStub(); final PsiElement resolved = resolveResult.getElement(); if (!(resolved instanceof PsiClass)) return null; return new LightClassReference(getManager(), getClassReference().getText(), (PsiClass)resolved, resolveResult.getSubstitutor()); }
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); }
@Nullable public PsiJavaCodeReferenceElement getNameReferenceElement() { final GroovyResolveResult resolveResult = getClassReference().advancedResolve(); final PsiElement resolved = resolveResult.getElement(); if (resolved instanceof PsiClass) { return new LightClassReference(getManager(), getClassReference().getText(), (PsiClass)resolved, resolveResult.getSubstitutor()); } else { return null; } }
@NotNull @Override public PsiJavaCodeReferenceElement createClassReferenceElement(@NotNull final PsiClass aClass) { final String text; if(aClass instanceof PsiAnonymousClass) { text = ((PsiAnonymousClass) aClass).getBaseClassType().getPresentableText(); } else { text = aClass.getName(); } return new LightClassReference(myManager, text, aClass); }
@NotNull @Override public PsiJavaCodeReferenceElement createReferenceElementByFQClassName(@NotNull final String qName, @NotNull final GlobalSearchScope resolveScope) { final String shortName = PsiNameHelper.getShortClassName(qName); return new LightClassReference(myManager, shortName, qName, resolveScope); }
@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()); }
@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); }
@Override @NotNull public PsiJavaCodeReferenceElement getBaseClassReference() { PsiClass containingClass = getBaseClass(); return new LightClassReference(getManager(), containingClass.getName(), containingClass); }
@NotNull @Override public PsiJavaCodeReferenceElement createFQClassNameReferenceElement(@NotNull final String qName, @NotNull final GlobalSearchScope resolveScope) { return new LightClassReference(myManager, qName, qName, resolveScope); }