Skip to content

Commit 80ad2aa

Browse files
committed
Improvement to getCustomOptions to prevent premature loading of element info
Signed-off-by: Rob Stryker <[email protected]>
1 parent e6ca7ef commit 80ad2aa

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,8 +1579,16 @@ public void setOptions(Map<String, String> newOptions) {
15791579
@Override
15801580
public Map<String, String> getCustomOptions() {
15811581
if (this.owner != null) {
1582-
try {
1583-
Map<String, String> customOptions = this.getCompilationUnitElementInfo().getCustomOptions();
1582+
// try {
1583+
Map<String, String> customOptions = null;
1584+
JavaModelManager manager = JavaModelManager.getJavaModelManager();
1585+
IElementInfo info = manager.getInfo(this);
1586+
// If the info has not been loaded, then nobody has called setOptions() yet.
1587+
// So no need to load the IElementInfo, which may also parse the cu.
1588+
if (info != null)
1589+
customOptions = ((CompilationUnitElementInfo)info).getCustomOptions();
1590+
1591+
// Map<String, String> customOptions = this.getCompilationUnitElementInfo().getCustomOptions();
15841592
IJavaProject parentProject = getJavaProject();
15851593
Map<String, String> parentOptions = parentProject == null ? JavaCore.getOptions() : parentProject.getOptions(true);
15861594
if (JavaCore.ENABLED.equals(parentOptions.get(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES)) &&
@@ -1593,9 +1601,9 @@ public Map<String, String> getCustomOptions() {
15931601
}
15941602
}
15951603
return customOptions == null ? Collections.emptyMap() : customOptions;
1596-
} catch (JavaModelException e) {
1597-
// do nothing
1598-
}
1604+
// } catch (JavaModelException e) {
1605+
// // do nothing
1606+
// }
15991607
}
16001608

16011609
return Collections.emptyMap();

0 commit comments

Comments
 (0)