public static Expression propX(Expression owner, Expression property) { return new PropertyExpression(owner, property); }
public static Expression propX(Expression owner, String property) { return new PropertyExpression(owner, property); }
public static Expression findArg(String argName) { return new PropertyExpression(new VariableExpression("args"), argName); }
private BinaryExpression createAssignmentToField(final Expression rightExpression, final Token operation, final String fieldName) { return new BinaryExpression( new PropertyExpression( new VariableExpression(weaved), fieldName ), operation, transform(rightExpression)); }
protected static void setPropertyGetterDispatcher(BlockStatement block, Expression thiz, Parameter[] parameters) { List<ConstantExpression> gStringStrings = new ArrayList<ConstantExpression>(); gStringStrings.add(new ConstantExpression("")); gStringStrings.add(new ConstantExpression("")); List<Expression> gStringValues = new ArrayList<Expression>(); gStringValues.add(new VariableExpression(parameters[0])); block.addStatement( new ReturnStatement( new PropertyExpression( thiz, new GStringExpression("$name", gStringStrings, gStringValues) ) ) ); }
public List<AnnotationNode> visit(AnnotationNode collector, AnnotationNode aliasAnnotationUsage, AnnotatedNode aliasAnnotated, SourceUnit source) { AnnotationNode node = new AnnotationNode(COMPILESTATIC_NODE); node.addMember("value", new PropertyExpression(new ClassExpression(TYPECHECKINGMODE_NODE), "SKIP")); return Collections.singletonList(node); } }
private void insertThis0ToSuperCall(final ConstructorCallExpression call, final ClassNode cn) { // calculate outer class which we need for this$0 ClassNode parent = classNode; int level = 0; for (; parent != null && parent != cn.getOuterClass(); parent = parent.getOuterClass()) { level++; } // if constructor call is not in outer class, don't pass 'this' implicitly. Return. if (parent == null) return; //add this parameter to node Expression argsExp = call.getArguments(); if (argsExp instanceof TupleExpression) { TupleExpression argsListExp = (TupleExpression) argsExp; Expression this0 = VariableExpression.THIS_EXPRESSION; for (int i = 0; i != level; ++i) this0 = new PropertyExpression(this0, "this$0"); argsListExp.getExpressions().add(0, this0); } } }
protected static void setPropertySetterDispatcher(BlockStatement block, Expression thiz, Parameter[] parameters) { List<ConstantExpression> gStringStrings = new ArrayList<ConstantExpression>(); gStringStrings.add(new ConstantExpression("")); gStringStrings.add(new ConstantExpression("")); List<Expression> gStringValues = new ArrayList<Expression>(); gStringValues.add(new VariableExpression(parameters[0])); block.addStatement( new ExpressionStatement( new BinaryExpression( new PropertyExpression( thiz, new GStringExpression("$name", gStringStrings, gStringValues) ), Token.newSymbol(Types.ASSIGN, -1, -1), new VariableExpression(parameters[1]) ) ) ); }
private Expression findStaticPropertyAccessor(ClassNode staticImportType, String propName) { String accessorName = getAccessorName(propName); Expression accessor = findStaticPropertyAccessorByFullName(staticImportType, accessorName); if (accessor == null && accessorName.startsWith("get")) { accessor = findStaticPropertyAccessorByFullName(staticImportType, "is" + accessorName.substring(3)); } if (accessor == null && hasStaticProperty(staticImportType, propName)) { // args will be replaced if (inLeftExpression) accessor = new StaticMethodCallExpression(staticImportType, accessorName, ArgumentListExpression.EMPTY_ARGUMENTS); else accessor = new PropertyExpression(new ClassExpression(staticImportType), propName); } return accessor; }
private MethodCallExpression referenceToCurrentClosure() { return new MethodCallExpression( new VariableExpression("this"), new ConstantExpression("each"), new ArgumentListExpression( new PropertyExpression( new ClassExpression(ClassHelper.makeWithoutCaching(Closure.class)), new ConstantExpression("IDENTITY") ) ) ); }
private static Expression findStaticField(ClassNode staticImportType, String fieldName) { if (staticImportType.isPrimaryClassNode() || staticImportType.isResolved()) { FieldNode field = getField(staticImportType, fieldName); if (field != null && field.isStatic()) return new PropertyExpression(new ClassExpression(staticImportType), fieldName); } return null; }
public Expression transformExpression(ExpressionTransformer transformer) { PropertyExpression ret = new PropertyExpression(transformer.transform(objectExpression), transformer.transform(property), safe); ret.setSpreadSafe(spreadSafe); ret.setStatic(isStatic); ret.setImplicitThis(implicitThis); ret.setSourcePosition(this); ret.copyNodeMetaData(this); return ret; }
private ClassNode getTypeForListPropertyExpression(ClassNode testClass, ClassNode objectExpressionType, PropertyExpression pexp) { if (!implementsInterfaceOrIsSubclassOf(testClass, LIST_TYPE)) return null; ClassNode intf = GenericsUtils.parameterizeType(objectExpressionType, LIST_TYPE.getPlainNodeReference()); GenericsType[] types = intf.getGenericsTypes(); if (types == null || types.length != 1) return OBJECT_TYPE; PropertyExpression subExp = new PropertyExpression(varX("{}", types[0].getType()), pexp.getPropertyAsString()); AtomicReference<ClassNode> result = new AtomicReference<ClassNode>(); if (existsProperty(subExp, true, new PropertyLookupVisitor(result))) { intf = LIST_TYPE.getPlainNodeReference(); ClassNode itemType = result.get(); intf.setGenericsTypes(new GenericsType[]{new GenericsType(wrapTypeIfNecessary(itemType))}); return intf; } return null; }
private void addBlockMetadata(Block block, BlockKind kind) { AnnotationNode blockAnn = new AnnotationNode(nodeCache.BlockMetadata); blockAnn.setMember(BlockMetadata.KIND, new PropertyExpression( new ClassExpression(nodeCache.BlockKind), kind.name())); ListExpression textExprs = new ListExpression(); for (String text : block.getDescriptions()) textExprs.addExpression(new ConstantExpression(text)); blockAnn.setMember(BlockMetadata.TEXTS, textExprs); blockAnnElems.addExpression(new AnnotationConstantExpression(blockAnn)); }
private ClassNode getTypeForSpreadExpression(ClassNode testClass, ClassNode objectExpressionType, PropertyExpression pexp) { if (!pexp.isSpreadSafe()) return null; MethodCallExpression mce = callX(varX("_", testClass), "iterator", ArgumentListExpression.EMPTY_ARGUMENTS); mce.setImplicitThis(false); mce.visit(this); ClassNode callType = getType(mce); if (!implementsInterfaceOrIsSubclassOf(callType, Iterator_TYPE)) return null; GenericsType[] types = callType.getGenericsTypes(); ClassNode contentType = OBJECT_TYPE; if (types != null && types.length == 1) contentType = types[0].getType(); PropertyExpression subExp = new PropertyExpression(varX("{}", contentType), pexp.getPropertyAsString()); AtomicReference<ClassNode> result = new AtomicReference<ClassNode>(); if (existsProperty(subExp, true, new PropertyLookupVisitor(result))) { ClassNode intf = LIST_TYPE.getPlainNodeReference(); intf.setGenericsTypes(new GenericsType[]{new GenericsType(getWrapper(result.get()))}); return intf; } return null; }
private static Expression tryTransformDelegateToProperty(VariableExpression expr) { // we need to transform variable expressions that go to a delegate // to a property expression, as ACG would loose the information // in processClassVariable before it reaches any makeCall, that could // handle it Object val = expr.getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER); if (val == null) return null; VariableExpression implicitThis = new VariableExpression("this"); PropertyExpression pexp = new PropertyExpression(implicitThis, expr.getName()); pexp.copyNodeMetaData(expr); pexp.setImplicitThis(true); pexp.getProperty().setSourcePosition(expr); ClassNode owner = expr.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER); if (owner != null) { implicitThis.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, owner); implicitThis.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, val); } return pexp; }
private boolean tryVariableExpressionAsProperty(final VariableExpression vexp, final String dynName) { VariableExpression implicitThis = varX("this"); PropertyExpression pe = new PropertyExpression(implicitThis, dynName); pe.setImplicitThis(true); if (visitPropertyExpressionSilent(pe, vexp)) { ClassNode previousIt = vexp.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE); vexp.copyNodeMetaData(implicitThis); vexp.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, previousIt); storeType(vexp, getType(pe)); Object val = pe.getNodeMetaData(StaticTypesMarker.READONLY_PROPERTY); if (val != null) vexp.putNodeMetaData(StaticTypesMarker.READONLY_PROPERTY, val); val = pe.getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER); if (val != null) vexp.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, val); return true; } return false; }
@Override public void visitPropertyExpression(PropertyExpression expr) { PropertyExpression conversion = new PropertyExpression( expr.isImplicitThis() ? expr.getObjectExpression() : convert(expr.getObjectExpression()), expr.getProperty(), expr.isSafe()); conversion.setSourcePosition(expr); conversion.setSpreadSafe(expr.isSpreadSafe()); conversion.setStatic(expr.isStatic()); conversion.setImplicitThis(expr.isImplicitThis()); result = record(conversion); }
@Override public void visitPropertyExpression(PropertyExpression expr) { PropertyExpression result = new PropertyExpression( replaceExpr(expr.getObjectExpression()), replaceExpr(expr.getProperty()), expr.isSafe() ); result.setSpreadSafe(expr.isSpreadSafe()); result.setStatic(expr.isStatic()); result.setImplicitThis(expr.isImplicitThis()); result.setType(expr.getType()); result.setSourcePosition(expr); replaceVisitedExpressionWith(result); }
private void processClassVariable(VariableExpression expression) { if (passingParams && controller.isInScriptBody()) { //TODO: check if this part is actually used MethodVisitor mv = controller.getMethodVisitor(); // let's create a ScriptReference to pass into the closure mv.visitTypeInsn(NEW, "org/codehaus/groovy/runtime/ScriptReference"); mv.visitInsn(DUP); loadThisOrOwner(); mv.visitLdcInsn(expression.getName()); mv.visitMethodInsn(INVOKESPECIAL, "org/codehaus/groovy/runtime/ScriptReference", "<init>", "(Lgroovy/lang/Script;Ljava/lang/String;)V", false); } else { PropertyExpression pexp = new PropertyExpression(new VariableExpression("this"), expression.getName()); pexp.getObjectExpression().setSourcePosition(expression); pexp.getProperty().setSourcePosition(expression); pexp.setImplicitThis(true); visitPropertyExpression(pexp); } }