Skip to content
Permalink
Browse files
Fix reflect_type, add copy button to code on site.
Update jQuery. Exclude LLVMFunctions from trying to be site-deployed.
Add documentation on options for bind. Rename
getSuperclasses/InterfacesForType to getTypeSuperclasses/Interfaces.
  • Loading branch information
LadyCailin committed May 25, 2020
1 parent e2ab808 commit 5391659742972129fdf65e9b7ddd21e9ef335502
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 39 deletions.
11 pom.xml
@@ -573,7 +573,6 @@
add it to the dependecies list to fully integrate it. -->
<include>com.google.code.gson:gson:jar:*</include>
<include>com.google.guava:guava:jar:*</include>
<include>com.microsoft.azure:applicationinsights-core:jar:*</include>
<!-- Swagger dependencies -->
<include>com.squareup.okhttp:okhttp:jar:*</include>
<include>com.squareup.okio:okio:jar:*</include>
@@ -715,7 +714,7 @@
<pattern>io.gsonfire</pattern>
<shadedPattern>com.laytonsmith.libs.io.gsonfire</shadedPattern>
</relocation>
</relocations>
</relocations>
<filters>
<filter>
<artifact>org.xerial:sqlite-jdbc:jar:*</artifact>
@@ -884,12 +883,6 @@
<exlude>com/google/common/collect/**</exlude>
</excludes>
</filter>
<filter>
<artifact>com.microsoft.azure:applicationinsights-core:jar:*</artifact>
<excludes>
<exclude>META-INF/**</exclude>
</excludes>
</filter>
<filter>
<artifact>com.squareup.okhttp:okhttp:jar:*</artifact>
<includes>
@@ -1078,7 +1071,7 @@
</execution>
</executions>
</plugin>-->

</plugins>
</build>
<profiles>
@@ -8,6 +8,7 @@
import com.laytonsmith.core.MSVersion;
import com.laytonsmith.core.compiler.CompilerEnvironment;
import com.laytonsmith.core.environments.Environment;
import com.laytonsmith.core.exceptions.CRE.CRECastException;
import com.laytonsmith.core.exceptions.CRE.CREUnsupportedOperationException;
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
import com.laytonsmith.core.natives.interfaces.MEnumType;
@@ -432,7 +433,7 @@ public CClassType[] getInterfaces() {
* @param env
* @return
*/
public CClassType[] getSuperclassesForType(Environment env) {
public CClassType[] getTypeSuperclasses(Environment env) {
instantiateInvalidType(env);
try {
return Stream.of(invalidType).flatMap(e -> Stream.of(e.getSuperclasses()))
@@ -449,7 +450,7 @@ public CClassType[] getSuperclassesForType(Environment env) {
* @param env
* @return
*/
public CClassType[] getInterfacesForType(Environment env) {
public CClassType[] getTypeInterfaces(Environment env) {
instantiateInvalidType(env);
return Stream.of(invalidType).flatMap(e -> Stream.of(e.getInterfaces()))
.collect(Collectors.toSet()).toArray(CClassType.EMPTY_CLASS_ARRAY);
@@ -506,6 +507,29 @@ public String docs() {
return "A ClassType is a value that represents an object type. This includes primitives or other value types.";
}

/**
* Returns the type if this is not a class union, and throws a CRECastException if it's a type union.
* @return
*/
private CClassType getOnlyTypeOrFail(Target t) {
if(types.size() == 1) {
return new TreeSet<>(getTypes()).first();
}
throw new CRECastException("This operation is not supported on a type union.", t);
}

public String getTypeDocs(Target t, Environment env) {
getOnlyTypeOrFail(t);
instantiateInvalidType(env);
return invalidType[0].docs();
}

public Version getTypeSince(Target t, Environment env) {
getOnlyTypeOrFail(t);
instantiateInvalidType(env);
return invalidType[0].since();
}

@Override
public Version since() {
return MSVersion.V3_3_1;
@@ -41,10 +41,10 @@ private static Set<CClassType> getAllCastableClassesWithBlacklist(CClassType c,
}
blacklist.add(c);
try {
for(CClassType s : c.getSuperclassesForType(env)) {
for(CClassType s : c.getTypeSuperclasses(env)) {
blacklist.addAll(getAllCastableClassesWithBlacklist(s, blacklist, env));
}
for(CClassType iface : c.getInterfacesForType(env)) {
for(CClassType iface : c.getTypeInterfaces(env)) {
blacklist.addAll(getAllCastableClassesWithBlacklist(iface, blacklist, env));
}
} catch (UnsupportedOperationException ex) {
@@ -1,5 +1,6 @@
package com.laytonsmith.core.functions;

import com.laytonsmith.PureUtilities.Common.StringUtils;
import com.laytonsmith.PureUtilities.Version;
import com.laytonsmith.abstraction.StaticLayer;
import com.laytonsmith.annotations.api;
@@ -72,7 +73,9 @@ public Integer[] numArgs() {
public String docs() {
return "string {event_name, options, prefilter, event_obj, [custom_params], &lt;code&gt;} Binds some functionality to an event, so that"
+ " when said event occurs, the event handler will fire. Returns the id of this event, so it can be unregistered"
+ " later, if need be. See more on the page detailing [[Events]].";
+ " later, if need be. See more on the page detailing [[Events]]. The options array can contain"
+ " \"id\" and \"priority\", where priority is one of: "
+ StringUtils.Join(Priority.values(), ", ", ", or ") + ". The prefilters vary from event to event.";
}

@Override
@@ -54,6 +54,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
@@ -362,11 +363,20 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
CArray ret = new CArray(t);
ret.set("fqcn", type.getFQCN().getFQCN());
ret.set("name", type.getFQCN().getSimpleName());
ret.set("package", type.getPackage() == null ? CNull.NULL : type.getPackage(), t);
ret.set("docs", type.docs());
ret.set("isNative", CBoolean.get(type.getNativeType() != null), t);
ret.set("interfaces", new CArray(t, type.getInterfacesForType(environment)), t);
ret.set("superclasses", new CArray(t, type.getSuperclassesForType(environment)), t);
ret.set("interfaces", new CArray(t, type.getTypeInterfaces(environment)), t);
ret.set("superclasses", new CArray(t, type.getTypeSuperclasses(environment)), t);

CArray typeDocs = new CArray(t);
// When type unions are a thing, this will need to be implemented slightly differently.
for(CClassType m : Arrays.asList(type)) {
CArray docs = CArray.GetAssociativeArray(t);
docs.set("package", type.getPackage() == null ? CNull.NULL : type.getPackage(), t);
docs.set("isNative", CBoolean.get(type.getNativeType() != null), t);
docs.set("docs", m.getTypeDocs(t, environment));
docs.set("since", m.getTypeSince(t, environment).toString());
typeDocs.push(docs, t);
}
ret.set("typeDocs", typeDocs, t);
return ret;
}

@@ -390,6 +400,14 @@ public Version since() {
return MSVersion.V3_3_4;
}

@Override
public ExampleScript[] examples() throws ConfigCompileException {
return new ExampleScript[]{
new ExampleScript("With ClassType references", "reflect_type(string)"),
new ExampleScript("Via typeof()", "int @i = 1;\nmsg(reflect_type(typeof(@i)));")
};
}

}

@api
@@ -276,7 +276,12 @@ private String highlight() throws Exception {
+ " border-color: #" + getRGB(classes.get(ElementTypes.BORDER_COLOR))
+ "; ")
+ " border-style: solid; border-width: 1px 0px 1px 0px; margin: 1em 2em;"
+ " padding: 12px 2px 1em 1em;\" class=\"methodscript_code\">" + out.toString() + "</div>";
+ " padding: 12px 2px 1em 1em;\" class=\"methodscript_code\">"
+ "<div class=\"rawCode\" style=\"display: none;\">"
+ DocGenTemplates.escapeWiki(code)
+ "</div><div class=\"copyButton\">"
+ "<img src=\"%%cacheBuster|images/clipboard.png%%\" alt=\"\"> Copy Code</div>"
+ out.toString() + "</div>";
return totalOutput;
}

@@ -26,6 +26,7 @@
import com.laytonsmith.core.Optimizable;
import com.laytonsmith.core.Profiles;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.asm.LLVMFunction;
import com.laytonsmith.core.events.Event;
import com.laytonsmith.core.exceptions.CRE.CREThrowable;
import com.laytonsmith.core.exceptions.ConfigCompileException;
@@ -1237,6 +1238,10 @@ private void deployAPI() {
-> o1.getCanonicalName().compareTo(o2.getCanonicalName()));
List<String> hiddenFunctions = new ArrayList<>();
for(Class<? extends Function> functionClass : functionClasses) {
if(LLVMFunction.class.isAssignableFrom(functionClass)) {
// Skip these for now.
continue;
}
try {
if(!data.containsKey(functionClass.getEnclosingClass())) {
data.put(functionClass.getEnclosingClass(), new ArrayList<>());
@@ -203,13 +203,16 @@ msg(typeof(@m)); // ms.lang.string
mixed @m = 'string';
msg(reflect_type(typeof(@m)));
/*{
docs: A ClassType is a value that represents an object type. This includes primitives or other value types.,
fqcn: ms.lang.string,
interfaces: {ms.lang.Iterable},
isNative: true,
name: string,
package: ms.lang,
superclasses: {ms.lang.primitive}
superclasses: {ms.lang.primitive},
typeDocs: {{
docs: A string is a value that contains character data. The character encoding is stored with the string as well.,
since: 3.0.1
}}
}*/

// We can also get other information about it with always_trace:
@@ -3,28 +3,33 @@ array {type} Returns information about the given ClassType. ----
The following information is returned:

{|
!-
! Entry
! Description
|-
| docs
| The documentation for the type.
|-
| fqcn
| The Fully Qualified Class Name, that is, the name that unambiguously identifies this class.
|-
| interfaces
| An array of interfaces that this type implements, may be empty.
|-
| isNative
| True if this is a class defined in native code.
|-
| name
| The simple name of the class.
|-
| superclasses
| An array of classes that this type inherits from. With the exception of the root mixed type, this will never be empty.
|-
| package
| The package that the class lives in.
|-
| superclasses
| An array of classes that this type inherits from. With the exception of the root mixed type, this will never be empty.
| docs
| The documentation for the type.
|-
| since
| When the type was added.
|-
| isNative
| True if this is a class defined in native code.
|}

Note that docs, package, since, and isNative are in an object in an array. If the given type represent a type union,
there will be more than one object in this array. (Note that type unions aren't supported yet.)
@@ -49,35 +49,91 @@
<link rel="icon" href="%%cacheBuster|images/favicon.ico%%" type="image/x-icon">

<link rel="stylesheet" href="%%cacheBuster|css/highlight/default.css%%" />

<script src="%%cacheBuster|js/highlight.pack.js%%" type="text/javascript"></script>
<!-- Theme CSS must come after all other css -->
<!-- Want to help build new themes? Drop a css file in the themes folder, and add a link to it here. -->
<link data-style-name="Dark" rel="stylesheet" type="text/css" href="%%cacheBuster|css/themes/dark.css%%" disabled="true"/>
<link data-style-name="Nilleke Dark" rel="stylesheet" type="text/css" href="%%cacheBuster|css/themes/nilleke_dark.css%%" disabled="true"/>
<!-- End Theme CSS -->
<script type="text/javascript">
(function($){
$.fn.innerText = function(msg) {
if (msg) {
if (document.body.innerText) {
for (var i in this) {
this[i].innerText = msg;
}
} else {
for (var i in this) {
this[i].innerHTML.replace(/&amp;lt;br&amp;gt;/gi,"n")
.replace(/(&amp;lt;([^&amp;gt;]+)&amp;gt;)/gi, "");
}
}
return this;
} else {
if (document.body.innerText) {
return this[0].innerText;
} else {
return this[0].innerHTML.replace(/&amp;lt;br&amp;gt;/gi,"n")
.replace(/(&amp;lt;([^&amp;gt;]+)&amp;gt;)/gi, "");
}
}
};
})(jQuery);
var theme = Cookies.get("site-theme");
function setTheme(theme) {
$('[data-style-name]').each(function(index, element) {
if(theme === $(element).attr('data-style-name')) {
element.disabled = false;
element.disabled = false;
} else {
element.disabled = true;
}
});
}
function showMessage(message) {
var $toast = $('.toastMessage');
$toast.text(message);
$toast.show(function() {
setTimeout(function(){
$toast.hide(function(){});
// Make the length of time longer based on how long the message is
}, Math.min(3, message.split(" ").length + 1) * 1000);
});
}
setTheme(theme);
pageRender.then(function() {
$('pre code').each(function(i, block) {
hljs.highlightBlock(block);
});
$('#loadingSpinner').hide();

// Make the code copy buttons work
$('.copyButton').on('click', function(event) {
function copyToClipboard(element) {
var $temp = $("<textarea>");
$("body").append($temp);
$temp.val($(element).innerText()).select();
document.execCommand("copy");
$temp.remove();
}
var $target = $(event.currentTarget);
if(!$target.hasClass('copyButton')) {
$target = $target.parents('.copyButton');
}
var $code = $target.parent().children('.rawCode');
console.log($code.innerText());
copyToClipboard($code);
showMessage("Code copied!");
});
});
</script>
</head>

<body>
<div class="toastMessage" style="display:none;">
Test Message!
</div>
<!-- Header -->
<header id="header">
<img src="%%cacheBuster|images/CommandHelper_Icon.png%%" alt="" class="header-icon"/>
@@ -190,7 +246,7 @@ <h1><a id="mainBranding" href="%%siteRoot%%">%%branding%%</a></h1>
});
var currentTheme = Cookies.get("site-theme");
if(themes.indexOf(currentTheme) !== -1) {
$("#theme-select").val(currentTheme);
$("#theme-select").val(currentTheme);
}
$("#theme-select").on('change', function() {
Cookies.set("site-theme", this.value);

0 comments on commit 5391659

Please sign in to comment.