use of com.devonfw.cobigen.eclipse.wizard.common.model.stubs.IFileStub in project cobigen by devonfw.
the class SelectFileContentProvider method stubNonExistentChildren.
/**
* Stubs all non existent resources, which are selected to be generated
*
* @param parentElement parent {@link IJavaElement} to retrieve the children from
* @param stubbedChildren the so far stubbed resources and similarly the output of this method as new stubbed
* resources will be added to this list. This is necessary in order to avoid duplicates in this list.
*/
private void stubNonExistentChildren(IResource parentElement, List<Object> stubbedChildren) {
String debugInfo;
IPath parentPath = parentElement.getFullPath();
List<String> nonExistentChildren = getNonExistentChildren(parentPath);
for (String path : nonExistentChildren) {
IResourceStub resourceStub = null;
IPath childPath = new Path(path);
IPath childPathFragment = childPath.removeFirstSegments(parentPath.segmentCount());
if (childPathFragment.segmentCount() > 1) {
// target path is no atomic child -> stub next element if necessary
childPathFragment = childPathFragment.removeFirstSegments(1);
IPath atomicChildPath = new Path(path);
atomicChildPath = atomicChildPath.removeLastSegments(childPathFragment.segmentCount());
// parent
if (ResourcesPlugin.getWorkspace().getRoot().exists(atomicChildPath)) {
continue;
} else if (this._cachedProvidedResources.containsKey(atomicChildPath.toString())) {
// if already seen, just get it and skip creation
Object cachedStub = this._cachedProvidedResources.get(atomicChildPath.toString());
if (!stubbedChildren.contains(cachedStub)) {
stubbedChildren.add(cachedStub);
}
continue;
}
if (targetIsFile(atomicChildPath, nonExistentChildren)) {
resourceStub = new IFileStub();
debugInfo = "File";
} else {
resourceStub = new IFolderStub();
debugInfo = "Folder";
}
resourceStub.setFullPath(atomicChildPath);
} else if (childPathFragment.segmentCount() == 1) {
if (this._cachedProvidedResources.containsKey(childPath.toString())) {
// if already seen, just get it and skip creation
Object cachedStub = this._cachedProvidedResources.get(childPath.toString());
if (!stubbedChildren.contains(cachedStub)) {
stubbedChildren.add(cachedStub);
}
continue;
}
if (targetIsFile(childPath, nonExistentChildren)) {
resourceStub = new IFileStub();
debugInfo = "File";
} else {
resourceStub = new IFolderStub();
debugInfo = "Folder";
}
resourceStub.setFullPath(childPath);
} else {
// no child of parentPath
continue;
}
if (!stubbedChildren.contains(resourceStub)) {
stubbedChildren.add(resourceStub);
this._cachedProvidedResources.put(resourceStub.getFullPath().toString(), resourceStub);
}
LOG.debug("Stub created for {} with name '{}' and path '{}'", debugInfo, resourceStub.getName(), resourceStub.getFullPath().toString());
}
}
Aggregations