public MethodNode getTargetMethod(final Expression expression) { return (MethodNode) expression.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET); }
private static SetterInfo removeSetterInfo(Expression exp) { Object nodeMetaData = exp.getNodeMetaData(SetterInfo.class); if (nodeMetaData != null) { exp.removeNodeMetaData(SetterInfo.class); return (SetterInfo) nodeMetaData; } return null; }
@Override public Expression transform(final Expression exp) { if (exp != null) { Expression replacement = exp.getNodeMetaData(TraitASTTransformation.POST_TYPECHECKING_REPLACEMENT); if (replacement!=null) { return replacement; } } return super.transform(exp); } }
private static boolean hasInferredReturnType(Expression expression) { ClassNode type = expression.getNodeMetaData(StaticTypesMarker.INFERRED_RETURN_TYPE); return type != null && !type.getName().equals("java.lang.Object"); }
private static ClassNode getDeclaringClass(MethodNode method, Expression arguments) { ClassNode declaringClass = method.getDeclaringClass(); // correcting declaring class for extension methods: if (arguments instanceof ArgumentListExpression) { ArgumentListExpression al = (ArgumentListExpression) arguments; List<Expression> list = al.getExpressions(); if (list.isEmpty()) return declaringClass; Expression exp = list.get(0); ClassNode cn = exp.getNodeMetaData(ExtensionMethodDeclaringClass.class); if (cn != null) return cn; } return declaringClass; }
private boolean addedReadOnlyPropertyError(Expression expr) { // if expr is of READONLY_PROPERTY_RETURN type, then it means we are on a missing property if (expr.getNodeMetaData(StaticTypesMarker.READONLY_PROPERTY) == null) return false; String name; if (expr instanceof VariableExpression) { name = ((VariableExpression) expr).getName(); } else { name = ((PropertyExpression) expr).getPropertyAsString(); } addStaticTypeError("Cannot set read-only property: " + name, expr); return true; }
if (expression.getNodeMetaData(StaticTypesMarker.DELEGATION_METADATA) != null) { expression.removeNodeMetaData(StaticTypesMarker.DELEGATION_METADATA);
@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); }
boolean exists = super.existsProperty(pexp, checkForReadOnly, receiverMemoizer); if (exists) { if (objectExpression.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER)==null) { objectExpression.putNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER, rType.get());
boolean tryImplicitReceiver(final Expression origin, final Expression message, final Expression arguments, final MethodCallerMultiAdapter adapter, final boolean safe, final boolean spreadSafe, final boolean implicitThis) { Object implicitReceiver = origin.getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER); if (implicitThis && implicitReceiver==null && origin instanceof MethodCallExpression) { implicitReceiver = ((MethodCallExpression) origin).getObjectExpression().getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER); rewritten.setImplicitThis(false); rewritten.visit(controller.getAcg()); rewritten.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, origin.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE)); return true;
ClassNode oldDIT = (ClassNode) exp.getNodeMetaData(StaticTypesMarker.DECLARATION_INFERRED_TYPE); if (oldDIT != null) { exp.putNodeMetaData(StaticTypesMarker.DECLARATION_INFERRED_TYPE, cn == null ? oldDIT : lowestUpperBound(oldDIT, cn));
if (origin!=null) meta = origin.getNodeMetaData(StatementMeta.class); MethodNode mn = null; if (meta!=null) mn = meta.target;
ClassNode closureReturnType = expression.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE); if (closureReturnType != null && closureReturnType.isUsingGenerics()) { ClassNode unwrapped = closureReturnType.getGenericsTypes()[0].getType(); Parameter[] closureParams = ((ClosureExpression) expression).getParameters(); ClassNode[] closureParamTypes = extractTypesFromParameters(closureParams); if (expression.getNodeMetaData(StaticTypesMarker.CLOSURE_ARGUMENTS) != null) { closureParamTypes = expression.getNodeMetaData(StaticTypesMarker.CLOSURE_ARGUMENTS);
public ClassNode resolveType(final Expression exp, final ClassNode current) { if (exp instanceof ClassExpression) return ClassHelper.CLASS_Type; OptimizingStatementWriter.StatementMeta meta = exp.getNodeMetaData(OptimizingStatementWriter.StatementMeta.class); ClassNode type = null; if (meta != null) type = meta.type; if (type != null) return type; if (exp instanceof VariableExpression) { VariableExpression ve = (VariableExpression) exp; if (ve.isClosureSharedVariable()) return ve.getType(); type = ve.getOriginType(); if (ve.getAccessedVariable() instanceof FieldNode) { FieldNode fn = (FieldNode) ve.getAccessedVariable(); if (!fn.getDeclaringClass().equals(current)) return fn.getOriginType(); } } else if (exp instanceof Variable) { Variable v = (Variable) exp; type = v.getOriginType(); } else { type = exp.getType(); } return type.redirect(); } }
@Override protected void writePostOrPrefixMethod(int op, String method, Expression expression, Expression orig) { MethodNode mn = orig.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET); WriterController controller = getController(); OperandStack operandStack = controller.getOperandStack(); if (mn!=null) { operandStack.pop(); MethodCallExpression call = new MethodCallExpression( expression, method, ArgumentListExpression.EMPTY_ARGUMENTS ); call.setMethodTarget(mn); call.visit(controller.getAcg()); return; } ClassNode top = operandStack.getTopOperand(); if (ClassHelper.isPrimitiveType(top) && (ClassHelper.isNumberType(top)||char_TYPE.equals(top))) { MethodVisitor mv = controller.getMethodVisitor(); visitInsnByType(top, mv, ICONST_1, LCONST_1, FCONST_1, DCONST_1); if ("next".equals(method)) { visitInsnByType(top, mv, IADD, LADD, FADD, DADD); } else { visitInsnByType(top, mv, ISUB, LSUB, FSUB, DSUB); } return; } super.writePostOrPrefixMethod(op, method, expression, orig); }
@Override public void makeSingleArgumentCall(final Expression receiver, final String message, final Expression arguments) { TypeChooser typeChooser = controller.getTypeChooser(); ClassNode classNode = controller.getClassNode(); ClassNode rType = typeChooser.resolveType(receiver, classNode); ClassNode aType = typeChooser.resolveType(arguments, classNode); if (trySubscript(receiver, message, arguments, rType, aType)) { return; } // now try with flow type instead of declaration type rType = receiver.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE); if (receiver instanceof VariableExpression && rType == null) { // TODO: can STCV be made smarter to avoid this check? Variable accessedVariable = ((VariableExpression)receiver).getAccessedVariable(); VariableExpression ve = (VariableExpression) accessedVariable; rType = ve.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE); } if (rType!=null && trySubscript(receiver, message, arguments, rType, aType)) { return; } // todo: more cases throw new GroovyBugError( "At line " + receiver.getLineNumber() + " column " + receiver.getColumnNumber() + "\n" + "On receiver: " + receiver.getText() + " with message: " + message + " and arguments: " + arguments.getText() + "\n" + "This method should not have been called. Please try to create a simple example reproducing\n" + "this error and file a bug report at https://issues.apache.org/jira/browse/GROOVY"); }
typeOfFalse = falseExpression.getNodeMetaData(StaticTypesMarker.INFERRED_RETURN_TYPE); typeOfTrue = trueExpression.getNodeMetaData(StaticTypesMarker.INFERRED_RETURN_TYPE);
inferredRightExpressionType = rightExpression.getNodeMetaData(StaticTypesMarker.INFERRED_RETURN_TYPE);
type = expression.getNodeMetaData(StaticTypesMarker.INFERRED_RETURN_TYPE);
private void writeListDotProperty(final Expression receiver, final String methodName, final MethodVisitor mv, final boolean safe) { ClassNode componentType = receiver.getNodeMetaData(StaticCompilationMetadataKeys.COMPONENT_TYPE); if (componentType==null) { componentType = OBJECT_TYPE;