List<GrField> (PsiMethod constructor, final GrTypeDefinition clazz) { final List<GrField> usedFields = new ArrayList<>(); final GrOpenBlock block = constructor instanceof GrMethod ? ((GrMethod)constructor).getBlock() : null; if (block == null) { return usedFields; } final PsiManager manager = clazz.getManager(); block.accept(new GroovyRecursiveElementVisitor() { @Override public void visitReferenceExpression(@NotNull GrReferenceExpression referenceExpression) { super.visitReferenceExpression(referenceExpression); final PsiElement resolved = referenceExpression.resolve(); if (resolved instanceof GrField && manager.areElementsEquivalent(((GrField)resolved).getContainingClass(), clazz) && PsiUtil.isAccessedForWriting(referenceExpression)) { usedFields.add((GrField)resolved); } } @Override public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) { } @Override public void visitClosure(@NotNull GrClosableBlock closure) { } }); List<GrField> fields = new ArrayList<>(); for (final GrField field : clazz.getFields()) { if (field.getInitializerGroovy() != null) continue; if (ContainerUtil.find(usedFields, (Condition<PsiField>)o -> manager.areElementsEquivalent(o, field)) == null) { fields.add(field); } } return fields; }