private static boolean isInitializedImplicitly(PsiField field) {
   field = CompletionUtil.getOriginalOrSelf(field);
   for (ImplicitUsageProvider provider : ImplicitUsageProvider.EP_NAME.getExtensions()) {
     if (provider.isImplicitWrite(field)) {
       return true;
     }
   }
   return false;
 }
Esempio n. 2
0
 private static boolean hasImplicitReadOrWriteUsage(
     final PsiField field, ImplicitUsageProvider[] implicitUsageProviders) {
   for (ImplicitUsageProvider provider : implicitUsageProviders) {
     if (provider.isImplicitRead(field) || provider.isImplicitWrite(field)) {
       return true;
     }
   }
   return false;
 }
  @Override
  protected ClassMember[] getAllOriginalMembers(PsiClass aClass) {
    PsiField[] fields = aClass.getFields();
    ArrayList<ClassMember> array = new ArrayList<ClassMember>();
    ImplicitUsageProvider[] implicitUsageProviders =
        Extensions.getExtensions(ImplicitUsageProvider.EP_NAME);
    fieldLoop:
    for (PsiField field : fields) {
      if (field.hasModifierProperty(PsiModifier.STATIC)) continue;

      if (field.hasModifierProperty(PsiModifier.FINAL) && field.getInitializer() != null) continue;

      for (ImplicitUsageProvider provider : implicitUsageProviders) {
        if (provider.isImplicitWrite(field)) continue fieldLoop;
      }
      array.add(new PsiFieldMember(field));
    }
    return array.toArray(new ClassMember[array.size()]);
  }
 @Override
 public void visitField(@NotNull PsiField field) {
   if (field.hasModifierProperty(PsiModifier.STATIC)) {
     return;
   }
   if (field.getInitializer() != null) {
     return;
   }
   final PsiAnnotation annotation = AnnotationUtil.findAnnotation(field, annotationNames);
   if (annotation != null) {
     return;
   }
   if (m_ignorePrimitives) {
     final PsiType fieldType = field.getType();
     if (ClassUtils.isPrimitive(fieldType)) {
       return;
     }
   }
   final PsiClass aClass = field.getContainingClass();
   if (aClass == null) {
     return;
   }
   for (ImplicitUsageProvider provider :
       Extensions.getExtensions(ImplicitUsageProvider.EP_NAME)) {
     if (provider.isImplicitWrite(field)) {
       return;
     }
   }
   final UninitializedReadCollector uninitializedReadsCollector =
       new UninitializedReadCollector();
   if (!isInitializedInInitializer(field, uninitializedReadsCollector)) {
     final PsiMethod[] constructors = aClass.getConstructors();
     for (final PsiMethod constructor : constructors) {
       final PsiCodeBlock body = constructor.getBody();
       uninitializedReadsCollector.blockAssignsVariable(body, field);
     }
   }
   final PsiExpression[] badReads = uninitializedReadsCollector.getUninitializedReads();
   for (PsiExpression expression : badReads) {
     registerError(expression);
   }
 }