<commit_before>/*
 * fb-contrib - Auxiliary detectors for Java programs
 * Copyright (C) 2005-2013 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package com.mebigfatguy.fbcontrib.detect;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.CodeException;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.generic.Type;

import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
import com.mebigfatguy.fbcontrib.utils.TernaryPatcher;

import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
import edu.umd.cs.findbugs.OpcodeStack;
import edu.umd.cs.findbugs.ba.ClassContext;
import edu.umd.cs.findbugs.ba.XField;

/**
 * looks for variable assignments at a scope larger than its use. In this case,
 * the assignment can be pushed down into the smaller scope to reduce the
 * performance impact of that assignment.
 */
public class BloatedAssignmentScope extends BytecodeScanningDetector {
	private static final Set<String> dangerousAssignmentClassSources = new HashSet<String>(7);
	private static final Set<String> dangerousAssignmentMethodSources = new HashSet<String>(4);

	static {
        dangerousAssignmentClassSources.add("java/io/BufferedInputStream");
        dangerousAssignmentClassSources.add("java/io/DataInputStream");
        dangerousAssignmentClassSources.add("java/io/InputStream");
        dangerousAssignmentClassSources.add("java/io/ObjectInputStream");
        dangerousAssignmentClassSources.add("java/io/BufferedReader");
        dangerousAssignmentClassSources.add("java/io/FileReader");
        dangerousAssignmentClassSources.add("java/io/Reader");
        dangerousAssignmentMethodSources.add("java/lang/System.currentTimeMillis()J");
        dangerousAssignmentMethodSources.add("java/lang/System.nanoTime()J");
        dangerousAssignmentMethodSources.add("java/util/Iterator.next()Ljava/lang/Object;");
        dangerousAssignmentMethodSources.add("java/util/regex/Matcher.start()I");
	}

	BugReporter bugReporter;
	private OpcodeStack stack;
	private Set<Integer> ignoreRegs;
	private ScopeBlock rootScopeBlock;
	private Set<Integer> catchHandlers;
	private Set<Integer> switchTargets;
	private List<Integer> monitorSyncPCs;
	private boolean dontReport;
	private boolean sawDup;
	private boolean sawNull;

	/**
	 * constructs a BAS detector given the reporter to report bugs on
	 *
	 * @param bugReporter
	 *            the sync of bug reports
	 */
	public BloatedAssignmentScope(BugReporter bugReporter) {
		this.bugReporter = bugReporter;
	}

	/**
	 * implements the visitor to create and the clear the register to location<commit_msg>add Calendar.get(int), GregorianCalendar.get(int) to dangerousmethod of BAS<commit_after>/*
 * fb-contrib - Auxiliary detectors for Java programs
 * Copyright (C) 2005-2013 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package com.mebigfatguy.fbcontrib.detect;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.CodeException;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.generic.Type;

import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
import com.mebigfatguy.fbcontrib.utils.TernaryPatcher;

import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
import edu.umd.cs.findbugs.OpcodeStack;
import edu.umd.cs.findbugs.ba.ClassContext;
import edu.umd.cs.findbugs.ba.XField;

/**
 * looks for variable assignments at a scope larger than its use. In this case,
 * the assignment can be pushed down into the smaller scope to reduce the
 * performance impact of that assignment.
 */
public class BloatedAssignmentScope extends BytecodeScanningDetector {
	private static final Set<String> dangerousAssignmentClassSources = new HashSet<String>(7);
	private static final Set<String> dangerousAssignmentMethodSources = new HashSet<String>(4);

	static {
        dangerousAssignmentClassSources.add("java/io/BufferedInputStream");
        dangerousAssignmentClassSources.add("java/io/DataInputStream");
        dangerousAssignmentClassSources.add("java/io/InputStream");
        dangerousAssignmentClassSources.add("java/io/ObjectInputStream");
        dangerousAssignmentClassSources.add("java/io/BufferedReader");
        dangerousAssignmentClassSources.add("java/io/FileReader");
        dangerousAssignmentClassSources.add("java/io/Reader");
        dangerousAssignmentMethodSources.add("java/lang/System.currentTimeMillis()J");
        dangerousAssignmentMethodSources.add("java/lang/System.nanoTime()J");
        dangerousAssignmentMethodSources.add("java/util/Calendar.get(I)I");
        dangerousAssignmentMethodSources.add("java/util/GregorianCalendar.get(I)I");
        dangerousAssignmentMethodSources.add("java/util/Iterator.next()Ljava/lang/Object;");
        dangerousAssignmentMethodSources.add("java/util/regex/Matcher.start()I");
	}

	BugReporter bugReporter;
	private OpcodeStack stack;
	private Set<Integer> ignoreRegs;
	private ScopeBlock rootScopeBlock;
	private Set<Integer> catchHandlers;
	private Set<Integer> switchTargets;
	private List<Integer> monitorSyncPCs;
	private boolean dontReport;
	private boolean sawDup;
	private boolean sawNull;

	/**
	 * constructs a BAS detector given the reporter to report bugs on
	 *
	 * @param bugReporter
	 *            the sync of bug reports
	 */
	public BloatedAssignmentScope(BugReporter bugReporter) {
		this.bugReporter = bugReporter;
	}

	/**
	 * implements the visitor to create and the clear the register to location
{'fraction_non_alphanumeric': 0.08872836309118168, 'fraction_numerical': 0.007087365408204988, 'mean_word_length': 4.7283372365339575, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6125520', 'n_tokens_mistral': 2104, 'n_tokens_neox': 2067, 'n_words': 595}