Bug 332359 - org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding should return number of fields directly
Summary: org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding should return numbe...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7 M5   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-11 09:34 EST by Ayushman Jain CLA
Modified: 2011-01-25 03:44 EST (History)
2 users (show)

See Also:


Attachments
proposed fix (836 bytes, patch)
2010-12-13 03:39 EST, Ayushman Jain CLA
no flags Details | Diff
proposed fix extended (2.31 KB, patch)
2010-12-15 04:06 EST, Ayushman Jain CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ayushman Jain CLA 2010-12-11 09:34:31 EST
Currently , org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding has a fieldCount() API which calls the field() api, that in turns does resolution and other things that may sometimes not be needed in order to just obtain the no. of fields from the binding. 

It will be good to have a simple api in ReferenceBinding that can return the no. of fields:

public int fieldCountSimple() {
	return this.fields.length;
}

Srikanth, what do you think?
Comment 1 Stephan Herrmann CLA 2010-12-11 12:13:58 EST
This reminds me of unResolvedMethods() 
  (in ReferenceBinding, SourceTypeBinding and BinaryTypeBinding)
as well as unResolvedFields()
  (only in SourceTypeBinding)

So we could either add unResolvedFields() to the remaining two classes
or create the same structure for unResolvedFieldsCount().
Comment 2 Srikanth Sankaran CLA 2010-12-13 00:06:02 EST
(In reply to comment #0)

> Srikanth, what do you think?

What is motivating the change ?
Comment 3 Ayushman Jain CLA 2010-12-13 01:02:49 EST
(In reply to comment #2)
> (In reply to comment #0)
> 
> > Srikanth, what do you think?
> 
> What is motivating the change ?

This is required for bug 247564 where I need to calculate TypeDeclaration$maxFieldCount as a cumulative count of no. of fields from all supertypes, from the binding.
Comment 4 Ayushman Jain CLA 2010-12-13 02:09:23 EST
(In reply to comment #1)
> This reminds me of unResolvedMethods() 
>   (in ReferenceBinding, SourceTypeBinding and BinaryTypeBinding)
> as well as unResolvedFields()
>   (only in SourceTypeBinding)
> 
> So we could either add unResolvedFields() to the remaining two classes
> or create the same structure for unResolvedFieldsCount().

I just checked and I actually didnt see how unResolvedMethods actually doesnt do resolution. Its internally calling methods(), and in both SourceTypeBinding and BinaryTypeBinding, methods() does the whole resolution. So unResolvedMethods() indirectly returns methods after resolution. This looks strange!
Comment 5 Srikanth Sankaran CLA 2010-12-13 03:04:34 EST
(In reply to comment #4)
> (In reply to comment #1)
> > This reminds me of unResolvedMethods() 
> >   (in ReferenceBinding, SourceTypeBinding and BinaryTypeBinding)
> > as well as unResolvedFields()
> >   (only in SourceTypeBinding)
> > 
> > So we could either add unResolvedFields() to the remaining two classes
> > or create the same structure for unResolvedFieldsCount().
> 
> I just checked and I actually didnt see how unResolvedMethods actually doesnt
> do resolution. Its internally calling methods(), and in both SourceTypeBinding
> and BinaryTypeBinding, methods() does the whole resolution. So
> unResolvedMethods() indirectly returns methods after resolution. 

Not for BinaryTypeBinding. For SourceTypeBinding, yes, what you say is true
and seems to have been that way for ever.
Comment 6 Ayushman Jain CLA 2010-12-13 03:39:09 EST
Created attachment 185040 [details]
proposed fix

I believe this should be sufficient here.

As for the SourceTypeBinding, I guess we should raise another bug and fix that as well?
Comment 7 Srikanth Sankaran CLA 2010-12-15 03:53:33 EST
(In reply to comment #6)
> Created an attachment (id=185040) [details]
> proposed fix
> 
> I believe this should be sufficient here.

I think a suitable implementation is needed in BinaryTypeBinding and
perhaps ParameterizedTypeBinding too.

> As for the SourceTypeBinding, I guess we should raise another bug and fix that
> as well?

I would leave this alone unless it is causing some known problem as this has
been the case since day one.
Comment 8 Ayushman Jain CLA 2010-12-15 04:06:38 EST
Created attachment 185209 [details]
proposed fix extended

Extended the fix to BinaryTypeBinding and ParameterizedTypeBinding.
Comment 9 Ayushman Jain CLA 2010-12-23 09:08:51 EST
Released in HEAD for 3.7M5.
Comment 10 Srikanth Sankaran CLA 2011-01-25 03:44:18 EST
Verified for 3.7 M5 by code inspection.