catch (final IOException ignored) {
}
if (StringUtils.isBlank(fileContents)) {
return getCompilationUnitContents(cid);
}
CompilationUnit compilationUnit;
try {
compilationUnit = JavaParser.parse(new ByteArrayInputStream(
fileContents.getBytes()));
}
catch (final IOException e) {
throw new IllegalStateException(e);
}
catch (final ParseException e) {
throw new IllegalStateException(e);
}
// Load new compilation unit from cid information
final String cidContents = getCompilationUnitContents(cid);
CompilationUnit cidCompilationUnit;
try {
cidCompilationUnit = JavaParser.parse(new ByteArrayInputStream(
cidContents.getBytes()));
}
catch (final IOException e) {
throw new IllegalStateException(e);
}
catch (final ParseException e) {
throw new IllegalStateException(e);
}
// Update package
if (!compilationUnit.getPackage().getName().getName()
.equals(cidCompilationUnit.getPackage().getName().getName())) {
compilationUnit.setPackage(cidCompilationUnit.getPackage());
}
// Update imports
UpdateCompilationUnitUtils.updateCompilationUnitImports(
compilationUnit, cidCompilationUnit);