<commit_before>package jadx.gui.utils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jadx.api.CodePosition;
import jadx.api.JavaClass;
import jadx.api.JavaNode;
import jadx.gui.treemodel.CodeNode;
import jadx.gui.treemodel.JNode;
import jadx.gui.utils.search.StringRef;

public class CodeUsageInfo {
	private static final Logger LOG = LoggerFactory.getLogger(CodeUsageInfo.class);

	public static class UsageInfo {
		private final List<CodeNode> usageList = new ArrayList<>();

		public List<CodeNode> getUsageList() {
			return usageList;
		}

		public synchronized void addUsage(CodeNode codeNode) {
			usageList.add(codeNode);
		}

		public synchronized void removeUsageIf(Predicate<? super CodeNode> filter) {
			usageList.removeIf(filter);
		}
	}

	private final JNodeCache nodeCache;

	public CodeUsageInfo(JNodeCache nodeCache) {
		this.nodeCache = nodeCache;
	}

	private final Map<JNode, UsageInfo> usageMap = new ConcurrentHashMap<>();

	public void processClass(JavaClass javaClass, CodeLinesInfo linesInfo, List<StringRef> lines) {
		try {
			Map<CodePosition, JavaNode> usage = javaClass.getUsageMap();
			for (Map.Entry<CodePosition, JavaNode> entry : usage.entrySet()) {
				CodePosition codePosition = entry.getKey();
				JavaNode javaNode = entry.getValue();
				addUsage(nodeCache.makeFrom(javaNode), javaClass, linesInfo, codePosition, lines);
			}<commit_msg>fix(gui): exclude declaration from usage list (#1110)<commit_after>package jadx.gui.utils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jadx.api.CodePosition;
import jadx.api.JavaClass;
import jadx.api.JavaNode;
import jadx.gui.treemodel.CodeNode;
import jadx.gui.treemodel.JNode;
import jadx.gui.utils.search.StringRef;

public class CodeUsageInfo {
	private static final Logger LOG = LoggerFactory.getLogger(CodeUsageInfo.class);

	public static class UsageInfo {
		private final List<CodeNode> usageList = new ArrayList<>();

		public List<CodeNode> getUsageList() {
			return usageList;
		}

		public synchronized void addUsage(CodeNode codeNode) {
			usageList.add(codeNode);
		}

		public synchronized void removeUsageIf(Predicate<? super CodeNode> filter) {
			usageList.removeIf(filter);
		}
	}

	private final JNodeCache nodeCache;

	public CodeUsageInfo(JNodeCache nodeCache) {
		this.nodeCache = nodeCache;
	}

	private final Map<JNode, UsageInfo> usageMap = new ConcurrentHashMap<>();

	public void processClass(JavaClass javaClass, CodeLinesInfo linesInfo, List<StringRef> lines) {
		try {
			Map<CodePosition, JavaNode> usage = javaClass.getUsageMap();
			for (Map.Entry<CodePosition, JavaNode> entry : usage.entrySet()) {
				CodePosition codePosition = entry.getKey();
				JavaNode javaNode = entry.getValue();
				if (javaNode.getTopParentClass().equals(javaClass)
						&& codePosition.getPos() == javaNode.getDefPos()) {
					// skip declaration
					continue;
				}
				addUsage(nodeCache.makeFrom(javaNode), javaClass, linesInfo, codePosition, lines);
			}
{'fraction_non_alphanumeric': 0.10465461013934184, 'fraction_numerical': 0.0023717758671805513, 'mean_word_length': 5.145719489981785, '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': '5625467', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1041, 'n_words': 239}