Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-dev] How to properly do AST parsing

Hi,
we have the following problem.
in our builder, we use

IBinding[] bindings = astParser.createBindings(new IJavaElement[] { jdtType }, null);
// jdtType== SourceType retrieved via name lookup
to resolve bindings.

when our code runs directly after an undo of an import organizing save action,
then the binding returned will be null

the problem is here in
CompilationUnitResolver$1Requestor.acceptAST(ICompilationUnit, CompilationUnit) line: 815
the problem is that here we DOMFInder.search is called

public ASTNode search() throws JavaModelException {
ISourceRange range = null;
if (this.element instanceof IMember && !(this.element instanceof IInitializer)
&& !(this.element instanceof LambdaMethod) && !(this.element instanceof org.eclipse.jdt.internal.core.LambdaExpression))
range = ((IMember) this.element).getNameRange();
else if (this.element instanceof ITypeParameter || this.element instanceof ILocalVariable)
range = this.element.getNameRange();
else
range = this.element.getSourceRange();
this.rangeStart = range.getOffset();
this.rangeLength = range.getLength();
this.ast.accept(this);
return this.foundNode;
}

here the .getNameRange() on member will return the old element info
and so the range guard in
org.eclipse.jdt.internal.core.util.DOMFinder.found(ASTNode, ASTNode)
will return false and no resolving will take place

if

TypeDeclaration(AbstractTypeDeclaration).setName(SimpleName) line: 154
ASTConverter.convert(TypeDeclaration) line: 3293
ASTConverter.convert(CompilationUnitDeclaration, char[]) line: 1526
AST.convertCompilationUnit(int, CompilationUnitDeclaration, Map, boolean, CompilationUnit, int, IProgressMonitor) line: 501
CompilationUnit.buildStructure(OpenableElementInfo, IProgressMonitor, Map, IResource) line: 201
CompilationUnit(Openable).generateInfos(Object, HashMap, IProgressMonitor) line: 266
CompilationUnit(JavaElement).openWhenClosed(Object, boolean, IProgressMonitor) line: 597
CompilationUnit.makeConsistent(int, boolean, int, HashMap, IProgressMonitor) line: 1142
ReconcileWorkingCopyOperation.makeConsistent(CompilationUnit) line: 173
ReconcileWorkingCopyOperation.executeOperation() line: 94
ReconcileWorkingCopyOperation(JavaModelOperation).run(IProgressMonitor) line: 740
ReconcileWorkingCopyOperation(JavaModelOperation).runOperation(IProgressMonitor) line: 806
CompilationUnit.reconcile(int, int, WorkingCopyOwner, IProgressMonitor) line: 1319
JavaReconcilingStrategy.reconcile(ICompilationUnit, boolean) line: 131
JavaReconcilingStrategy$1.run() line: 93
SafeRunner.run(ISafeRunnable) line: 45
JavaReconcilingStrategy.reconcile(boolean) line: 90
JavaReconcilingStrategy.reconcile(IRegion) line: 157
JavaCompositeReconcilingStrategy(CompositeReconcilingStrategy).reconcile(IRegion) line: 94
JavaCompositeReconcilingStrategy.reconcile(IRegion) line: 107
JavaReconciler(MonoReconciler).process(DirtyRegion) line: 76
AbstractReconciler$BackgroundThread.run() line: 210

will run first/faster than our builder,
the we will see the NEW name position after the undo as expected.

why are the element infos not updated togther with the sources returned by search?
how can i avoid this problem?

Thanks and Regards
Christian

p.s.:



Vorstand/Board: Jens Wagener (Vors./chairman), Dr. Stephan Eberle, Abdelghani El-Kacimi, Wolfgang Neuhaus, Franz-Josef Schuermann
Aufsichtsrat/Supervisory Board: Michael Neuhaus (Vors./chairman), Harald Goertz, Eric Swehla
Sitz der Gesellschaft/Registered Office: Am Brambusch 15-24, 44536 Lünen (Germany)
Registergericht/Registry Court: Amtsgericht Dortmund | HRB 20621

Back to the top