private void setPropertyName() { Expression propertyNameExpr = ((PropertyExpression) call).getProperty(); String constraint = selectNameConstraint(propertyNameExpr, InteractionBuilder.ADD_EQUAL_PROPERTY_NAME, InteractionBuilder.ADD_REGEX_PROPERTY_NAME); call(constraint, propertyNameExpr); }
@Override public void visitPropertyExpression(PropertyExpression expr) { result = new ExpressionInfo( TextRegion.of(expr), TextPosition.startOf(expr.getProperty()), expr.getPropertyAsString(), expr.isImplicitThis() ? Collections.<ExpressionInfo>emptyList() : Collections.singletonList(convert(expr.getObjectExpression()))); }
/** * Set the source position of toSet including its property expression if it has one. * * @param toSet resulting node * @param origNode original node */ private static void setSourcePosition(Expression toSet, Expression origNode) { toSet.setSourcePosition(origNode); if (toSet instanceof PropertyExpression) { ((PropertyExpression) toSet).getProperty().setSourcePosition(origNode); } }
public void visitPropertyExpression(final PropertyExpression expression) { assertExpressionAuthorized(expression); Expression receiver = expression.getObjectExpression(); final String typeName = receiver.getType().getName(); if (receiversWhiteList != null && !receiversWhiteList.contains(typeName)) { throw new SecurityException("Property access not allowed on [" + typeName + "]"); } else if (receiversBlackList != null && receiversBlackList.contains(typeName)) { throw new SecurityException("Property access not allowed on [" + typeName + "]"); } receiver.visit(this); final Expression property = expression.getProperty(); checkConstantTypeIfNotMethodNameOrProperty(property); }
public void visitPropertyExpression(PropertyExpression expression) { expression.getObjectExpression().visit(this); expression.getProperty().visit(this); }
private boolean isInternalFieldAccess(final Expression exp) { if (exp instanceof VariableExpression) { Variable accessedVariable = ((VariableExpression) exp).getAccessedVariable(); if (accessedVariable instanceof FieldNode) { return knownFields.contains(accessedVariable.getName()); } } if (exp instanceof PropertyExpression) { if (((PropertyExpression) exp).isImplicitThis() || "this".equals(((PropertyExpression) exp).getObjectExpression().getText())) { return knownFields.contains(((PropertyExpression) exp).getProperty().getText()); } } return false; }
propertyExpression.getProperty() instanceof ConstantExpression && "RUNTIME".equals(((ConstantExpression) (propertyExpression.getProperty())).getValue()) || "CLASS".equals(((ConstantExpression) (propertyExpression.getProperty())).getValue()) );
public void visitPropertyExpression(PropertyExpression expression) { expression.getObjectExpression().visit(this); expression.getProperty().visit(this); checkPropertyOnExplicitThis(expression); }
private static groovy.transform.PackageScopeTarget extractTarget(PropertyExpression expr) { Expression oe = expr.getObjectExpression(); if (oe instanceof ClassExpression) { ClassExpression ce = (ClassExpression) oe; if (ce.getType().getName().equals("groovy.transform.PackageScopeTarget")) { Expression prop = expr.getProperty(); if (prop instanceof ConstantExpression) { String propName = (String) ((ConstantExpression) prop).getValue(); try { return PackageScopeTarget.valueOf(propName); } catch(IllegalArgumentException iae) { /* ignore */ } } } } throw new GroovyBugError("Internal error during " + MY_TYPE_NAME + " processing. Annotation parameters must be of type: " + TARGET_CLASS_NAME + "."); }
public void fallbackAttributeOrPropertySite(PropertyExpression expression, Expression objectExpression, String name, MethodCallerMultiAdapter adapter) { if (controller.getCompileStack().isLHS()) controller.getOperandStack().box(); controller.getInvocationWriter().makeCall( expression, objectExpression, // receiver new CastExpression(ClassHelper.STRING_TYPE, expression.getProperty()), // messageName MethodCallExpression.NO_ARGUMENTS, adapter, expression.isSafe(), expression.isSpreadSafe(), expression.isImplicitThis() ); } }
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; }
@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 visitAnnotationArrayElement(Expression expr, int arrayElementType, AnnotationVisitor av) { switch (arrayElementType) { case 1: AnnotationNode atAttr = (AnnotationNode) ((AnnotationConstantExpression) expr).getValue(); AnnotationVisitor av2 = av.visitAnnotation(null, BytecodeHelper.getTypeDescription(atAttr.getClassNode())); visitAnnotationAttributes(atAttr, av2); av2.visitEnd(); break; case 2: av.visit(null, ((ConstantExpression) expr).getValue()); break; case 3: av.visit(null, Type.getType(BytecodeHelper.getTypeDescription(expr.getType()))); break; case 4: PropertyExpression propExpr = (PropertyExpression) expr; av.visitEnum(null, BytecodeHelper.getTypeDescription(propExpr.getObjectExpression().getType()), String.valueOf(((ConstantExpression) propExpr.getProperty()).getValue())); break; } }
private static Expression tryTransformPrivateFieldAccess(VariableExpression expr) { FieldNode field = expr.getNodeMetaData(StaticTypesMarker.PV_FIELDS_ACCESS); if (field == null) { field = expr.getNodeMetaData(StaticTypesMarker.PV_FIELDS_MUTATION); } if (field != null) { // access to a private field from a section of code that normally doesn't have access to it, like a // closure or an inner class VariableExpression receiver = new VariableExpression("this"); PropertyExpression pexp = new PropertyExpression( receiver, expr.getName() ); pexp.setImplicitThis(true); pexp.getProperty().setSourcePosition(expr); // put the receiver inferred type so that the class writer knows that it will have to call a bridge method receiver.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, field.getDeclaringClass()); // add inferred type information pexp.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, field.getOriginType()); return pexp; } return null; } }
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); } }
public void visitPropertyExpression(PropertyExpression expression) { Expression objectExpression = expression.getObjectExpression(); OperandStack operandStack = controller.getOperandStack(); int mark = operandStack.getStackLength()-1; MethodCallerMultiAdapter adapter; if (controller.getCompileStack().isLHS()) { //operandStack.box(); adapter = setProperty; if (isGroovyObject(objectExpression)) adapter = setGroovyObjectProperty; if (isThisOrSuperInStaticContext(objectExpression)) adapter = setProperty; } else { adapter = getProperty; if (isGroovyObject(objectExpression)) adapter = getGroovyObjectProperty; if (isThisOrSuperInStaticContext(objectExpression)) adapter = getProperty; } visitAttributeOrProperty(expression, adapter); if (controller.getCompileStack().isLHS()) { // remove surplus values operandStack.remove(operandStack.getStackLength()-mark); } else { controller.getAssertionWriter().record(expression.getProperty()); } }
PropertyExpression rewritten = new PropertyExpression( pexp, ((PropertyExpression) origin).getProperty(), ((PropertyExpression) origin).isSafe() );
@Override public void evaluateEqual(final BinaryExpression expression, final boolean defineVariable) { if (!defineVariable) { Expression leftExpression = expression.getLeftExpression(); if (leftExpression instanceof PropertyExpression) { PropertyExpression pexp = (PropertyExpression) leftExpression; if (makeSetProperty( pexp.getObjectExpression(), pexp.getProperty(), expression.getRightExpression(), pexp.isSafe(), pexp.isSpreadSafe(), pexp.isImplicitThis(), pexp instanceof AttributeExpression)) return; } } // GROOVY-5620: Spread safe/Null safe operator on LHS is not supported if (expression.getLeftExpression() instanceof PropertyExpression && ((PropertyExpression) expression.getLeftExpression()).isSpreadSafe() && StaticTypeCheckingSupport.isAssignment(expression.getOperation().getType())) { // rewrite it so that it can be statically compiled transformSpreadOnLHS(expression); return; } super.evaluateEqual(expression, defineVariable); }
PropertyExpression pexp = new PropertyExpression( new ClassExpression(currentClass.getSuperClass()), transform(pe.getProperty()) ); pexp.setSourcePosition(pe);