This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 154894
Collapse All | Expand All

(-)a/java.project/src/org/netbeans/spi/java/project/support/JavadocAndSourceRootDetection.java (-2 / +2 lines)
Lines 160-168 Link Here
160
        return null;
160
        return null;
161
    }
161
    }
162
162
163
    private static final Pattern JAVA_FILE, PACKAGE_INFO;
163
    static final Pattern JAVA_FILE, PACKAGE_INFO;
164
    static {
164
    static {
165
        String whitespace = "(?:(?://[^\n]*\n)|(?:/\\*(?:[^*]|\\*[^/])*\\*/)|\\s)"; //NOI18N
165
        String whitespace = "(?:(?://[^\n]*\n)|(?:/\\*.*?\\*/)|\\s)"; //NOI18N
166
        String javaIdentifier = "(?:\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)"; //NOI18N
166
        String javaIdentifier = "(?:\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)"; //NOI18N
167
        String packageStatement = "package" + whitespace + "+(" + javaIdentifier + "(?:\\." + javaIdentifier + ")*)" + whitespace + "*;"; //NOI18N
167
        String packageStatement = "package" + whitespace + "+(" + javaIdentifier + "(?:\\." + javaIdentifier + ")*)" + whitespace + "*;"; //NOI18N
168
        JAVA_FILE = Pattern.compile("(?ms)" + whitespace + "*" + packageStatement + ".*", Pattern.MULTILINE | Pattern.DOTALL); //NOI18N
168
        JAVA_FILE = Pattern.compile("(?ms)" + whitespace + "*" + packageStatement + ".*", Pattern.MULTILINE | Pattern.DOTALL); //NOI18N
(-)a/java.project/test/unit/src/org/netbeans/spi/java/project/support/JavadocAndSourceRootDetectionTest.java (-10 / +15 lines)
Lines 40-62 Link Here
40
package org.netbeans.spi.java.project.support;
40
package org.netbeans.spi.java.project.support;
41
41
42
import java.io.File;
42
import java.io.File;
43
import java.io.FileOutputStream;
44
import java.io.FileWriter;
45
import java.io.IOException;
46
import java.io.Writer;
47
import java.net.URL;
43
import java.net.URL;
48
import java.util.zip.CRC32;
44
import java.util.regex.Matcher;
49
import java.util.zip.ZipEntry;
50
import java.util.zip.ZipOutputStream;
51
import org.netbeans.junit.NbTestCase;
45
import org.netbeans.junit.NbTestCase;
52
import org.openide.filesystems.FileObject;
46
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileUtil;
47
import org.openide.filesystems.FileUtil;
54
import org.openide.filesystems.URLMapper;
48
import org.openide.filesystems.URLMapper;
55
import org.openide.filesystems.test.TestFileUtils;
49
import org.openide.filesystems.test.TestFileUtils;
56
50
57
/**
58
 *
59
 */
60
public class JavadocAndSourceRootDetectionTest extends NbTestCase {
51
public class JavadocAndSourceRootDetectionTest extends NbTestCase {
61
52
62
    public JavadocAndSourceRootDetectionTest(String testName) {
53
    public JavadocAndSourceRootDetectionTest(String testName) {
Lines 110-113 Link Here
110
        assertEquals(lib.getFileObject("a-library-version-1.0/docs/api"), javadocRoot);
101
        assertEquals(lib.getFileObject("a-library-version-1.0/docs/api"), javadocRoot);
111
    }
102
    }
112
103
104
    public void testParsing() throws Exception {
105
        assertParse("/**\n * Some license here\n */\n\npackage foo;\n\npublic class Foo {}\n", false, "foo");
106
        assertParse("package foo;", false, "foo");
107
        assertParse("package foo; ", false, "foo");
108
        assertParse("/**/package foo;", false, "foo");
109
        assertParse("/***/package foo;", false, "foo");
110
        assertParse("/*****/package foo;", false, "foo");
111
        // would like to test stack overflow from #154894, but never managed to reproduce it in a unit test (only in standalone j2seproject)
112
    }
113
    private void assertParse(String text, boolean packageInfo, String expectedPackage) {
114
        Matcher m = (packageInfo ? JavadocAndSourceRootDetection.PACKAGE_INFO : JavadocAndSourceRootDetection.JAVA_FILE).matcher(text);
115
        assertEquals("Misparse of:\n" + text, expectedPackage, m.matches() ? m.group(1) : null);
116
    }
117
113
}
118
}

Return to bug 154894