Example #1
0
 private static List<PsiImportStaticStatement> getMatchingImports(
     @NotNull PsiImportList importList, @NotNull String className) {
   final List<PsiImportStaticStatement> imports = new ArrayList();
   for (PsiImportStaticStatement staticStatement : importList.getImportStaticStatements()) {
     final PsiClass psiClass = staticStatement.resolveTargetClass();
     if (psiClass == null) {
       continue;
     }
     if (!className.equals(psiClass.getQualifiedName())) {
       continue;
     }
     imports.add(staticStatement);
   }
   return imports;
 }
Example #2
0
 @Nullable
 private static PsiImportStaticStatement findOnDemandImportStaticStatement(
     PsiImportList importList, String qualifierClass) {
   final PsiImportStaticStatement[] importStaticStatements =
       importList.getImportStaticStatements();
   for (PsiImportStaticStatement importStaticStatement : importStaticStatements) {
     if (!importStaticStatement.isOnDemand()) {
       continue;
     }
     final PsiJavaCodeReferenceElement importReference =
         importStaticStatement.getImportReference();
     if (importReference == null) {
       continue;
     }
     final String text = importReference.getText();
     if (qualifierClass.equals(text)) {
       return importStaticStatement;
     }
   }
   return null;
 }
Example #3
0
 private static boolean hasExactImportStaticConflict(
     String qualifierClass, String memberName, PsiElement context) {
   final PsiFile file = context.getContainingFile();
   if (!(file instanceof PsiJavaFile)) {
     return false;
   }
   final PsiJavaFile javaFile = (PsiJavaFile) file;
   final PsiImportList importList = javaFile.getImportList();
   if (importList == null) {
     return false;
   }
   final PsiImportStaticStatement[] importStaticStatements =
       importList.getImportStaticStatements();
   for (PsiImportStaticStatement importStaticStatement : importStaticStatements) {
     if (importStaticStatement.isOnDemand()) {
       continue;
     }
     final String name = importStaticStatement.getReferenceName();
     if (!memberName.equals(name)) {
       continue;
     }
     final PsiJavaCodeReferenceElement importReference =
         importStaticStatement.getImportReference();
     if (importReference == null) {
       continue;
     }
     final PsiElement qualifier = importReference.getQualifier();
     if (qualifier == null) {
       continue;
     }
     final String qualifierText = qualifier.getText();
     if (!qualifierClass.equals(qualifierText)) {
       return true;
     }
   }
   return false;
 }
Example #4
0
 private static boolean hasOnDemandImportStaticConflict(
     String fqName, String memberName, PsiElement context, boolean strict) {
   final PsiFile file = context.getContainingFile();
   if (!(file instanceof PsiJavaFile)) {
     return false;
   }
   final PsiJavaFile javaFile = (PsiJavaFile) file;
   final PsiImportList importList = javaFile.getImportList();
   if (importList == null) {
     return false;
   }
   final PsiImportStaticStatement[] importStaticStatements =
       importList.getImportStaticStatements();
   for (PsiImportStaticStatement importStaticStatement : importStaticStatements) {
     if (!importStaticStatement.isOnDemand()) {
       continue;
     }
     final PsiClass targetClass = importStaticStatement.resolveTargetClass();
     if (targetClass == null) {
       continue;
     }
     final String name = targetClass.getQualifiedName();
     if (fqName.equals(name)) {
       continue;
     }
     final PsiField field = targetClass.findFieldByName(memberName, true);
     if (field != null && (!strict || memberReferenced(field, javaFile))) {
       return true;
     }
     final PsiMethod[] methods = targetClass.findMethodsByName(memberName, true);
     if (methods.length > 0 && (!strict || membersReferenced(methods, javaFile))) {
       return true;
     }
   }
   return false;
 }