public static boolean isSuperExpression(Expression expr) { return expr instanceof VariableExpression && ((VariableExpression) expr).isSuperExpression(); }
private void checkSuperOrThisOnLHS(Expression expression) { if (!(expression instanceof VariableExpression)) return; VariableExpression ve = (VariableExpression) expression; if (ve.isThisExpression()) { addError("cannot have 'this' as LHS of an assignment", expression); } else if (ve.isSuperExpression()) { addError("cannot have 'super' as LHS of an assignment", expression); } }
private boolean storeTypeForSuper(VariableExpression vexp) { if (vexp == VariableExpression.SUPER_EXPRESSION) return true; if (!vexp.isSuperExpression()) return false; ClassNode superClassNode = typeCheckingContext.getEnclosingClassNode().getSuperClass(); storeType(vexp, makeType(superClassNode, typeCheckingContext.isInStaticContext)); return true; }
private boolean forbidUseOfSuperInFixtureMethod(MethodCallExpression expr) { Method currMethod = resources.getCurrentMethod(); Expression target = expr.getObjectExpression(); if (currMethod instanceof FixtureMethod && target instanceof VariableExpression && ((VariableExpression)target).isSuperExpression() && currMethod.getName().equals(expr.getMethodAsString())) { resources.getErrorReporter().error(expr, "A base class fixture method should not be called explicitly " + "because it is always invoked automatically by the framework"); return true; } return false; }
private void checkSuperCallFromClosure(Expression call, MethodNode directCallTarget) { if (call instanceof MethodCallExpression && typeCheckingContext.getEnclosingClosure() != null) { Expression objectExpression = ((MethodCallExpression) call).getObjectExpression(); if (objectExpression instanceof VariableExpression) { VariableExpression var = (VariableExpression) objectExpression; if (var.isSuperExpression()) { ClassNode current = typeCheckingContext.getEnclosingClassNode(); LinkedList<MethodNode> list = current.getNodeMetaData(StaticTypesMarker.SUPER_MOP_METHOD_REQUIRED); if (list == null) { list = new LinkedList<MethodNode>(); current.putNodeMetaData(StaticTypesMarker.SUPER_MOP_METHOD_REQUIRED, list); } list.add(directCallTarget); call.putNodeMetaData(StaticTypesMarker.SUPER_MOP_METHOD_REQUIRED, current); } } } }
protected Expression expression(AST node, boolean convertToConstant) { Expression expression = expressionSwitch(node); if (convertToConstant && expression instanceof VariableExpression) { // a method name can never be a VariableExpression, so it must converted // to a ConstantExpression then. This is needed as the expression // method doesn't know we want a ConstantExpression instead of a // VariableExpression VariableExpression ve = (VariableExpression) expression; if (!ve.isThisExpression() && !ve.isSuperExpression()) { expression = new ConstantExpression(ve.getName()); } } configureAST(expression, node); return expression; }
VariableExpression ve = (VariableExpression) it; if (ve.isSuperExpression() || ve.isThisExpression()) { return null;
@Override protected boolean makeDirectCall(final Expression origin, final Expression receiver, final Expression message, final Expression arguments, final MethodCallerMultiAdapter adapter, final boolean implicitThis, final boolean containsSpreadExpression) { if (origin instanceof MethodCallExpression && receiver instanceof VariableExpression && ((VariableExpression) receiver).isSuperExpression()) { ClassNode superClass = receiver.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER); if (superClass!=null && !controller.getCompileStack().isLHS()) { // GROOVY-7300 MethodCallExpression mce = (MethodCallExpression) origin; MethodNode node = superClass.getDeclaredMethod(mce.getMethodAsString(), Parameter.EMPTY_ARRAY); mce.setMethodTarget(node); } } return super.makeDirectCall(origin, receiver, message, arguments, adapter, implicitThis, containsSpreadExpression); }
private void addStaticVariableError(VariableExpression ve) { // closures are always dynamic // propertyExpressions will handle the error a bit differently if (!inSpecialConstructorCall && (inClosure || !ve.isInStaticContext())) return; if (ve.isThisExpression() || ve.isSuperExpression()) return; Variable v = ve.getAccessedVariable(); if (currentMethod != null && currentMethod.isStatic()) { FieldNode fieldNode = getDeclaredOrInheritedField(currentMethod.getDeclaringClass(), ve.getName()); if (fieldNode != null && fieldNode.isStatic()) return; } if (v != null && !(v instanceof DynamicVariable) && v.isInStaticContext()) return; addVariableError(ve); }
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()),
return res; if (vexp.isSuperExpression()) { throwSuperError(vexp);
boolean isThisOrSuper = false; if (receiver instanceof VariableExpression) { isThisOrSuper = ((VariableExpression) receiver).isThisExpression() || ((VariableExpression) receiver).isSuperExpression(); boolean isThisOrSuper = false; if (receiver instanceof VariableExpression) { isThisOrSuper = ((VariableExpression) receiver).isThisExpression() || ((VariableExpression) receiver).isSuperExpression(); boolean callToSuper = receiver instanceof VariableExpression && ((VariableExpression) receiver).isSuperExpression(); if (!callToSuper) { fixedReceiver = fixedReceiver == null ? receiver : fixedReceiver;
if (object instanceof VariableExpression) { VariableExpression ve = (VariableExpression) object; isExplicitThisOrSuper = !mce.isImplicitThis() && (ve.isThisExpression() || ve.isSuperExpression()); isExplicitSuper = ve.isSuperExpression();
if (target.isStatic()) { opcode = INVOKESTATIC; } else if (target.isPrivate() || ((receiver instanceof VariableExpression && ((VariableExpression) receiver).isSuperExpression()))) { opcode = INVOKESPECIAL; } else if (declaringClass.isInterface()) {
protected Expression expression(AST node, boolean convertToConstant) { Expression expression = expressionSwitch(node); if (convertToConstant && expression instanceof VariableExpression) { // a method name can never be a VariableExpression, so it must converted // to a ConstantExpression then. This is needed as the expression // method doesn't know we want a ConstantExpression instead of a // VariableExpression VariableExpression ve = (VariableExpression) expression; if (!ve.isThisExpression() && !ve.isSuperExpression()) { expression = new ConstantExpression(ve.getName()); } } configureAST(expression, node); return expression; }
protected Expression expression(AST node, boolean convertToConstant) { Expression expression = expressionSwitch(node); if (convertToConstant && expression instanceof VariableExpression) { // a method name can never be a VariableExpression, so it must converted // to a ConstantExpression then. This is needed as the expression // method doesn't know we want a ConstantExpression instead of a // VariableExpression VariableExpression ve = (VariableExpression) expression; if (!ve.isThisExpression() && !ve.isSuperExpression()) { expression = new ConstantExpression(ve.getName()); } } configureAST(expression, node); return expression; }
protected Expression expression(AST node, boolean convertToConstant) { Expression expression = expressionSwitch(node); if (convertToConstant && expression instanceof VariableExpression) { // a method name can never be a VariableExprssion, so it must converted // to a ConstantExpression then. This is needed as the expression // method doesn't know we want a ConstantExpression instead of a // VariableExpression VariableExpression ve = (VariableExpression) expression; if (!ve.isThisExpression() && !ve.isSuperExpression()) { expression = new ConstantExpression(ve.getName()); } } configureAST(expression, node); return expression; }
private void addStaticVariableError(VariableExpression ve) { // closures are always dynamic // propertiesExpressions will handle the error a bit differently if (!inSpecialConstructorCall && (inClosure || !ve.isInStaticContext())) return; if (stillResolving) return; if (ve.isThisExpression() || ve.isSuperExpression()) return; Variable v = ve.getAccessedVariable(); if (v != null && !(v instanceof DynamicVariable) && v.isInStaticContext()) return; addError("Apparent variable '" + ve.getName() + "' was found in a static scope but doesn't refer" + " to a local variable, static field or class. Possible causes:\n" + "You attempted to reference a variable in the binding or an instance variable from a static context.\n" + "You misspelled a classname or statically imported field. Please check the spelling.\n" + "You attempted to use a method '" + ve.getName() + "' but left out brackets in a place not allowed by the grammar.", ve); }
private void addStaticVariableError(VariableExpression ve) { // closures are always dynamic // propertiesExpressions will handle the error a bit different if (!inSpecialConstructorCall && (inClosure || !ve.isInStaticContext())) return; if (stillResolving) return; if (ve.isThisExpression() || ve.isSuperExpression()) return; Variable v = ve.getAccessedVariable(); if (v != null && !(v instanceof DynamicVariable) && v.isInStaticContext()) return; addError("Apparent variable '" + ve.getName() + "' was found in a static scope but doesn't refer" + " to a local variable, static field or class. Possible causes:\n" + "You attemped to reference a variable in the binding or an instance variable from a static context.\n" + "You mispelled a classname or statically imported field. Please check the spelling.\n" + "You attempted to use a method '" + ve.getName() + "' but left out brackets in a place not allowed by the grammar.", ve); }
private void addStaticVariableError(VariableExpression ve) { // closures are always dynamic // propertyExpressions will handle the error a bit differently if (!inSpecialConstructorCall && (inClosure || !ve.isInStaticContext())) return; if (ve.isThisExpression() || ve.isSuperExpression()) return; Variable v = ve.getAccessedVariable(); if (currentMethod != null && currentMethod.isStatic()) { FieldNode fieldNode = currentMethod.getDeclaringClass().getField(ve.getName()); if (fieldNode != null && fieldNode.isStatic()) return; } if (v != null && !(v instanceof DynamicVariable) && v.isInStaticContext()) return; addError("Apparent variable '" + ve.getName() + "' was found in a static scope but doesn't refer" + " to a local variable, static field or class. Possible causes:\n" + "You attempted to reference a variable in the binding or an instance variable from a static context.\n" + "You misspelled a classname or statically imported field. Please check the spelling.\n" + "You attempted to use a method '" + ve.getName() + "' but left out brackets in a place not allowed by the grammar.", ve); } }