diff --git a/src/org/opensolaris/opengrok/analysis/JFlexXref.java b/src/org/opensolaris/opengrok/analysis/JFlexXref.java index ff0d20d16e9..f8076d59f27 100644 --- a/src/org/opensolaris/opengrok/analysis/JFlexXref.java +++ b/src/org/opensolaris/opengrok/analysis/JFlexXref.java @@ -236,7 +236,7 @@ protected String getProjectPostfix(boolean encoded) { } protected void startScope() { - if (scopesEnabled && scope == null) { + if (scopesEnabled && scope == null && defs != null) { int line = getLineNumber(); List tags = defs.getTags(line); if (tags != null) { diff --git a/src/org/opensolaris/opengrok/analysis/plain/AbstractSourceCodeAnalyzer.java b/src/org/opensolaris/opengrok/analysis/plain/AbstractSourceCodeAnalyzer.java index 8f1344d6a0b..41e2bb63208 100644 --- a/src/org/opensolaris/opengrok/analysis/plain/AbstractSourceCodeAnalyzer.java +++ b/src/org/opensolaris/opengrok/analysis/plain/AbstractSourceCodeAnalyzer.java @@ -31,6 +31,7 @@ import org.opensolaris.opengrok.analysis.JFlexXref; import org.opensolaris.opengrok.analysis.StreamSource; import org.opensolaris.opengrok.configuration.Project; +import org.opensolaris.opengrok.configuration.RuntimeEnvironment; import org.opensolaris.opengrok.history.Annotation; /** @@ -76,6 +77,8 @@ static protected void writeXref(JFlexXref lxref, Reader in, Writer out, Definiti lxref.reInit(in); lxref.annotation = annotation; lxref.project = project; + lxref.setScopesEnabled(RuntimeEnvironment.getInstance().isScopesEnabled()); + lxref.setFoldingEnabled(RuntimeEnvironment.getInstance().isFoldingEnabled()); lxref.setDefs(defs); lxref.write(out); } diff --git a/test/org/opensolaris/opengrok/analysis/haskell/HaskellXrefTest.java b/test/org/opensolaris/opengrok/analysis/haskell/HaskellXrefTest.java index e73ac7de3e4..2dd9de55996 100644 --- a/test/org/opensolaris/opengrok/analysis/haskell/HaskellXrefTest.java +++ b/test/org/opensolaris/opengrok/analysis/haskell/HaskellXrefTest.java @@ -18,7 +18,7 @@ */ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. */ package org.opensolaris.opengrok.analysis.haskell; @@ -30,8 +30,10 @@ import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; +import org.junit.Before; import org.junit.Test; import org.opensolaris.opengrok.analysis.Definitions; +import org.opensolaris.opengrok.configuration.RuntimeEnvironment; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -43,6 +45,11 @@ */ public class HaskellXrefTest { + @Before + public void setUp() { + RuntimeEnvironment.getInstance().setScopesEnabled(false); + } + @Test public void basicTest() throws IOException { String s = "putStrLn \"Hello, world!\""; @@ -104,4 +111,45 @@ public void sampleTest() throws IOException { String expected[] = new String(expectedOutputSteam.toByteArray(), "UTF-8").split("\n"); assertArrayEquals(expected, actual); } + + @Test + public void sampleTestWithScopes() throws IOException { + // enable scopes + RuntimeEnvironment.getInstance().setScopesEnabled(true); + // load sample source + InputStream sampleInputStream = getClass().getClassLoader().getResourceAsStream( + "org/opensolaris/opengrok/analysis/haskell/sample.hs"); + ByteArrayOutputStream sampleOutputStream = new ByteArrayOutputStream(); + + Definitions defs = new Definitions(); + defs.addTag(6, "x'y'", "functions", "x'y' = let f' = 1; g'h = 2 in f' + g'h"); + try { + writeHaskellXref(sampleInputStream, new PrintStream(sampleOutputStream), defs); + } finally { + sampleInputStream.close(); + sampleOutputStream.close(); + } + + // load expected xref + InputStream expectedInputStream = getClass().getClassLoader().getResourceAsStream( + "org/opensolaris/opengrok/analysis/haskell/sampleXrefWithScopesExpected.html"); + ByteArrayOutputStream expectedOutputSteam = new ByteArrayOutputStream(); + try { + byte buffer[] = new byte[8192]; + int numBytesRead; + do { + numBytesRead = expectedInputStream.read(buffer, 0, buffer.length); + if (numBytesRead > 0) { + expectedOutputSteam.write(buffer, 0, numBytesRead); + } + } while (numBytesRead >= 0); + } finally { + expectedInputStream.close(); + expectedOutputSteam.close(); + } + + String actual[] = new String(sampleOutputStream.toByteArray(), "UTF-8").split("\n"); + String expected[] = new String(expectedOutputSteam.toByteArray(), "UTF-8").split("\n"); + assertArrayEquals(expected, actual); + } } diff --git a/test/org/opensolaris/opengrok/analysis/haskell/sampleXrefWithScopesExpected.html b/test/org/opensolaris/opengrok/analysis/haskell/sampleXrefWithScopesExpected.html new file mode 100644 index 00000000000..4f99a247ebe --- /dev/null +++ b/test/org/opensolaris/opengrok/analysis/haskell/sampleXrefWithScopesExpected.html @@ -0,0 +1,10 @@ +Haskell Xref Test +
+1 -- classic quick sort (short but not so efficient)
+2 qsort [] = []
+3 qsort (x:xs) = qsort [ x' | x' <- xs, x' < x ] ++ [x] ++ qsort [ x' | x' <- xs, x' >= x ]
+4 
+5 -- weird but legal identifiers
+x'y'null6 x'y' = let f' = 1; g'h = 2 in f' + g'h
+7 
diff --git a/test/org/opensolaris/opengrok/analysis/php/PhpXrefTest.java b/test/org/opensolaris/opengrok/analysis/php/PhpXrefTest.java index 5e518ee5284..3f3c94b7941 100644 --- a/test/org/opensolaris/opengrok/analysis/php/PhpXrefTest.java +++ b/test/org/opensolaris/opengrok/analysis/php/PhpXrefTest.java @@ -18,7 +18,7 @@ */ /* - * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. */ package org.opensolaris.opengrok.analysis.php; @@ -32,7 +32,9 @@ import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; +import org.junit.Before; import org.junit.Test; +import org.opensolaris.opengrok.configuration.RuntimeEnvironment; import static org.junit.Assert.assertEquals; @@ -43,6 +45,11 @@ */ public class PhpXrefTest { + @Before + public void setUp() { + RuntimeEnvironment.getInstance().setScopesEnabled(false); + } + @Test public void basicTest() throws IOException { String s = "