<commit_before>package de.endrullis.idea.postfixtemplates.templates;

import com.intellij.openapi.util.Condition;
import com.intellij.psi.*;
import com.intellij.psi.util.InheritanceUtil;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * Some static additions to {@link com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils}.
 *
 * @author <NAME> &lt;<EMAIL>&gt;
 */
public abstract class MyJavaPostfixTemplatesUtils {

	private MyJavaPostfixTemplatesUtils() {
	}

	@NotNull
	public static Condition<PsiElement> isCustomClass(String clazz) {
		return element -> element instanceof PsiExpression && isCustomClass(((PsiExpression) element).getType(), clazz);
	}

	public static final Condition<PsiElement> IS_DECIMAL_NUMBER =
		element -> element instanceof PsiExpression && isDecimalNumber(((PsiExpression) element).getType());

	public static final Condition<PsiElement> IS_VOID =
		element -> element instanceof PsiExpression && isVoid(((PsiExpression) element).getType());

	public static final Condition<PsiElement> IS_ANY =
		element -> element instanceof PsiExpression;

	public static final Condition<PsiElement> IS_FIELD =
		element -> element instanceof PsiField;

	public static final Condition<PsiElement> IS_CLASS =
		element -> element instanceof PsiReferenceExpression &&
			((PsiReferenceExpression) element).advancedResolve(true).getElement() instanceof PsiClass;

	public static final Condition<PsiElement> IS_LOCAL_VARIABLE =
		element -> element instanceof PsiLocalVariable;

	public static final Condition<PsiElement> IS_VARIABLE =
		element -> element instanceof PsiField || element instanceof PsiLocalVariable;

	public static final Condition<PsiElement> IS_ASSIGNMENT =
		element -> element instanceof PsiField || element instanceof PsiAssignmentExpression;

	public static Condition<PsiElement> isCertainNumberType(@NotNull PsiType expectedType) {
		return element -> element instanceof PsiExpression && isCertainDecimalNumberType(((PsiExpression) element).getType(), expectedType);
	}

	/**
	 * Contains byte, short, char, int, long, float, and double.
	 */
	public static final Set<PsiType> NUMERIC_TYPES = new HashSet<>(Arrays.asList(
		PsiType.BYTE, PsiType.SHORT, PsiType.CHAR, PsiType.INT, PsiType.LONG, PsiType.FLOAT, PsiType.DOUBLE)
	);<commit_msg>ANY shouldn't be restricted to an expression<commit_after>package de.endrullis.idea.postfixtemplates.templates;

import com.intellij.openapi.util.Condition;
import com.intellij.psi.*;
import com.intellij.psi.util.InheritanceUtil;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * Some static additions to {@link com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils}.
 *
 * @author <NAME> &lt;<EMAIL>&gt;
 */
public abstract class MyJavaPostfixTemplatesUtils {

	private MyJavaPostfixTemplatesUtils() {
	}

	@NotNull
	public static Condition<PsiElement> isCustomClass(String clazz) {
		return element -> element instanceof PsiExpression && isCustomClass(((PsiExpression) element).getType(), clazz);
	}

	public static final Condition<PsiElement> IS_DECIMAL_NUMBER =
		element -> element instanceof PsiExpression && isDecimalNumber(((PsiExpression) element).getType());

	public static final Condition<PsiElement> IS_VOID =
		element -> element instanceof PsiExpression && isVoid(((PsiExpression) element).getType());

	public static final Condition<PsiElement> IS_ANY =
		element -> true;

	public static final Condition<PsiElement> IS_FIELD =
		element -> element instanceof PsiField;

	public static final Condition<PsiElement> IS_CLASS =
		element -> element instanceof PsiReferenceExpression &&
			((PsiReferenceExpression) element).advancedResolve(true).getElement() instanceof PsiClass;

	public static final Condition<PsiElement> IS_LOCAL_VARIABLE =
		element -> element instanceof PsiLocalVariable;

	public static final Condition<PsiElement> IS_VARIABLE =
		element -> element instanceof PsiField || element instanceof PsiLocalVariable;

	public static final Condition<PsiElement> IS_ASSIGNMENT =
		element -> element instanceof PsiField || element instanceof PsiAssignmentExpression;

	public static Condition<PsiElement> isCertainNumberType(@NotNull PsiType expectedType) {
		return element -> element instanceof PsiExpression && isCertainDecimalNumberType(((PsiExpression) element).getType(), expectedType);
	}

	/**
	 * Contains byte, short, char, int, long, float, and double.
	 */
	public static final Set<PsiType> NUMERIC_TYPES = new HashSet<>(Arrays.asList(
		PsiType.BYTE, PsiType.SHORT, PsiType.CHAR, PsiType.INT, PsiType.LONG, PsiType.FLOAT, PsiType.DOUBLE)
	);
{'fraction_non_alphanumeric': 0.09904413260117959, 'fraction_numerical': 0.0, 'mean_word_length': 6.076258992805755, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 51, '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': '1092696', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1371, 'n_words': 348}