本文整理汇总了Java中org.codehaus.groovy.ast.expr.Expression.getText方法的典型用法代码示例。如果您正苦于以下问题:Java Expression.getText方法的具体用法?Java Expression.getText怎么用?Java Expression.getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.expr.Expression
的用法示例。
在下文中一共展示了Expression.getText方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateDuplicatedNamedParameter
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private void validateDuplicatedNamedParameter(List<MapEntryExpression> mapEntryExpressionList, MapEntryExpression mapEntryExpression) {
Expression keyExpression = mapEntryExpression.getKeyExpression();
if (null == keyExpression) {
return;
}
if (isInsideParentheses(keyExpression)) {
return;
}
String parameterName = keyExpression.getText();
boolean isDuplicatedNamedParameter =
mapEntryExpressionList.stream()
.anyMatch(m -> m.getKeyExpression().getText().equals(parameterName));
if (!isDuplicatedNamedParameter) {
return;
}
throw createParsingFailedException("Duplicated named parameter '" + parameterName + "' found", mapEntryExpression);
}
示例2: convertToStringArray
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private static String[] convertToStringArray(final Expression options) {
if (options==null) {
return EMPTY_STRING_ARRAY;
}
if (options instanceof ConstantExpression) {
return new String[] { options.getText() };
}
if (options instanceof ListExpression) {
List<Expression> list = ((ListExpression) options).getExpressions();
List<String> result = new ArrayList<String>(list.size());
for (Expression expression : list) {
result.add(expression.getText());
}
return result.toArray(new String[result.size()]);
}
throw new IllegalArgumentException("Unexpected options for @ClosureParams:"+options);
}
示例3: transformMethodCallOnThis
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private Expression transformMethodCallOnThis(final MethodCallExpression call) {
Expression method = call.getMethod();
Expression arguments = call.getArguments();
if (method instanceof ConstantExpression) {
String methodName = method.getText();
List<MethodNode> methods = traitClass.getMethods(methodName);
for (MethodNode methodNode : methods) {
if (methodName.equals(methodNode.getName()) && methodNode.isPrivate()) {
if (inClosure) {
return transformPrivateMethodCallOnThisInClosure(call, arguments, methodName);
}
return transformPrivateMethodCallOnThis(call, arguments, methodName);
}
}
}
if (inClosure) {
return transformMethodCallOnThisInClosure(call);
}
return transformMethodCallOnThisFallBack(call, method, arguments);
}
示例4: getMethodName
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
protected String getMethodName(Expression message) {
String methodName = null;
if (message instanceof CastExpression) {
CastExpression msg = (CastExpression) message;
if (msg.getType() == ClassHelper.STRING_TYPE) {
final Expression methodExpr = msg.getExpression();
if (methodExpr instanceof ConstantExpression)
methodName = methodExpr.getText();
}
}
if (methodName == null && message instanceof ConstantExpression) {
ConstantExpression constantExpression = (ConstantExpression) message;
methodName = constantExpression.getText();
}
return methodName;
}
示例5: makeSingleArgumentCall
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
@Override
public void makeSingleArgumentCall(final Expression receiver, final String message, final Expression arguments, boolean safe) {
TypeChooser typeChooser = controller.getTypeChooser();
ClassNode classNode = controller.getClassNode();
ClassNode rType = typeChooser.resolveType(receiver, classNode);
ClassNode aType = typeChooser.resolveType(arguments, classNode);
if (trySubscript(receiver, message, arguments, rType, aType, safe)) {
return;
}
// now try with flow type instead of declaration type
rType = receiver.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE);
if (receiver instanceof VariableExpression && rType == null) {
// TODO: can STCV be made smarter to avoid this check?
VariableExpression ve = (VariableExpression) ((VariableExpression)receiver).getAccessedVariable();
rType = ve.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE);
}
if (rType!=null && trySubscript(receiver, message, arguments, rType, aType, safe)) {
return;
}
// todo: more cases
throw new GroovyBugError(
"At line " + receiver.getLineNumber() + " column " + receiver.getColumnNumber() + "\n" +
"On receiver: " + receiver.getText() + " with message: " + message + " and arguments: " + arguments.getText() + "\n" +
"This method should not have been called. Please try to create a simple example reproducing\n" +
"this error and file a bug report at https://issues.apache.org/jira/browse/GROOVY");
}
示例6: checkGroovyConstructorMap
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
protected void checkGroovyConstructorMap(final Expression receiver, final ClassNode receiverType, final MapExpression mapExpression) {
// workaround for map-style checks putting setter info on wrong AST nodes
typeCheckingContext.pushEnclosingBinaryExpression(null);
for (MapEntryExpression entryExpression : mapExpression.getMapEntryExpressions()) {
Expression keyExpr = entryExpression.getKeyExpression();
if (!(keyExpr instanceof ConstantExpression)) {
addStaticTypeError("Dynamic keys in map-style constructors are unsupported in static type checking", keyExpr);
} else {
AtomicReference<ClassNode> lookup = new AtomicReference<ClassNode>();
PropertyExpression pexp = new PropertyExpression(varX("_", receiverType), keyExpr.getText());
boolean hasProperty = existsProperty(pexp, false, new PropertyLookupVisitor(lookup));
if (!hasProperty) {
addStaticTypeError("No such property: " + keyExpr.getText() +
" for class: " + receiverType.getName(), receiver);
} else {
ClassNode valueType = getType(entryExpression.getValueExpression());
MethodNode setter = receiverType.getSetterMethod("set" + MetaClassHelper.capitalize(pexp.getPropertyAsString()), false);
ClassNode toBeAssignedTo = setter == null ? lookup.get() : setter.getParameters()[0].getType();
if (!isAssignableTo(valueType, toBeAssignedTo)
&& !extension.handleIncompatibleAssignment(toBeAssignedTo, valueType, entryExpression)) {
addAssignmentError(toBeAssignedTo, valueType, entryExpression);
}
}
}
}
typeCheckingContext.popEnclosingBinaryExpression();
}
示例7: lookupLogFieldName
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private static String lookupLogFieldName(AnnotationNode logAnnotation) {
Expression member = logAnnotation.getMember("value");
if (member != null && member.getText() != null) {
return member.getText();
} else {
return "log";
}
}
示例8: lookupCategoryName
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private static String lookupCategoryName(AnnotationNode logAnnotation) {
Expression member = logAnnotation.getMember("category");
if (member != null && member.getText() != null) {
return member.getText();
}
return DEFAULT_CATEGORY_NAME;
}
示例9: getConstantExpression
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private ConstantExpression getConstantExpression(Expression exp, ClassNode attrType) {
if (exp instanceof ConstantExpression) {
return (ConstantExpression) exp;
}
String base = "Expected '" + exp.getText() + "' to be an inline constant of type " + attrType.getName();
if (exp instanceof PropertyExpression) {
addError(base + " not a property expression", exp);
} else if (exp instanceof VariableExpression && ((VariableExpression)exp).getAccessedVariable() instanceof FieldNode) {
addError(base + " not a field expression", exp);
} else {
addError(base, exp);
}
return ConstantExpression.EMPTY_EXPRESSION;
}
示例10: printValue
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private static void printValue(PrintWriter out, Expression re, boolean assumeClass) {
if (assumeClass) {
if (re.getType().getName().equals("groovy.lang.Closure")) {
out.print("groovy.lang.Closure.class");
return;
}
String className = re.getText();
out.print(className);
if (!className.endsWith(".class")) {
out.print(".class");
}
} else {
if (re instanceof ConstantExpression) {
ConstantExpression ce = (ConstantExpression) re;
Object value = ce.getValue();
if (ClassHelper.STRING_TYPE.equals(ce.getType())) {
out.print(formatString((String)value));
} else if (ClassHelper.char_TYPE.equals(ce.getType()) || ClassHelper.Character_TYPE.equals(ce.getType())) {
out.print(formatChar(value.toString()));
} else if (ClassHelper.long_TYPE.equals(ce.getType())) {
out.print("" + value + "L");
} else if (ClassHelper.float_TYPE.equals(ce.getType())) {
out.print("" + value + "f");
} else if (ClassHelper.double_TYPE.equals(ce.getType())) {
out.print("" + value + "d");
} else {
out.print(re.getText());
}
} else {
out.print(re.getText());
}
}
}
示例11: getStringValue
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
/**
* Returns the {@link String} representation of the member "value" of the annotation
* passed as parameter
*
* @param annotationNode The node we want the value from
* @return the value of the member "value" as a {@link String}
* @since 0.1.4
*/
public String getStringValue(final AnnotationNode annotationNode) {
final Expression expr = annotationNode.getMember(ANNOTATION_VALUE);
if (expr != null) {
return expr.getText();
}
return null;
}
示例12: extractTemporaryTypeInfoKey
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
/**
* When instanceof checks are found in the code, we store temporary type information data in the {@link
* TypeCheckingContext#temporaryIfBranchTypeInformation} table. This method computes the key which must be used to store this type
* info.
*
* @param expression the expression for which to compute the key
* @return a key to be used for {@link TypeCheckingContext#temporaryIfBranchTypeInformation}
*/
protected Object extractTemporaryTypeInfoKey(final Expression expression) {
return expression instanceof VariableExpression ? findTargetVariable((VariableExpression) expression) : expression.getText();
}