diff --git a/java.project/src/org/netbeans/spi/java/project/support/JavadocAndSourceRootDetection.java b/java.project/src/org/netbeans/spi/java/project/support/JavadocAndSourceRootDetection.java --- a/java.project/src/org/netbeans/spi/java/project/support/JavadocAndSourceRootDetection.java +++ b/java.project/src/org/netbeans/spi/java/project/support/JavadocAndSourceRootDetection.java @@ -160,9 +160,9 @@ return null; } - private static final Pattern JAVA_FILE, PACKAGE_INFO; + static final Pattern JAVA_FILE, PACKAGE_INFO; static { - String whitespace = "(?:(?://[^\n]*\n)|(?:/\\*(?:[^*]|\\*[^/])*\\*/)|\\s)"; //NOI18N + String whitespace = "(?:(?://[^\n]*\n)|(?:/\\*.*?\\*/)|\\s)"; //NOI18N String javaIdentifier = "(?:\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)"; //NOI18N String packageStatement = "package" + whitespace + "+(" + javaIdentifier + "(?:\\." + javaIdentifier + ")*)" + whitespace + "*;"; //NOI18N JAVA_FILE = Pattern.compile("(?ms)" + whitespace + "*" + packageStatement + ".*", Pattern.MULTILINE | Pattern.DOTALL); //NOI18N diff --git a/java.project/test/unit/src/org/netbeans/spi/java/project/support/JavadocAndSourceRootDetectionTest.java b/java.project/test/unit/src/org/netbeans/spi/java/project/support/JavadocAndSourceRootDetectionTest.java --- a/java.project/test/unit/src/org/netbeans/spi/java/project/support/JavadocAndSourceRootDetectionTest.java +++ b/java.project/test/unit/src/org/netbeans/spi/java/project/support/JavadocAndSourceRootDetectionTest.java @@ -40,23 +40,14 @@ package org.netbeans.spi.java.project.support; import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Writer; import java.net.URL; -import java.util.zip.CRC32; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; +import java.util.regex.Matcher; import org.netbeans.junit.NbTestCase; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; import org.openide.filesystems.test.TestFileUtils; -/** - * - */ public class JavadocAndSourceRootDetectionTest extends NbTestCase { public JavadocAndSourceRootDetectionTest(String testName) { @@ -110,4 +101,18 @@ assertEquals(lib.getFileObject("a-library-version-1.0/docs/api"), javadocRoot); } + public void testParsing() throws Exception { + assertParse("/**\n * Some license here\n */\n\npackage foo;\n\npublic class Foo {}\n", false, "foo"); + assertParse("package foo;", false, "foo"); + assertParse("package foo; ", false, "foo"); + assertParse("/**/package foo;", false, "foo"); + assertParse("/***/package foo;", false, "foo"); + assertParse("/*****/package foo;", false, "foo"); + // would like to test stack overflow from #154894, but never managed to reproduce it in a unit test (only in standalone j2seproject) + } + private void assertParse(String text, boolean packageInfo, String expectedPackage) { + Matcher m = (packageInfo ? JavadocAndSourceRootDetection.PACKAGE_INFO : JavadocAndSourceRootDetection.JAVA_FILE).matcher(text); + assertEquals("Misparse of:\n" + text, expectedPackage, m.matches() ? m.group(1) : null); + } + }