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

The following examples show how to use com.intellij.psi.PsiClass#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: CamelDocumentationProvider.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
private boolean isPsiMethodCamelLanguage(PsiMethod method) {
    PsiType type = method.getReturnType();
    if (type != null && type instanceof PsiClassReferenceType) {
        PsiClassReferenceType clazz = (PsiClassReferenceType) type;
        PsiClass resolved = clazz.resolve();
        if (resolved != null) {
            boolean language = getCamelIdeaUtils().isCamelExpressionOrLanguage(resolved);
            // try parent using some weird/nasty stub stuff which is how complex IDEA AST
            // is when its parsing the Camel route builder
            if (!language) {
                PsiElement elem = resolved.getParent();
                if (elem instanceof PsiTypeParameterList) {
                    elem = elem.getParent();
                }
                if (elem instanceof PsiClass) {
                    language = getCamelIdeaUtils().isCamelExpressionOrLanguage((PsiClass) elem);
                }
            }
            return language;
        }
    }

    return false;
}
 
Example 2
Source File: FieldNameConstantsPredefinedInnerClassFieldProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NotNull
@Override
public List<? super PsiElement> process(@NotNull PsiClass psiClass) {
  if (psiClass.getParent() instanceof PsiClass) {
    PsiClass parentClass = (PsiClass) psiClass.getParent();
    PsiAnnotation psiAnnotation = PsiAnnotationSearchUtil.findAnnotation(parentClass, getSupportedAnnotationClasses());
    if (null != psiAnnotation && supportAnnotationVariant(psiAnnotation)) {
      ProblemEmptyBuilder problemBuilder = ProblemEmptyBuilder.getInstance();
      if (super.validate(psiAnnotation, parentClass, problemBuilder)) {
        final String typeName = FieldNameConstantsHandler.getTypeName(parentClass, psiAnnotation);
        if (typeName.equals(psiClass.getName())) {
          if (validate(psiAnnotation, parentClass, problemBuilder)) {
            List<? super PsiElement> result = new ArrayList<>();
            generatePsiElements(parentClass, psiClass, psiAnnotation, result);
            return result;
          }
        }
      }
    }
  }
  return Collections.emptyList();
}
 
Example 3
Source File: LombokProcessorProvider.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean verifyLombokAnnotationPresent(@NotNull PsiClass psiClass) {
  if (PsiAnnotationSearchUtil.checkAnnotationsSimpleNameExistsIn(psiClass, registeredAnnotationNames)) {
    return true;
  }
  Collection<PsiField> psiFields = PsiClassUtil.collectClassFieldsIntern(psiClass);
  for (PsiField psiField : psiFields) {
    if (PsiAnnotationSearchUtil.checkAnnotationsSimpleNameExistsIn(psiField, registeredAnnotationNames)) {
      return true;
    }
  }
  Collection<PsiMethod> psiMethods = PsiClassUtil.collectClassMethodsIntern(psiClass);
  for (PsiMethod psiMethod : psiMethods) {
    if (PsiAnnotationSearchUtil.checkAnnotationsSimpleNameExistsIn(psiMethod, registeredAnnotationNames)) {
      return true;
    }
  }
  final PsiElement psiClassParent = psiClass.getParent();
  if (psiClassParent instanceof PsiClass) {
    return verifyLombokAnnotationPresent((PsiClass) psiClassParent);
  }

  return false;
}
 
Example 4
Source File: UtilityClassModifierTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void testUtilityClassModifiersInnerClass() {
  PsiFile file = myFixture.configureByFile(getTestName(false) + ".java");
  PsiClass innerClass = PsiTreeUtil.getParentOfType(file.findElementAt(myFixture.getCaretOffset()), PsiClass.class);

  assertNotNull(innerClass);
  assertNotNull(innerClass.getModifierList());

  PsiElement parent = innerClass.getParent();

  assertNotNull(parent);
  assertTrue(parent instanceof PsiClass);

  PsiClass parentClass = (PsiClass) parent;

  assertNotNull(parentClass.getModifierList());
  assertTrue("@UtilityClass should make parent class final", ((PsiClass) innerClass.getParent()).getModifierList().hasModifierProperty(PsiModifier.FINAL));
  assertTrue("@UtilityClass should make inner class static", innerClass.getModifierList().hasModifierProperty(PsiModifier.STATIC));
}
 
Example 5
Source File: AbstractClassProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Optional<PsiClass> getSupportedParentClass(@NotNull PsiClass psiClass) {
  final PsiElement parentElement = psiClass.getParent();
  if (parentElement instanceof PsiClass && !(parentElement instanceof LombokLightClassBuilder)) {
    return Optional.of((PsiClass) parentElement);
  }
  return Optional.empty();
}