mirror of https://github.com/FabricMC/yarn.git
Move the copy on click script to yarn
Signed-off-by: liach <liach@users.noreply.github.com>
This commit is contained in:
parent
0e63622a59
commit
c682bce08b
|
@ -1,129 +1,103 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020 FabricMC
|
* Copyright (c) 2020 FabricMC
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.fabricmc.mappingpoet.jd;
|
package net.fabricmc.mappingpoet.jd;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.util.EnumSet;
|
||||||
import java.io.IOException;
|
import java.util.List;
|
||||||
import java.io.InputStreamReader;
|
import java.util.Set;
|
||||||
import java.io.UncheckedIOException;
|
import java.util.stream.Collectors;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.EnumSet;
|
import javax.lang.model.element.Element;
|
||||||
import java.util.List;
|
import javax.lang.model.element.TypeElement;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
import com.sun.source.doctree.DocTree;
|
||||||
import java.util.stream.Collectors;
|
import com.sun.source.doctree.LiteralTree;
|
||||||
|
import com.sun.source.doctree.UnknownBlockTagTree;
|
||||||
import javax.lang.model.element.Element;
|
import jdk.javadoc.doclet.Taglet;
|
||||||
import javax.lang.model.element.TypeElement;
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
import com.sun.source.doctree.DocTree;
|
public final class MappingTaglet implements Taglet {
|
||||||
import com.sun.source.doctree.LiteralTree;
|
|
||||||
import com.sun.source.doctree.UnknownBlockTagTree;
|
public MappingTaglet() {
|
||||||
import jdk.javadoc.doclet.Taglet;
|
// Required by javadoc
|
||||||
|
}
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public final class MappingTaglet implements Taglet {
|
@Override
|
||||||
|
public Set<Location> getAllowedLocations() {
|
||||||
private static final String JS_CONTENT;
|
return EnumSet.of(Location.TYPE, Location.CONSTRUCTOR, Location.METHOD, Location.FIELD);
|
||||||
|
}
|
||||||
public MappingTaglet() {
|
|
||||||
// Required by javadoc
|
@Override
|
||||||
}
|
public boolean isInlineTag() {
|
||||||
|
return false;
|
||||||
@Override
|
}
|
||||||
public Set<Location> getAllowedLocations() {
|
|
||||||
return EnumSet.of(Location.TYPE, Location.CONSTRUCTOR, Location.METHOD, Location.FIELD);
|
@Override
|
||||||
}
|
public String getName() {
|
||||||
|
return "mapping";
|
||||||
@Override
|
}
|
||||||
public boolean isInlineTag() {
|
|
||||||
return false;
|
@Override
|
||||||
}
|
public String toString(List<? extends DocTree> tags, Element element) {
|
||||||
|
boolean typeDecl = element instanceof TypeElement; // means it's a class, itf, enum, etc.
|
||||||
@Override
|
StringBuilder builder = new StringBuilder();
|
||||||
public String getName() {
|
builder.append("<dt>Mappings:</dt>\n");
|
||||||
return "mapping";
|
// Java 15 required for style consistency
|
||||||
}
|
builder.append("<dd><div class=\"member-summary\"><table class=\"summary-table\" summary=\"Mapping data\">\n");
|
||||||
|
builder.append("<thead>\n");
|
||||||
@Override
|
builder.append("<th class=\"col-first\">Namespace</th>\n");
|
||||||
public String toString(List<? extends DocTree> tags, Element element) {
|
builder.append("<th class=\"").append(typeDecl ? "col-second" : "col-last").append("\">Name</th>\n");
|
||||||
boolean typeDecl = element instanceof TypeElement; // means it's a class, itf, enum, etc.
|
if (!typeDecl) {
|
||||||
StringBuilder builder = new StringBuilder();
|
builder.append("<th class=\"col-last\" scope=\"col\">Mixin selector</th>\n");
|
||||||
builder.append("<dt>Mappings:</dt>\n");
|
}
|
||||||
// Java 15 required for style consistency
|
builder.append("</thead>\n");
|
||||||
builder.append("<dd><div class=\"member-summary\"><table class=\"summary-table\" summary=\"Mapping data\">\n");
|
builder.append("<tbody>\n");
|
||||||
builder.append("<thead>\n");
|
|
||||||
builder.append("<th class=\"col-first\">Namespace</th>\n");
|
boolean altColor = true;
|
||||||
builder.append("<th class=\"").append(typeDecl ? "col-second" : "col-last").append("\">Name</th>\n");
|
for (DocTree each : tags) {
|
||||||
if (!typeDecl) {
|
String body = ((UnknownBlockTagTree) each).getContent().stream().map(t -> ((LiteralTree) t).getBody().getBody()).collect(Collectors.joining());
|
||||||
builder.append("<th class=\"col-last\" scope=\"col\">Mixin selector</th>\n");
|
String[] ans = body.split(":", 3);
|
||||||
}
|
builder.append("<tr class=\"").append(altColor ? "alt-color" : "row-color").append("\">\n");
|
||||||
builder.append("</thead>\n");
|
builder.append(String.format("<td class=\"col-first\">%s</td>\n", escaped(ans[0])));
|
||||||
builder.append("<tbody>\n");
|
builder.append(String.format("<td class=\"col-second\"><span class=\"copyable\"><code>%s</code></span></td>\n", escaped(ans[1])));
|
||||||
|
if (!typeDecl) {
|
||||||
boolean altColor = true;
|
builder.append(String.format("<td class=\"col-last\" scope=\"row\"><span class=\"copyable\"><code>%s</code></span></td>\n", escaped(ans[2])));
|
||||||
for (DocTree each : tags) {
|
}
|
||||||
String body = ((UnknownBlockTagTree) each).getContent().stream().map(t -> ((LiteralTree) t).getBody().getBody()).collect(Collectors.joining());
|
builder.append("</tr>\n");
|
||||||
String[] ans = body.split(":", 3);
|
altColor = !altColor;
|
||||||
builder.append("<tr class=\"").append(altColor ? "alt-color" : "row-color").append("\">\n");
|
}
|
||||||
builder.append(String.format("<td class=\"col-first\">%s</td>\n", escaped(ans[0])));
|
|
||||||
builder.append(String.format("<td class=\"col-second\"><span class=\"copyable\"><code>%s</code></span></td>\n", escaped(ans[1])));
|
builder.append("</tbody>\n");
|
||||||
if (!typeDecl) {
|
builder.append("</table></div></dd>\n");
|
||||||
builder.append(String.format("<td class=\"col-last\" scope=\"row\"><span class=\"copyable\"><code>%s</code></span></td>\n", escaped(ans[2])));
|
return builder.toString();
|
||||||
}
|
}
|
||||||
builder.append("</tr>\n");
|
|
||||||
altColor = !altColor;
|
// I hate <init>
|
||||||
}
|
private static String escaped(String original) {
|
||||||
|
StringBuilder builder = new StringBuilder(original.length());
|
||||||
builder.append("</tbody>\n");
|
final int len = original.length();
|
||||||
builder.append("</table></div></dd>\n");
|
for (int i = 0; i < len; i++) {
|
||||||
if (typeDecl) {
|
char c = original.charAt(i);
|
||||||
builder.append("<script>\n");
|
if (c > 127 || c == '"' || c == '\'' || c == '<' || c == '>' || c == '&') {
|
||||||
builder.append(JS_CONTENT);
|
builder.append("&#").append((int) c).append(";");
|
||||||
builder.append("</script>\n");
|
} else {
|
||||||
}
|
builder.append(c);
|
||||||
return builder.toString();
|
}
|
||||||
}
|
}
|
||||||
|
return builder.toString();
|
||||||
// I hate <init>
|
}
|
||||||
private static String escaped(String original) {
|
}
|
||||||
StringBuilder builder = new StringBuilder(original.length());
|
|
||||||
final int len = original.length();
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
char c = original.charAt(i);
|
|
||||||
if (c > 127 || c == '"' || c == '\'' || c == '<' || c == '>' || c == '&') {
|
|
||||||
builder.append("&#").append((int) c).append(";");
|
|
||||||
} else {
|
|
||||||
builder.append(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(MappingTaglet.class.getResourceAsStream("/copy_on_click.js"), "copy_on_click.js stream"), StandardCharsets.UTF_8))) {
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
sb.append(line).append("\n");
|
|
||||||
}
|
|
||||||
} catch (IOException ex) {
|
|
||||||
throw new UncheckedIOException(ex);
|
|
||||||
}
|
|
||||||
JS_CONTENT = sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue