本文整理汇总了Java中ch.njol.skript.lang.ParseContext类的典型用法代码示例。如果您正苦于以下问题:Java ParseContext类的具体用法?Java ParseContext怎么用?Java ParseContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParseContext类属于ch.njol.skript.lang包,在下文中一共展示了ParseContext类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: parseSimple
import ch.njol.skript.lang.ParseContext; //导入依赖的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;
}
开发者ID:nfell2009,项目名称:Skript,代码行数:32,代码来源:Classes.java
示例2: getValue
import ch.njol.skript.lang.ParseContext; //导入依赖的package包/类
@Nullable
protected <T> T getValue(final SectionNode n, final String key, final Class<T> type) {
final String v = n.getValue(key);
if (v == null) {
Skript.error("The config is missing the entry for '" + key + "' in the database '" + databaseName + "'");
return null;
}
final ParseLogHandler log = SkriptLogger.startParseLogHandler();
try {
final T r = Classes.parse(v, type, ParseContext.CONFIG);
if (r == null)
log.printError("The entry for '" + key + "' in the database '" + databaseName + "' must be " + Classes.getSuperClassInfo(type).getName().withIndefiniteArticle());
else
log.printLog();
return r;
} finally {
log.stop();
}
}
开发者ID:nfell2009,项目名称:Skript,代码行数:20,代码来源:VariablesStorage.java
示例3: parse
import ch.njol.skript.lang.ParseContext; //导入依赖的package包/类
@Override
public Changer.ChangeMode parse(String s, ParseContext context) {
s = s.toUpperCase();
if (s.startsWith("TO ")) {
s = s.substring(3).trim();
try {
return Changer.ChangeMode.valueOf(s.replace(' ', '_'));
} catch (IllegalArgumentException ex) {
return null;
}
}
return null;
}
开发者ID:btk5h,项目名称:skript-mirror,代码行数:14,代码来源:Types.java
示例4: parse
import ch.njol.skript.lang.ParseContext; //导入依赖的package包/类
/**
* Parses a string to get an object of the desired type.
* <p>
* Instead of repeatedly calling this with the same class argument, you should get a parser with {@link #getParser(Class)} and use it for parsing.
* <p>
* Can log an error if it returned null.
*
* @param s The string to parse
* @param c The desired type. The returned value will be of this type or a subclass if it.
* @return The parsed object
*/
@SuppressWarnings({"rawtypes", "unchecked"})
@Nullable
public static <T> T parse(final String s, final Class<T> c, final ParseContext context) {
final ParseLogHandler log = SkriptLogger.startParseLogHandler();
try {
T t = parseSimple(s, c, context);
if (t != null) {
log.printLog();
return t;
}
for (final ConverterInfo<?, ?> conv : Converters.getConverters()) {
if (context == ParseContext.COMMAND && (conv.options & Converter.NO_COMMAND_ARGUMENTS) != 0)
continue;
if (c.isAssignableFrom(conv.to)) {
log.clear();
final Object o = parseSimple(s, conv.from, context);
if (o != null) {
t = (T) ((Converter) conv.converter).convert(o);
if (t != null) {
log.printLog();
return t;
}
}
}
}
log.printError();
} finally {
log.stop();
}
return null;
}
开发者ID:nfell2009,项目名称:Skript,代码行数:43,代码来源:Classes.java
示例5: parse
import ch.njol.skript.lang.ParseContext; //导入依赖的package包/类
@Nullable
public final static EffFunctionCall parse(final String line) {
final FunctionReference<?> function = new SkriptParser(line, SkriptParser.ALL_FLAGS, ParseContext.DEFAULT).parseFunction((Class<?>[]) null);
if (function != null)
return new EffFunctionCall(function);
return null;
}
开发者ID:nfell2009,项目名称:Skript,代码行数:8,代码来源:EffFunctionCall.java
示例6: validate
import ch.njol.skript.lang.ParseContext; //导入依赖的package包/类
@Override
public boolean validate(final Node node) {
if (!super.validate(node))
return false;
final T t = parser.parse(((EntryNode) node).getValue(), ParseContext.CONFIG);
if (t == null)
return false;
setter.set(t);
return true;
}
开发者ID:nfell2009,项目名称:Skript,代码行数:11,代码来源:ParsedEntryValidator.java
示例7: Option
import ch.njol.skript.lang.ParseContext; //导入依赖的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;
}
};
}
}
开发者ID:nfell2009,项目名称:Skript,代码行数:33,代码来源:Option.java
示例8: canParse
import ch.njol.skript.lang.ParseContext; //导入依赖的package包/类
@Override
public boolean canParse(ParseContext context) {
return false;
}
开发者ID:btk5h,项目名称:skript-mirror,代码行数:5,代码来源:Types.java
示例9: parse
import ch.njol.skript.lang.ParseContext; //导入依赖的package包/类
@Override
@Nullable
public EntityType parse(final String s, final ParseContext context) {
return EntityType.parse(s);
}
开发者ID:nfell2009,项目名称:Skript,代码行数:6,代码来源:EntityType.java
示例10: parse
import ch.njol.skript.lang.ParseContext; //导入依赖的package包/类
@Override
@Nullable
public Money parse(final String s, final ParseContext context) {
return Money.parse(s);
}
开发者ID:nfell2009,项目名称:Skript,代码行数:6,代码来源:Money.java
示例11: newInstance
import ch.njol.skript.lang.ParseContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Nullable
public static <T> Parameter<T> newInstance(final String name, final ClassInfo<T> type, final boolean single, final @Nullable String def) {
if (!Variable.isValidVariableName(name, false, false)) {
Skript.error("An argument's name must be a valid variable name, and cannot be a list variable.");
return null;
}
Expression<? extends T> d = null;
if (def != null) {
// if (def.startsWith("%") && def.endsWith("%")) {
// final RetainingLogHandler log = SkriptLogger.startRetainingLog();
// try {
// d = new SkriptParser("" + def.substring(1, def.length() - 1), SkriptParser.PARSE_EXPRESSIONS, ParseContext.FUNCTION_DEFAULT).parseExpression(type.getC());
// if (d == null) {
// log.printErrors("Can't understand this expression: " + def + "");
// return null;
// }
// log.printLog();
// } finally {
// log.stop();
// }
// } else {
final RetainingLogHandler log = SkriptLogger.startRetainingLog();
try {
if (type.getC() == String.class) {
if (def.startsWith("\"") && def.endsWith("\""))
d = (Expression<? extends T>) VariableString.newInstance("" + def.substring(1, def.length() - 1));
else
d = (Expression<? extends T>) new SimpleLiteral<String>(def, false);
} else {
d = new SkriptParser(def, SkriptParser.PARSE_LITERALS, ParseContext.DEFAULT).parseExpression(type.getC());
}
if (d == null) {
log.printErrors("'" + def + "' is not " + type.getName().withIndefiniteArticle());
return null;
}
log.printLog();
} finally {
log.stop();
}
// }
}
return new Parameter<T>(name, type, single, d);
}
开发者ID:nfell2009,项目名称:Skript,代码行数:45,代码来源:Parameter.java
示例12: canParse
import ch.njol.skript.lang.ParseContext; //导入依赖的package包/类
/**
* @return Whether {@link #parse(String, ParseContext)} can actually return something other that null for the given context
*/
public boolean canParse(final ParseContext context) {
return true;
}
开发者ID:nfell2009,项目名称:Skript,代码行数:7,代码来源:Parser.java
示例13: parse
import ch.njol.skript.lang.ParseContext; //导入依赖的package包/类
public T parse(String s, ParseContext parseContext){
return null;
}
开发者ID:TheLimeGlass,项目名称:Skellett,代码行数:4,代码来源:TypeClassInfo.java
示例14: parse
import ch.njol.skript.lang.ParseContext; //导入依赖的package包/类
/**
* Parses the input. This method may print an error prior to returning null if the input couldn't be parsed.
* <p>
* Remember to override {@link #canParse(ParseContext)} if this parser doesn't parse at all (i.e. you only use it's toString methods) or only parses for certain contexts.
*
* @param s The String to parse. This string is already trim()med.
* @param context Context of parsing, may not be null
* @return The parsed input or null if the input is invalid for this parser.
*/
@Nullable
public abstract T parse(String s, ParseContext context);
开发者ID:nfell2009,项目名称:Skript,代码行数:12,代码来源:Parser.java
注:本文中的ch.njol.skript.lang.ParseContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论