DevBoost / JaMoPP

JaMoPP can parse Java source and byte code into EMF-based models and vice versa. It preserves source formatting and can be used for code analysis and refactoring.
17 stars 18 forks source link

Parsing looses original ResourceSet JavaOptions settings. #20

Closed BenjaminKlatt closed 10 years ago

BenjaminKlatt commented 10 years ago

In the JavaParser, the parse methods such as parse_org_emftext_language_java_annotations_AnnotationAttributeSetting() creates new model elements such as

element = org.emftext.language.java.annotations.AnnotationsFactory.eINSTANCE.createAnnotationAttributeSetting();

These elements are not associated with the original resource set.

As a result, during the downstream parsing, the new default resource set associated to those elements does not have the original ResourceSet options set such as to disable the layout information processing. This prevents to disable layout or location map processings for performance gains.

To reproduce this issue, initialize your resource set with a disabled Layout processing:

ResourceSet rs = new ResourceSetImpl();
Map<Object, Object> options = rs.getLoadOptions();
options.put(IJavaOptions.DISABLE_LAYOUT_INFORMATION_RECORDING, Boolean.TRUE);
options.put(IJavaOptions.DISABLE_LOCATION_MAP, Boolean.TRUE);

set a breakpoint in JavaANTLRParserBase.retrieveLayoutInformation() after the disableLayoutRecording check:

    protected void retrieveLayoutInformation(org.eclipse.emf.ecore.EObject element, org.emftext.language.java.resource.java.grammar.JavaSyntaxElement syntaxElement, Object object, boolean ignoreTokensAfterLastVisibleToken) {
  if (disableLayoutRecording || element == null) {
    return;
  }
  // set breakpoint here

Run your test app in debug mode and the debugger will stop because of disableLayoutRecording set to false.

disableLayoutRecording is set during JavaANTLRParserBase.setOptions() only. If you follow the call stack in the debugger, you will notice a ResourceSet with default loadOptions set only.

BenjaminKlatt commented 10 years ago

The new ResourceSets are created in JavaCodeCompletionHelper.computeCompletionProposals()

BenjaminKlatt commented 10 years ago

The issue is not relevant anymore and no fix needed