Analyze an AST node; this involves collecting a list of all the nodes that needs rewriting,
and speculatively type-check the rewritten code to compare results against previously attributed code.
425513
void analyze(JCStatement statement, Env<AttrContext> env) {
        AnalysisContext context = new AnalysisContext();
        StatementScanner statementScanner = new StatementScanner(context);
        statementScanner.scan(statement);

        if (!context.treesToAnalyzer.isEmpty()) {

            //add a block to hoist potential dangling variable declarations
            JCBlock fakeBlock = make.Block(SYNTHETIC, List.of(statement));

            TreeMapper treeMapper = new TreeMapper(context);
            //TODO: to further refine the analysis, try all rewriting combinations
            deferredAttr.attribSpeculative(fakeBlock, env, attr.statInfo, treeMapper,
                    t -> new AnalyzeDeferredDiagHandler(context),
                    argumentAttr.withLocalCacheContext());
            context.treeMap.entrySet().forEach(e -> {
                context.treesToAnalyzer.get(e.getKey())
                        .process(e.getKey(), e.getValue(), context.errors.nonEmpty());
            });
        }
    }
1199062
def _analyze(self):
        
        if self.value is None or self.value == self.previous:
            pass

        elif self._operation == "append":
            self._append = self.value

        elif self._operation == "prepend":
            self._prepend = self.value

        elif self.previous is None:
            self._assignments = self.value

        elif len(self.value) < len(self.previous):
            # if elements have been removed,
            # rewrite the whole list
            self._assignments = self.value

        elif len(self.previous) == 0:
            # if we're updating from an empty
            # list, do a complete insert
            self._assignments = self.value
        else:

            # the max start idx we want to compare
            search_space = len(self.value) - max(0, len(self.previous) - 1)

            # the size of the sub lists we want to look at
            search_size = len(self.previous)

            for i in range(search_space):
                # slice boundary
                j = i + search_size
                sub = self.value[i:j]
                idx_cmp = lambda idx: self.previous[idx] == sub[idx]
                if idx_cmp(0) and idx_cmp(-1) and self.previous == sub:
                    self._prepend = self.value[:i] or None
                    self._append = self.value[j:] or None
                    break

            # if both append and prepend are still None after looking
            # at both lists, an insert statement will be created
            if self._prepend is self._append is None:
                self._assignments = self.value

        self._analyzed = True
410273
def node_query(self, node):
        

        if isinstance(node, ast.Call):
            assert node.args
            arg = node.args[0]
            if not isinstance(arg, ast.Str):
                return
        else:
            raise TypeError(type(node))

        return arg.s
237276
def debug_inspect_node(self, node_msindex):
        
        return inspect_node(self.nlinks, self.unariesalt2, self.msinds, node_msindex)
38691
async function analyze(resource) {
	const libInfo = {
		noLibraryCSS: false,
		types: [],
		controls: [],
		elements: [],
		interfaces: []
	};

	function visit(node) {
		if ( node.type == Syntax.CallExpression
				&& node.callee.type === Syntax.MemberExpression
				&& isMethodCall(node.callee.object, CALL__SAP_UI_GETCORE)
				&& isIdentifier(node.callee.property, "initLibrary")
				&& node.arguments.length === 1
				&& node.arguments[0].type === Syntax.ObjectExpression ) {
			node.arguments[0].properties.forEach( (prop) => {
				const key = getPropertyKey(prop);
				const value = prop.value;
				if ( key === "noLibraryCSS"
						&& (value.type === Syntax.Literal && typeof value.value === "boolean") ) {
					libInfo.noLibraryCSS = value.value;
				} else if ( key === "types" && value.type == Syntax.ArrayExpression ) {
					libInfo.types = getStringArray(value, true);
				} else if ( key === "interfaces" && value.type == Syntax.ArrayExpression ) {
					libInfo.interfaces = getStringArray(value, true);
				} else if ( key === "controls" && value.type == Syntax.ArrayExpression ) {
					libInfo.controls = getStringArray(value, true);
				} else if ( key === "elements" && value.type == Syntax.ArrayExpression ) {
					libInfo.elements = getStringArray(value, true);
				}
			});

			return true; // abort, we're done
		}

		for ( const key of VisitorKeys[node.type] ) {
			const child = node[key];
			if ( Array.isArray(child) ) {
				if ( child.some(visit) ) {
					return true;
				}
			} else if ( child ) {
				if ( visit(child) ) {
					return true;
				}
			}
		}

		return false;
	}

	const code = await resource.getBuffer();
	visit( esprima.parseScript(code.toString()) );

	return libInfo;
}
529015
function checkASTandNodeArray(ast, nodes) {
  typeCheckObject(ast, 'ast');
  typeCheckArray(nodes, 'nodes');
  nodes.forEach((node, index) => {
    typeCheckObject(node, 'nodes (index: ' + index + ')');
  });
  runValidator(ast, 'ast');
  nodes.forEach((node, index) => {
    runValidator(node, 'nodes (index: ' + index + ')');
  });
}
283867
def write_ast(patched_ast_node):
    
    result = []
    for child in patched_ast_node.sorted_children:
        if isinstance(child, ast.AST):
            result.append(write_ast(child))
        else:
            result.append(child)
    return ''.join(result)
889190
def check_syntax(code):
    """"""
    try:
        return compile(code, '<string>', 'exec', dont_inherit=True)
    except (SyntaxError, TypeError, ValueError):
        return False
920464
@Override
    public DominatorsAnalysis analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
        CFG cfg = getCFG(analysisCache, descriptor);
        DepthFirstSearch dfs = getDepthFirstSearch(analysisCache, descriptor);
        DominatorsAnalysis analysis = new DominatorsAnalysis(cfg, dfs, true);
        Dataflow<java.util.BitSet, DominatorsAnalysis> dataflow = new Dataflow<>(cfg,
                analysis);
        dataflow.execute();
        return analysis;
    }
1252314
def each_node(from = covered_code.root, &block)
      return to_enum(:each_node) unless block_given?
      begin
        yield from unless from.is_a?(Node::Root)
      rescue ProblemWithDiagnostic
        raise
      rescue StandardError, SystemStackError => e
        raise ProblemWithDiagnostic.new(covered_code, from.diagnostic_expression, e)
      end
      node_children(from).each do |child|
        each_node(child, &block)
      end
    end
188990
function verify(node) {
            if (node.operator !== "=" || node.right.type !== "BinaryExpression") {
                return;
            }

            const left = node.left;
            const expr = node.right;
            const operator = expr.operator;

            if (isCommutativeOperatorWithShorthand(operator) || isNonCommutativeOperatorWithShorthand(operator)) {
                if (same(left, expr.left)) {
                    context.report({
                        node,
                        messageId: "replaced",
                        fix(fixer) {
                            if (canBeFixed(left)) {
                                const equalsToken = getOperatorToken(node);
                                const operatorToken = getOperatorToken(expr);
                                const leftText = sourceCode.getText().slice(node.range[0], equalsToken.range[0]);
                                const rightText = sourceCode.getText().slice(operatorToken.range[1], node.right.range[1]);

                                return fixer.replaceText(node, `${leftText}${expr.operator}=${rightText}`);
                            }
                            return null;
                        }
                    });
                } else if (same(left, expr.right) && isCommutativeOperatorWithShorthand(operator)) {

                    /*
                     * This case can't be fixed safely.
                     * If `a` and `b` both have custom valueOf() behavior, then fixing `a = b * a` to `a *= b` would
                     * change the execution order of the valueOf() functions.
                     */
                    context.report({
                        node,
                        messageId: "replaced"
                    });
                }
            }
        }
1234659
def analyze_document(doc)
     # Add a namespace declaration for XPath expressions
     doc.root.namespaces.default_prefix = 'db'
     # Analyze the document starting with the root node
     doc_maps = check_node(doc.root,0,[])
     @sections = []
     section_name = doc_maps[0][:title]
     section_type = doc_maps[0][:name]
     section_ctr = 0
     section_level = 0
     max_section_level = 0
     doc_ctr = 0
     xms = doc_maps.drop(1)
     # Compute word counts per section
     xms.each do |m|
       if (m[:type] == :para)
         doc_ctr += m[:words]
         section_ctr += m[:words]
       else
         @sections << {:title => section_name, :words => section_ctr, :level => section_level, :tag => section_type}
         section_name = m[:title]
         section_ctr = 0
         section_level = m[:level]
         max_section_level = m[:level] if (m[:level] > max_section_level)
         section_type = m[:name]
       end
     end
     @sections << {:title => section_name, :words => section_ctr, :level => section_level, :tag => section_type}
     # OPTIMIZE Not nice, but works
     @sections = sum_sections(@sections,max_section_level).map {|s|
       s[:words] = s[:words]+s[:swords];
       s.delete(:swords)
       s
     }
     @sections
   end
851662
function check(node) {
            if (TARGET_NODE_TYPE.test(node.parent.type) &&
                isMixedWithParent(node) &&
                !shouldIgnore(node)
            ) {
                reportBothOperators(node);
            }
        }
403824
def detect_deprecated_references_in_node(self, node):
        
        # Define our results list
        results = []

        # If this node has an expression, we check the underlying expression.
        if node.expression:
            results += self.detect_deprecation_in_expression(node.expression)

        # Check if there is usage of any deprecated solidity variables or functions
        for dep_node in self.DEPRECATED_NODE_TYPES:
            if node.type == dep_node[0]:
                results.append(dep_node)

        return results
1197414
def find_comprehension_as_statement(node):
    """"""
    return (
        isinstance(node, ast.Expr)
        and isinstance(node.value, (ast.ListComp,
                                    ast.DictComp,
                                    ast.SetComp))
    )
1107406
function verify(node) {
            const parentType = node.parent.type;
            const validParent =
                astUtils.STATEMENT_LIST_PARENTS.has(parentType) ||
                parentType === "SwitchStatement";

            if (!validParent) {
                return;
            }

            // Save this node as the current previous statement.
            const prevNode = scopeInfo.prevNode;

            // Verify.
            if (prevNode) {
                const type = getPaddingType(prevNode, node);
                const paddingLines = getPaddingLineSequences(prevNode, node);

                type.verify(context, prevNode, node, paddingLines);
            }

            scopeInfo.prevNode = node;
        }
1068780
def get_matches_lineno(code, fn_name):
    ""
    class Walker(ast.NodeVisitor):
        def __init__(self):
            self._hits = set()

        #pylint: disable=E0213,E1102    
        def onvisit(fn):
            def wrap(self, node):
                fn(self,node)
                super(Walker, self).generic_visit(node)
            return wrap
        
        @onvisit
        def visit_FunctionDef(self, node):
            if node.name == fn_name:
                self._hits.add(node)
            return node
        
        @property
        def hits(self):
            return list(sorted([n.lineno + 1 for n in self._hits]))
    
    walker = Walker()
    walker.visit(ast.parse(code))
    return walker.hits