Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 362462 - [xtend] Highlight unused fields
Summary: [xtend] Highlight unused fields
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.1.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: M4   Edit
Assignee: Holger Schill CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-31 06:29 EDT by Sebastian Zarnekow CLA
Modified: 2017-09-19 17:30 EDT (History)
2 users (show)

See Also:
sven.efftinge: juno+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Zarnekow CLA 2011-10-31 06:29:02 EDT
Declared fields and extensions should be flagged as unused if they are not referenced. Unused private fields should be flagged with a warning. I think protected or public fields that are not used locally deserve an info marker.
Comment 1 Sven Efftinge CLA 2011-11-22 09:56:11 EST
No marker for protected or public fields members, please.
Unused local variables should also be marked.
Comment 2 Holger Schill CLA 2011-11-23 04:17:36 EST
pushed validation for XtendField and XVariableDeclaration and tests for that to master. As Sven mentioned only with warnings for private fields and variables.
Comment 3 Sven Efftinge CLA 2011-11-23 05:03:34 EST
Cool, thanks!
We'd need this for private methods as well.
Comment 4 Holger Schill CLA 2011-11-23 05:28:04 EST
No problem.
Comment 5 Holger Schill CLA 2011-11-23 08:30:11 EST
pushed validation and tests for unused XFunctions  with resprect to dispatch functions to master.
Comment 6 Sven Efftinge CLA 2011-11-25 07:22:16 EST
The validation marks used extension fields.
Comment 7 Holger Schill CLA 2011-11-25 08:55:07 EST
fixed in head
Comment 8 Sebastian Zarnekow CLA 2011-11-25 09:11:58 EST
I don't think that it's a good idea to search usages for all members of each declared extension.

a) it would miss the members of the super type
b) it would result in false positives

The problem is likely caused by the algorithm in the cross references which uses allContents to traverse the content of a resource / an object:


XFeatureCall feature = allContents.next()
(assuming XFeatureCall#getFeature is still a proxy)

references = feature.allReferences

XFeatureCall#implicitReceiver = references.next == null
XFeatureCall#feature = references.next -> resolve -> #implicitReceiver is set but not considered by the subsequent references.next

We may have to use a subclass of UsageCrossReferencer and override 
boolean containment(EObject eObject)
where we could check for XAbstractFeatureCall and invoke #getFeature eager before any cross ref processing happens.
Comment 9 Sebastian Zarnekow CLA 2011-11-25 09:42:15 EST
(In reply to comment #8)
> The problem is likely caused by the algorithm in the cross references which
> uses allContents to traverse the content of a resource / an object:
> 

Sven pointed out that it is rather unlikely to be caused by that. When the validation kicks in, all references are already resolved.
Comment 10 Holger Schill CLA 2011-11-25 09:43:18 EST
So what should we so?
Comment 11 Holger Schill CLA 2011-11-25 09:43:34 EST
So what should we do?
Comment 12 Holger Schill CLA 2011-11-25 09:47:53 EST
What I understood is that we should search for XFeatureCalls in the container that use a feature of the type of the extension field. There we should find out if the feature is a feature of the type itself or one of the superclasses?
Comment 13 Holger Schill CLA 2011-11-25 09:49:32 EST
Ok I'll try that.
Comment 14 Sebastian Zarnekow CLA 2011-11-25 09:51:12 EST
The problem is cause by the semantics of Eobject#eContents

Containment references that are marked as derived are not considered by eContents thus the usages will not found.

We need a custom model traversal for that, e.g. override UsageCrossReferencer#newContentsIterator and 

ContentTreeIterator.getEObjectChildren(EObject) 

and return the derived #implicitXYZ containments as children, too iff the EObject is an XAbstractFeatureCall
Comment 15 Holger Schill CLA 2011-11-25 11:10:53 EST
Introduced org.eclipse.xtext.xbase.util.XbaseUsageCrossReferencer.
Fixed in head.
Comment 16 Karsten Thoms CLA 2017-09-19 17:18:40 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 17 Karsten Thoms CLA 2017-09-19 17:30:01 EDT
Closing all bugs that were set to RESOLVED before Neon.0