Kind (@NotNull PsiFile containingFile) { if (!containingFile.isValid()) { // optimization to avoid relatively expensive this.isValid check // but still provide diagnostics for this element, not for its containing DummyHolder file PsiUtilCore.ensureValid(this); } CompositeElement treeParent = getTreeParent(); IElementType i = treeParent.getElementType(); if (isDummy(i)) { return myKindWhenDummy; } if (i == JavaElementType.TYPE) { return treeParent.getTreeParent().getPsi() instanceof PsiTypeCodeFragment ? Kind.CLASS_OR_PACKAGE_NAME_KIND : Kind.CLASS_NAME_KIND; } if (i == JavaElementType.EXTENDS_LIST || i == JavaElementType.IMPLEMENTS_LIST || i == JavaElementType.PERMITS_LIST || i == JavaElementType.EXTENDS_BOUND_LIST || i == JavaElementType.THROWS_LIST || i == JavaElementType.THIS_EXPRESSION || i == JavaElementType.SUPER_EXPRESSION || i == JavaDocElementType.DOC_METHOD_OR_FIELD_REF || i == JavaDocElementType.DOC_TAG_VALUE_ELEMENT || i == JavaElementType.REFERENCE_PARAMETER_LIST || i == JavaElementType.ANNOTATION || i == JavaElementType.USES_STATEMENT || i == JavaElementType.PROVIDES_STATEMENT || i == JavaElementType.PROVIDES_WITH_LIST) { return isQualified() ? Kind.CLASS_OR_PACKAGE_NAME_KIND : Kind.CLASS_NAME_KIND; } if (i == JavaElementType.NEW_EXPRESSION) { ASTNode qualifier = treeParent.findChildByRole(ChildRole.QUALIFIER); return qualifier != null ? Kind.CLASS_IN_QUALIFIED_NEW_KIND : Kind.CLASS_NAME_KIND; } if (i == JavaElementType.ANONYMOUS_CLASS) { if (treeParent.getChildRole(this) == ChildRole.BASE_CLASS_REFERENCE) { CompositeElement granny = treeParent.getTreeParent(); IElementType gType = granny.getElementType(); LOG.assertTrue(gType == JavaElementType.NEW_EXPRESSION, gType); ASTNode qualifier = granny.findChildByRole(ChildRole.QUALIFIER); return qualifier != null ? Kind.CLASS_IN_QUALIFIED_NEW_KIND : Kind.CLASS_NAME_KIND; } else { return Kind.CLASS_OR_PACKAGE_NAME_KIND; // incomplete code } } if (i == JavaElementType.PACKAGE_STATEMENT || i == JavaElementType.EXPORTS_STATEMENT || i == JavaElementType.OPENS_STATEMENT) { return Kind.PACKAGE_NAME_KIND; } if (i == JavaElementType.IMPORT_STATEMENT) { PsiElement parent = treeParent.getPsi(); if (parent instanceof PsiImportStatement) { boolean isOnDemand = ((PsiImportStatement)parent).isOnDemand(); return isOnDemand ? Kind.CLASS_FQ_OR_PACKAGE_NAME_KIND : Kind.CLASS_FQ_NAME_KIND; } // otherwise, fallthrough to diagnoseUnknownParent() } if (i == JavaElementType.IMPORT_STATIC_STATEMENT) { return Kind.CLASS_FQ_OR_PACKAGE_NAME_KIND; } if (i == JavaElementType.JAVA_CODE_REFERENCE) { Kind parentKind = ((PsiJavaCodeReferenceElementImpl)treeParent).getKindEnum(containingFile); if (parentKind == Kind.CLASS_NAME_KIND) { return Kind.CLASS_OR_PACKAGE_NAME_KIND; } if (parentKind == Kind.CLASS_FQ_NAME_KIND) { return Kind.CLASS_FQ_OR_PACKAGE_NAME_KIND; } return parentKind; } if (i == JavaElementType.CLASS || i == JavaElementType.PARAMETER_LIST || i == TokenType.ERROR_ELEMENT) { return Kind.CLASS_OR_PACKAGE_NAME_KIND; } if (i == JavaElementType.IMPORT_STATIC_REFERENCE) { return Kind.CLASS_FQ_OR_PACKAGE_NAME_KIND; } if (i == JavaDocElementType.DOC_TAG || i == JavaDocElementType.DOC_INLINE_TAG || i == JavaDocElementType.DOC_REFERENCE_HOLDER || i == JavaDocElementType.DOC_TYPE_HOLDER) { PsiDocComment docComment = PsiTreeUtil.getParentOfType(this, PsiDocComment.class); if (JavaDocUtil.isInsidePackageInfo(docComment)) { return Kind.CLASS_FQ_OR_PACKAGE_NAME_KIND; } return Kind.CLASS_OR_PACKAGE_NAME_KIND; } if (isCodeFragmentType(i)) { PsiJavaCodeReferenceCodeFragment fragment = (PsiJavaCodeReferenceCodeFragment)treeParent.getPsi(); return fragment.isClassesAccepted() ? Kind.CLASS_FQ_OR_PACKAGE_NAME_KIND : Kind.PACKAGE_NAME_KIND; } diagnoseUnknownParent(treeParent, i); return Kind.CLASS_NAME_KIND; }