本文整理汇总了Java中ch.njol.skript.classes.Parser类的典型用法代码示例。如果您正苦于以下问题:Java Parser类的具体用法?Java Parser怎么用?Java Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Parser类属于ch.njol.skript.classes包,在下文中一共展示了Parser类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseSimple
import ch.njol.skript.classes.Parser; //导入依赖的package包/类
/**
* Parses without trying to convert anything.
* <p>
* Can log an error xor other log messages.
*
* @param s
* @param c
* @return The parsed object
*/
@Nullable
public static <T> T parseSimple(final String s, final Class<T> c, final ParseContext context) {
final ParseLogHandler log = SkriptLogger.startParseLogHandler();
try {
for (final ClassInfo<?> info : getClassInfos()) {
final Parser<?> parser = info.getParser();
if (parser == null || !parser.canParse(context) || !c.isAssignableFrom(info.getC()))
continue;
log.clear();
@SuppressWarnings("unchecked")
final T t = (T) parser.parse(s, context);
if (t != null) {
log.printLog();
return t;
}
}
log.printError();
} finally {
log.stop();
}
return null;
}
示例2: checkVariableConflicts
import ch.njol.skript.classes.Parser; //导入依赖的package包/类
private static void checkVariableConflicts(final String name, final StringMode mode, final @Nullable Iterable<Object> string) {
if (mode != StringMode.VARIABLE_NAME || variableNames.containsKey(name))
return;
if (name.startsWith("%")) {// inside the if to only print this message once per variable
final Config script = ScriptLoader.currentScript;
if (script != null)
Skript.warning("Starting a variable's name with an expression is discouraged ({" + name + "}). You could prefix it with the script's name: {" + StringUtils.substring(script.getFileName(), 0, -3) + "." + name + "}");
}
final Pattern pattern;
if (string != null) {
final StringBuilder p = new StringBuilder();
stringLoop: for (final Object o : string) {
if (o instanceof Expression) {
for (final ClassInfo<?> ci : Classes.getClassInfos()) {
final Parser<?> parser = ci.getParser();
if (parser != null && ci.getC().isAssignableFrom(((Expression<?>) o).getReturnType())) {
p.append("(?!%)" + parser.getVariableNamePattern() + "(?<!%)");
continue stringLoop;
}
}
p.append("[^%*](.*[^%*])?"); // [^*] to not report {var::%index%}/{var::*} as conflict
} else {
p.append(Pattern.quote(o.toString()));
}
}
pattern = Pattern.compile(p.toString());
} else {
pattern = Pattern.compile(Pattern.quote(name));
}
if (!SkriptConfig.disableVariableConflictWarnings.value()) {
for (final Entry<String, Pattern> e : variableNames.entrySet()) {
if (e.getValue().matcher(name).matches() || pattern.matcher(e.getKey()).matches()) {
Skript.warning("Possible name conflict of variables {" + name + "} and {" + e.getKey() + "} (there might be more conflicts).");
break;
}
}
}
variableNames.put(name, pattern);
}
示例3: Option
import ch.njol.skript.classes.Parser; //导入依赖的package包/类
public Option(final String key, final T defaultValue) {
this.key = "" + key.toLowerCase(Locale.ENGLISH);
this.defaultValue = defaultValue;
parsedValue = defaultValue;
@SuppressWarnings("unchecked")
final Class<T> c = (Class<T>) defaultValue.getClass();
if (c == String.class) {
parser = new Converter<String, T>() {
@SuppressWarnings("unchecked")
@Override
public T convert(final String s) {
return (T) s;
}
};
} else {
final ClassInfo<T> ci = Classes.getExactClassInfo(c);
final Parser<? extends T> p;
if (ci == null || (p = ci.getParser()) == null)
throw new IllegalArgumentException(c.getName());
this.parser = new Converter<String, T>() {
@Override
@Nullable
public T convert(final String s) {
final T t = p.parse(s, ParseContext.CONFIG);
if (t != null)
return t;
Skript.error("'" + s + "' is not " + ci.getName().withIndefiniteArticle());
return null;
}
};
}
}
示例4: addEntry
import ch.njol.skript.classes.Parser; //导入依赖的package包/类
public <T> SectionValidator addEntry(final String name, final Parser<? extends T> parser, final Setter<T> setter, final boolean optional) {
addNode(name, new ParsedEntryValidator<T>(parser, setter), optional);
return this;
}
示例5: ParsedEntryValidator
import ch.njol.skript.classes.Parser; //导入依赖的package包/类
public ParsedEntryValidator(final Parser<? extends T> parser, final Setter<T> setter) {
assert parser != null;
assert setter != null;
this.parser = parser;
this.setter = setter;
}