Package org.opensolaris.opengrok.analysis

Examples of org.opensolaris.opengrok.analysis.Definitions$LineTagMap


            try {
                Document doc = docs.get(ii);
                String filename = doc.get(QueryBuilder.PATH);

                Genre genre = Genre.get(doc.get(QueryBuilder.T));
                Definitions tags = null;
                IndexableField tagsField = doc.getField(QueryBuilder.TAGS);
                if (tagsField != null) {
                    tags = Definitions.deserialize(tagsField.binaryValue().bytes);
                }
                int nhits = docs.size();
View Full Code Here


            boolean uniqueDefinition = false;
            if (isSingleDefinitionSearch && hits != null && hits.length == 1) {
                Document doc = searcher.doc(hits[0].doc);
                if (doc.getField(QueryBuilder.TAGS) != null) {
                    byte[] rawTags = doc.getField(QueryBuilder.TAGS).binaryValue().bytes;
                    Definitions tags = Definitions.deserialize(rawTags);
                    String symbol = ((TermQuery) query).getTerm().text();
                    if (tags.occurrences(symbol) == 1) {
                        uniqueDefinition = true;
                    }
                }
            }
            // @TODO fix me. I should try to figure out where the exact hit is
View Full Code Here

        String actualOutput = hitList ? hits.get(0).getLine() : out.toString();

        assertEquals(expectedOutput, actualOutput);

        // Search with definitions
        Definitions defs = new Definitions();
        defs.addTag(1, "def", "type", "text");
        in = new StringReader("abc def ghi\n");
        out = hitList ? null : new StringWriter();
        hits = hitList ? new ArrayList<Hit>() : null;
        qb = new QueryBuilder().setDefs("def");
        c = new Context(qb.build(), qb.getQueries());
        assertTrue(c.getContext(in, out, "", "", "", defs, limit, qb.isDefSearch(), hits));

        if (hitList) {
            assertEquals(1, hits.size());
            assertEquals("1", hits.get(0).getLineno());
        }

        expectedOutput = hitList
                ? "abc <b>def</b> ghi"
                : "<a class=\"s\" href=\"#1\"><span class=\"l\">1</span> "
                + "abc <b>def</b> ghi</a> <i> type</i> <br/>";
        actualOutput = hitList ? hits.get(0).getLine() : out.toString();
        assertEquals(expectedOutput, actualOutput);
       
        in = new StringReader("abc def ghi\nbah def foobar");
        out = hitList ? null : new StringWriter();
        hits = hitList ? new ArrayList<Hit>() : null;
        assertTrue(c.getContext(in, out, "", "", "", defs, limit, qb.isDefSearch(), hits));

        if (hitList) {
            assertEquals(1, hits.size());
            assertEquals("1", hits.get(0).getLineno());
        }
       
        //test case - if this is def search, don't show false results (defs
        // weren't defined)
        assertEquals(expectedOutput, actualOutput);       
                       
        // Search with no input (will search definitions)
        in = null;
        out = hitList ? null : new StringWriter();
        hits = hitList ? new ArrayList<Hit>() : null;
        qb = new QueryBuilder().setDefs("def");
        c = new Context(qb.build(), qb.getQueries());
        assertTrue(c.getContext(in, out, "", "", "", defs, limit, qb.isDefSearch(), hits));

        if (hitList) {
            assertEquals(1, hits.size());
            assertEquals("1", hits.get(0).getLineno());
        }

        expectedOutput = hitList
                ? "text"
                : "<a class=\"s\" href=\"#1\"><span class=\"l\">1</span> "
                + "text</a> <i>type</i><br/>";
        actualOutput = hitList ? hits.get(0).getLine() : out.toString();
        assertEquals(expectedOutput, actualOutput);
       
        defs = new Definitions();
        defs.addTag(2, "def", "type", "text");
        in = new StringReader("abc1 def ghi\nabc def ghi\nabc3 def ghi\n");
        out = hitList ? null : new StringWriter();
        hits = hitList ? new ArrayList<Hit>() : null;
        qb = new QueryBuilder().setDefs("def");
        c = new Context(qb.build(), qb.getQueries());
View Full Code Here

    private void bug17582(QueryBuilder builder, int[] lines, String[] tags)
            throws Exception {
        assertEquals(lines.length, tags.length);

        StringReader in = new StringReader("abc\nbug17582\nBug17582\n");
        Definitions defs = new Definitions();
        defs.addTag(2, "bug17582", "type1", "text1");
        defs.addTag(3, "Bug17582", "type2", "text2");

        Context context = new Context(builder.build(), builder.getQueries());
        ArrayList<Hit> hits = new ArrayList<Hit>();
        assertEquals(lines.length != 0,
                context.getContext(in, null, "", "", "", defs, false, builder.isDefSearch(), hits));
View Full Code Here

                out.write("\">");
                out.write(rpath.substring(rpath.lastIndexOf('/') + 1)); // htmlize ???
                out.write("</a></td><td><tt class=\"con\">");
                if (sh.sourceContext != null) {
                    Genre genre = Genre.get(doc.get("t"));
                    Definitions tags = null;
                    IndexableField tagsField = doc.getField("tags");
                    if (tagsField != null) {
                        tags = Definitions.deserialize(tagsField.binaryValue().bytes);
                    }
                    if (Genre.XREFABLE == genre && sh.summerizer != null) {
View Full Code Here

    @Test
    public void testGetDefinitions() throws Exception {
        // Test that we can get definitions for one of the files in the
        // repository.
        File f1 = new File(repository.getSourceRoot() + "/c/foobar.c");
        Definitions defs1 = IndexDatabase.getDefinitions(f1);
        assertNotNull(defs1);
        assertTrue(defs1.hasSymbol("foobar"));
        assertTrue(defs1.hasSymbol("a"));
        assertFalse(defs1.hasSymbol("b"));
        assertTrue(defs1.hasDefinitionAt("foobar", 1, new String[1]));
       
        //same for windows delimiters
        f1 = new File(repository.getSourceRoot() + "\\c\\foobar.c");
        defs1 = IndexDatabase.getDefinitions(f1);
        assertNotNull(defs1);
        assertTrue(defs1.hasSymbol("foobar"));
        assertTrue(defs1.hasSymbol("a"));
        assertFalse(defs1.hasSymbol("b"));
        assertTrue(defs1.hasDefinitionAt("foobar", 1, new String[1]));

        // Test that we get null back if we request definitions for a file
        // that's not in the repository.
        File f2 = new File(repository.getSourceRoot() + "/c/foobar.d");
        Definitions defs2 = IndexDatabase.getDefinitions(f2);
        assertNull(defs2);
    }
View Full Code Here

TOP

Related Classes of org.opensolaris.opengrok.analysis.Definitions$LineTagMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.