Skip to content

Commit 409884a

Browse files
committed
cleanUpProject fix
Signed-off-by: AndreSonntag <Andre-Sonntag@gmx.de>
1 parent 58cd553 commit 409884a

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

  • plugins/de.cognicrypt.codegenerator/src/main/java/de/cognicrypt/codegenerator/generator

plugins/de.cognicrypt.codegenerator/src/main/java/de/cognicrypt/codegenerator/generator/CodeGenerator.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected boolean insertCallCodeIntoFile(final String temporaryOutputFile, final
132132
final TreeSet<SimpleEntry<Integer, Integer>> methLims = new TreeSet<>();
133133
final SimpleEntry<Integer, SimpleEntry<Integer, Integer>> classlims = new SimpleEntry<>(0, null);
134134

135-
final ASTParser astp = ASTParser.newParser(AST.JLS10);
135+
final ASTParser astp = ASTParser.newParser(AST.JLS9);
136136
astp.setSource(docContent.toCharArray());
137137
astp.setKind(ASTParser.K_COMPILATION_UNIT);
138138
final CompilationUnit cu = (CompilationUnit) astp.createAST(null);
@@ -198,7 +198,7 @@ private String[] getCallsForGenClasses(final String filePath) throws IOException
198198
// Retrieve complete content from file
199199
final String fileContent = String.join(Constants.lineSeparator, Files.readAllLines(Paths.get(filePath)));
200200
// Determine start and end position for relevant extract
201-
final ASTParser astp = ASTParser.newParser(AST.JLS10);
201+
final ASTParser astp = ASTParser.newParser(AST.JLS9);
202202
astp.setSource(fileContent.toCharArray());
203203
astp.setKind(ASTParser.K_COMPILATION_UNIT);
204204
final CompilationUnit cu = (CompilationUnit) astp.createAST(null);
@@ -322,26 +322,29 @@ memberPath, new File(this.project
322322
* @throws CoreException
323323
* {@link DeveloperProject#refresh() refresh()} and {@link DeveloperProject#getPackagesOfProject(String) getPackagesOfProject()}
324324
*/
325-
protected void cleanUpProject(final IEditorPart editor) throws CoreException {
325+
protected void cleanUpProject(IEditorPart editor) throws CoreException {
326326
this.project.refresh();
327-
boolean fileOpen = false;
328-
329-
//prevent Organize Imports Problems
330-
if (editor.getTitle().equals(this.temporaryOutputFile)) {
331-
fileOpen = true;
332-
Utils.closeEditor(editor);
327+
final ICompilationUnit[] generatedCUnits = this.project.getPackagesOfProject(Constants.PackageNameAsName).getCompilationUnits();
328+
boolean noClassOpen = false;
329+
330+
if(editor == null) {
331+
if (generatedCUnits[0].getResource().getType() == IResource.FILE) {
332+
IFile genClass = (IFile) generatedCUnits[0].getResource();
333+
IDE.openEditor(Utils.getCurrentlyOpenPage(), genClass);
334+
editor = Utils.getCurrentlyOpenPage().getActiveEditor();
335+
noClassOpen = true;
336+
}
333337
}
334338

335339
final OrganizeImportsAction organizeImportsActionForAllFilesTouchedDuringGeneration = new OrganizeImportsAction(editor.getSite());
336340
final FormatAllAction faa = new FormatAllAction(editor.getSite());
337-
final ICompilationUnit[] generatedCUnits = this.project.getPackagesOfProject(Constants.PackageNameAsName).getCompilationUnits();
338341
faa.runOnMultiple(generatedCUnits);
339342
organizeImportsActionForAllFilesTouchedDuringGeneration.runOnMultiple(generatedCUnits);
340343

341-
if (fileOpen) {
342-
final IFile outputFile = this.project.getIFile(this.temporaryOutputFile);
343-
IDE.openEditor(Utils.getCurrentlyOpenPage(), outputFile);
344+
if (noClassOpen) {
345+
Utils.closeEditor(editor);
344346
}
347+
345348
final ICompilationUnit openClass = JavaCore.createCompilationUnitFrom(Utils.getCurrentlyOpenFile(editor));
346349
organizeImportsActionForAllFilesTouchedDuringGeneration.run(openClass);
347350
faa.runOnMultiple(new ICompilationUnit[] { openClass });

0 commit comments

Comments
 (0)