Search in sources :

Example 66 with PsiField

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;
}
Also used : PsiField(com.intellij.psi.PsiField) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) Nullable(org.jetbrains.annotations.Nullable)

Example 67 with PsiField

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;
}
Also used : PsiField(com.intellij.psi.PsiField) ArrayList(java.util.ArrayList) PsiMember(com.intellij.psi.PsiMember)

Example 68 with PsiField

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) {
    }
}
Also used : PsiField(com.intellij.psi.PsiField)

Example 69 with PsiField

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()]);
}
Also used : EncapsulateVariableFix(com.siyeh.ig.fixes.EncapsulateVariableFix) PsiField(com.intellij.psi.PsiField) ArrayList(java.util.ArrayList) InspectionGadgetsFix(com.siyeh.ig.InspectionGadgetsFix) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with PsiField

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) };
}
Also used : CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) PsiField(com.intellij.psi.PsiField) PsiType(com.intellij.psi.PsiType) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiField (com.intellij.psi.PsiField)86 PsiClass (com.intellij.psi.PsiClass)34 PsiElement (com.intellij.psi.PsiElement)27 ArrayList (java.util.ArrayList)13 PsiMethod (com.intellij.psi.PsiMethod)11 NotNull (org.jetbrains.annotations.NotNull)11 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)8 PsiReference (com.intellij.psi.PsiReference)7 PsiType (com.intellij.psi.PsiType)7 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)6 Nullable (org.jetbrains.annotations.Nullable)6 Nullable (com.android.annotations.Nullable)5 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)5 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)5 PsiExpression (com.intellij.psi.PsiExpression)5 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)5 ResourceType (com.android.resources.ResourceType)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)4 PsiFile (com.intellij.psi.PsiFile)4