public static boolean isClassType(@Nullable PsiType type, @NotNull String qName) { if (type instanceof PsiClassType) { final PsiClass psiClass = ((PsiClassType) type).resolve(); return psiClass != null && qName.equals(psiClass.getQualifiedName()); } return false; }
public static boolean resolvesTo(PsiType type, String fqn) { if (type instanceof PsiClassType) { final PsiClass resolved = ((PsiClassType) type).resolve(); return resolved != null && fqn.equals(resolved.getQualifiedName()); } return false; }
@Nullable public static PsiType getExpectedClosureReturnType(GrClosableBlock closure) { final Set<PsiType> expectedTypes = getDefaultExpectedTypes(closure); List<PsiType> expectedReturnTypes = new ArrayList<PsiType>(); for (PsiType expectedType : expectedTypes) { if (!(expectedType instanceof PsiClassType)) return null; final PsiClassType.ClassResolveResult resolveResult = ((PsiClassType) expectedType).resolveGenerics(); final PsiClass resolved = resolveResult.getElement(); if (resolved == null || !(GroovyCommonClassNames.GROOVY_LANG_CLOSURE.equals(resolved.getQualifiedName()))) return null; final PsiTypeParameter[] typeParameters = resolved.getTypeParameters(); if (typeParameters.length != 1) return null; final PsiTypeParameter expected = typeParameters[0]; final PsiType expectedReturnType = resolveResult.getSubstitutor().substitute(expected); if (expectedReturnType == PsiType.VOID || expectedReturnType == null) return null; expectedReturnTypes.add(expectedReturnType); } return TypesUtil.getLeastUpperBoundNullable(expectedReturnTypes, closure.getManager()); }
public static PsiType unboxPrimitiveTypeWrapper(@Nullable PsiType type) { if (type instanceof PsiClassType) { final PsiClass psiClass = ((PsiClassType) type).resolve(); if (psiClass != null) { PsiType unboxed = ourQNameToUnboxed.get(psiClass.getQualifiedName()); if (unboxed != null) type = unboxed; } } return type; }
public static Map<String, PsiClass> getSuperClassesWithCache(@NotNull PsiClass aClass) { Map<String, PsiClass> superClassNames = PARENT_CACHE_KEY.getCachedValue(aClass); if (superClassNames == null) { Set<PsiClass> superClasses = new THashSet<PsiClass>(); superClasses.add(aClass); InheritanceUtil.getSuperClasses(aClass, superClasses, true); superClassNames = new LinkedHashMap<String, PsiClass>(); for (PsiClass superClass : superClasses) { superClassNames.put(superClass.getQualifiedName(), superClass); } superClassNames = PARENT_CACHE_KEY.putCachedValue(aClass, superClassNames); } return superClassNames; }
@Nullable public static PsiElement getOriginalElement(PsiClass clazz, PsiFile containingFile) { VirtualFile vFile = containingFile.getVirtualFile(); final JavaPsiFacade facade = JavaPsiFacade.getInstance(clazz.getProject()); final ProjectFileIndex idx = ProjectRootManager.getInstance(facade.getProject()).getFileIndex(); if (vFile == null || !idx.isInLibrarySource(vFile)) return clazz; final String qName = clazz.getQualifiedName(); if (qName == null) return null; final List<OrderEntry> orderEntries = idx.getOrderEntriesForFile(vFile); PsiClass original = facade.findClass( qName, new GlobalSearchScope(facade.getProject()) { public int compare(VirtualFile file1, VirtualFile file2) { return 0; } public boolean contains(VirtualFile file) { // order for file and vFile has non empty intersection. List<OrderEntry> entries = idx.getOrderEntriesForFile(file); //noinspection ForLoopReplaceableByForEach for (int i = 0; i < entries.size(); i++) { final OrderEntry entry = entries.get(i); if (orderEntries.contains(entry)) return true; } return false; } public boolean isSearchInModuleContent(@NotNull Module aModule) { return false; } public boolean isSearchInLibraries() { return true; } }); return original != null ? original : clazz; }
private static boolean isFromDGM(GrGdkMethod resolved) { final PsiClass containingClass = resolved.getStaticMethod().getContainingClass(); return containingClass != null && GroovyCommonClassNames.DEFAULT_GROOVY_METHODS.equals(containingClass.getQualifiedName()); }