Java Code Examples for com.intellij.psi.PsiModifierList#getParent()

The following examples show how to use com.intellij.psi.PsiModifierList#getParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UtilityClassModifierProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static boolean isModifierListSupported(@NotNull PsiModifierList modifierList) {
  PsiElement modifierListParent = modifierList.getParent();

  if (modifierListParent instanceof PsiClass) {
    PsiClass parentClass = (PsiClass) modifierListParent;
    if (PsiAnnotationSearchUtil.isAnnotatedWith(parentClass, UtilityClass.class)) {
      return UtilityClassProcessor.validateOnRightType(parentClass, new ProblemNewBuilder());
    }
  }

  if (!isElementFieldOrMethodOrInnerClass(modifierListParent)) {
    return false;
  }

  PsiClass searchableClass = PsiTreeUtil.getParentOfType(modifierListParent, PsiClass.class, true);

  return null != searchableClass && PsiAnnotationSearchUtil.isAnnotatedWith(searchableClass, UtilityClass.class) && UtilityClassProcessor.validateOnRightType(searchableClass, new ProblemNewBuilder());
}
 
Example 2
Source File: UtilityClassModifierProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void transformModifiers(@NotNull PsiModifierList modifierList, @NotNull final Set<String> modifiers) {
  final PsiElement parent = modifierList.getParent();

  // FINAL
  if (parent instanceof PsiClass) {
    PsiClass psiClass = (PsiClass) parent;
    if (PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, UtilityClass.class)) {
      modifiers.add(PsiModifier.FINAL);
    }
  }

  // STATIC
  if (isElementFieldOrMethodOrInnerClass(parent)) {
    modifiers.add(PsiModifier.STATIC);
  }
}
 
Example 3
Source File: ValueModifierProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void transformModifiers(@NotNull PsiModifierList modifierList, @NotNull final Set<String> modifiers) {
  if (modifiers.contains(PsiModifier.STATIC)) {
    return; // skip static fields
  }

  final PsiModifierListOwner parentElement = PsiTreeUtil.getParentOfType(modifierList, PsiModifierListOwner.class, false);
  if (null != parentElement) {

    // FINAL
    if (!PsiAnnotationSearchUtil.isAnnotatedWith(parentElement, lombok.experimental.NonFinal.class)) {
      modifiers.add(PsiModifier.FINAL);
    }

    // PRIVATE
    if (modifierList.getParent() instanceof PsiField &&
      // Visibility is only changed for package private fields
      hasPackagePrivateModifier(modifierList) &&
      // except they are annotated with @PackagePrivate
      !PsiAnnotationSearchUtil.isAnnotatedWith(parentElement, lombok.experimental.PackagePrivate.class)) {
      modifiers.add(PsiModifier.PRIVATE);

      // IDEA _right now_ checks if other modifiers are set, and ignores PACKAGE_LOCAL but may as well clean it up
      modifiers.remove(PsiModifier.PACKAGE_LOCAL);
    }
  }
}
 
Example 4
Source File: ValModifierProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean isSupported(@NotNull PsiModifierList modifierList) {
  final PsiElement parent = modifierList.getParent();

  return (parent instanceof PsiLocalVariable && ValProcessor.isVal((PsiLocalVariable) parent));
}
 
Example 5
Source File: ValueModifierProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
@Override
public boolean isSupported(@NotNull PsiModifierList modifierList) {

  final PsiElement modifierListParent = modifierList.getParent();

  if (!(modifierListParent instanceof PsiField || modifierListParent instanceof PsiClass)) {
    return false;
  }

  PsiClass searchableClass = PsiTreeUtil.getParentOfType(modifierList, PsiClass.class, true);

  return null != searchableClass && PsiAnnotationSearchUtil.isAnnotatedWith(searchableClass, lombok.Value.class);
}