IDEA-359853 introduce JavaBinaryOperations

GitOrigin-RevId: 8c4cd1a8fb76a7c79bce882a669af0a057045ab0
This commit is contained in:
Max Medvedev
2025-04-01 00:38:44 +00:00
committed by intellij-monorepo-bot
parent 33f7af38d9
commit c4d2a83d30
13 changed files with 56 additions and 29 deletions
@@ -0,0 +1,17 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.lang.java.parser
import com.intellij.java.frontback.psi.impl.syntax.BasicJavaElementTypeConverter
import com.intellij.java.syntax.parser.ExpressionParser
import com.intellij.platform.syntax.psi.asTokenSet
import com.intellij.psi.tree.TokenSet
import org.jetbrains.annotations.ApiStatus
@ApiStatus.Internal
object JavaBinaryOperations {
// todo replace BasicJavaElementTypeConverter with another Converter when parsers are merged
@JvmField val ASSIGNMENT_OPS: TokenSet = ExpressionParser.ASSIGNMENT_OPS.asTokenSet(BasicJavaElementTypeConverter)
@JvmField val SHIFT_OPS: TokenSet = ExpressionParser.SHIFT_OPS.asTokenSet(BasicJavaElementTypeConverter)
@JvmField val ADDITIVE_OPS: TokenSet = ExpressionParser.ADDITIVE_OPS.asTokenSet(BasicJavaElementTypeConverter)
@JvmField val MULTIPLICATIVE_OPS: TokenSet = ExpressionParser.MULTIPLICATIVE_OPS.asTokenSet(BasicJavaElementTypeConverter)
}
@@ -3,7 +3,7 @@ package com.intellij.psi.impl.source;
import com.intellij.lang.ASTNode;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.lang.java.parser.BasicExpressionParser;
import com.intellij.lang.java.parser.JavaBinaryOperations;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.tree.TreeUtil;
@@ -19,6 +19,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@@ -143,6 +144,10 @@ public final class BasicJavaAstTreeUtil {
return findChildByType(astNode, ParentAwareTokenSet.create(targets));
}
public static @Nullable ASTNode findChildByType(@Nullable ASTNode astNode, Collection<IElementType> targets) {
return findChildByType(astNode, ParentAwareTokenSet.create(targets));
}
public static @Nullable ASTNode findChildByType(@Nullable ASTNode astNode, ParentAwareTokenSet targets) {
if (astNode == null) {
return null;
@@ -668,7 +673,7 @@ public final class BasicJavaAstTreeUtil {
if (expr == null) {
return null;
}
ASTNode ASTNode = findChildByType(expr, BasicExpressionParser.ASSIGNMENT_OPS.getTypes());
ASTNode ASTNode = findChildByType(expr, JavaBinaryOperations.ASSIGNMENT_OPS.getTypes());
if (ASTNode == null) {
return null;
}