TokenSet (@NotNull TokenSet a, @NotNull TokenSet b) { List<IElementType.Predicate> orConditions = new ArrayList<>(); ContainerUtil.addIfNotNull(orConditions, a.myOrCondition); ContainerUtil.addIfNotNull(orConditions, b.myOrCondition); IElementType.Predicate conjunction = orConditions.isEmpty() ? null : orConditions.size() == 1 ? orConditions.get(0) : t -> Objects.requireNonNull(a.myOrCondition).matches(t) && Objects.requireNonNull(b.myOrCondition).matches(t); TokenSet newSet = new TokenSet((short)Math.min(a.myShift, b.myShift), (short)Math.max(a.myMax, b.myMax), conjunction); for (int i = 0; i < newSet.myWords.length; i++) { final int ai = newSet.myShift - a.myShift + i; final int bi = newSet.myShift - b.myShift + i; newSet.myWords[i] = (0 <= ai && ai < a.myWords.length ? a.myWords[ai] : 0L) & (0 <= bi && bi < b.myWords.length ? b.myWords[bi] : 0L); } return newSet; }