Java Code Examples for org.codehaus.groovy.ast.expr.MapExpression#getMapEntryExpressions()
The following examples show how to use
org.codehaus.groovy.ast.expr.MapExpression#getMapEntryExpressions() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DependenciesVisitor.java From synopsys-detect with Apache License 2.0 | 6 votes |
private void addDependencyFromMapExpression(final MapExpression mapExpression) { final List<MapEntryExpression> mapEntryExpressions = mapExpression.getMapEntryExpressions(); String group = null; String name = null; String version = null; for (final MapEntryExpression mapEntryExpression : mapEntryExpressions) { final String key = mapEntryExpression.getKeyExpression().getText(); final String value = mapEntryExpression.getValueExpression().getText(); if ("group".equals(key)) { group = value; } else if ("name".equals(key)) { name = value; } else if ("version".equals(key)) { version = value; } } addDependency(group, name, version); }
Example 2
Source File: MarkupBuilderCodeTransformer.java From groovy with Apache License 2.0 | 5 votes |
private Expression tryTransformInclude(final MethodCallExpression exp) { Expression arguments = exp.getArguments(); if (arguments instanceof TupleExpression) { List<Expression> expressions = ((TupleExpression) arguments).getExpressions(); if (expressions.size() == 1 && expressions.get(0) instanceof MapExpression) { MapExpression map = (MapExpression) expressions.get(0); List<MapEntryExpression> entries = map.getMapEntryExpressions(); if (entries.size() == 1) { MapEntryExpression mapEntry = entries.get(0); Expression keyExpression = mapEntry.getKeyExpression(); try { IncludeType includeType = IncludeType.valueOf(keyExpression.getText().toLowerCase()); MethodCallExpression call = new MethodCallExpression( exp.getObjectExpression(), includeType.getMethodName(), new ArgumentListExpression( mapEntry.getValueExpression() ) ); call.setImplicitThis(true); call.setSafe(exp.isSafe()); call.setSpreadSafe(exp.isSpreadSafe()); call.setSourcePosition(exp); return call; } catch (IllegalArgumentException e) { // not a valid import type, do not modify the code } } } } return super.transform(exp); }
Example 3
Source File: AsmClassGenerator.java From groovy with Apache License 2.0 | 5 votes |
@Override public void visitMapExpression(final MapExpression expression) { MethodVisitor mv = controller.getMethodVisitor(); List<MapEntryExpression> entries = expression.getMapEntryExpressions(); int size = entries.size(); BytecodeHelper.pushConstant(mv, size * 2); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); int i = 0; for (Object object : entries) { MapEntryExpression entry = (MapEntryExpression) object; mv.visitInsn(DUP); BytecodeHelper.pushConstant(mv, i++); entry.getKeyExpression().visit(this); controller.getOperandStack().box(); mv.visitInsn(AASTORE); mv.visitInsn(DUP); BytecodeHelper.pushConstant(mv, i++); entry.getValueExpression().visit(this); controller.getOperandStack().box(); mv.visitInsn(AASTORE); controller.getOperandStack().remove(2); } createMapMethod.call(mv); controller.getOperandStack().push(ClassHelper.MAP_TYPE); }