List<PsiElement> (@NotNull List<Instruction> subGraph, @NotNull List<Instruction> graph) { final List<PsiElement> result = new ArrayList<>(); final Set<PsiElement> subGraphElements = getSubGraphElements(subGraph); for (Instruction instruction : getReadInstructions(subGraph)) { final PsiElement element = instruction.getElement(); if (element != null) { final PsiReference reference = element.getReference(); if (reference != null) { for (PsiElement resolved : multiResolve(reference)) { if (!subGraphElements.contains(resolved)) { result.add(element); break; } } } } } final List<PsiElement> outputElements = getOutputElements(subGraph, graph); for (Instruction instruction : getWriteInstructions(subGraph)) { final PsiElement element = instruction.getElement(); if (element != null) { final PsiReference reference = element.getReference(); if (reference != null) { for (PsiElement resolved : multiResolve(reference)) { if (!subGraphElements.contains(resolved) && outputElements.contains(element)) { result.add(element); } } } } } return result; }