[completion] IJPL-207762 TailType nullability

GitOrigin-RevId: 73a919ee73797ac4aa114421f719d78718bd098b
This commit is contained in:
Max Medvedev
2025-10-12 11:39:37 +00:00
committed by intellij-monorepo-bot
parent 6ef13aa11e
commit ffac8155cf
13 changed files with 43 additions and 50 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.codeInsight;
import com.intellij.codeInsight.completion.*;
@@ -1612,7 +1612,7 @@ public final class ExpectedTypesProvider {
}
@Override
public int processTail(Editor editor, int tailOffset) {
public int processTail(@NotNull Editor editor, int tailOffset) {
int result = CommaTailType.INSTANCE.processTail(editor, tailOffset);
if (myOriginalCall.isValid()) {
PsiDocumentManager.getInstance(myOriginalCall.getProject()).commitDocument(editor.getDocument());
@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// 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.codeInsight;
import com.intellij.codeInsight.completion.InsertionContext;
@@ -50,7 +50,7 @@ public final class JavaTailTypes {
}
@Override
public int processTail(final Editor editor, int tailOffset) {
public int processTail(final @NotNull Editor editor, int tailOffset) {
return insertChar(editor, super.processTail(editor, tailOffset), ';');
}
};
@@ -124,7 +124,7 @@ public final class JavaTailTypes {
private static final String ARROW = " -> ";
public static final TailType CASE_ARROW = new TailType() {
@Override
public int processTail(Editor editor, int tailOffset) {
public int processTail(@NotNull Editor editor, int tailOffset) {
Document document = editor.getDocument();
document.insertString(tailOffset, ARROW);
return moveCaret(editor, tailOffset, ARROW.length());
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// 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.codeInsight.completion.simple;
@@ -28,11 +14,12 @@ import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.NotNull;
public class BracesTailType extends TailType {
@Override
public int processTail(final Editor editor, int tailOffset) {
public int processTail(final @NotNull Editor editor, int tailOffset) {
int startOffset = tailOffset;
CharSequence seq = editor.getDocument().getCharsSequence();
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// 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.codeInsight.completion.simple;
@@ -8,6 +8,7 @@ import com.intellij.codeInsight.editorActions.TabOutScopesTracker;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import org.jetbrains.annotations.NotNull;
public abstract class ParenthesesTailType extends TailType {
@@ -16,7 +17,7 @@ public abstract class ParenthesesTailType extends TailType {
protected abstract boolean isSpaceWithinParentheses(CommonCodeStyleSettings styleSettings, Editor editor, final int tailOffset);
@Override
public int processTail(final Editor editor, int tailOffset) {
public int processTail(final @NotNull Editor editor, int tailOffset) {
CommonCodeStyleSettings styleSettings = CodeStyle.getLocalLanguageSettings(editor, tailOffset);
if (isSpaceBeforeParentheses(styleSettings, editor, tailOffset)) {
tailOffset = insertChar(editor, tailOffset, ' ');
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.codeInsight.completion.simple;
import com.intellij.application.options.CodeStyle;
@@ -16,6 +16,7 @@ import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.java.IJavaElementType;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
public abstract class RParenthTailType extends TailType {
private static final Logger LOG = Logger.getInstance(RParenthTailType.class);
@@ -35,7 +36,7 @@ public abstract class RParenthTailType extends TailType {
protected abstract boolean isSpaceWithinParentheses(CommonCodeStyleSettings styleSettings, Editor editor, final int tailOffset);
@Override
public int processTail(final Editor editor, int tailOffset) {
public int processTail(final @NotNull Editor editor, int tailOffset) {
return addRParenth(editor, tailOffset,
isSpaceWithinParentheses(CodeStyle.getLocalLanguageSettings(editor, tailOffset), editor, tailOffset));
}
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.codeInsight;
import com.intellij.codeInsight.completion.InsertionContext;
@@ -29,7 +29,7 @@ public class CharTailType extends TailType {
}
@Override
public int processTail(final Editor editor, final int tailOffset) {
public int processTail(final @NotNull Editor editor, final int tailOffset) {
return insertChar(editor, tailOffset, myChar, myOverwrite);
}
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.codeInsight;
import com.intellij.codeInsight.completion.InsertionContext;
@@ -29,17 +29,17 @@ import org.jetbrains.annotations.NotNull;
* {@link TailTypes} must be used.
*/
public abstract class TailType {
public abstract int processTail(final Editor editor, int tailOffset);
public abstract int processTail(@NotNull Editor editor, int tailOffset);
public boolean isApplicable(final @NotNull InsertionContext context) {
public boolean isApplicable(@NotNull InsertionContext context) {
return true;
}
public static int insertChar(final Editor editor, final int tailOffset, final char c) {
public static int insertChar(@NotNull Editor editor, int tailOffset, char c) {
return insertChar(editor, tailOffset, c, true);
}
public static int insertChar(Editor editor, int tailOffset, char c, boolean overwrite) {
public static int insertChar(@NotNull Editor editor, int tailOffset, char c, boolean overwrite) {
Document document = editor.getDocument();
int textLength = document.getTextLength();
CharSequence chars = document.getCharsSequence();
@@ -49,12 +49,12 @@ public abstract class TailType {
return moveCaret(editor, tailOffset, 1);
}
public static TailType createSimpleTailType(final char c) {
public static @NotNull TailType createSimpleTailType(char c) {
return new CharTailType(c);
}
protected static int moveCaret(final Editor editor, final int tailOffset, final int delta) {
final CaretModel model = editor.getCaretModel();
protected static int moveCaret(@NotNull Editor editor, int tailOffset, int delta) {
CaretModel model = editor.getCaretModel();
if (model.getOffset() == tailOffset) {
model.moveToOffset(tailOffset + delta);
}
@@ -79,7 +79,7 @@ public abstract class TailType {
@Deprecated(forRemoval = true)
public static final TailType NONE = new TailType() {
@Override
public int processTail(final Editor editor, final int tailOffset) {
public int processTail(@NotNull Editor editor, int tailOffset) {
return tailOffset;
}
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.codeInsight;
import com.intellij.codeInsight.completion.InsertionContext;
@@ -12,7 +12,7 @@ public final class TailTypes {
private static final TailType UNKNOWN = new TailType() {
@Override
public int processTail(final Editor editor, final int tailOffset) {
public int processTail(final @NotNull Editor editor, final int tailOffset) {
return tailOffset;
}
@@ -24,7 +24,7 @@ public final class TailTypes {
private static final TailType NONE = new TailType() {
@Override
public int processTail(final Editor editor, final int tailOffset) {
public int processTail(final @NotNull Editor editor, final int tailOffset) {
return tailOffset;
}
@@ -68,7 +68,7 @@ public final class TailTypes {
private static final TailType COND_EXPR_COLON = new TailType() {
@Override
public int processTail(final Editor editor, final int tailOffset) {
public int processTail(final @NotNull Editor editor, final int tailOffset) {
Document document = editor.getDocument();
int textLength = document.getTextLength();
CharSequence chars = document.getCharsSequence();
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.codeInsight.lookup;
import com.intellij.codeInsight.TailType;
@@ -11,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
* Consider using {@link com.intellij.codeInsight.completion.InsertHandler} instead
*/
public abstract class TailTypeDecorator<T extends LookupElement> extends LookupElementDecorator<T> {
public TailTypeDecorator(T delegate) {
public TailTypeDecorator(@NotNull T delegate) {
super(delegate);
}
@@ -40,5 +40,4 @@ public abstract class TailTypeDecorator<T extends LookupElement> extends LookupE
tailType.processTail(context.getEditor(), tailOffset);
}
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// 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.codeInsight.lookup;
import com.intellij.application.options.CodeStyle;
@@ -9,12 +9,13 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettingsFacade;
import com.intellij.psi.util.PsiEditorUtil;
import com.intellij.psi.util.PsiUtilCore;
import org.jetbrains.annotations.NotNull;
public class CommaTailType extends TailType {
public static final TailType INSTANCE = new CommaTailType();
@Override
public int processTail(final Editor editor, int tailOffset) {
public int processTail(final @NotNull Editor editor, int tailOffset) {
PsiFile psiFile = PsiEditorUtil.getPsiFile(editor);
Language language = PsiUtilCore.getLanguageAtOffset(PsiEditorUtil.getPsiFile(editor), tailOffset);
CodeStyleSettingsFacade codeStyleFacade = CodeStyle.getFacade(psiFile).withLanguage(language);
@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// 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.codeInsight.lookup;
import com.intellij.application.options.CodeStyle;
@@ -10,6 +10,7 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettingsFacade;
import com.intellij.psi.util.PsiEditorUtil;
import com.intellij.psi.util.PsiUtilCore;
import org.jetbrains.annotations.NotNull;
public class EqTailType extends TailType {
public static final TailType INSTANCE = new EqTailType();
@@ -22,7 +23,7 @@ public class EqTailType extends TailType {
}
@Override
public int processTail(final Editor editor, int tailOffset) {
public int processTail(final @NotNull Editor editor, int tailOffset) {
Document document = editor.getDocument();
int textLength = document.getTextLength();
CharSequence chars = document.getCharsSequence();
@@ -1,15 +1,16 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.codeInsight;
import com.intellij.openapi.editor.Editor;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
public final class TailTypeEx {
public static final TailType SMART_LPARENTH = new TailType() {
@Override
public int processTail(final Editor editor, int tailOffset) {
public int processTail(final @NotNull Editor editor, int tailOffset) {
tailOffset = insertChar(editor, tailOffset, '(');
return moveCaret(editor, insertChar(editor, tailOffset, ')'), -1);
}
@@ -1,3 +1,4 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.groovy.util;
import com.intellij.application.options.CodeStyle;
@@ -5,6 +6,7 @@ import com.intellij.codeInsight.TailType;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import org.jetbrains.annotations.NotNull;
public class FieldInitializerTailTypes extends TailType {
@@ -22,7 +24,7 @@ public class FieldInitializerTailTypes extends TailType {
}
@Override
public int processTail(Editor editor, int tailOffset) {
public int processTail(@NotNull Editor editor, int tailOffset) {
CommonCodeStyleSettings styleSettings = CodeStyle.getLocalLanguageSettings(editor, tailOffset);
Document document = editor.getDocument();
CharSequence chars = document.getCharsSequence();