<commit_before>package edu.umd.cs.findbugs.detect;


import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.Method;

import edu.umd.cs.findbugs.BugAccumulator;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
import edu.umd.cs.findbugs.SourceLineAnnotation;
import edu.umd.cs.findbugs.SystemProperties;

public class IDivResultCastToDouble extends BytecodeScanningDetector {
	private static final boolean DEBUG = SystemProperties.getBoolean("idcd.debug");

	private final BugReporter bugReporter;
	private final BugAccumulator bugAccumulator;
	private int prevOpCode;

	public IDivResultCastToDouble(BugReporter bugReporter) {
		this.bugReporter = bugReporter;
		this.bugAccumulator = new BugAccumulator(bugReporter);
	}


	@Override
		 public void visit(Method obj) {
		if (DEBUG) System.out.println("Visiting " + obj);
	}

	@Override
	public void visit(Code obj) {
		super.visit(obj);
		bugAccumulator.reportAccumulatedBugs();
	}
	SourceLineAnnotation pendingIdivCastToDivBugLocation = null;
	@Override
		 public void sawOpcode(int seen) {

		if (DEBUG) System.out.println("Saw opcode " + OPCODE_NAMES[seen] + " " + pendingIdivCastToDivBugLocation);



		if ((prevOpCode  == I2D || prevOpCode == L2D)
						&& seen == INVOKESTATIC
								&& getClassConstantOperand().equals("java/lang/Math")
								&& getNameConstantOperand().equals("ceil")) {
			bugAccumulator.accumulateBug(new BugInstance(this, 
				"ICAST_INT_CAST_TO_DOUBLE_PASSED_TO_CEIL", 
				HIGH_PRIORITY)
					.addClassAndMethod(this), this);
			pendingIdivCastToDivBugLocation = null;
		}
		else if ((prevOpCode  == I2F || prevOpCode == L2F)
				&& seen == INVOKESTATIC
						&& getClassConstantOperand().equals("java/lang/Math")
						&& getNameConstantOperand().equals("round")) {
			bugAccumulator.accumulateBug(new BugInstance(this, 
					"ICAST_INT_CAST_TO_FLOAT_PASSED_TO_ROUND", 
					HIGH_PRIORITY)
			.addClassAndMethod(this), this);
			pendingIdivCastToDivBugLocation = null;
		}
		else if (pendingIdivCastToDivBugLocation != null) {
			bugAccumulator.accumulateBug(
					new BugInstance(this, "ICAST_IDIV_CAST_TO_DOUBLE", NORMAL_PRIORITY)
						.addClassAndMethod(this), 
				pendingIdivCastToDivBugLocation);
			pendingIdivCastToDivBugLocation = null;
		}

		if (prevOpCode  == IDIV && (seen == I2D|| seen == I2F)
			|| prevOpCode  == LDIV && (seen == L2D || seen==L2F))
			pendingIdivCastToDivBugLocation = SourceLineAnnotation.fromVisitedInstruction(this);
		prevOpCode = seen;
		}
}<commit_msg>change priority of ICAST_INT_CAST_TO_FLOAT_PASSED_TO_ROUND to medium<commit_after>package edu.umd.cs.findbugs.detect;


import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.Method;

import edu.umd.cs.findbugs.BugAccumulator;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
import edu.umd.cs.findbugs.SourceLineAnnotation;
import edu.umd.cs.findbugs.SystemProperties;

public class IDivResultCastToDouble extends BytecodeScanningDetector {
	private static final boolean DEBUG = SystemProperties.getBoolean("idcd.debug");

	private final BugReporter bugReporter;
	private final BugAccumulator bugAccumulator;
	private int prevOpCode;

	public IDivResultCastToDouble(BugReporter bugReporter) {
		this.bugReporter = bugReporter;
		this.bugAccumulator = new BugAccumulator(bugReporter);
	}


	@Override
		 public void visit(Method obj) {
		if (DEBUG) System.out.println("Visiting " + obj);
	}

	@Override
	public void visit(Code obj) {
		super.visit(obj);
		bugAccumulator.reportAccumulatedBugs();
	}
	SourceLineAnnotation pendingIdivCastToDivBugLocation = null;
	@Override
		 public void sawOpcode(int seen) {

		if (DEBUG) System.out.println("Saw opcode " + OPCODE_NAMES[seen] + " " + pendingIdivCastToDivBugLocation);



		if ((prevOpCode  == I2D || prevOpCode == L2D)
						&& seen == INVOKESTATIC
								&& getClassConstantOperand().equals("java/lang/Math")
								&& getNameConstantOperand().equals("ceil")) {
			bugAccumulator.accumulateBug(new BugInstance(this, 
				"ICAST_INT_CAST_TO_DOUBLE_PASSED_TO_CEIL", 
				HIGH_PRIORITY)
					.addClassAndMethod(this), this);
			pendingIdivCastToDivBugLocation = null;
		}
		else if ((prevOpCode  == I2F || prevOpCode == L2F)
				&& seen == INVOKESTATIC
						&& getClassConstantOperand().equals("java/lang/Math")
						&& getNameConstantOperand().equals("round")) {
			bugAccumulator.accumulateBug(new BugInstance(this, 
					"ICAST_INT_CAST_TO_FLOAT_PASSED_TO_ROUND", 
					NORMAL_PRIORITY)
			.addClassAndMethod(this), this);
			pendingIdivCastToDivBugLocation = null;
		}
		else if (pendingIdivCastToDivBugLocation != null) {
			bugAccumulator.accumulateBug(
					new BugInstance(this, "ICAST_IDIV_CAST_TO_DOUBLE", NORMAL_PRIORITY)
						.addClassAndMethod(this), 
				pendingIdivCastToDivBugLocation);
			pendingIdivCastToDivBugLocation = null;
		}

		if (prevOpCode  == IDIV && (seen == I2D|| seen == I2F)
			|| prevOpCode  == LDIV && (seen == L2D || seen==L2F))
			pendingIdivCastToDivBugLocation = SourceLineAnnotation.fromVisitedInstruction(this);
		prevOpCode = seen;
		}
}
{'fraction_non_alphanumeric': 0.10938399539435809, 'fraction_numerical': 0.003070427940894262, 'mean_word_length': 4.963386727688787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6745386', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1783, 'n_words': 289}