Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbeaa6b8

Browse files
committed
Added src and pom.xml.
1 parent8cb8d2c commitbeaa6b8

File tree

3 files changed

+325
-0
lines changed

3 files changed

+325
-0
lines changed

‎pom.xml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>generatejavadoc</groupId>
4+
<artifactId>generatejavadoc</artifactId>
5+
<version>1.0</version>
6+
<packaging>jar</packaging>
7+
<name>generatejavadoc</name>
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
</properties>
11+
<build>
12+
<plugins>
13+
<plugin>
14+
<artifactId>maven-compiler-plugin</artifactId>
15+
<version>3.8.1</version>
16+
<configuration>
17+
<source>1.8</source>
18+
<target>1.8</target>
19+
</configuration>
20+
</plugin>
21+
<plugin>
22+
<groupId>org.apache.maven.plugins</groupId>
23+
<artifactId>maven-jar-plugin</artifactId>
24+
<version>3.2.0</version>
25+
<configuration>
26+
<archive>
27+
<manifestEntries>
28+
<Main-Class>generatejavadoc.Main</Main-Class>
29+
<Built-By></Built-By>
30+
<Created-By></Created-By>
31+
<Build-Jdk></Build-Jdk>
32+
</manifestEntries>
33+
</archive>
34+
</configuration>
35+
</plugin>
36+
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
38+
<artifactId>maven-shade-plugin</artifactId>
39+
<version>2.4.3</version>
40+
<executions>
41+
<execution>
42+
<phase>package</phase>
43+
<goals>
44+
<goal>shade</goal>
45+
</goals>
46+
<configuration>
47+
<filters>
48+
<filter>
49+
<artifact>*:*</artifact>
50+
<excludes>
51+
<exclude>META-INF/maven/**</exclude>
52+
<exclude>META-INF/services/**</exclude>
53+
<exclude>META-INF/LICENSE*</exclude>
54+
<exclude>META-INF/NOTICE*</exclude>
55+
<exclude>META-INF/CHANGES*</exclude>
56+
<exclude>META-INF/README.md*</exclude>
57+
</excludes>
58+
</filter>
59+
</filters>
60+
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
61+
</configuration>
62+
</execution>
63+
</executions>
64+
</plugin>
65+
</plugins>
66+
</build>
67+
</project>
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
packagegeneratejavadoc;
2+
3+
importstaticjava.nio.charset.StandardCharsets.UTF_8;
4+
5+
importjava.io.File;
6+
importjava.io.IOException;
7+
importjava.nio.file.DirectoryStream;
8+
importjava.nio.file.Files;
9+
importjava.nio.file.Path;
10+
importjava.nio.file.Paths;
11+
importjava.util.ArrayList;
12+
importjava.util.List;
13+
importjava.util.regex.Pattern;
14+
importjava.util.stream.Collectors;
15+
16+
publicclassMain {
17+
privatestaticfinalPatternPATTERN =Pattern.compile("\\r?\\n");
18+
19+
privatestaticvoidfillFilesRecursively(
20+
Pathdirectory,finalList<File>resultFiles)
21+
throwsIOException {
22+
Files.walkFileTree(
23+
directory,
24+
newjava.nio.file.SimpleFileVisitor<Path>() {
25+
@Override
26+
publicjava.nio.file.FileVisitResultvisitFile(
27+
Pathfile,java.nio.file.attribute.BasicFileAttributesattrs) {
28+
finalStringfilePath =file.toString().toLowerCase();
29+
if (filePath.endsWith("readme.md")) {
30+
resultFiles.add(file.toFile());
31+
}
32+
returnjava.nio.file.FileVisitResult.CONTINUE;
33+
}
34+
});
35+
}
36+
37+
publicstaticvoidmain(String[]args)throwsIOException {
38+
List<File>resultFiles =newArrayList<>();
39+
fillFilesRecursively(Paths.get("."),resultFiles);
40+
intind =0;
41+
for (Filefile :resultFiles) {
42+
if (ind %20 ==0) {
43+
System.out.println(file.getAbsolutePath());
44+
}
45+
ind++;
46+
finalbyte[]readmeMd =Files.readAllBytes(Paths.get(file.getAbsolutePath()));
47+
StringreadmeMdText =newString(readmeMd,UTF_8);
48+
try (DirectoryStream<Path>dirStream =
49+
Files.newDirectoryStream(
50+
Paths.get(file.getAbsolutePath().replace("readme.md","")),"*.java")) {
51+
for (Pathentry :dirStream) {
52+
FilejavaFile =entry.toFile();
53+
Pathpath =Paths.get(javaFile.getAbsolutePath());
54+
finalbyte[]solutionJava =Files.readAllBytes(path);
55+
StringsolutionJavaText =newString(solutionJava,UTF_8);
56+
int[]index = {0};
57+
String[]fromStr = {
58+
"(\"{{",
59+
"=\"{{",
60+
"\n- [",
61+
" board = [[",
62+
" grid = [[",
63+
" = [[",
64+
",**",
65+
"**,",
66+
"**]",
67+
"(**",
68+
"**)"
69+
};
70+
String[]toStr = {
71+
"(\"{ {",
72+
"=\"{ {",
73+
"\n-\\[",
74+
" board = [ [",
75+
" grid = [ [",
76+
" =\\[\\[",
77+
", **",
78+
"** ,",
79+
"** ]",
80+
"( **",
81+
"** )"
82+
};
83+
StringreadmeMdJavadoc =
84+
"/**\n"
85+
+StringUtils.replaceEach(
86+
PATTERN.splitAsStream(readmeMdText)
87+
.map(
88+
line -> {
89+
StringfirstLine =
90+
line.replace(
91+
"\\.",
92+
" -")
93+
+"\\.";
94+
Stringstr =
95+
index[0]++ ==0
96+
?firstLine
97+
:line;
98+
returnline.isEmpty()
99+
?" *"
100+
:" * " +str;
101+
})
102+
.collect(Collectors.joining("\n")),
103+
fromStr,
104+
toStr)
105+
.replace("`**","` **")
106+
.replace("/*","{@literal /}*")
107+
.replace("*/","*{@literal /}")
108+
+"\n**/";
109+
StringpublicClass =
110+
solutionJavaText.contains("@SuppressWarnings")
111+
?"@SuppressWarnings"
112+
:"public class ";
113+
Files.write(path,getBytes(solutionJavaText,readmeMdJavadoc,publicClass));
114+
}
115+
}
116+
}
117+
}
118+
119+
privatestaticbyte[]getBytes(
120+
StringsolutionJavaText,StringreadmeMdJavadoc,StringpublicClass) {
121+
returnsolutionJavaText
122+
.replace("\n" +publicClass,"\n" +readmeMdJavadoc +"\n" +publicClass)
123+
.getBytes(UTF_8);
124+
}
125+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
packagegeneratejavadoc;
2+
3+
importjava.lang.reflect.Array;
4+
5+
@SuppressWarnings("java:S3776")
6+
publicclassStringUtils {
7+
privateStringUtils() {}
8+
9+
publicstaticStringreplaceEach(
10+
finalStringtext,finalString[]searchList,finalString[]replacementList) {
11+
if (isEmpty(text) ||isEmpty(searchList) ||isEmpty(replacementList)) {
12+
returntext;
13+
}
14+
15+
finalintsearchLength =searchList.length;
16+
finalintreplacementLength =replacementList.length;
17+
18+
// make sure lengths are ok, these need to be equal
19+
if (searchLength !=replacementLength) {
20+
thrownewIllegalArgumentException(
21+
"Search and Replace array lengths don't match: "
22+
+searchLength
23+
+" vs "
24+
+replacementLength);
25+
}
26+
27+
// keep track of which still have matches
28+
finalboolean[]noMoreMatchesForReplIndex =newboolean[searchLength];
29+
30+
// index on index that the match was found
31+
inttextIndex = -1;
32+
intreplaceIndex = -1;
33+
inttempIndex = -1;
34+
35+
// index of replace array that will replace the search string found
36+
for (inti =0;i <searchLength;i++) {
37+
if (noMoreMatchesForReplIndex[i]
38+
||isEmpty(searchList[i])
39+
||replacementList[i] ==null) {
40+
continue;
41+
}
42+
tempIndex =text.indexOf(searchList[i]);
43+
44+
// see if we need to keep searching for this
45+
if (tempIndex == -1) {
46+
noMoreMatchesForReplIndex[i] =true;
47+
}elseif (textIndex == -1 ||tempIndex <textIndex) {
48+
textIndex =tempIndex;
49+
replaceIndex =i;
50+
}
51+
}
52+
// no search strings found, we are done
53+
if (textIndex == -1) {
54+
returntext;
55+
}
56+
57+
intstart =0;
58+
59+
// get a good guess on the size of the result buffer so it doesn't have to double if it goes
60+
// over a bit
61+
intincrease =0;
62+
63+
// count the replacement text elements that are larger than their corresponding text being
64+
// replaced
65+
for (inti =0;i <searchList.length;i++) {
66+
if (searchList[i] ==null ||replacementList[i] ==null) {
67+
continue;
68+
}
69+
finalintgreater =replacementList[i].length() -searchList[i].length();
70+
if (greater >0) {
71+
increase +=3 *greater;// assume 3 matches
72+
}
73+
}
74+
// have upper-bound at 20% increase, then let Java take over
75+
increase =Math.min(increase,text.length() /5);
76+
77+
finalStringBuilderbuf =newStringBuilder(text.length() +increase);
78+
79+
while (textIndex != -1) {
80+
81+
for (inti =start;i <textIndex;i++) {
82+
buf.append(text.charAt(i));
83+
}
84+
buf.append(replacementList[replaceIndex]);
85+
86+
start =textIndex +searchList[replaceIndex].length();
87+
88+
textIndex = -1;
89+
replaceIndex = -1;
90+
// find the next earliest match
91+
// NOTE: logic mostly duplicated above START
92+
for (inti =0;i <searchLength;i++) {
93+
if (noMoreMatchesForReplIndex[i]
94+
||searchList[i] ==null
95+
||searchList[i].isEmpty()
96+
||replacementList[i] ==null) {
97+
continue;
98+
}
99+
tempIndex =text.indexOf(searchList[i],start);
100+
101+
// see if we need to keep searching for this
102+
if (tempIndex == -1) {
103+
noMoreMatchesForReplIndex[i] =true;
104+
}elseif (textIndex == -1 ||tempIndex <textIndex) {
105+
textIndex =tempIndex;
106+
replaceIndex =i;
107+
}
108+
}
109+
// NOTE: logic duplicated above END
110+
111+
}
112+
finalinttextLength =text.length();
113+
for (inti =start;i <textLength;i++) {
114+
buf.append(text.charAt(i));
115+
}
116+
returnbuf.toString();
117+
}
118+
119+
publicstaticbooleanisEmpty(CharSequencecs) {
120+
returncs ==null ||cs.length() ==0;
121+
}
122+
123+
publicstaticbooleanisEmpty(finalObject[]array) {
124+
returngetLength(array) ==0;
125+
}
126+
127+
publicstaticintgetLength(finalObjectarray) {
128+
if (array ==null) {
129+
return0;
130+
}
131+
returnArray.getLength(array);
132+
}
133+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp