[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [pdt-dev] Provide type-hints for variables declared in different SourceModule


yes, i've tried that, but the extensions array in the PHPIndexingVisitor is private,
so i can't simply override the constructor and cast them to my own Extensions.

This is the plugin.xml of my current implementation:


I've created a patch though to pass the requestor over to the PhpIndexingVisitorExtension (attached).

Couldn't find another way to actually add elements to the Sql Index.

Am i missing something?


On 6/27/11 8:52 AM, èåä wrote:
hi Robert ,

Do you implement your own IndexingVisitor?
btw,does it make sense if we pass requestor(IIndexingRequestor) to PhpIndexingVisitorExtension ?

2011/6/25 Robert GrÃndler <r.gruendler@xxxxxxxxx>
sorry for spamming the list, but there's really not much information in the net available concerning PDT indexing.

I've followed the "contributing to index" chapter in the wiki http://wiki.eclipse.org/Extending_PDT_2.2#Contributing_to_index
but i'm not sure if this is still up-to-date, because when i contribute additional fields to a TypeDeclaration,
nothing appears in code assist for $this-> in that class.

What confuses me is that a PDT Indexing Extension needs to subclass PhpIndexingVisitorExtension
and provide declarationinfos using modifyDeclaration() calls.

However, the modifyDeclaration() method in the PhpIndexingVisitorExtension is completely empty,
as apposed to the PhpIndexingVisitor which calls requestor.addDeclaration(info) in this method.

The requestor is not available to extensions though.

My IndexingVisitor does basically the same like the one in the Wiki (inside the endVisit(TypeDeclaration) method):

ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ DeclarationInfo info = new DeclarationInfo(IModelElement.FIELD,
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ Modifiers.AccPublic, start, length, start, length, name,
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ null, null, namespace.getName(), currentClass.getName());ÂÂÂ ÂÂÂ
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ modifyDeclaration(field, info);

Do i need to specify an implementation for the modifyDeclaration() method in my indexer as well?



2011/6/24 Robert GrÃndler <r.gruendler@xxxxxxxxx>

a lot of PHP Frameworks implement the MVC pattern, and i'm wondering what's the
best way to provide codeassist for PHP variables in files that have been declared
in other SourceModules.

Let's say you have the class UserController with the method showUser() (in /UserController.php)

... class declaration

public function showUser() {

 $user = UserDAO::retrieveUserByID($id);
 return array('showUser.php', array('user' => $user'))


The framework then renders the file 'showUser.php' and passes in the $user object
as a variable named $user.

What i have done right now is the following:

1. In the SourceElementRequestor extension i visit the ReturnStatements of methods in Controller
2. I detect the variables returned by that method and store it in some custom Singleton.
3. Register a completionContext/Strategy which retrieves the correct variables for the current php file from the Singleton.

This approach works, though it doesn't feel properly integrated into the DLTK/PDT model, as

1. I'm simply storing the ViewVariable in-memory in my singleton, so after Eclipse relaunches, the whole project needs to be rebuilt for completion to work.
2. I'm getting ConcurrentModificationExceptions in my Singleton class during the BuildPhase as apparently the SourceParsing
takes place in multiple threads.

So my question is, is there a way to contribute those Variables which are being passed to the View-Templates properly to the DLTK/PDT model ?



pdt-dev mailing list



Best Regards!

_______________________________________________ pdt-dev mailing list pdt-dev@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/pdt-dev

### Eclipse Workspace Patch 1.0
#P org.eclipse.php.core
Index: src/org/eclipse/php/core/index/PhpIndexingVisitorExtension.java
RCS file: /cvsroot/tools/org.eclipse.pdt/plugins/org.eclipse.php.core/src/org/eclipse/php/core/index/PhpIndexingVisitorExtension.java,v
retrieving revision 1.1
diff -u -r1.1 PhpIndexingVisitorExtension.java
--- src/org/eclipse/php/core/index/PhpIndexingVisitorExtension.java	30 Jul 2009 09:12:20 -0000	1.1
+++ src/org/eclipse/php/core/index/PhpIndexingVisitorExtension.java	27 Jun 2011 07:35:41 -0000
@@ -13,6 +13,7 @@
 import org.eclipse.dltk.ast.ASTNode;
 import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.core.index2.IIndexingRequestor;
 import org.eclipse.dltk.core.index2.IIndexingRequestor.DeclarationInfo;
 import org.eclipse.dltk.core.index2.IIndexingRequestor.ReferenceInfo;
@@ -24,6 +25,8 @@
 public abstract class PhpIndexingVisitorExtension extends ASTVisitor {
+	protected IIndexingRequestor requestor;
 	 * This is a last chance before modifying element declaration information
 	 * before inserting it into index.
@@ -47,4 +50,9 @@
 	public void modifyReference(ASTNode node, ReferenceInfo info) {
+	public void setRequestor(IIndexingRequestor requestor) {
+		this.requestor = requestor;
+	}
Index: src/org/eclipse/php/internal/core/index/PhpIndexingVisitor.java
RCS file: /cvsroot/tools/org.eclipse.pdt/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/index/PhpIndexingVisitor.java,v
retrieving revision 1.13
diff -u -r1.13 PhpIndexingVisitor.java
--- src/org/eclipse/php/internal/core/index/PhpIndexingVisitor.java	24 Mar 2011 01:12:02 -0000	1.13
+++ src/org/eclipse/php/internal/core/index/PhpIndexingVisitor.java	27 Jun 2011 07:35:41 -0000
@@ -99,8 +99,10 @@
 		for (IConfigurationElement element : extensionElements) {
 			try {
-				extensions.add((PhpIndexingVisitorExtension) element
-						.createExecutableExtension(CLASS_ATTR));
+				PhpIndexingVisitorExtension ext = (PhpIndexingVisitorExtension) element
+						.createExecutableExtension(CLASS_ATTR);
+				ext.setRequestor(requestor);
+				extensions.add(ext);
 			} catch (CoreException e) {