Bug 440965 - Move namespaces from IType to IPackageDeclaration
Summary: Move namespaces from IType to IPackageDeclaration
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: PHP Core CLA
QA Contact:
URL:
Whiteboard:
Keywords: investigate, performance
Depends on: 438087 462138
Blocks:
  Show dependency tree
 
Reported: 2014-08-01 06:46 EDT by Dawid Pakula CLA
Modified: 2020-05-14 10:16 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dawid Pakula CLA 2014-08-01 06:46:35 EDT
Namespaces were implemented as ITypes 5 years ago by 
Michael Spector. None remember why. Maybe problem with old DLTK api? 

In theory this should be implemented by IElementRequestor.acceptPackage instead 
of IElementRequestor.acceptType.

Advantages:
1. Performance: we don’t have to filter namespaces while search (for ex. group 
by namespaces in PHPExplorer or any findType call)
2. Performance: less IType in H2 database, so faster SQL search.
3. No more ugly green icon :P
4. Cleaner PHP outliner, more JDT like

Disadvantages:
1. Migration ;)
2. Problem with sorting if file have more than one namespace, probably easy to fix.
Comment 1 Michal Niewrzal CLA 2015-03-30 17:27:03 EDT
I started to look at this problem and I think I know why it was implemented with IType and not with IPackageDeclaration. IPackageDeclaration api doesn't have any type of "getChildren" method, so there is not place for fields, methods, types. Probably we can implement custom member type to fill this gap, but I just started to review it.

In general I agree that we need separate types from namespaces in DB. It should give big performance improvement for some queries e.g. where element name is not specified. With some projects I noticed that overall number of types can be even around 30K+ and almost half of it were namespaces.
Comment 2 Dawid Pakula CLA 2015-03-30 17:31:39 EDT
I think we can start on index level, without changing models: 
Index everything as packages, but while search resolve as types (PhpElementResolver).
PHPModelAccess will need additional method : findNamespaces or findPackages.
Comment 3 Michal Niewrzal CLA 2015-03-30 17:48:17 EDT
Sounds good from performance perspective:)
Comment 4 Eclipse Genie CLA 2015-03-31 18:12:40 EDT
New Gerrit change created: https://git.eclipse.org/r/44958
Comment 5 Michal Niewrzal CLA 2015-04-01 05:04:40 EDT
Gerrit patch is in general ready to review, but I think this change should be accepted only when bug #462138 will be fixed.
Comment 7 Michal Niewrzal CLA 2015-04-10 09:36:45 EDT
Conversation from Gerrit:
@Dawid
I also thought to split this bug into 3 smaller pieces: Index (this patch), INamespace usage (IType.getNamespace), PackageDeclaration.
@Michal
I agree that implementing working IType.getNamespace can be useful, but what is your plan for IPackageDeclaration?
@Dawid
IType.getChildren() isn't important, because namespace and type declarations should be reported on same level (IType.getNamespace() and you can forget about namespace declaration, also see what happens in IType.getParent()). Like in JDT for one type per file pattern. Import declarations use only package names (bug 455754).
In general, IPackageDeclaration is lighter than IType. Problems with two namespaces in file may be easy resolved by outliner / explorer contentproviders or sorters.
Besides I personally hate current icon, it's too similar to class icon.

First part of changes was merged (Namespaces are indexed as IPackageDeclaration now).
Comment 8 Eclipse Genie CLA 2017-08-09 06:47:33 EDT
New Gerrit change created: https://git.eclipse.org/r/102761