Source:
<code>public Object[] getChildren(Object parentElement) { if (parentElement instanceof ConnectionWrapper) { ConnectionWrapper connection = (ConnectionWrapper) parentElement; if (connection.load(e -> { handleLoadingException(parentElement, e); })) { return new Object[] { makeStub(parentElement) }; } else { stubs.remove(parentElement); Object[] result = connection.getProjects().toArray(); if (result == null || result.length == 0) { result = new Object[] { new NewProjectLinkNode((Connection) connection.getConnection()) }; } return result; } } else if (parentElement instanceof ProjectWrapper) { ProjectWrapper project = (ProjectWrapper) parentElement; <START> if (project.load(e -> { <END> handleLoadingException(parentElement, e); })) { return new Object[] { makeStub(parentElement) }; } else { stubs.remove(parentElement); return project.getResourcesOfKind(ResourceKind.SERVICE).toArray(); } } else if (parentElement instanceof ServiceWrapper) { ServiceWrapper wrapper = (ServiceWrapper) parentElement; ArrayList<Object> result = new ArrayList<>(); wrapper.getResourcesOfKind(ResourceKind.BUILD).stream() .filter(b -> !isTerminatedBuild((IBuild) b.getResource())).forEach(r -> result.add(r)); wrapper.getResourcesOfKind(ResourceKind.POD).stream().filter(p -> !isBuildPod((IPod) p.getResource())) .forEach(r -> result.add(r)); return result.toArray(); } else if (parentElement instanceof LoadingStub) { return ((LoadingStub) parentElement).getChildren(); } return new Object[0]; }</code><technical_language>is opportunity refactor some loading logic a common method ConnectionWraper</technical_language>

Target:
public Object[] getChildren(Object parentElement) { if (parentElement instanceof IConnectionWrapper) { IConnectionWrapper connection = (IConnectionWrapper) parentElement; if (connection.getState() == LoadingState.LOADED) { synchronized (stubs) { stubs.remove(parentElement); } Object[] result = connection.getResources().toArray(); if (result == null || result.length == 0) { result = new Object[] { new NewProjectLinkNode((Connection) connection.getWrapped()) }; } return result; } else { connection.load(e -> { handleLoadingException(parentElement, e); }); return new Object[] { makeStub(parentElement) }; } } else if (parentElement instanceof IProjectWrapper) { IProjectWrapper project = (IProjectWrapper) parentElement; if (project.getState() == LoadingState.LOADED) { synchronized (stubs) { stubs.remove(parentElement); } return project.getResourcesOfKind(ResourceKind.SERVICE).toArray(); } else { project.load(e -> { handleLoadingException(parentElement, e); }); return new Object[] { makeStub(parentElement) }; } } else if (parentElement instanceof IServiceWrapper) { IServiceWrapper wrapper = (IServiceWrapper) parentElement; ArrayList<Object> result = new ArrayList<>(); wrapper.getResourcesOfKind(ResourceKind.BUILD).stream() .filter(b -> !isTerminatedBuild((IBuild) b.getWrapped())).forEach(r -> result.add(r)); wrapper.getResourcesOfKind(ResourceKind.POD).stream() .filter(p -> !ResourceUtils.isBuildPod((IPod) p.getWrapped())).forEach(r -> result.add(r)); return result.toArray(); } else if (parentElement instanceof LoadingStub) { return ((LoadingStub) parentElement).getChildren(); } return new Object[0]; }