[java] IDEA-365317 delete BasicJavaAstTreeUtil.java

GitOrigin-RevId: 43bab264eeba7c3145946e2c814cdaa7c1a78650
This commit is contained in:
Mikhail Pyltsin
2025-11-20 12:44:52 +00:00
committed by intellij-monorepo-bot
parent 9c48ef111a
commit 96c069a043
8 changed files with 25 additions and 112 deletions
@@ -1,84 +0,0 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.source;
import com.intellij.lang.ASTNode;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentAwareTokenSet;
import com.intellij.psi.tree.ParentProviderElementType;
import com.intellij.psi.tree.TokenSet;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
public final class BasicJavaAstTreeUtil {
private BasicJavaAstTreeUtil() { }
@Contract("null ,_ -> false")
public static boolean is(@Nullable ASTNode element, @Nullable IElementType iElementType) {
boolean notNull = element != null && iElementType != null;
if (!notNull) {
return false;
}
IElementType sourceElementType = element.getElementType();
return is(sourceElementType, iElementType);
}
public static boolean is(@NotNull IElementType source, @NotNull IElementType target) {
if (source == target) {
return true;
}
if (source instanceof ParentProviderElementType) {
Set<IElementType> parents = ((ParentProviderElementType)source).getParents();
return ContainerUtil.exists(parents, parent -> parent != null && is(parent, target));
}
return false;
}
@Contract("null ,_ -> false")
public static boolean is(@Nullable ASTNode element, @NotNull Set<IElementType> iElementTypes) {
boolean isNotNull = element != null;
if (!isNotNull) {
return false;
}
return is(element.getElementType(), iElementTypes);
}
//needs for FrontBackJavaTokenSet
public static boolean is(@Nullable ASTNode element, @NotNull TokenSet tokenSet) {
boolean isNotNull = element != null;
if (!isNotNull) {
return false;
}
return ParentProviderElementType.containsWithSourceParent(element.getElementType(), tokenSet);
}
public static boolean is(@Nullable ASTNode element, @NotNull ParentAwareTokenSet tokenSet) {
boolean isNotNull = element != null;
if (!isNotNull) {
return false;
}
return is(element.getElementType(), tokenSet);
}
private static boolean is(@NotNull IElementType source, @NotNull ParentAwareTokenSet tokenSet) {
//not call iteratively!
if (tokenSet.contains(source)) {
return true;
}
return false;
}
private static boolean is(@NotNull IElementType source, @NotNull Set<IElementType> tokenSet) {
if (tokenSet.contains(source)) {
return true;
}
if (source instanceof ParentProviderElementType) {
Set<IElementType> parents = ((ParentProviderElementType)source).getParents();
return ContainerUtil.exists(parents, parent -> parent != null && is(parent, tokenSet));
}
return false;
}
}
@@ -20,8 +20,8 @@ import static com.intellij.psi.tree.ParentAwareTokenSet.orSet;
/**
* @deprecated Use the new Java syntax library instead.
* See {@link com.intellij.java.syntax.parser.JavaParser}
* @deprecated Use the new Java syntax library instead.
* See {@link com.intellij.java.syntax.parser.JavaParser}
* You can temporarily use @{@link com.intellij.psi.impl.source.OldParserWhiteSpaceAndCommentSetHolder}
*
*/
@@ -94,20 +94,20 @@ public class WhiteSpaceAndCommentSetHolder {
if (mySupportMarkdown) {
//collect everything
for (int idx = tokens.size() - 1; idx >= 0; idx--) {
if (BasicJavaAstTreeUtil.is(tokens.get(idx), BASIC_DOC_COMMENT)) return idx;
if (tokens.get(idx) == BASIC_DOC_COMMENT) return idx;
}
}
else {
// To preserve previous orders, let's try to find the first non-markdown comment (and skip markdown comments).
// If there is no non-markdown, take the first markdown
for (int idx = tokens.size() - 1; idx >= 0; idx--) {
if (BasicJavaAstTreeUtil.is(tokens.get(idx), BASIC_DOC_COMMENT) && !isDocMarkdownComment(idx, getter)) {
if (tokens.get(idx) == BASIC_DOC_COMMENT && !isDocMarkdownComment(idx, getter)) {
return idx;
}
}
for (int idx = tokens.size() - 1; idx >= 0; idx--) {
if (BasicJavaAstTreeUtil.is(tokens.get(idx), BASIC_DOC_COMMENT)) return idx;
if (tokens.get(idx) == BASIC_DOC_COMMENT) return idx;
}
}