private static boolean isExtensionPointNameDeclarationField(PsiField psiField) { // *do* allow non-public if (!psiField.hasModifierProperty(PsiModifier.FINAL) || !psiField.hasModifierProperty(PsiModifier.STATIC) || psiField.hasModifierProperty(PsiModifier.ABSTRACT)) { return false; } if (!psiField.hasInitializer()) { return false; } final PsiExpression initializer = psiField.getInitializer(); if (!(initializer instanceof PsiMethodCallExpression) && !(initializer instanceof PsiNewExpression)) { return false; } final PsiClass fieldClass = PsiTypesUtil.getPsiClass(psiField.getType()); if (fieldClass == null) { return false; } return ExtensionPointName.class.getName().equals(fieldClass.getQualifiedName()); }
public static boolean isFieldInitializedAfterObjectConstruction(@NotNull PsiField field) { if (field.hasInitializer()) return true; final boolean isFieldStatic = field.hasModifierProperty(PsiModifier.STATIC); final PsiClass aClass = field.getContainingClass(); if (aClass != null) { // field might be assigned in the other field initializers if (isFieldInitializedInOtherFieldInitializer(aClass, field, isFieldStatic)) return true; } final PsiClassInitializer[] initializers; if (aClass != null) { initializers = aClass.getInitializers(); } else { return false; } for (PsiClassInitializer initializer : initializers) { if (initializer.hasModifierProperty(PsiModifier.STATIC) == isFieldStatic && variableDefinitelyAssignedIn(field, initializer.getBody())) { return true; } } if (isFieldStatic) { return false; } else { // instance field should be initialized at the end of the each constructor final PsiMethod[] constructors = aClass.getConstructors(); if (constructors.length == 0) return false; nextConstructor: for (PsiMethod constructor : constructors) { PsiCodeBlock ctrBody = constructor.getBody(); if (ctrBody == null) return false; final List<PsiMethod> redirectedConstructors = JavaHighlightUtil.getChainedConstructors(constructor); for (int j = 0; redirectedConstructors != null && j < redirectedConstructors.size(); j++) { PsiMethod redirectedConstructor = redirectedConstructors.get(j); final PsiCodeBlock body = redirectedConstructor.getBody(); if (body != null && variableDefinitelyAssignedIn(field, body)) continue nextConstructor; } if (!ctrBody.isValid() || variableDefinitelyAssignedIn(field, ctrBody)) { continue; } return false; } return true; } }