Leveraging the JavaIndexerPlugin to speed-up the indexing.
authorJan Lahoda <jlahoda@netbeans.org>
Fri, 28 Oct 2011 17:25:39 +0200
changeset 70506d6b74d9149
parent 704 b4d868f39eae
child 706 c1f1e5a21269
Leveraging the JavaIndexerPlugin to speed-up the indexing.
remoting/server/indexer/impl/src/org/netbeans/modules/jackpot30/backend/impl/spi/IndexAccessor.java
remoting/server/indexer/usages/nbproject/genfiles.properties
remoting/server/indexer/usages/nbproject/project.xml
remoting/server/indexer/usages/src/org/netbeans/modules/jackpot30/indexer/usages/IndexerImpl.java
remoting/server/indexer/usages/test/unit/src/org/netbeans/modules/jackpot30/indexer/usages/IndexerImplTest.java
     1.1 --- a/remoting/server/indexer/impl/src/org/netbeans/modules/jackpot30/backend/impl/spi/IndexAccessor.java	Fri Oct 28 17:22:24 2011 +0200
     1.2 +++ b/remoting/server/indexer/impl/src/org/netbeans/modules/jackpot30/backend/impl/spi/IndexAccessor.java	Fri Oct 28 17:25:39 2011 +0200
     1.3 @@ -4,9 +4,13 @@
     1.4   */
     1.5  package org.netbeans.modules.jackpot30.backend.impl.spi;
     1.6  
     1.7 +import java.net.URISyntaxException;
     1.8 +import java.net.URL;
     1.9  import org.apache.lucene.index.IndexWriter;
    1.10  import org.openide.filesystems.FileObject;
    1.11 +import org.openide.filesystems.FileStateInvalidException;
    1.12  import org.openide.filesystems.FileUtil;
    1.13 +import org.openide.util.Exceptions;
    1.14  
    1.15  /**
    1.16   *
    1.17 @@ -30,6 +34,18 @@
    1.18          return FileUtil.getRelativePath(root, file);
    1.19      }
    1.20  
    1.21 +    public String getPath(URL file) {
    1.22 +        try {
    1.23 +            return root.getURL().toURI().relativize(file.toURI()).toString();
    1.24 +        } catch (FileStateInvalidException ex) {
    1.25 +            Exceptions.printStackTrace(ex);
    1.26 +        } catch (URISyntaxException ex) {
    1.27 +            Exceptions.printStackTrace(ex);
    1.28 +        }
    1.29 +
    1.30 +        return file.toExternalForm();
    1.31 +    }
    1.32 +
    1.33      public static IndexAccessor current;
    1.34      public static IndexAccessor getCurrent() {
    1.35          return current;
     2.1 --- a/remoting/server/indexer/usages/nbproject/genfiles.properties	Fri Oct 28 17:22:24 2011 +0200
     2.2 +++ b/remoting/server/indexer/usages/nbproject/genfiles.properties	Fri Oct 28 17:25:39 2011 +0200
     2.3 @@ -1,8 +1,8 @@
     2.4 -build.xml.data.CRC32=81ab83b5
     2.5 +build.xml.data.CRC32=80410336
     2.6  build.xml.script.CRC32=4ae79e41
     2.7 -build.xml.stylesheet.CRC32=a56c6a5b@2.45
     2.8 +build.xml.stylesheet.CRC32=a56c6a5b@2.47
     2.9  # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
    2.10  # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
    2.11 -nbproject/build-impl.xml.data.CRC32=81ab83b5
    2.12 +nbproject/build-impl.xml.data.CRC32=80410336
    2.13  nbproject/build-impl.xml.script.CRC32=16d3b827
    2.14 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.45
    2.15 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.47
     3.1 --- a/remoting/server/indexer/usages/nbproject/project.xml	Fri Oct 28 17:22:24 2011 +0200
     3.2 +++ b/remoting/server/indexer/usages/nbproject/project.xml	Fri Oct 28 17:25:39 2011 +0200
     3.3 @@ -50,6 +50,14 @@
     3.4                      </run-dependency>
     3.5                  </dependency>
     3.6                  <dependency>
     3.7 +                    <code-name-base>org.netbeans.modules.java.preprocessorbridge</code-name-base>
     3.8 +                    <build-prerequisite/>
     3.9 +                    <compile-dependency/>
    3.10 +                    <run-dependency>
    3.11 +                        <implementation-version/>
    3.12 +                    </run-dependency>
    3.13 +                </dependency>
    3.14 +                <dependency>
    3.15                      <code-name-base>org.netbeans.modules.java.source</code-name-base>
    3.16                      <build-prerequisite/>
    3.17                      <compile-dependency/>
     4.1 --- a/remoting/server/indexer/usages/src/org/netbeans/modules/jackpot30/indexer/usages/IndexerImpl.java	Fri Oct 28 17:22:24 2011 +0200
     4.2 +++ b/remoting/server/indexer/usages/src/org/netbeans/modules/jackpot30/indexer/usages/IndexerImpl.java	Fri Oct 28 17:25:39 2011 +0200
     4.3 @@ -42,16 +42,18 @@
     4.4  package org.netbeans.modules.jackpot30.indexer.usages;
     4.5  
     4.6  import com.sun.source.tree.ClassTree;
     4.7 +import com.sun.source.tree.CompilationUnitTree;
     4.8  import com.sun.source.tree.IdentifierTree;
     4.9  import com.sun.source.tree.MemberSelectTree;
    4.10  import com.sun.source.tree.MethodTree;
    4.11  import com.sun.source.tree.NewClassTree;
    4.12  import com.sun.source.tree.VariableTree;
    4.13  import com.sun.source.util.TreePathScanner;
    4.14 +import com.sun.source.util.Trees;
    4.15  import java.io.IOException;
    4.16 +import java.net.URL;
    4.17  import java.util.Arrays;
    4.18  import java.util.Collection;
    4.19 -import java.util.Collections;
    4.20  import java.util.HashSet;
    4.21  import java.util.LinkedList;
    4.22  import java.util.List;
    4.23 @@ -70,224 +72,192 @@
    4.24  import javax.lang.model.type.TypeMirror;
    4.25  import javax.lang.model.type.TypeVariable;
    4.26  import javax.lang.model.type.WildcardType;
    4.27 +import javax.lang.model.util.Elements;
    4.28  import org.apache.lucene.document.Document;
    4.29  import org.apache.lucene.document.Field;
    4.30  import org.apache.lucene.document.Field.Index;
    4.31  import org.apache.lucene.document.Field.Store;
    4.32  import org.apache.lucene.index.CorruptIndexException;
    4.33  import org.netbeans.api.editor.mimelookup.MimeRegistration;
    4.34 -import org.netbeans.api.java.source.ClasspathInfo;
    4.35 -import org.netbeans.api.java.source.CompilationController;
    4.36 -import org.netbeans.api.java.source.CompilationInfo;
    4.37  import org.netbeans.api.java.source.ElementHandle;
    4.38 -import org.netbeans.api.java.source.JavaSource;
    4.39 -import org.netbeans.api.java.source.JavaSource.Phase;
    4.40 -import org.netbeans.api.java.source.Task;
    4.41 +import org.netbeans.api.java.source.ElementUtilities;
    4.42  import org.netbeans.modules.jackpot30.backend.impl.spi.IndexAccessor;
    4.43 +import org.netbeans.modules.java.preprocessorbridge.spi.JavaIndexerPlugin;
    4.44  import org.netbeans.modules.java.source.usages.ClassFileUtil;
    4.45 -import org.netbeans.modules.parsing.spi.indexing.Context;
    4.46 -import org.netbeans.modules.parsing.spi.indexing.CustomIndexer;
    4.47 -import org.netbeans.modules.parsing.spi.indexing.CustomIndexerFactory;
    4.48  import org.netbeans.modules.parsing.spi.indexing.Indexable;
    4.49  import org.openide.filesystems.FileObject;
    4.50 -import org.openide.filesystems.URLMapper;
    4.51  import org.openide.util.Exceptions;
    4.52 +import org.openide.util.Lookup;
    4.53  
    4.54  /**
    4.55   *
    4.56   * @author lahvac
    4.57   */
    4.58 -public class IndexerImpl extends CustomIndexer {
    4.59 +public class IndexerImpl implements JavaIndexerPlugin {
    4.60  
    4.61      private static final String KEY_SIGNATURES = "signatures";
    4.62 -    
    4.63 -    @Override
    4.64 -    protected void index(Iterable<? extends Indexable> files, Context context) {
    4.65 -        Collection<FileObject> toIndex = new LinkedList<FileObject>(); //XXX: better would be to use File
    4.66  
    4.67 -        for (Indexable i : files) {
    4.68 -            FileObject f = URLMapper.findFileObject(i.getURL());
    4.69 +    private final URL root;
    4.70  
    4.71 -            if (f != null) {
    4.72 -                toIndex.add(f);
    4.73 -            }
    4.74 -        }
    4.75 -
    4.76 -        if (toIndex.isEmpty()) {
    4.77 -            return ;
    4.78 -        }
    4.79 -
    4.80 -        doIndex(context, toIndex, Collections.<String>emptyList());
    4.81 +    public IndexerImpl(URL root) {
    4.82 +        this.root = root;
    4.83      }
    4.84  
    4.85 -    public static void doIndex(final Context context, Collection<? extends FileObject> toIndex, Iterable<? extends String> deleted) {
    4.86 -        if (toIndex.isEmpty() && !deleted.iterator().hasNext()) {
    4.87 -            return ;
    4.88 -        }
    4.89 +    @Override
    4.90 +    public void process(CompilationUnitTree toProcess, Indexable indexable, Lookup services) {
    4.91 +        try {
    4.92 +            final String file = IndexAccessor.getCurrent().getPath(indexable.getURL());
    4.93 +            final Trees trees = services.lookup(Trees.class);
    4.94 +            final Elements elements = services.lookup(Elements.class);
    4.95 +            final ElementUtilities eu = services.lookup(ElementUtilities.class);
    4.96 +            final Document usages = new Document();
    4.97  
    4.98 -        try {
    4.99 -            ClasspathInfo cpInfo = ClasspathInfo.create(context.getRoot());
   4.100 +            usages.add(new Field("file", file, Store.YES, Index.NO));
   4.101  
   4.102 -            for (String path : deleted) {
   4.103 -                assert false;
   4.104 -            }
   4.105 +            new TreePathScanner<Void, Void>() {
   4.106 +                private final Set<String> SEEN_SIGNATURES = new HashSet<String>();
   4.107 +                @Override public Void visitIdentifier(IdentifierTree node, Void p) {
   4.108 +                    handleNode();
   4.109 +                    return super.visitIdentifier(node, p);
   4.110 +                }
   4.111 +                @Override public Void visitMemberSelect(MemberSelectTree node, Void p) {
   4.112 +                    handleNode();
   4.113 +                    return super.visitMemberSelect(node, p);
   4.114 +                }
   4.115 +                @Override public Void visitNewClass(NewClassTree node, Void p) {
   4.116 +                    handleNode();
   4.117 +                    return super.visitNewClass(node, p);
   4.118 +                }
   4.119 +                private void handleNode() {
   4.120 +                    Element el = trees.getElement(getCurrentPath());
   4.121  
   4.122 -            if (!toIndex.isEmpty()) {
   4.123 -                JavaSource.create(cpInfo, toIndex).runUserActionTask(new Task<CompilationController>() {
   4.124 -                    public void run(final CompilationController cc) throws Exception {
   4.125 -                        if (cc.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0)
   4.126 -                            return ;
   4.127 +                    if (el != null && Common.SUPPORTED_KINDS.contains(el.getKind())) {
   4.128 +                        String serialized = Common.serialize(ElementHandle.create(el));
   4.129  
   4.130 -                        final String file = IndexAccessor.getCurrent().getPath(cc.getFileObject());
   4.131 -                        final Document usages = new Document();
   4.132 +                        if (SEEN_SIGNATURES.add(serialized)) {
   4.133 +                            usages.add(new Field(KEY_SIGNATURES, serialized, Store.YES, Index.NOT_ANALYZED));
   4.134 +                        }
   4.135  
   4.136 -                        usages.add(new Field("file", file, Store.YES, Index.NO));
   4.137 -                        
   4.138 -                        new TreePathScanner<Void, Void>() {
   4.139 -                            private final Set<String> SEEN_SIGNATURES = new HashSet<String>();
   4.140 -                            @Override public Void visitIdentifier(IdentifierTree node, Void p) {
   4.141 -                                handleNode();
   4.142 -                                return super.visitIdentifier(node, p);
   4.143 +                        if (el.getKind() == ElementKind.METHOD) {
   4.144 +                            for (ExecutableElement e : overrides(eu, (ExecutableElement) el)) {
   4.145 +                                serialized = Common.serialize(ElementHandle.create(e));
   4.146 +
   4.147 +                                if (SEEN_SIGNATURES.add(serialized)) {
   4.148 +                                    usages.add(new Field(KEY_SIGNATURES, serialized, Store.YES, Index.NOT_ANALYZED));
   4.149 +                                }
   4.150                              }
   4.151 -                            @Override public Void visitMemberSelect(MemberSelectTree node, Void p) {
   4.152 -                                handleNode();
   4.153 -                                return super.visitMemberSelect(node, p);
   4.154 +                        }
   4.155 +                    }
   4.156 +                }
   4.157 +
   4.158 +                private String currentClassFQN;
   4.159 +                @Override public Void visitClass(ClassTree node, Void p) {
   4.160 +                    String oldClassFQN = currentClassFQN;
   4.161 +                    boolean oldInMethod = inMethod;
   4.162 +
   4.163 +                    try {
   4.164 +                        Element el = trees.getElement(getCurrentPath());
   4.165 +
   4.166 +                        if (el != null) {
   4.167 +                            try {
   4.168 +                                TypeElement tel = (TypeElement) el;
   4.169 +                                currentClassFQN = elements.getBinaryName(tel).toString();
   4.170 +                                Document currentClassDocument = new Document();
   4.171 +
   4.172 +                                currentClassDocument.add(new Field("classFQN", currentClassFQN, Store.YES, Index.NO));
   4.173 +                                currentClassDocument.add(new Field("classSimpleName", node.getSimpleName().toString(), Store.YES, Index.NOT_ANALYZED));
   4.174 +                                currentClassDocument.add(new Field("classSimpleNameLower", node.getSimpleName().toString().toLowerCase(), Store.YES, Index.NOT_ANALYZED));
   4.175 +
   4.176 +                                recordSuperTypes(currentClassDocument, tel, new HashSet<String>(Arrays.asList(tel.getQualifiedName().toString())));
   4.177 +
   4.178 +                                currentClassDocument.add(new Field("file", file, Store.YES, Index.NO));
   4.179 +
   4.180 +                                IndexAccessor.getCurrent().getIndexWriter().addDocument(currentClassDocument);
   4.181 +                            } catch (CorruptIndexException ex) {
   4.182 +                                Exceptions.printStackTrace(ex);
   4.183 +                            } catch (IOException ex) {
   4.184 +                                Exceptions.printStackTrace(ex);
   4.185                              }
   4.186 -                            @Override public Void visitNewClass(NewClassTree node, Void p) {
   4.187 -                                handleNode();
   4.188 -                                return super.visitNewClass(node, p);
   4.189 +                        }
   4.190 +
   4.191 +                        inMethod = false;
   4.192 +
   4.193 +                        return super.visitClass(node, p);
   4.194 +                    } finally {
   4.195 +                        currentClassFQN = oldClassFQN;
   4.196 +                        inMethod = oldInMethod;
   4.197 +                    }
   4.198 +                }
   4.199 +
   4.200 +                private boolean inMethod;
   4.201 +                @Override public Void visitMethod(MethodTree node, Void p) {
   4.202 +                    boolean oldInMethod = inMethod;
   4.203 +
   4.204 +                    try {
   4.205 +                        handleFeature();
   4.206 +                        inMethod = true;
   4.207 +                        return super.visitMethod(node, p);
   4.208 +                    } finally {
   4.209 +                        inMethod = oldInMethod;
   4.210 +                    }
   4.211 +                }
   4.212 +
   4.213 +                @Override public Void visitVariable(VariableTree node, Void p) {
   4.214 +                    if (!inMethod)
   4.215 +                        handleFeature();
   4.216 +                    return super.visitVariable(node, p);
   4.217 +                }
   4.218 +
   4.219 +                public void handleFeature() {
   4.220 +                    Element el = trees.getElement(getCurrentPath());
   4.221 +
   4.222 +                    if (el != null) {
   4.223 +                        try {
   4.224 +                            Document currentFeatureDocument = new Document();
   4.225 +
   4.226 +                            currentFeatureDocument.add(new Field("featureClassFQN", currentClassFQN, Store.YES, Index.NO));
   4.227 +                            currentFeatureDocument.add(new Field("featureSimpleName", el.getSimpleName().toString(), Store.YES, Index.NOT_ANALYZED));
   4.228 +                            currentFeatureDocument.add(new Field("featureSimpleNameLower", el.getSimpleName().toString().toLowerCase(), Store.YES, Index.NOT_ANALYZED));
   4.229 +                            currentFeatureDocument.add(new Field("featureKind", el.getKind().name(), Store.YES, Index.NO));
   4.230 +                            for (Modifier m : el.getModifiers()) {
   4.231 +                                currentFeatureDocument.add(new Field("featureModifiers", m.name(), Store.YES, Index.NO));
   4.232                              }
   4.233 -                            private void handleNode() {
   4.234 -                                Element el = cc.getTrees().getElement(getCurrentPath());
   4.235 +                            currentFeatureDocument.add(new Field("file", file, Store.YES, Index.NO));
   4.236  
   4.237 -                                if (el != null && Common.SUPPORTED_KINDS.contains(el.getKind())) {
   4.238 -                                    String serialized = Common.serialize(ElementHandle.create(el));
   4.239 +                            if (el.getKind() == ElementKind.METHOD || el.getKind() == ElementKind.CONSTRUCTOR) {
   4.240 +                                String featureSignature = methodTypeSignature(elements, (ExecutableElement) el);
   4.241  
   4.242 -                                    if (SEEN_SIGNATURES.add(serialized)) {
   4.243 -                                        usages.add(new Field(KEY_SIGNATURES, serialized, Store.YES, Index.NOT_ANALYZED));
   4.244 -                                    }
   4.245 +                                currentFeatureDocument.add(new Field("featureSignature", featureSignature, Store.YES, Index.NO));
   4.246 +                                currentFeatureDocument.add(new Field("featureVMSignature", ClassFileUtil.createExecutableDescriptor((ExecutableElement) el)[2], Store.YES, Index.NO));
   4.247  
   4.248 -                                    if (el.getKind() == ElementKind.METHOD) {
   4.249 -                                        for (ExecutableElement e : overrides(cc, (ExecutableElement) el)) {
   4.250 -                                            serialized = Common.serialize(ElementHandle.create(e));
   4.251 -
   4.252 -                                            if (SEEN_SIGNATURES.add(serialized)) {
   4.253 -                                                usages.add(new Field(KEY_SIGNATURES, serialized, Store.YES, Index.NOT_ANALYZED));
   4.254 -                                            }
   4.255 -                                        }
   4.256 -                                    }
   4.257 +                                for (ExecutableElement e : overrides(eu, (ExecutableElement) el)) {
   4.258 +                                    currentFeatureDocument.add(new Field("featureOverrides", Common.serialize(ElementHandle.create(e)), Store.YES, Index.NOT_ANALYZED));
   4.259                                  }
   4.260                              }
   4.261  
   4.262 -                            private String currentClassFQN;
   4.263 -                            @Override public Void visitClass(ClassTree node, Void p) {
   4.264 -                                String oldClassFQN = currentClassFQN;
   4.265 -                                boolean oldInMethod = inMethod;
   4.266 +                            IndexAccessor.getCurrent().getIndexWriter().addDocument(currentFeatureDocument);
   4.267 +                        } catch (CorruptIndexException ex) {
   4.268 +                            Exceptions.printStackTrace(ex);
   4.269 +                        } catch (IOException ex) {
   4.270 +                            Exceptions.printStackTrace(ex);
   4.271 +                        }
   4.272 +                    }
   4.273 +                }
   4.274 +            }.scan(toProcess, null);
   4.275  
   4.276 -                                try {
   4.277 -                                    Element el = cc.getTrees().getElement(getCurrentPath());
   4.278 -
   4.279 -                                    if (el != null) {
   4.280 -                                        try {
   4.281 -                                            TypeElement tel = (TypeElement) el;
   4.282 -                                            currentClassFQN = cc.getElements().getBinaryName(tel).toString();
   4.283 -                                            Document currentClassDocument = new Document();
   4.284 -
   4.285 -                                            currentClassDocument.add(new Field("classFQN", currentClassFQN, Store.YES, Index.NO));
   4.286 -                                            currentClassDocument.add(new Field("classSimpleName", node.getSimpleName().toString(), Store.YES, Index.NOT_ANALYZED));
   4.287 -                                            currentClassDocument.add(new Field("classSimpleNameLower", node.getSimpleName().toString().toLowerCase(), Store.YES, Index.NOT_ANALYZED));
   4.288 -
   4.289 -                                            recordSuperTypes(currentClassDocument, tel, new HashSet<String>(Arrays.asList(tel.getQualifiedName().toString())));
   4.290 -
   4.291 -                                            currentClassDocument.add(new Field("file", file, Store.YES, Index.NO));
   4.292 -
   4.293 -                                            IndexAccessor.getCurrent().getIndexWriter().addDocument(currentClassDocument);
   4.294 -                                        } catch (CorruptIndexException ex) {
   4.295 -                                            Exceptions.printStackTrace(ex);
   4.296 -                                        } catch (IOException ex) {
   4.297 -                                            Exceptions.printStackTrace(ex);
   4.298 -                                        }
   4.299 -                                    }
   4.300 -
   4.301 -                                    inMethod = false;
   4.302 -
   4.303 -                                    return super.visitClass(node, p);
   4.304 -                                } finally {
   4.305 -                                    currentClassFQN = oldClassFQN;
   4.306 -                                    inMethod = oldInMethod;
   4.307 -                                }
   4.308 -                            }
   4.309 -
   4.310 -                            private boolean inMethod;
   4.311 -                            @Override public Void visitMethod(MethodTree node, Void p) {
   4.312 -                                boolean oldInMethod = inMethod;
   4.313 -
   4.314 -                                try {
   4.315 -                                    handleFeature();
   4.316 -                                    inMethod = true;
   4.317 -                                    return super.visitMethod(node, p);
   4.318 -                                } finally {
   4.319 -                                    inMethod = oldInMethod;
   4.320 -                                }
   4.321 -                            }
   4.322 -
   4.323 -                            @Override public Void visitVariable(VariableTree node, Void p) {
   4.324 -                                if (!inMethod)
   4.325 -                                    handleFeature();
   4.326 -                                return super.visitVariable(node, p);
   4.327 -                            }
   4.328 -
   4.329 -                            public void handleFeature() {
   4.330 -                                Element el = cc.getTrees().getElement(getCurrentPath());
   4.331 -
   4.332 -                                if (el != null) {
   4.333 -                                    try {
   4.334 -                                        Document currentFeatureDocument = new Document();
   4.335 -
   4.336 -                                        currentFeatureDocument.add(new Field("featureClassFQN", currentClassFQN, Store.YES, Index.NO));
   4.337 -                                        currentFeatureDocument.add(new Field("featureSimpleName", el.getSimpleName().toString(), Store.YES, Index.NOT_ANALYZED));
   4.338 -                                        currentFeatureDocument.add(new Field("featureSimpleNameLower", el.getSimpleName().toString().toLowerCase(), Store.YES, Index.NOT_ANALYZED));
   4.339 -                                        currentFeatureDocument.add(new Field("featureKind", el.getKind().name(), Store.YES, Index.NO));
   4.340 -                                        for (Modifier m : el.getModifiers()) {
   4.341 -                                            currentFeatureDocument.add(new Field("featureModifiers", m.name(), Store.YES, Index.NO));
   4.342 -                                        }
   4.343 -                                        currentFeatureDocument.add(new Field("file", file, Store.YES, Index.NO));
   4.344 -
   4.345 -                                        if (el.getKind() == ElementKind.METHOD || el.getKind() == ElementKind.CONSTRUCTOR) {
   4.346 -                                            String featureSignature = methodTypeSignature(cc, (ExecutableElement) el);
   4.347 -                                            
   4.348 -                                            currentFeatureDocument.add(new Field("featureSignature", featureSignature, Store.YES, Index.NO));
   4.349 -                                            currentFeatureDocument.add(new Field("featureVMSignature", ClassFileUtil.createExecutableDescriptor((ExecutableElement) el)[2], Store.YES, Index.NO));
   4.350 -
   4.351 -                                            for (ExecutableElement e : overrides(cc, (ExecutableElement) el)) {
   4.352 -                                                currentFeatureDocument.add(new Field("featureOverrides", Common.serialize(ElementHandle.create(e)), Store.YES, Index.NOT_ANALYZED));
   4.353 -                                            }
   4.354 -                                        }
   4.355 -
   4.356 -                                        IndexAccessor.getCurrent().getIndexWriter().addDocument(currentFeatureDocument);
   4.357 -                                    } catch (CorruptIndexException ex) {
   4.358 -                                        Exceptions.printStackTrace(ex);
   4.359 -                                    } catch (IOException ex) {
   4.360 -                                        Exceptions.printStackTrace(ex);
   4.361 -                                    }
   4.362 -                                }
   4.363 -                            }
   4.364 -                        }.scan(cc.getCompilationUnit(), null);
   4.365 -
   4.366 -                        IndexAccessor.getCurrent().getIndexWriter().addDocument(usages);
   4.367 -                    }
   4.368 -                }, true);
   4.369 -            }
   4.370 +            IndexAccessor.getCurrent().getIndexWriter().addDocument(usages);
   4.371 +        } catch (CorruptIndexException ex) {
   4.372 +            Exceptions.printStackTrace(ex);
   4.373          } catch (IOException ex) {
   4.374              Exceptions.printStackTrace(ex);
   4.375          }
   4.376      }
   4.377  
   4.378 -    private static Iterable<? extends ExecutableElement> overrides(CompilationInfo info, ExecutableElement method) {
   4.379 +    private static Iterable<? extends ExecutableElement> overrides(ElementUtilities eu, ExecutableElement method) {
   4.380          List<ExecutableElement> result = new LinkedList<ExecutableElement>();
   4.381  
   4.382          //XXX: one method may override+implement more than one method
   4.383 -        while ((method = info.getElementUtilities().getOverriddenMethod(method)) != null) {
   4.384 +        while ((method = eu.getOverriddenMethod(method)) != null) {
   4.385              result.add(method);
   4.386          }
   4.387  
   4.388 @@ -312,7 +282,7 @@
   4.389          }
   4.390      }
   4.391  
   4.392 -    private static void encodeTypeParameters(CompilationInfo info, Collection<? extends TypeParameterElement> params, StringBuilder result) {
   4.393 +    private static void encodeTypeParameters(Elements elements, Collection<? extends TypeParameterElement> params, StringBuilder result) {
   4.394          if (params.isEmpty()) return;
   4.395          result.append("<");
   4.396          for (TypeParameterElement tpe : params) {
   4.397 @@ -328,30 +298,30 @@
   4.398                  
   4.399                  wasClass = true;
   4.400                  result.append(':');
   4.401 -                encodeType(info, tm, result);
   4.402 +                encodeType(elements, tm, result);
   4.403              }
   4.404          }
   4.405          result.append(">");
   4.406      }
   4.407      
   4.408 -    static String methodTypeSignature(CompilationInfo info, ExecutableElement ee) {
   4.409 +    static String methodTypeSignature(Elements elements, ExecutableElement ee) {
   4.410          StringBuilder sb = new StringBuilder ();
   4.411 -        encodeTypeParameters(info, ee.getTypeParameters(), sb);
   4.412 +        encodeTypeParameters(elements, ee.getTypeParameters(), sb);
   4.413          sb.append('(');             // NOI18N
   4.414          for (VariableElement pd : ee.getParameters()) {
   4.415 -            encodeType(info, pd.asType(),sb);
   4.416 +            encodeType(elements, pd.asType(),sb);
   4.417          }
   4.418          sb.append(')');             // NOI18N
   4.419 -        encodeType(info, ee.getReturnType(), sb);
   4.420 +        encodeType(elements, ee.getReturnType(), sb);
   4.421          for (TypeMirror tm : ee.getThrownTypes()) {
   4.422              sb.append('^');
   4.423 -            encodeType(info, tm, sb);
   4.424 +            encodeType(elements, tm, sb);
   4.425          }
   4.426          sb.append(';'); //TODO: unsure about this, but classfile signatures seem to have it
   4.427          return sb.toString();
   4.428      }
   4.429  
   4.430 -    private static void encodeType (CompilationInfo info, final TypeMirror type, final StringBuilder sb) {
   4.431 +    private static void encodeType(Elements elements, final TypeMirror type, final StringBuilder sb) {
   4.432  	switch (type.getKind()) {
   4.433  	    case VOID:
   4.434  		sb.append('V');	    // NOI18N
   4.435 @@ -383,18 +353,18 @@
   4.436  	    case ARRAY:
   4.437  		sb.append('[');	    // NOI18N
   4.438  		assert type instanceof ArrayType;
   4.439 -		encodeType(info, ((ArrayType)type).getComponentType(),sb);
   4.440 +		encodeType(elements, ((ArrayType)type).getComponentType(),sb);
   4.441  		break;
   4.442  	    case DECLARED:
   4.443              {
   4.444  		sb.append('L');	    // NOI18N
   4.445                  DeclaredType dt = (DeclaredType) type;
   4.446  		TypeElement te = (TypeElement) dt.asElement();
   4.447 -                sb.append(info.getElements().getBinaryName(te).toString().replace('.', '/'));
   4.448 +                sb.append(elements.getBinaryName(te).toString().replace('.', '/'));
   4.449                  if (!dt.getTypeArguments().isEmpty()) {
   4.450                      sb.append('<');
   4.451                      for (TypeMirror tm : dt.getTypeArguments()) {
   4.452 -                        encodeType(info, tm, sb);
   4.453 +                        encodeType(elements, tm, sb);
   4.454                      }
   4.455                      sb.append('>');
   4.456                  }
   4.457 @@ -415,10 +385,10 @@
   4.458  
   4.459                  if (wt.getExtendsBound() != null) {
   4.460                      sb.append('+');
   4.461 -                    encodeType(info, wt.getExtendsBound(), sb);
   4.462 +                    encodeType(elements, wt.getExtendsBound(), sb);
   4.463                  } else if (wt.getSuperBound() != null) {
   4.464                      sb.append('-');
   4.465 -                    encodeType(info, wt.getSuperBound(), sb);
   4.466 +                    encodeType(elements, wt.getSuperBound(), sb);
   4.467                  } else {
   4.468                      sb.append('*');
   4.469                  }
   4.470 @@ -429,7 +399,7 @@
   4.471                  TypeElement te = (TypeElement) ((ErrorType)type).asElement();
   4.472                  if (te != null) {
   4.473                      sb.append('L');
   4.474 -                    sb.append(info.getElements().getBinaryName(te).toString().replace('.', '/'));
   4.475 +                    sb.append(elements.getBinaryName(te).toString().replace('.', '/'));
   4.476                      sb.append(';');	    // NOI18N
   4.477                      break;
   4.478                  }
   4.479 @@ -439,44 +409,21 @@
   4.480  	}
   4.481      }
   4.482  
   4.483 -    @MimeRegistration(mimeType="text/x-java", service=CustomIndexerFactory.class)
   4.484 -    public static final class FactoryImpl extends CustomIndexerFactory {
   4.485 +
   4.486 +    @Override
   4.487 +    public void delete(Indexable indexable) {
   4.488 +//        assert false : indexable.getURL().toExternalForm() + "/" + indexable.getRelativePath();
   4.489 +    }
   4.490 +
   4.491 +    @Override
   4.492 +    public void finish() {}
   4.493 +
   4.494 +    @MimeRegistration(mimeType="text/x-java", service=Factory.class)
   4.495 +    public static final class FactoryImpl implements Factory {
   4.496  
   4.497          @Override
   4.498 -        public CustomIndexer createIndexer() {
   4.499 -            return new IndexerImpl();
   4.500 -        }
   4.501 -
   4.502 -        @Override
   4.503 -        public boolean supportsEmbeddedIndexers() {
   4.504 -            return false;
   4.505 -        }
   4.506 -
   4.507 -        @Override
   4.508 -        public void filesDeleted(Iterable<? extends Indexable> deleted, Context context) {
   4.509 -            assert false;
   4.510 -            Collection<String> deletedPaths = new LinkedList<String>();
   4.511 -
   4.512 -            for (Indexable i : deleted) {
   4.513 -                deletedPaths.add(i.getRelativePath());
   4.514 -
   4.515 -            }
   4.516 -
   4.517 -            doIndex(context, Collections.<FileObject>emptyList(), deletedPaths);
   4.518 -        }
   4.519 -
   4.520 -        @Override
   4.521 -        public void filesDirty(Iterable<? extends Indexable> dirty, Context context) {
   4.522 -        }
   4.523 -
   4.524 -        @Override
   4.525 -        public String getIndexerName() {
   4.526 -            return "javausages";
   4.527 -        }
   4.528 -
   4.529 -        @Override
   4.530 -        public int getIndexVersion() {
   4.531 -            return 1;
   4.532 +        public JavaIndexerPlugin create(URL root, FileObject cacheFolder) {
   4.533 +            return new IndexerImpl(root);
   4.534          }
   4.535  
   4.536      }
     5.1 --- a/remoting/server/indexer/usages/test/unit/src/org/netbeans/modules/jackpot30/indexer/usages/IndexerImplTest.java	Fri Oct 28 17:22:24 2011 +0200
     5.2 +++ b/remoting/server/indexer/usages/test/unit/src/org/netbeans/modules/jackpot30/indexer/usages/IndexerImplTest.java	Fri Oct 28 17:25:39 2011 +0200
     5.3 @@ -116,7 +116,7 @@
     5.4  
     5.5                  ExecutableElement method = ElementFilter.methodsIn(parameter.getTopLevelElements().get(0).getEnclosedElements()).iterator().next();
     5.6  
     5.7 -                assertEquals(signature, IndexerImpl.methodTypeSignature(parameter, method));
     5.8 +                assertEquals(signature, IndexerImpl.methodTypeSignature(parameter.getElements(), method));
     5.9                  invoked[0] = true;
    5.10              }
    5.11          }, true);