public void process()

in remoting/server/indexer/usages/src/org/netbeans/modules/jackpot30/indexer/usages/IndexerImpl.java [105:298]


    public void process(CompilationUnitTree toProcess, Indexable indexable, Lookup services) {
        if (!IndexAccessor.getCurrent().isAcceptable(indexable.getURL())) return;
        try {
            doDelete(indexable);
            
            final String file = IndexAccessor.getCurrent().getPath(indexable.getURL());
            final Trees trees = services.lookup(Trees.class);
            final Elements elements = services.lookup(Elements.class);
            final Types types = services.lookup(Types.class);
            final Document usages = new Document();

            usages.add(new Field("file", file, Store.YES, Index.NOT_ANALYZED));
            usages.add(new Field(KEY_MARKER, "true", Store.NO, Index.NOT_ANALYZED));

            final StringBuilder attributedSignatures = new StringBuilder();
            final StringBuilder attributedSubSignatures = new StringBuilder();

            new TreePathScanner<Void, Void>() {
                private final Set<String> SEEN_SIGNATURES = new HashSet<String>();
                @Override public Void visitIdentifier(IdentifierTree node, Void p) {
                    handleNode();
                    return super.visitIdentifier(node, p);
                }
                @Override public Void visitMemberSelect(MemberSelectTree node, Void p) {
                    handleNode();
                    return super.visitMemberSelect(node, p);
                }
                @Override public Void visitNewClass(NewClassTree node, Void p) {
                    handleNode();
                    return super.visitNewClass(node, p);
                }
                private void handleNode() {
                    Element el = trees.getElement(getCurrentPath());

                    if (el != null && Common.SUPPORTED_KINDS.contains(el.getKind())) {
                        String serialized = Common.serialize(ElementHandle.create(el));

                        if (SEEN_SIGNATURES.add(serialized)) {
                            usages.add(new Field(KEY_SIGNATURES, serialized, Store.YES, Index.NOT_ANALYZED));
                        }

                        long pos = treePosition(trees, getCurrentPath());

                        if (NAVIGABLE) {
                            attributedSignatures.append(Long.toString(pos));
                            attributedSignatures.append(":");
                            attributedSignatures.append(serialized);
                            attributedSignatures.append(",");
                            attributedSubSignatures.append(Long.toString(pos));
                            attributedSubSignatures.append(":");
                            attributedSubSignatures.append(serialized);
                            attributedSubSignatures.append(",");
                        }

                        if (el.getKind() == ElementKind.METHOD) {
                            for (ExecutableElement e : overrides(types, elements, (ExecutableElement) el)) {
                                serialized = Common.serialize(ElementHandle.create(e));

                                if (SEEN_SIGNATURES.add(serialized)) {
                                    usages.add(new Field(KEY_SIGNATURES, serialized, Store.YES, Index.NOT_ANALYZED));
                                }

                                if (NAVIGABLE) {
                                    attributedSubSignatures.append(Long.toString(pos));
                                    attributedSubSignatures.append(":");
                                    attributedSubSignatures.append(serialized);
                                    attributedSubSignatures.append(",");
                                }
                            }
                        }
                    }
                }

                private String currentClassFQN;
                @Override public Void visitClass(ClassTree node, Void p) {
                    String oldClassFQN = currentClassFQN;
                    boolean oldInMethod = inMethod;

                    try {
                        Element el = trees.getElement(getCurrentPath());

                        if (el != null) {
                            try {
                                TypeElement tel = (TypeElement) el;
                                currentClassFQN = elements.getBinaryName(tel).toString();
                                Document currentClassDocument = new Document();

                                currentClassDocument.add(new Field("classFQN", currentClassFQN, Store.YES, Index.NO));
                                currentClassDocument.add(new Field("classSimpleName", node.getSimpleName().toString(), Store.YES, Index.NOT_ANALYZED));
                                currentClassDocument.add(new Field("classSimpleNameLower", node.getSimpleName().toString().toLowerCase(), Store.YES, Index.NOT_ANALYZED));
                                currentClassDocument.add(new Field("classKind", el.getKind().name(), Store.YES, Index.NO));
                                for (Modifier m : el.getModifiers()) {
                                    currentClassDocument.add(new Field("classModifiers", m.name(), Store.YES, Index.NO));
                                }

                                recordSuperTypes(currentClassDocument, tel, new HashSet<String>(Arrays.asList(tel.getQualifiedName().toString())));

                                currentClassDocument.add(new Field("file", file, Store.YES, Index.NOT_ANALYZED));
                                currentClassDocument.add(new Field(KEY_MARKER, "true", Store.NO, Index.NOT_ANALYZED));

                                if (NAVIGABLE) {
                                    currentClassDocument.add(new Field("declarationSignature", Common.serialize(ElementHandle.create(el)), Store.YES, Index.NOT_ANALYZED));
                                    currentClassDocument.add(new Field("declarationPosition", Long.toString(trees.getSourcePositions().getStartPosition(getCurrentPath().getCompilationUnit(), node)), Store.YES, Index.NO));
                                }

                                IndexAccessor.getCurrent().getIndexWriter().addDocument(currentClassDocument);
                            } catch (CorruptIndexException ex) {
                                Exceptions.printStackTrace(ex);
                            } catch (IOException ex) {
                                Exceptions.printStackTrace(ex);
                            }
                        }

                        inMethod = false;

                        return super.visitClass(node, p);
                    } finally {
                        currentClassFQN = oldClassFQN;
                        inMethod = oldInMethod;
                    }
                }

                private boolean inMethod;
                @Override public Void visitMethod(MethodTree node, Void p) {
                    boolean oldInMethod = inMethod;

                    try {
                        handleFeature();
                        inMethod = true;
                        return super.visitMethod(node, p);
                    } finally {
                        inMethod = oldInMethod;
                    }
                }

                @Override public Void visitVariable(VariableTree node, Void p) {
                    if (!inMethod)
                        handleFeature();
                    return super.visitVariable(node, p);
                }

                public void handleFeature() {
                    Element el = trees.getElement(getCurrentPath());

                    if (el != null) {
                        try {
                            Document currentFeatureDocument = new Document();

                            currentFeatureDocument.add(new Field("featureClassFQN", currentClassFQN, Store.YES, Index.NO));
                            currentFeatureDocument.add(new Field("featureSimpleName", el.getSimpleName().toString(), Store.YES, Index.NOT_ANALYZED));
                            currentFeatureDocument.add(new Field("featureSimpleNameLower", el.getSimpleName().toString().toLowerCase(), Store.YES, Index.NOT_ANALYZED));
                            currentFeatureDocument.add(new Field("featureKind", el.getKind().name(), Store.YES, Index.NO));
                            for (Modifier m : el.getModifiers()) {
                                currentFeatureDocument.add(new Field("featureModifiers", m.name(), Store.YES, Index.NO));
                            }
                            currentFeatureDocument.add(new Field("file", file, Store.YES, Index.NOT_ANALYZED));
                            currentFeatureDocument.add(new Field(KEY_MARKER, "true", Store.NO, Index.NOT_ANALYZED));

                            if (el.getKind() == ElementKind.METHOD || el.getKind() == ElementKind.CONSTRUCTOR) {
                                String featureSignature = methodTypeSignature(elements, (ExecutableElement) el);

                                currentFeatureDocument.add(new Field("featureSignature", featureSignature, Store.YES, Index.NO));
                                currentFeatureDocument.add(new Field("featureVMSignature", ClassFileUtil.createExecutableDescriptor((ExecutableElement) el)[2], Store.YES, Index.NO));

                                for (ExecutableElement e : overrides(types, elements, (ExecutableElement) el)) {
                                    currentFeatureDocument.add(new Field("featureOverrides", Common.serialize(ElementHandle.create(e)), Store.YES, Index.NOT_ANALYZED));
                                }
                            }

                            if (NAVIGABLE) {
                                currentFeatureDocument.add(new Field("declarationSignature", Common.serialize(ElementHandle.create(el)), Store.YES, Index.NOT_ANALYZED));
                                currentFeatureDocument.add(new Field("declarationPosition", Long.toString(trees.getSourcePositions().getStartPosition(getCurrentPath().getCompilationUnit(), getCurrentPath().getLeaf())), Store.YES, Index.NO));
                            }

                            IndexAccessor.getCurrent().getIndexWriter().addDocument(currentFeatureDocument);
                        } catch (CorruptIndexException ex) {
                            Exceptions.printStackTrace(ex);
                        } catch (IOException ex) {
                            Exceptions.printStackTrace(ex);
                        }
                    }
                }
            }.scan(toProcess, null);

            if (NAVIGABLE) {
                usages.add(new Field("attributedSignatures", CompressionTools.compressString(attributedSignatures.toString())));
                usages.add(new Field("attributedSubSignatures", CompressionTools.compressString(attributedSubSignatures.toString())));
            }
            
            IndexAccessor.getCurrent().getIndexWriter().addDocument(usages);
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }