private void injectAutoAnnotation(PsiElementFactory factory, PsiClass cls) { PsiModifierList modifierList = cls.getModifierList(); if (modifierList != null) { PsiElement firstChild = modifierList.getFirstChild(); Pattern pattern = Pattern.compile("@.*?AutoValue"); if (firstChild != null && !pattern.matcher(firstChild.getText()).find()) { PsiAnnotation annotationFromText = factory.createAnnotationFromText("@com.google.auto.value.AutoValue", cls); modifierList.addBefore(annotationFromText, firstChild); } if (!modifierList.hasModifierProperty(PsiModifier.ABSTRACT)) { modifierList.setModifierProperty(PsiModifier.ABSTRACT, true); } } }
public static void setVisibility(PsiModifierList modifierList, @PsiModifier.ModifierConstant String newVisibility) throws IncorrectOperationException { modifierList.setModifierProperty(newVisibility, true); }
public static void setModifierProperty(@NotNull PsiModifierListOwner owner, @NotNull @PsiModifier.ModifierConstant String property, boolean value) { final PsiModifierList modifierList = owner.getModifierList(); assert modifierList != null : owner; modifierList.setModifierProperty(property, value); }