After some debugging i've noticed some strange behavior in the
PHPIndexingVisitorExtension:
The following code throws a ModelException when being executed on a
SourceModule containing a PHP 5 namespace,
and works as expected (no exception) without the namespace declaration:
public boolean endvisit(TypeDeclaration s) {
try {
if (s instanceof ClassDeclaration) {
IType type = sourceModule.getType(s.getName());
ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new
NullProgressMonitor());
}
} catch (Exception e) {
e.printStackTrace();
}
}
The PHP class looks like this:
<?php
namespace My\Test\Space;
class SomeClass {
public function foobar() {
}
}
Without the namespace declaration, the call to newSupertypeHierarchy() works
and returns an ITypeHierarchy, but with
the namespace i'm getting:
SomeClass [in SomeClass.php [in <default> [in src [in test]]]] does not
exist
What's the difference for the newSupertypeHierarchy() call when it's being
used inside a namespace?
The full stack trace of the exception:
org.eclipse.dltk.core.ModelException: SomeClass [in SomeClass.php [in
<default> [in src [in test]]]] does not exist
at
org.eclipse.dltk.internal.core.ModelOperation.runOperation(ModelOperation.java:760)
at
org.eclipse.dltk.internal.core.SourceType.newSupertypeHierarchy(SourceType.java:404)
at
org.eclipse.dltk.internal.core.SourceType.newSupertypeHierarchy(SourceType.java:369)
at
com.dubture.symfony.core.index.SymfonyIndexingVisitorExtension.endvisit(SymfonyIndexingVisitorExtension.java:353)
at
org.eclipse.php.internal.core.index.PhpIndexingVisitor.endvisit(PhpIndexingVisitor.java:208)
at
org.eclipse.dltk.ast.declarations.TypeDeclaration.traverse(TypeDeclaration.java:160)
at org.eclipse.dltk.ast.statements.Block.traverse(Block.java:43)
at
org.eclipse.dltk.ast.declarations.TypeDeclaration.traverse(TypeDeclaration.java:158)
at org.eclipse.dltk.ast.statements.Block.traverse(Block.java:43)
at
org.eclipse.dltk.ast.declarations.ModuleDeclaration.traverse(ModuleDeclaration.java:71)
at
org.eclipse.php.internal.core.index.PhpIndexingParser.parseSourceModule(PhpIndexingParser.java:30)
at
com.dubture.symfony.core.index.SymfonyIndexingParser.parseSourceModule(SymfonyIndexingParser.java:29)
at
org.eclipse.dltk.core.index2.AbstractIndexer.indexDocument(AbstractIndexer.java:45)
at
org.eclipse.dltk.internal.core.index.sql.SqlIndexer.indexDocument(SqlIndexer.java:143)
at
org.eclipse.dltk.internal.core.index2.AddSourceModuleRequest.run(AddSourceModuleRequest.java:47)
at
org.eclipse.dltk.core.search.indexing.AbstractJob.execute(AbstractJob.java:76)
at
org.eclipse.dltk.internal.core.search.processing.JobManager.run(JobManager.java:467)
at java.lang.Thread.run(Thread.java:680)
regards
-robert
On Thu, Oct 27, 2011 at 5:21 PM, Robert Gruendler <[email protected]>wrote:
> Here's what i've come up with so far:
>
> BindingResolver resolver = new DefaultBindingResolver(sourceModule,
> sourceModule.getOwner());
> IType type = sourceModule.getType(currentClass.getName());
> PHPClassType evaluatedType = PHPClassType.fromIType(type);
>
> TypeBinding binding = new TypeBinding(resolver, evaluatedType,
> type);
> ITypeBinding typeBinding = Bindings.findTypeInHierarchy(binding,
> "Symfony\\Component\\DependencyInjection\\ContainerAwareInterface");
>
>
> However, in the call to findTypeInHierarchy(), i'm getting a
> ModelException:
>
> org.eclipse.dltk.core.ModelException: UserController [in UserController.php
> [in Acme/DemoBundle/Controller [in src [in Test]]]] does not exist
>
>
> UserController is the class being indexed and the above 5 lines of code are
> being called inside the endvisit(ModuleDeclaration) of my IndexingVisitor.
>
>
> The Type definitely exists. Any ideas why i'm getting this Exception?
>
>
> thanks again,
>
>
> -robert
>
>
>
>
>
>
> On 10/27/11 4:01 PM, Robert Gruendler wrote:
>
> Hi,
>
> findTypeInHierarchy() expectes an ITypeBinding as the first parameter. In
> the IndexingVisitorExtension
> i only have AstNodes from the package *
> org.eclipse.php.internal.core.compiler.ast.nodes.** available.
>
> It looks like the TypeDeclarations from the *
> org.eclipse.php.internal.core.ast.nodes.** package
> have a method resolveTypeBinding() which returns an ITypeBinding.
>
> This raises a more general question: What's the difference between the
> AstNode classes in the 2 packages:
>
> org.eclipse.php.internal.core.compiler.ast.nodes.*
> org.eclipse.php.internal.core.ast.nodes.*
>
> And if i'm inside a PHPASTVisitor, can i convert the classes from the
> org.eclipse.php.internal.core.compiler.ast.nodes somehow
> to the corresponding org.eclipse.php.internal.core.ast.nodes.* class?
>
>
> regards
>
> -robert
>
>
> ps: i've tried to search the pdt source for any examples of
> findTypeInHierarchy(), but it looks like it's not
> being used anywhere.
>
>
>
> On 10/27/11 2:33 PM, Roy Ganor wrote:
>
> Hi,
>
> Try using
> org.eclipse.php.internal.core.ast.nodes.Bindings.findTypeInHierarchy(ITypeBinding,
> String)
>
> Roy
> -----Original Message-----
> From: [email protected] [mailto:[email protected]
> <[email protected]>] On Behalf Of Robert Gruendler
> Sent: Thursday, October 27, 2011 12:36 PM
> To: [email protected]
> Subject: [pdt-dev] Check if any class in the superclasshierarchy implements
> an interface
>
> Hi,
>
> i'm trying to check in my IndexingVisitorExtension if a visited class
> implements a certain interface.
>
> The ClassDeclaration's "getSuperclasses()" method seemed to be a way to
> do this,
> but as it turns out it only evaluates the direct superclass and the
> direct implemented
> interfaces.
>
> So i'm wondering if i somehow can walk through the complete superclass
> hierarchy during
> indexing of a php class?
>
> regards
>
> -robert
>
>
> _______________________________________________
> pdt-dev mailing
> [email protected]https://dev.eclipse.org/mailman/listinfo/pdt-dev
> _______________________________________________
> pdt-dev mailing
> [email protected]https://dev.eclipse.org/mailman/listinfo/pdt-dev
>
>
>
>
_______________________________________________
pdt-dev mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/pdt-dev