Skip to content

Commit

Permalink
ASTParser should use CompilationUnit options.
Browse files Browse the repository at this point in the history
Instead of parent project one, as the CompilationUnit may override some
options.
  • Loading branch information
mickaelistria authored and rgrunber committed Apr 16, 2024
1 parent d13e7b5 commit b2ac1e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@ public void setSource(char[] source) {
*
* <p>This method automatically sets the project (and compiler
* options) based on the given compilation unit, in a manner
* equivalent to {@link #setProject(IJavaProject) setProject(source.getJavaProject())}.</p>
* equivalent to {@link #setProject(IJavaProject) setProject(source.getJavaProject())}
* and the custom compiler options supported by the compilation unit through
* {@link ICompilationUnit#getCustomOptions() getCustomOptions()}.</p>
*
* <p>This source is not used when the AST is built using
* {@link #createASTs(ICompilationUnit[], String[], ASTRequestor, IProgressMonitor)}.</p>
Expand All @@ -612,6 +614,9 @@ public void setSource(char[] source) {
*/
public void setSource(ICompilationUnit source) {
setSource((ITypeRoot)source);
if (source != null) {
setCompilerOptions(source.getOptions(true));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1453,11 +1453,13 @@ public void setOptions(Map<String, String> newOptions) {

@Override
public Map<String, String> getCustomOptions() {
try {
Map<String, String> customOptions = this.getCompilationUnitElementInfo().getCustomOptions();
return customOptions == null ? Collections.emptyMap() : customOptions;
} catch (JavaModelException e) {
// do nothing
if (this.owner != null) {
try {
Map<String, String> customOptions = this.getCompilationUnitElementInfo().getCustomOptions();
return customOptions == null ? Collections.emptyMap() : customOptions;
} catch (JavaModelException e) {
// do nothing
}
}

return Collections.emptyMap();
Expand Down

0 comments on commit b2ac1e4

Please sign in to comment.