Exemple #1
0
 @NotNull
 private Field fieldToField(@NotNull PsiField field, PsiClass psiClass) {
   Set<String> modifiers = modifiersListToModifiersSet(field.getModifierList());
   if (field instanceof PsiEnumConstant) // TODO: remove instanceof
   {
     return new EnumConstant(
         new IdentifierImpl(field.getName()), // TODO
         modifiers,
         typeToType(field.getType()),
         elementToElement(((PsiEnumConstant) field).getArgumentList()));
   }
   return new Field(
       new IdentifierImpl(field.getName()), // TODO
       modifiers,
       typeToType(field.getType(), ConverterUtil.isAnnotatedAsNotNull(field.getModifierList())),
       createSureCallOnlyForChain(field.getInitializer(), field.getType()), // TODO: add modifiers
       countWritingAccesses(field, psiClass));
 }
 public void visitReferenceExpression(PsiReferenceExpression expression) {
   super.visitReferenceExpression(expression);
   if (isProhibitedReference(expression)) {
     final PsiField field = getReferencedField(expression);
     if (!hasGetter(field)
         && !isStaticFinal(field)
         && !field.getModifierList().hasModifierProperty(PsiModifier.PUBLIC)) {
       fieldsNeedingGetter.add(field);
     }
   }
 }
    public void visitAssignmentExpression(PsiAssignmentExpression expression) {
      super.visitAssignmentExpression(expression);

      final PsiExpression lhs = expression.getLExpression();
      if (isProhibitedReference(lhs)) {
        final PsiField field = getReferencedField(lhs);
        if (!hasGetter(field)
            && !isStaticFinal(field)
            && !field.getModifierList().hasModifierProperty(PsiModifier.PUBLIC)) {
          fieldsNeedingSetter.add(field);
        }
      }
    }
 @Nullable
 private static PsiField getReferencedFinalField(final PsiExpression argument) {
   if (argument instanceof PsiReferenceExpression) {
     final PsiElement element = ((PsiReferenceExpression) argument).resolve();
     if (element instanceof PsiField) {
       final PsiField field = (PsiField) element;
       final PsiModifierList modifierList = field.getModifierList();
       if (modifierList != null && modifierList.hasModifierProperty(PsiModifier.FINAL)) {
         return field;
       }
     }
   }
   return null;
 }
 private boolean isStaticFinal(PsiField field) {
   final PsiModifierList modifierList = field.getModifierList();
   logger.assertTrue(modifierList != null);
   return modifierList.hasModifierProperty(PsiModifier.STATIC)
       && modifierList.hasModifierProperty(PsiModifier.FINAL);
 }