use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class GrFieldMember method generateGetter.
@Override
@Nullable
public GroovyGenerationInfo<GrMethod> generateGetter() {
PsiField field = getElement();
final GrMethod method = createMethodIfNotExists(field, GroovyPropertyUtils.generateGetterPrototype(field));
return method != null ? new GroovyGenerationInfo<>(method) : null;
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class ElementUtils method getOnlyAsFieldElements.
/**
* Gets the list of members to be put in the VelocityContext.
*
* @param members a list of {@link PsiMember} objects.
* @param selectedNotNullMembers
* @param useAccessors
* @return a filtered list of only the fields as {@link FieldElement} objects.
*/
public static List<FieldElement> getOnlyAsFieldElements(Collection<? extends PsiMember> members, Collection<? extends PsiMember> selectedNotNullMembers, boolean useAccessors) {
List<FieldElement> fieldElementList = new ArrayList<>();
for (PsiMember member : members) {
if (member instanceof PsiField) {
PsiField field = (PsiField) member;
FieldElement fe = ElementFactory.newFieldElement(field, useAccessors);
if (selectedNotNullMembers.contains(member)) {
fe.setNotNull(true);
}
fieldElementList.add(fe);
}
}
return fieldElementList;
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class RenameGrAccessorProcessor method prepareRenaming.
@Override
public void prepareRenaming(PsiElement element, String newName, Map<PsiElement, String> allRenames, SearchScope scope) {
super.prepareRenaming(element, newName, allRenames, scope);
final PsiField field = GroovyPropertyUtils.findFieldForAccessor((PsiMethod) element, false);
if (field != null) {
}
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class PublicFieldInspection method buildFixes.
@NotNull
@Override
protected InspectionGadgetsFix[] buildFixes(Object... infos) {
final List<InspectionGadgetsFix> fixes = new ArrayList<>();
final PsiField field = (PsiField) infos[0];
fixes.add(new EncapsulateVariableFix(field.getName()));
AddToIgnoreIfAnnotatedByListQuickFix.build(field, ignorableAnnotations, fixes);
return fixes.toArray(new InspectionGadgetsFix[fixes.size()]);
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class FieldCanBeMovedToSubclassInspection method checkElement.
@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager inspectionManager, @NotNull GlobalInspectionContext globalInspectionContext) {
if (!(refEntity instanceof RefField)) {
return null;
}
final RefField refField = (RefField) refEntity;
final PsiField field = refField.getElement();
if (field == null) {
return null;
}
final PsiType type = field.getType();
if (!type.equals(PsiType.BOOLEAN)) {
return null;
}
final RefClass fieldClass = refField.getOwnerClass();
final Collection<RefElement> inReferences = refField.getInReferences();
final RefJavaUtil refUtil = RefJavaUtil.getInstance();
final Set<RefClass> classesUsed = new HashSet<>();
for (RefElement inReference : inReferences) {
final RefClass referringClass = refUtil.getOwnerClass(inReference);
if (referringClass == null) {
return null;
}
if (referringClass.equals(fieldClass)) {
return null;
}
classesUsed.add(referringClass);
if (classesUsed.size() > 1) {
return null;
}
}
if (classesUsed.size() != 1) {
return null;
}
final RefClass referencingClass = classesUsed.iterator().next();
//TODO: check that referencing class is a subclass of the field class
final String errorString = "Field " + refEntity.getName() + " is only accessed in subclass " + referencingClass.getName();
return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(errorString) };
}
Aggregations