Skip to content

Instantly share code, notes, and snippets.

@ochafik
Created November 19, 2014 17:15
Show Gist options
  • Select an option

  • Save ochafik/09b1a1be12e0ee66c4d0 to your computer and use it in GitHub Desktop.

Select an option

Save ochafik/09b1a1be12e0ee66c4d0 to your computer and use it in GitHub Desktop.
//
// traverseClass(ClassElement cls) {
// for (MethodElement method in cls.methods) {
// traverseMethod(method);
// }
//
// for (FieldElement field in cls.fields) {
//// traverseField(field);
// }
//
// for (PropertyAccessorElement acc in cls.accessors) {
//// traversePropertyAccessor(acc);
// }
// }
//
// void printPropertyAccessor(PropertyAccessorElement acc) {
// }
//
// static _singleWhereOrNull(Iterable list, bool predicate(dynamic)) {
// Iterable good = list.where(predicate);
// return good.isNotEmpty ? good.single : null;
// }
//
// traverseExpression(Expression expr) {
// if (expr is AssignmentExpression) {
// traverseExpression(expr.leftHandSide);
// traverseExpression(expr.rightHandSide);
// } else if (expr is ConditionalExpression) {
// traverseExpression(expr.condition);
// traverseExpression(expr.thenExpression);
// traverseExpression(expr.elseExpression);
// } else if (expr is ThrowExpression) {
// traverseExpression(expr.expression);
// } else if (expr is MethodInvocation) {
// assert(!expr.isCascaded);
//
// var target = expr.target;
// var methodName = expr.methodName.name;
// if (target != null) {
// traverseExpression(target);
// }
// traverseArgList(expr.argumentList);
// } else if (expr is Literal) {
// // TODO
// } else if (expr is SimpleIdentifier) {
// // TODO
// } else if (expr is BinaryExpression) {
// traverseExpression(expr.leftOperand);
// traverseExpression(expr.rightOperand);
// } else if (expr is FunctionExpression) {
// traverseParamList(expr.parameters.parameters);
// traverseFunctionBody(expr.body, false /* isMethod */);
// } else {
// assert(false);
// }
// }
//
// void traverseArgList(ArgumentList argumentList) {
// for (var x in argumentList) {
// ParameterElement param = argumentList.getStaticParameterElementFor(x);
// traverseExpression(x);
// }
// }
// traverseMethod(MethodElement method) {
// traverseParamTypes(method.parameters);
// traverseParamList(method.node.parameters.parameters);
// traverseFunctionBody(method.node.body, true);
// }
//
// void traverseParamList(Iterable<FormalParameter> params) {
// for (FormalParameter p in params) {
// if (p is DefaultFormalParameter) {
// traverseExpression(p.defaultValue);
// }
// }
// }
//
// void traverseFunctionBody(FunctionBody body, bool isMethod, {header()}) {
// var printInside;
// if (body is BlockFunctionBody) {
// traverseStatements(body.block.statements);
// } else if (body is EmptyFunctionBody) {
// } else if (body is ExpressionFunctionBody) {
// traverseExpression(body.expression);
// } else {
// assert(false);
// }
// }
//
// void traverseBlock(Block block) {
// traverseStatements(block.statements);
// }
//
// void traverseStatements(Iterable<Statement> statements) {
// statements.forEach(traverseStatement);
// }
//
// void traverseStatement(Statement s) {
// if (s is Block) {
// traverseBlock(s);
// } else if (s is VariableDeclarationStatement) {
// // TODO
// assert(false);
// } else if (s is ForStatement) {
// // TODO
// assert(false);
// } else if (s is ForEachStatement) {
// // TODO
// assert(false);
// } else if (s is WhileStatement) {
// // TODO
// assert(false);
// } else if (s is DoStatement) {
// // TODO
// assert(false);
// } else if (s is SwitchStatement) {
// // TODO
// assert(false);
// } else if (s is IfStatement) {
// // TODO
// assert(false);
// } else if (s is TryStatement) {
// // TODO
// assert(false);
// } else if (s is BreakStatement) {
// // TODO
// assert(false);
// } else if (s is ContinueStatement) {
// // TODO
// assert(false);
// } else if (s is ReturnStatement) {
// // TODO
// assert(false);
// } else if (s is ExpressionStatement) {
// traverseExpression(s.expression);
// } else if (s is FunctionDeclarationStatement) {
// // TODO
// assert(false);
// } else {
// assert(false);
// }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment