Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 318815

Summary: [otjld] [compiler] Support the "Internal Role" pattern
Product: [Tools] Objectteams Reporter: Stephan Herrmann <stephan.herrmann>
Component: OTJAssignee: Stephan Herrmann <stephan.herrmann>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 Keywords: noteworthy
Version: 0.7   
Target Milestone: 0.7.1   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
proposed implementation
none
additional patch
none
ui-part none

Description Stephan Herrmann CLA 2010-07-04 09:53:15 EDT
As discussed in 
http://www.eclipse.org/forums/index.php?t=msg&&th=162947&goto=515854#msg_515854
the rules of OT/J could be relaxed to support the "Internal Role" pattern
by Graversen et al.

This implies to remove the restriction, that a role cannot be played by
an enclosing type (2.1.2(b)).

The change is not trivial because we'd want to give hints when such 
circularity of containment and role-playing could result in unwanted
recursions at runtime.
Comment 1 Stephan Herrmann CLA 2010-07-08 17:15:07 EDT
While working on this and turning test212_boundToRelatedClass3()
into a positive test I noticed that callout transformation failed,
because of a compile order problem:

- establishMethodMappingsResolved(RoleModel role) requires that the
  baseclass has STATE_MAPPINGS_TRANSFORMED
- if baseclass is an enclosing, it is not ready for mapping transformation
  because it is currently busy resolving those mappings.

This appears to be a special instance of the compiler order issue from
bug 318084.
Comment 2 Stephan Herrmann CLA 2010-07-09 12:04:54 EDT
Created attachment 173878 [details]
proposed implementation

* new diagnostics:
  - make errors baseclassCircularity/playedByEnclosing configurable (core only)
    - token = "baseclasscycle", def=warn
    - tag roles as _playedByEnclosing as precond for next two errors:
  - new errors: BaseAllocationDespiteBaseclassCycle, CalloutToEnclosing
* improve detection of baseclass circularity:
  - also consider supers of enclosings (see test212_boundToRelatedClass5)
* avoid compile order problem by skipping
    ensureBindingState(baseclass, STATE_MAPPINGS_TRANSFORMED)
  when _playedByEnclosing was detected

* more and changed tests (not part of the patch)
  - new errors (test212_boundToRelatedClass3, test214_boundToRelatedTeam1)
  - new positive case (test212_boundToRelatedClass4)
  - bound to super of enclosing team (test212_boundToRelatedClass5)
  - indirect baseclass circularity (test212_boundToRelatedClass6)
  - simulate original inf.recursion with direct outer-call instead of callout
    (test214_boundToRelatedTeam2)
  - challenge configuring "baseclasscycle" (ERROR, suppress - several tests)
Comment 3 Stephan Herrmann CLA 2010-07-09 12:07:04 EDT
Patch has been committed as r570, r571.

Since callout in affected roles is now an error anyway, the dependency
to bug 318084 no longer exists.
Comment 4 Stephan Herrmann CLA 2010-07-09 15:18:52 EDT
Created attachment 173901 [details]
additional patch

This patch fixes an NPE in the initial implementation.
Comment 5 Stephan Herrmann CLA 2010-07-09 16:46:31 EDT
Created attachment 173918 [details]
ui-part

Implementation of UI-configurability for new warning token "baseclasscycle".
Comment 6 Stephan Herrmann CLA 2010-09-23 11:22:15 EDT
Verified using I201009211735