Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element definition #519

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void checkForTypeInTypeofClasses() throws Exception {
}
} catch (ReflectionUtils.ReflectionException ex) {
errors.add(clazz.getClassName() + " needs to add the following:\n\t@SuppressWarnings(\"FieldNameHidesFieldInSuperclass\")\n"
+ "\tpublic static final CClassType TYPE = CClassType.get(\"" + clazz.getAnnotation(typeof.class).getValue("value") + "\");");
+ "\tpublic static final CClassType TYPE = CClassType.get(" + clazz.getSimpleName() + ".class);");
}
}
if(!errors.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
}
if(c != null) {
if(!c.isInterface()) {
StreamUtils.GetSystemErr().println("Only interfaces may be annotated with "
+ MustUseOverride.class.getName());
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR,
"Only interfaces may be annotated with " + MustUseOverride.class.getName());
}
Expand Down Expand Up @@ -240,6 +242,7 @@ public String toString(Class<?> item) {
.append(" with @Override to continue the build process.")
.append(StringUtils.NL)
.append(StringUtils.Join(stringMethodsInError, StringUtils.NL));
StreamUtils.GetSystemErr().println(b.toString());
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, b.toString());
} else {
StreamUtils.GetSystemOut().println("No @Override annotations were found to be missing.");
Expand Down
86 changes: 0 additions & 86 deletions src/main/java/com/laytonsmith/core/Method.java

This file was deleted.

44 changes: 44 additions & 0 deletions src/main/java/com/laytonsmith/core/constructs/CFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.laytonsmith.PureUtilities.Common.ReflectionUtils;
import com.laytonsmith.PureUtilities.Version;
import com.laytonsmith.core.ParseTree;
import com.laytonsmith.core.environments.Environment;
import com.laytonsmith.core.exceptions.ConfigCompileException;
import com.laytonsmith.core.functions.DryFunction;
import com.laytonsmith.core.functions.Function;
import com.laytonsmith.core.functions.FunctionBase;
import com.laytonsmith.core.functions.FunctionList;
Expand Down Expand Up @@ -82,6 +84,48 @@ public static boolean IsFunction(ParseTree tree, Class<? extends Function> ofTyp
return IsFunction(tree.getData(), ofType);
}

/**
* Checks to see if a ParseTree represents a DryFunction or not.
* @param data
* @return
*/
public static boolean CanDryEval(ParseTree data) {
if(!(data.getData() instanceof CFunction)) {
return false;
}
try {
FunctionBase fb = FunctionList.getFunction((CFunction) data.getData());
if(fb instanceof DryFunction) {
return true;
} else {
return false;
}
} catch (ConfigCompileException ex) {
return false;
}
}

/**
* Evaluates a DryFunction, or if this is a primitive Construct, simply returns that.
*
* @param env The environment
* @param data The ParseTree to evaluate.
* @return The Mixed that this function evaluates to
* @throws ConfigCompileException If the function execution throws a CCE
* @throws IllegalArgumentException If the underlying function doesn't represent a DryFunction
*/
public static Mixed evaluateDryFunction(Environment env, ParseTree data) throws ConfigCompileException {
if(!(data.getData() instanceof CFunction) && data.getData() instanceof Construct
&& data.getChildren().isEmpty()) {
return data.getData();
}
if(!CanDryEval(data)) {
throw new IllegalArgumentException("Data (" + data.getData() + ") does not contain a DryFunction");
}
DryFunction f = (DryFunction) FunctionList.getFunction((CFunction) data.getData());
return f.dryExec(data.getTarget(), env, data.getChildren().toArray(new ParseTree[data.getChildren().size()]));
}

@Override
public Version since() {
return super.since();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public enum ConstructType {
TOKEN, COMMAND, FUNCTION, VARIABLE, LITERAL, ARRAY, MAP, ENTRY, INT,
DOUBLE, BOOLEAN, NULL, STRING, VOID, IVARIABLE, CLOSURE, LABEL, SLICE,
SYMBOL, IDENTIFIER, BRACE, BRACKET, BYTE_ARRAY, RESOURCE, LOCK, MUTABLE_PRIMITIVE,
CLASS_TYPE, FULLY_QUALIFIED_CLASS_NAME;
CLASS_TYPE, FULLY_QUALIFIED_CLASS_NAME, METHOD, FIELD;
}

private final ConstructType ctype;
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/DryFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.laytonsmith.core.functions;

import com.laytonsmith.core.ParseTree;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.natives.interfaces.Mixed;

/**
* A DryFunction is a function that can be invoked at all times, even during compilation, and cannot rely on any other
* devices other than other DryFunctions and primitives. These functions are typically compiled out, but create a more
* complex data type at compile time. Essentially, it provides a method that looks nearly identical to execs, but does
* not accept a Script parameter.
*
* Generally speaking, this is not strictly necessary to implement, because functions that useSpecialExec and then
* don't use the Script parameter are functionally equivalent. However, implementing this interface, then simply
* having execs call dryExec is a good indication that this function should not be used in such a way to violate the
* contract.
*/
public interface DryFunction {
Mixed dryExec(Target t, com.laytonsmith.core.environments.Environment env, ParseTree... nodes);
}
Loading