Example #1
0
 @NotNull
 private static List<PsiJavaCodeReferenceElement> getImportsFromPackage(
     @NotNull PsiJavaFile file, @NotNull String packageName) {
   PsiClass[] refs = file.getSingleClassImports(true);
   List<PsiJavaCodeReferenceElement> array = new ArrayList<PsiJavaCodeReferenceElement>();
   for (PsiClass ref1 : refs) {
     String className = ref1.getQualifiedName();
     if (getPackageOrClassName(className).equals(packageName)) {
       final PsiJavaCodeReferenceElement ref = file.findImportReferenceTo(ref1);
       if (ref != null) {
         array.add(ref);
       }
     }
   }
   return array;
 }
Example #2
0
 private static PsiClass findSingleImportByShortName(
     @NotNull PsiJavaFile file, @NotNull String shortClassName) {
   PsiClass[] refs = file.getSingleClassImports(true);
   for (PsiClass ref : refs) {
     String className = ref.getQualifiedName();
     if (className != null && PsiNameHelper.getShortClassName(className).equals(shortClassName)) {
       return ref;
     }
   }
   for (PsiClass aClass : file.getClasses()) {
     String className = aClass.getQualifiedName();
     if (className != null && PsiNameHelper.getShortClassName(className).equals(shortClassName)) {
       return aClass;
     }
   }
   return null;
 }