@@ -93,9 +93,14 @@ public SourceIndexer(SearchDocument document) {
9393 super (document );
9494 this .requestor = new SourceIndexerRequestor (this );
9595 }
96+
97+ private boolean usedDomBasedIndexing () {
98+ return Boolean .getBoolean (getClass ().getSimpleName () + ".DOM_BASED_INDEXER" ); //$NON-NLS-1$
99+ }
100+
96101 @ Override
97102 public void indexDocument () {
98- if (Boolean . getBoolean ( getClass (). getSimpleName () + ".DOM_BASED_INDEXER" )) { //$NON-NLS-1$
103+ if (usedDomBasedIndexing ()) {
99104 indexDocumentFromDOM ();
100105 return ;
101106 }
@@ -156,18 +161,8 @@ public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, Acc
156161 }
157162
158163 public void resolveDocument () {
159- if (this .dom != null && getUnit () instanceof org .eclipse .jdt .internal .core .CompilationUnit unit ) {
160- String reducedDOM = reduceDOM (dom );
161- try {
162- ASTParser astParser = ASTParser .newParser (AST .getJLSLatest ()); // we don't seek exact compilation the more tolerant the better here
163- astParser .setSource (unit ); // configure projects and so on
164- astParser .setSource (reducedDOM .toCharArray ()); // trimmed contents
165- astParser .setStatementsRecovery (true );
166- astParser .setResolveBindings (true );
167- this .dom = astParser .createAST (null );
168- } catch (Exception e ) {
169- ILog .get ().error (e .getMessage (), e );
170- }
164+ if (usedDomBasedIndexing () && this .dom != null && getUnit () instanceof org .eclipse .jdt .internal .core .CompilationUnit unit ) {
165+ resolveDocumentDomImpl (unit );
171166 } else {
172167 try {
173168 IPath path = new Path (this .document .getPath ());
@@ -203,6 +198,20 @@ public void resolveDocument() {
203198 }
204199 }
205200
201+ private void resolveDocumentDomImpl (org .eclipse .jdt .internal .core .CompilationUnit unit ) {
202+ String reducedDOM = reduceDOM (this .dom );
203+ try {
204+ ASTParser astParser = ASTParser .newParser (AST .getJLSLatest ()); // we don't seek exact compilation the more tolerant the better here
205+ astParser .setSource (unit ); // configure projects and so on
206+ astParser .setSource (reducedDOM .toCharArray ()); // trimmed contents
207+ astParser .setStatementsRecovery (true );
208+ astParser .setResolveBindings (true );
209+ this .dom = astParser .createAST (null );
210+ } catch (Exception e ) {
211+ ILog .get ().error (e .getMessage (), e );
212+ }
213+ }
214+
206215 private String reduceDOM (org .eclipse .jdt .core .dom .ASTNode dom ) {
207216 dom .accept (new ASTVisitor (false ) {
208217 private boolean requiresBinding = false ;
@@ -308,7 +317,7 @@ private void purgeMethodStatements(TypeDeclaration type) {
308317
309318 @ Override
310319 public void indexResolvedDocument () {
311- if (Boolean . getBoolean ( getClass (). getSimpleName () + ".DOM_BASED_INDEXER" ) && this .dom != null ) { //$NON-NLS-1$
320+ if (usedDomBasedIndexing () && this .dom != null ) {
312321 // just re-run indexing, but with the resolved document (and its bindings)
313322 this .dom .accept (new DOMToIndexVisitor (this ));
314323 this .dom = null ;
0 commit comments