Пример #1
0
 @NotNull
 public static Set<String> modifiersListToModifiersSet(@Nullable PsiModifierList modifierList) {
   Set<String> modifiersSet = new HashSet<String>();
   if (modifierList != null) {
     if (modifierList.hasExplicitModifier(PsiModifier.ABSTRACT))
       modifiersSet.add(Modifier.ABSTRACT);
     if (modifierList.hasModifierProperty(PsiModifier.FINAL)) modifiersSet.add(Modifier.FINAL);
     if (modifierList.hasModifierProperty(PsiModifier.STATIC)) modifiersSet.add(Modifier.STATIC);
     if (modifierList.hasExplicitModifier(PsiModifier.PUBLIC)) modifiersSet.add(Modifier.PUBLIC);
     if (modifierList.hasExplicitModifier(PsiModifier.PROTECTED))
       modifiersSet.add(Modifier.PROTECTED);
     if (modifierList.hasExplicitModifier(PsiModifier.PACKAGE_LOCAL))
       modifiersSet.add(Modifier.INTERNAL);
     if (modifierList.hasExplicitModifier(PsiModifier.PRIVATE)) modifiersSet.add(Modifier.PRIVATE);
   }
   return modifiersSet;
 }
Пример #2
0
 private static boolean isNotOpenMethod(@NotNull PsiMethod method) {
   if (method.getParent() instanceof PsiClass) {
     PsiModifierList parentModifierList = ((PsiClass) method.getParent()).getModifierList();
     if ((parentModifierList != null && parentModifierList.hasExplicitModifier(Modifier.FINAL))
         || ((PsiClass) method.getParent()).isEnum()) {
       return true;
     }
   }
   return false;
 }
Пример #3
0
 @Override
 public boolean isAvailable(
     @NotNull Project project,
     @NotNull PsiFile file,
     @NotNull PsiElement startElement,
     @NotNull PsiElement endElement) {
   final PsiModifierList myModifierList = (PsiModifierList) startElement;
   PsiVariable variable = myVariable == null ? null : myVariable.getElement();
   return myModifierList.isValid()
       && myModifierList.getManager().isInProject(myModifierList)
       && myModifierList.hasExplicitModifier(myModifier) != myShouldHave
       && (variable == null || variable.isValid());
 }
  @Test
  public void shouldVerifyThatFieldIsNotSetInSetterMethodIfItIsPrivate() {
    // given
    given(psiClass.getAllMethods()).willReturn(methods);
    given(method.getModifierList()).willReturn(modifierList);
    given(psiField.getName()).willReturn("field");
    given(modifierList.hasExplicitModifier(PsiFieldVerifierImpl.PRIVATE_MODIFIER)).willReturn(true);
    given(method.getName()).willReturn("setField");
    // when
    boolean result = psiFieldVerifier.isSetInSetterMethod(psiField, psiClass);

    // then
    assertThat(result, is(false));
  }