@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) { result = new ExpressionInfo( TextRegion.of(expr), TextPosition.startOf(expr.getProperty()), expr.getPropertyAsString(), expr.isImplicitThis() ? Collections.<ExpressionInfo>emptyList() : Collections.singletonList(convert(expr.getObjectExpression()))); }
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 static Visibility getVisibility(Expression e) { if (e instanceof PropertyExpression) { PropertyExpression pe = (PropertyExpression) e; if (pe.getObjectExpression() instanceof ClassExpression && pe.getObjectExpression().getText().equals("groovy.transform.options.Visibility")) { return Visibility.valueOf(pe.getPropertyAsString()); } } return Visibility.UNDEFINED; } }
boolean ipe = inPropertyExpression; Expression objectExpression = pe.getObjectExpression(); inPropertyExpression = true; isTopLevelProperty = (objectExpression.getClass() != PropertyExpression.class); Expression property = transform(pe.getProperty()); isTopLevelProperty = itlp; inPropertyExpression = ipe; boolean spreadSafe = pe.isSpreadSafe(); PropertyExpression old = pe; pe = new PropertyExpression(objectExpression, property, pe.isSafe()); pe.setSpreadSafe(spreadSafe); pe.setSourcePosition(old); if (objectExpression instanceof ClassExpression && pe.getPropertyAsString() != null) { ClassNode type = new ConstructedNestedClass(classNode, pe.getPropertyAsString()); if (resolve(type, false, false, false)) { if (classNode == ce.getType() || isVisibleNestedClass(type, ce.getType())) {
Expression objectExpression = expression.getObjectExpression(); ClassNode classNode = controller.getClassNode(); String name = expression.getPropertyAsString(); if (name != null) { FieldNode field = null; if (controller.isNotExplicitThisInClosure(expression.isImplicitThis())) { field = classNode.getDeclaredField(name); if (field==null && classNode instanceof InnerClassNode) { PropertyExpression pexp = new PropertyExpression( new ClassExpression(outer), expression.getProperty() ); pexp.visit(controller.getAcg()); return; final String propName = expression.getPropertyAsString(); if (expression.getObjectExpression() instanceof ClassExpression && propName!=null && propName.equals("this")) if (adapter == getProperty && !expression.isSpreadSafe()) { controller.getCallSiteWriter().makeGetPropertySite(objectExpression, propName, expression.isSafe(), expression.isImplicitThis()); } else if (adapter == getGroovyObjectProperty && !expression.isSpreadSafe()) { controller.getCallSiteWriter().makeGroovyObjectGetPropertySite(objectExpression, propName, expression.isSafe(), expression.isImplicitThis()); } else { controller.getCallSiteWriter().fallbackAttributeOrPropertySite(expression, objectExpression, propName, adapter);
return makeCheckedCall("checkedGetProperty", transformObjectExpression(pe), boolExp(pe.isSafe()), boolExp(pe.isSpreadSafe()), transform(pe.getProperty()) ); PropertyExpression pexp = new PropertyExpression(VariableExpression.THIS_EXPRESSION, vexp.getName()); pexp.setImplicitThis(true); withLoc(exp,pexp); return transform(pexp); PropertyExpression pexp = new PropertyExpression(VariableExpression.THIS_EXPRESSION, vexp.getName()); pexp.setImplicitThis(true); pexp.setSourcePosition(vexp); name = "checkedSetAttribute"; } else { Expression receiver = pe.getObjectExpression(); if (receiver instanceof VariableExpression && ((VariableExpression) receiver).getName().equals("this")) { FieldNode field = clazz != null ? clazz.getField(pe.getPropertyAsString()) : null; if (field != null) { // could also verify that it is final, but not necessary pe.getProperty(), boolExp(pe.isSafe()), boolExp(pe.isSpreadSafe()), intExp(be.getOperation().getType()), transform(be.getRightExpression())
String[] propertyPath = ((String) implicitReceiver).split("\\."); PropertyExpression pexp = new PropertyExpression(new VariableExpression("this", CLOSURE_TYPE), propertyPath[0]); pexp.setImplicitThis(true); for (int i=1; i<propertyPath.length;i++) { pexp.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, CLOSURE_TYPE); pexp = new PropertyExpression(pexp, propertyPath[i]); pexp.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, implicitReceiver); origin.removeNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER); if (origin instanceof PropertyExpression) { PropertyExpression rewritten = new PropertyExpression( pexp, ((PropertyExpression) origin).getProperty(), ((PropertyExpression) origin).isSafe() ); rewritten.setSpreadSafe(((PropertyExpression) origin).isSpreadSafe()); rewritten.setImplicitThis(false); rewritten.visit(controller.getAcg()); rewritten.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, origin.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE)); return true;
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() ); } }
ClassNode classNode = controller.getClassNode(); int counter = labelCounter.incrementAndGet(); Expression receiver = spreadExpression.getObjectExpression(); DeclarationExpression declr = new DeclarationExpression( result, Token.newSymbol("=", spreadExpression.getLineNumber(), spreadExpression.getColumnNumber()), cce ); VariableExpression iteratorAsVar = new VariableExpression(iterator); PropertyExpression pexp = spreadExpression instanceof AttributeExpression? new AttributeExpression(iteratorAsVar, spreadExpression.getProperty(), true): new PropertyExpression(iteratorAsVar, spreadExpression.getProperty(), true); pexp.setImplicitThis(spreadExpression.isImplicitThis()); pexp.setSourcePosition(spreadExpression); BinaryExpression assignment = new BinaryExpression( pexp,
public void visitPropertyExpression(PropertyExpression expression) { expression.getObjectExpression().visit(this); expression.getProperty().visit(this); }
protected Expression transformPropertyExpression(PropertyExpression pe) { if (currentMethod!=null && currentMethod.isStatic() && pe.getObjectExpression() instanceof VariableExpression && ((VariableExpression) pe.getObjectExpression()).isSuperExpression()) { PropertyExpression pexp = new PropertyExpression( new ClassExpression(currentClass.getSuperClass()), transform(pe.getProperty()) ); pexp.setSourcePosition(pe); return pexp; foundArgs = null; foundConstant = null; Expression objectExpression = transform(pe.getObjectExpression()); boolean candidate = false; if (objectExpression instanceof MethodCallExpression) { foundArgs = oldFoundArgs; foundConstant = oldFoundConstant; pe.setObjectExpression(objectExpression); return pe;
@Deprecated protected SetterInfo hasSetter(final PropertyExpression pexp) { String propertyName = pexp.getPropertyAsString(); if (propertyName == null) return null; Expression objectExpression = pexp.getObjectExpression(); List<Receiver<String>> receivers = new LinkedList<Receiver<String>>(); List<Receiver<String>> owners = makeOwnerList(objectExpression); addReceivers(receivers, owners, pexp.isImplicitThis());
PropertyExpression pexp = new PropertyExpression(VariableExpression.THIS_EXPRESSION, ve.getName()); pexp.setImplicitThis(true); pexp.setSourcePosition(atom); return makeCheckedCall("checked" + mode + "Property", transformObjectExpression(pe), pe.getProperty(), boolExp(pe.isSafe()), boolExp(pe.isSpreadSafe()), stringExp(op) );
@Override public void run() { loc(exp); visit(exp.getObjectExpression()); visit(exp.getProperty()); literal(exp.isSafe()); } });
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); } }
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; }
private static Expression correctClassClassChain(PropertyExpression pe) { LinkedList<Expression> stack = new LinkedList<Expression>(); ClassExpression found = null; for (Expression it = pe; it != null; it = ((PropertyExpression) it).getObjectExpression()) { if (it instanceof ClassExpression) { found = (ClassExpression) it; break; } else if (!(it.getClass() == PropertyExpression.class)) { return pe; } stack.addFirst(it); } if (found == null) return pe; if (stack.isEmpty()) return pe; Object stackElement = stack.removeFirst(); if (!(stackElement.getClass() == PropertyExpression.class)) return pe; PropertyExpression classPropertyExpression = (PropertyExpression) stackElement; String propertyNamePart = classPropertyExpression.getPropertyAsString(); if (propertyNamePart == null || !propertyNamePart.equals("class")) return pe; found.setSourcePosition(classPropertyExpression); if (stack.isEmpty()) return found; stackElement = stack.removeFirst(); if (!(stackElement.getClass() == PropertyExpression.class)) return pe; PropertyExpression classPropertyExpressionContainer = (PropertyExpression) stackElement; classPropertyExpressionContainer.setObjectExpression(found); return pe; }
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; }
pexp = new CastExpression(controller.getOutermostClass(),mce); } else { pexp = new PropertyExpression( new ClassExpression(outerClass), "this" ); ((PropertyExpression)pexp).setImplicitThis(true);